Exemplo n.º 1
0
func (self *Client) CreateOperator(param map[string]string) error {
	u := config.MakeUrl("/operators")
	body, _ := json.Marshal(param)
	c := http.NewClient(self.apiKey, self.token)
	if _, err := c.Post(u, body); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 2
0
func (self *Client) reports(mode, imsi string, from, to int64, period string, v interface{}) error {
	url := config.MakeUrl("/stats/%s/subscribers/%s?from=%d&to=%d&period=%s", mode, imsi, from, to, period)
	c := http.NewClient(self.ApiKey, self.Token)
	data, err := c.Get(url)
	if err != nil {
		return err
	}
	if err := json.Unmarshal(data, v); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 3
0
func (self *Client) Sim(imsi string) (*Subscriber, error) {
	u := config.MakeUrl("/subscribers/%s", imsi)
	c := http.NewClient(self.apiKey, self.token)
	data, err := c.Get(u)
	if err != nil {
		return nil, err
	}
	s := Subscriber{}
	if err := json.Unmarshal(data, &s); err != nil {
		return nil, err
	}
	return &s, nil
}
Exemplo n.º 4
0
func (self *Client) FindId(id string) (*Operator, error) {
	u := config.MakeUrl("/operators/%s", id)
	c := http.NewClient(self.apiKey, self.token)
	data, err := c.Get(u)
	if err != nil {
		return nil, err
	}
	s := Operator{}
	if err := json.Unmarshal(data, &s); err != nil {
		return nil, err
	}
	return &s, nil
}
Exemplo n.º 5
0
func (self *Client) Find(q map[string]string) (*Subscribers, error) {
	val := url.Values{}
	for k, v := range q {
		val.Set(k, v)
	}
	u := config.MakeUrl("/subscribers?%s", val.Encode())
	c := http.NewClient(self.apiKey, self.token)
	data, err := c.Get(u)
	if err != nil {
		return nil, err
	}
	ss := Subscribers{}
	if err := json.Unmarshal(data, &ss); err != nil {
		return nil, err
	}
	return &ss, nil
}
Exemplo n.º 6
0
func (self *Client) ExportReport(mode, operatorId string, from, to int64) (string, error) {
	url := config.MakeUrl("/stats/%s/operators/%s/export", mode, operatorId)
	m := map[string]interface{}{
		"period": "month",
		"from":   from,
		"to":     to,
	}
	body, err := json.Marshal(m)
	c := http.NewClient(self.ApiKey, self.Token)
	data, err := c.Post(url, body)
	if err != nil {
		return "", err
	}
	v := make(map[string]string)
	if err := json.Unmarshal(data, &v); err != nil {
		return "", err
	}
	return v["url"], nil
}
Exemplo n.º 7
0
func (self *Client) delete(url string) error {
	c := http.NewClient(self.apiKey, self.token)
	return c.Delete(url)
}
Exemplo n.º 8
0
func (self *Client) put(url string, body []byte) (*Subscriber, error) {
	c := http.NewClient(self.apiKey, self.token)
	return command(c.Put, url, body)
}