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})->(),
=item * include_specs => 1
If you have a PRO account then you can include product specs:
=item * cache => "$ENV{HOME}/.octopart/cache"
An optional (but recommended) cache directory to minimize requests to Octopart:
=item * cache_age => 3
The cache age (in days) before re-querying octopart. Defaults to 30 days.
=item * query_limit: die if too many API requests are made.
Defaults to no limit. I exhasted 20,000 queries very quickly due to a bug!
This might help with that, set to a reasonable limit while testing.
=item * ua_debug => 1
( run in 0.862 second using v1.01-cache-2.11-cpan-39bf76dae61 )