From e8b87ff1746d7aaa7cd5915e34b3a016b285750f Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 15 May 2012 15:47:17 -0400 Subject: wip: b1gfoot notes, octopart start --- octopart.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 octopart.go (limited to 'octopart.go') diff --git a/octopart.go b/octopart.go new file mode 100644 index 0000000..a1f14df --- /dev/null +++ b/octopart.go @@ -0,0 +1,48 @@ +package main + +import ( + "net/http" +) + +/* +Routines to make (cached) API calls to Octopart and merge results into BOM +LineItems. +*/ + +var pricingSource *OctopartClient + +type OctopartClient struct { + ApiKey string + RemoteHost string + client *http.Client +} + +func NewOctopartClient(apikey string) *OctopartClient { + oc := &OctopartClient{ApiKey: apikey, + RemoteHost: "https://www.octopart.com"} + oc.client = &http.Client{} + return oc +} + +func openPricingSource() { + pricingSource = NewOctopartClient("") +} + +func (*oc OctopartClient) apiCall(method string, params map[string]string) (map[string]interface, error) { + paramString := "?apikey=" + oc.ApiKey + for key := range params { + paramString += "&" + key + "=" + params[key] + } + resp, err := oc.client.Get(oc.RemoteHost + "/api/v2/" + method) + + // resp as json, or interpret as error + return +} + +func (*oc OctopartClient) GetMarketInfo(mpn, manufacturer string) (map[string]interface, error) { + +} + +func (*oc OctopartClient) GetPricing(method string, params map[string]string) (map[string]interface, error) { + +} -- cgit v1.2.3