-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_tracking.go
50 lines (45 loc) · 1.28 KB
/
data_source_tracking.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
package main
import (
"fmt"
"time"
"log"
"net/http"
"encoding/json"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceTracking() *schema.Resource {
return &schema.Resource{
Read: resourceTrackingRead,
Schema: map[string]*schema.Schema{
"order_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"store_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
},
}
}
func resourceTrackingRead(d *schema.ResourceData, m interface{}) error {
var client = &http.Client{Timeout: 10 * time.Second}
order_id := d.Get("order_id").(string)
store_id := d.Get("store_id").(string)
_, err := getTrackingApiObject(fmt.Sprintf("https://trkweb.dominos.com/orderstorage/GetTrackerData?StoreID=%s&OrderKey=%s", store_id, order_id), client)
if err != nil {
return err
}
return nil
}
func getTrackingApiObject(url string, client *http.Client) (map[string]interface{}, error) {
r, err := client.Get(url)
if err != nil {
return nil, err
}
defer r.Body.Close()
resp := make(map[string]interface{})
err = json.NewDecoder(r.Body).Decode(&resp)
log.Printf("Tracking response: %#v", resp)
return resp, err
}