API-Octopart
view release on metacpan or search on metacpan
lib/API/Octopart.pm view on Meta::CPAN
#!/usr/bin/perl
# This module is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This module is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this module. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2022- eWheeler, Inc. L<https://www.linuxglobal.com/>
# Originally written by Eric Wheeler, KJ7LNW
# All rights reserved.
#
# All tradmarks, product names, logos, and brands are property of their
# respective owners and no grant or license is provided thereof.
#
package API::Octopart;
$VERSION = 1.003;
use 5.010;
use strict;
use warnings;
use JSON;
use LWP::UserAgent;
use Digest::MD5 qw(md5_hex);
use Data::Dumper;
=head1 NAME
API::Octopart - Simple inteface for querying part status across vendors at octopart.com.
=head1 SYNOPSIS
my $o = API::Octopart->new(
token => 'abcdefg-your-octopart-token-here',
cache => "$ENV{HOME}/.octopart/cache",
include_specs => 1,
ua_debug => 1,
query_limit => 10
);
# Query part stock:
my %opts = (
currency => 'USD',
max_moq => 100,
min_qty => 10,
max_price => 4,
#mfg => 'Murata',
);
print Dumper $o->get_part_stock_detail('RC0805FR-0710KL', %opts);
print Dumper $o->get_part_stock_detail('GQM1555C2DR90BB01D', %opts);
=head1 METHODS
=over 4
=item * $o = API::Octopart->new(%opts) - Returns new Octopart object.
Object Options (%opt):
=over 4
=item * token => 'abcdefg-your-octopart-token-here',
This is your Octopart API token. You could do something like this to read the token from a file:
token => (sub { my $t = `cat ~/.octopart/token`; chomp $t; return $t})->(),
lib/API/Octopart.pm view on Meta::CPAN
}
}
}
$part{sellers} = \%ss;
push @results, \%part;
}
# Delete sellers that do not meet the constraints and
# add matching results to @ret:
my @ret;
foreach my $r (@results)
{
next if (defined($opts{mfg}) && $r->{mfg} !~ /$opts{mfg}/i);
foreach my $s (keys %{ $r->{sellers} })
{
if (!defined($r->{sellers}{$s}{price_tier})
|| (defined($opts{min_qty}) && $r->{sellers}{$s}{stock} < $opts{min_qty})
|| (defined($opts{max_price}) && $r->{sellers}{$s}{moq_price} > $opts{max_price})
|| (defined($opts{max_moq}) && $r->{sellers}{$s}{moq} > $opts{max_moq}
|| defined($opts{seller}) && $s !~ /$opts{seller}/i)
)
{
delete $r->{sellers}{$s};
}
}
push @ret, $r;
}
return \@ret;
}
=back
=head1 SEE ALSO
L<https://octopart.com/>, L<https://octopart.com/api>
=head1 ATTRIBUTION
Octopart is a registered trademark and brand of Octopart, Inc. All tradmarks,
product names, logos, and brands are property of their respective owners and no
grant or license is provided thereof.
The copyright below applies to this software module; the copyright holder is
unaffiliated with Octopart, Inc.
=head1 AUTHOR
Originally written at eWheeler, Inc. dba Linux Global by Eric Wheeler
to facilitate optimization of RF matching components, but only for
components that are available for purchase at electronic component
vendors (of course!) L<https://youtu.be/xbdBjR4szjE>
=head1 COPYRIGHT
Copyright (C) 2022 eWheeler, Inc. dba Linux Global
L<https://www.linuxglobal.com/>
This module is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This module is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this module. If not, see <http://www.gnu.org/licenses/>.
=cut
1;
( run in 1.325 second using v1.01-cache-2.11-cpan-39bf76dae61 )