API-Octopart
view release on metacpan or search on metacpan
lib/API/Octopart.pm view on Meta::CPAN
$part, %opts: same as has_stock().
Returns the following structure:
{
'Mouser' => {
'moq_price' => '0.2',
'moq' => 1,
'stock' => 24071
},
'Digi-Key' => {
'moq_price' => '0.2',
'moq' => 1,
'stock' => 10000
}
};
=cut
sub get_part_stock
{
my ($self, $part, %opts) = @_;
my $results = $self->get_part_stock_detail($part, %opts);
my %ret;
foreach my $result (@$results)
{
my $sellers = $result->{sellers};
foreach my $s (keys %$sellers)
{
$ret{$s} = $sellers->{$s};
delete $ret{$s}->{price_tier};
}
}
return \%ret;
}
=item * $o->get_part_stock_detail($part, %opts) - Returns a stock detail structure
$part, %opts: same as has_stock().
Returns a structure like this:
[
{
'mfg' => 'Yageo',
'sellers' => {
'Digi-Key' => {
'moq' => 1,
'moq_price' => '0.1',
'price_tier' => {
'1' => '0.1',
'10' => '0.042',
'100' => '0.017',
'1000' => '0.00762',
'2500' => '0.00661',
'5000' => '0.00546'
},
'stock' => 4041192
},
...
},
'specs' => {
'case_package' => '0805',
'composition' => 'Thick Film',
'contactplating' => 'Tin',
'leadfree' => 'Lead Free',
'length' => '2mm',
'numberofpins' => '2',
'radiationhardening' => 'No',
'reachsvhc' => 'No SVHC',
'resistance' =>
"10k\x{ce}\x{a9}", # <- That is an Ohm symbol
'rohs' => 'Compliant',
'tolerance' => '1%',
'voltagerating_dc_' => '150V',
'width' => '1.25mm',
...
}
},
...
]
=cut
sub get_part_stock_detail
{
my ($self, $part, %opts) = @_;
my $p = $self->query_part_detail($part);
return $self->_parse_part_stock($p, %opts);
}
=item * $o->octo_query($q) - Queries the Octopart API
Return the JSON response structure as a perl ARRAY/HASH given a query meeting Octopart's
API specification.
=cut
sub octo_query
{
my ($self, $q) = @_;
my $part = shift;
my ($content, $hashfile);
if ($self->{cache})
{
system('mkdir', '-p', $self->{cache}) if (! -d $self->{cache});
my $h = md5_hex($q);
$hashfile = "$self->{cache}/$h.query";
# Load the cached version if older than cache_age days.
( run in 0.573 second using v1.01-cache-2.11-cpan-39bf76dae61 )