Octopart
This is a ruby gem that wraps the Octopart API.
Installation
Add this line to your application's Gemfile:
gem 'octopart'
And then execute:
$ bundle
Or, install it manually:
$ gem install octopart
Usage
Configuration
In order to make more than 100 requests/hour you need to register your application with Octopart and obtain your API key. Once you have your API key, you can set it like so.
Octopart.configure do |config|
config.apikey = 'your api key'
end
Parts
#find
Find a part by it's octopart ID.
part = Octopart::Part.find(39619421)
# => <Octopart::Part >
part.short_description
# => "Dial; Turns-Counting, Analog; 20 Turns; 100per Turn; Shaft Dia 0.25in"
part.mpn
# => "H-46-6A"
parts = Octopart::Part.find(39619421, 29035751, 31119928)
# => [<Octopart::Part >, ... ]
#search
Search all parts that match a given query string.
Octopart::Part.search('resistor')
# => [<Octopart::Part >, ... ]
Octopart::Part.search('resistor', limit: 10)
# => [<Octopart::Part >, ... ]
#match
Match (manufacturer name, mpn) to part uid.
Octopart::Part.match('texas instruments', 'SN74LS240N')
# => 42315325996
#bom
Return an array of parts for each line specified.
Octopart::Part.bom(mpn: 'SN74LS240N')
# => [[<Octopart::Part >, ... ]]
Octopart::Part.bom([{mpn: 'SN74LS240N'}, {mpn: 'ATMEGA328P-PU'}])
# => [[<Octopart::Part >, ... ], [<Octopart::Part >, ... ]]
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request