aboutsummaryrefslogtreecommitdiffstats
path: root/octopart.go
blob: a1f14df8b6f629616b292b2414392a307db705d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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) {

}