func (a *Adaptor) createFilter(userId int, f *Filter) error { var row_count int // enable filter err := a.apidClient.DoFunction("enableUserFilter", url.Values{ "userid": []string{strconv.Itoa(userId)}, "type": []string{f.Name}, }, &row_count) if err != nil { // only skip error if filter already enabled if strings.Contains(err.Error(), "already enabled for user") { ln.Debug("user filter already enabled", ln.Map{"debug": err}) } else { return err } } // create filters settings err = a.apidClient.DoFunction("addUserFilters", url.Values{ "userid": []string{strconv.Itoa(userId)}, "filterid": []string{strconv.Itoa(f.Id)}, "settings": []string{f.Settings}, }, &row_count) return err }
func (b *Adaptor) Subscribe(subscription *BossSubscriptionParams) error { ln.Debug("Boss Subscribe()", ln.Map{"subscription": subscription}) authToken := fmt.Sprintf("token=%s", b.authToken) client := &http.Client{} accountSubscriptionURL, err := b.urls.accountSubscriptionURL(subscription.AccountID) if err != nil { ln.Err("error when subscribing user, could not get url", ln.Map{"error": err.Error(), "subscription_params": subscription}) return err } data, err := json.Marshal(subscription) if err != nil { ln.Err("something went wrong marshalling subscription", ln.Map{"error": err.Error(), "user_id": subscription.AccountID}) return err } req, err := http.NewRequest("POST", accountSubscriptionURL, bytes.NewReader(data)) if err != nil { ln.Err("something went wrong creating http request for boss subscription", ln.Map{"error": err.Error()}) return err } req.Header.Set("Authorization", authToken) req.Header.Set("Content-Type", "application/json") curl := fmt.Sprintf("curl -v -X POST %s -d '%s' --header 'Authorization: <auth token>' --header 'Content-Type: application/json'", accountSubscriptionURL, string(data)) resp, err := client.Do(req) if err != nil { ln.Err(fmt.Sprintf("something went wrong executing http request to boss subscription endpoint, %s", curl), ln.Map{"error": err.Error()}) return err } defer resp.Body.Close() if resp.StatusCode != http.StatusCreated { b, err := ioutil.ReadAll(resp.Body) if err != nil { ln.Err(fmt.Sprintf("Error to read response body, %s", curl), ln.Map{"error": err.Error(), "boss_status_code": resp.StatusCode}) return err } ln.Err(fmt.Sprintf("Error posting to subscriptions, %s", curl), ln.Map{"status_code": resp.StatusCode, "response_body": string(b), "user_id": subscription.AccountID, "url": accountSubscriptionURL}) return errors.New("error when calling internal service") } return nil }
func (b *Adaptor) CollectBalance(userID int) *adaptor.AdaptorError { ln.Debug("Boss CollectBalance()", ln.Map{"account ID": userID}) authToken := fmt.Sprintf("token=%s", b.authToken) client := &http.Client{} accountCollectURL, err := b.urls.accountCollectURL(userID) if err != nil { ln.Err("error when collecting balance, could not get url", ln.Map{"error": err.Error(), "user_id": userID}) return adaptor.NewError("could not get the collect url") } req, err := http.NewRequest("PUT", accountCollectURL, nil) if err != nil { ln.Err("something went wrong creating http request for boss collect", ln.Map{"error": err.Error()}) return adaptor.NewError("could not create http request") } req.Header.Set("Authorization", authToken) req.Header.Set("Content-Type", "application/json") curl := fmt.Sprintf("curl -v -X PUT %s --header 'Authorization: <auth token>' --header 'Content-Type: application/json'", accountCollectURL) resp, err := client.Do(req) if err != nil { ln.Err(fmt.Sprintf("something went wrong executing http request to boss collect endpoint, %s", curl), ln.Map{"error": err.Error()}) return adaptor.NewError("could not execute request to boss collect endpoint") } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { respBody, err := ioutil.ReadAll(resp.Body) if err != nil { ln.Err(fmt.Sprintf("Error to read response body, %s", curl), ln.Map{"error": err.Error(), "boss_status_code": resp.StatusCode}) return adaptor.NewError("could not read response body") } ln.Err(fmt.Sprintf("Error putting to collect, %s", curl), ln.Map{"status_code": resp.StatusCode, "response_body": string(respBody), "user_id": userID, "url": accountCollectURL}) return adaptor.NewError("error when calling internal service") } return nil }