Beispiel #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
}
Beispiel #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
}
Beispiel #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
}
Beispiel #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
}
Beispiel #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
}
Beispiel #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
}
Beispiel #7
0
func (self *Client) delete(url string) error {
	c := http.NewClient(self.apiKey, self.token)
	return c.Delete(url)
}
Beispiel #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)
}