This repository has been archived by the owner on Jul 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_marketplace.go
74 lines (62 loc) · 1.9 KB
/
data_marketplace.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package mobius
import (
"net/url"
)
// MarketPlace strutures to communicate with the Data Marketplace
type MarketPlace struct {
mx *Mobiusimpl
}
type Feed struct {
DataFeed struct {
UID string `json:"uid"`
Name string `json:"name"`
Description string `json:"description"`
ImageURL string `json:"image_url"`
Price string `json:"price"`
Descriptor struct {
Name string `json:"name"`
Type string `json:"type"`
} `json:"descriptor"`
} `json:"data_feed"`
LastUpdated string `json:"last_updated,omitempty"`
}
// Get Returns DataFeed and last update timestamp, updated when new DataPoints are added.
func (m MarketPlace) Get(dataFeedUID string) (*Feed, error) {
r := newRequest(generateApiUrl(m.mx, dataFeedEndpoint), m.mx)
r.addHeader("Content-Type", "application/x-www-form-urlencoded")
data := url.Values{}
data.Set("data_feed_uid", dataFeedUID)
r.QueryValues = data
var response Feed
err := getJSONResponse(r, &response)
if err == nil {
return &response, nil
}
return nil, err
}
// Create a new DataPoint for the DataFeed
func (m MarketPlace) Create(data interface{}) (*Feed, error) {
r := newRequest(generateApiUrl(m.mx, createDataEndpoint), m.mx)
r.addHeader("Content-Type", "application/json")
var response Feed
err := postResponseFromJSON(r, data, &response)
if err == nil {
return &response, nil
}
return nil, err
}
// Buy purchases a Data Feed and sends its data to an Ethereum Contract Address
func (m MarketPlace) Buy(dataFeedUID, address string) (*Feed, error) {
r := newRequest(generateApiUrl(m.mx, buyEndpoint), m.mx)
r.addHeader("Content-Type", "application/x-www-form-urlencoded")
data := url.Values{}
data.Set("app_uid", m.mx.AppUID)
data.Add("data_feed_uid", dataFeedUID)
data.Add("address", address)
var response Feed
err := postResponseFromJSON(r, data.Encode(), &response)
if err == nil {
return &response, nil
}
return nil, err
}