Project

octopart

0.01
No commit activity in last 3 years
No release in over 3 years
Ruby gem for the Octopart API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

Octopart travis-ci

This is a ruby gem that wraps the Octopart API v2.

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 >, ... ]

#suggest

Suggest a search term. Can be used for autocomplete, although, you'd be better off doing autocomplete client side using JavaScript.

Octopart::Part.suggest('sn728')
# => ["SN72811", "SN72811N", "SN72810N", "SN72820N", "SN72810"]

#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 >, ... ]]

.datasheet

Returns the highest rated datasheet for the part, or nil if there are no datasheets.

part = Octopart::Part.find(39619421)
# => #<Octopart::Part >

part.datasheet
# => http://datasheet.octopart.com/H-46-6A-Bourns-datasheet-12570.pdf

.best_offer

Returns the best offer (lowest price) for the quantity specified.

part = Octopart::Part.find(39619421)
# => #<Octopart::Part >

part.best_offer
# => #<Hashie::Mash >

part.best_offer.prices
# => [[1, 14.67, "USD"], [10, 13.69, "USD"], [30, 12.84, "USD"]]

Returns the best price (lowest price) for the quantity specified.

.best_price

part = Octopart::Part.find(39619421)
# => #<Octopart::Part >

part.best_price
# => 14.67

part.best_price(100)
# => 12.84

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request