blob: d02b79726c3299dc389c14115778e89a1946c7ce [file] [log] [blame]
Brian Silverman8fa2aad2017-06-10 16:45:30 -07001=begin
2parts.yaml is a YAML file of mappings to mappings. The top-level key is the part
3number that shows up in the schematics and the second-level mappings are
4overrides for various things that can't be mapped automatically.
5
6Overrides:
7 package: The PCB-style package name.
8=end
9
10require 'json'
11require 'yaml'
12require 'net/http'
13
Brian Silverman856af592017-12-18 11:17:09 -050014#require './html'
Brian Silverman8fa2aad2017-06-10 16:45:30 -070015
16def get_octopart_results(mpn)
17 query = [{:mpn => mpn, :limit => 20}]
18 response_include = ['specs', 'descriptions', 'short_description', 'compliance_documents', 'external_links']
19
20 url = 'http://octopart.com/api/v3/parts/match?'
21 url += '&apikey=80a2e435'
22 response_include.each do |i|
23 url += '&include[]=' + i
24 end
25 url += '&queries=' + URI.encode(JSON.generate(query))
26
27 server_response = JSON.parse(retrieve_url(url))
28
29 server_response['results']
30end