func ToGAE(c appengine.Context, k key.Key) *datastore.Key { if len(k) < 1 { return nil } kind, stringID, intID, parent := k.Split() return datastore.NewKey(c, kind, stringID, intID, ToGAE(c, key.Key(parent))) }
// cacheKeys will append to oldKeys, and also return as newKeys, all cache keys this finder may use to find the provided model. // the reason there may be multiple keys is that we don't know which ancestor will be used when finding the model. func (self finder) cacheKeys(c PersistenceContext, model interface{}, oldKeys *[]string) (newKeys []string, err error) { var id key.Key if _, id, err = getTypeAndId(model); err != nil { return } values := make([]interface{}, len(self.fields)) val := reflect.ValueOf(model).Elem() for index, field := range self.fields { values[index] = val.FieldByName(field.Name).Interface() } if oldKeys == nil { oldKeys = &[]string{} } for id != "" { *oldKeys = append(*oldKeys, self.keyForValues(id.Parent(), values)) id = id.Parent() } newKeys = *oldKeys return }
func UpdateDoc(c ElasticConnector, index string, id key.Key, groovyCode string, params map[string]interface{}) (err error) { index = processIndexName(index) url := fmt.Sprintf("%s/%s/%s/%s/_update?retry_on_conflict=%v", c.GetElasticService(), index, id.Kind(), id.Encode(), UpdateConflictRetries) json, err := json.Marshal(UpdateRequest{ Script: groovyCode, Params: params, }) if err != nil { return } request, err := http.NewRequest("POST", url, bytes.NewBuffer(json)) if err != nil { return } if c.GetElasticUsername() != "" { request.SetBasicAuth(c.GetElasticUsername(), c.GetElasticPassword()) } response, err := c.Client().Do(request) if err != nil { return } defer response.Body.Close() if response.StatusCode != http.StatusOK { body, _ := ioutil.ReadAll(response.Body) err = errors.Errorf("Bad status code from elasticsearch %v: %v, %v", url, response.Status, string(body)) return } return }
func GetSpotifyAccount(c ServiceConnector, soundZone key.Key, token AccessToken) (result *RemoteSpotifyAccount, err error) { request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("sound_zones/%v/spotify_account", soundZone.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = &RemoteSpotifyAccount{} err = json.NewDecoder(response.Body).Decode(result) return }
func GetSoundZones(c ServiceConnector, account_id key.Key, token AccessToken) (result RemoteSoundZones, err error) { request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("accounts/%v/sound_zones", account_id.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = RemoteSoundZones{} err = json.NewDecoder(response.Body).Decode(&result) return }
func CreateBusinessAccount(c ServiceConnector, token AccessToken, account RemoteAccount, owner key.Key) (result *RemoteAccount, err error) { request, response, err := DoRequest(c, "POST", c.GetAuthService(), fmt.Sprintf("users/%v/accounts/business", owner.Encode()), token, account) if err != nil { return } if response.StatusCode != 201 { err = errorFor(request, response) return } result = &RemoteAccount{} err = json.NewDecoder(response.Body).Decode(result) return }
func UpdateSoundZoneErrors(c ServiceConnector, token AccessToken, soundZoneId key.Key, soundZoneError RemoteSoundZoneError) (err error) { request, response, err := DoRequest(c, "POST", c.GetAuthService(), fmt.Sprintf("sound_zones/%v/sound_zone_errors", soundZoneId.Encode()), token, soundZoneError) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } return }
func GetProductQueue(c ServiceConnector, productQueueId key.Key, token AccessToken) (result *RemoteProductQueue, err error) { request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("product_queues/%v", productQueueId.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = &RemoteProductQueue{} err = json.NewDecoder(response.Body).Decode(result) return }
func SetPassword(c ServiceConnector, user key.Key, password string, token AccessToken) (result *RemoteUser, err error) { request, response, err := DoRequest(c, "PUT", c.GetAuthService(), fmt.Sprintf("users/%s/password", user.Encode()), token, map[string]string{ "password": password, }) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = &RemoteUser{} err = json.NewDecoder(response.Body).Decode(result) return }
func GetBillingGroupsByAccountId(c ServiceConnector, account key.Key, token AccessToken) (result RemoteBillingGroups, err error) { request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("accounts/%v/billing_groups", account.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = RemoteBillingGroups{} err = json.NewDecoder(response.Body).Decode(&result) return }
func CreateSoundZoneError(c ServiceConnector, token AccessToken, e RemoteSoundZoneError, soundZoneId key.Key) (result *RemoteSoundZoneError, err error) { request, response, err := DoRequest(c, "POST", c.GetAuthService(), fmt.Sprintf("sound_zones/%v/sound_zone_errors", soundZoneId.Encode()), token, e) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = &RemoteSoundZoneError{} err = json.NewDecoder(response.Body).Decode(result) return }
func GetAccountContact(c ServiceConnector, account key.Key, token AccessToken) (result *RemoteUser, err error) { request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("accounts/%v/contact", account.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = &RemoteUser{} err = json.NewDecoder(response.Body).Decode(result) return }
func GetLocation(c ServiceConnector, location key.Key, token AccessToken) (result *RemoteLocation, err error) { request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("locations/%v", location.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = &RemoteLocation{} err = json.NewDecoder(response.Body).Decode(result) return }
func ReplaceScheduleForSoundZones(c ServiceConnector, oldSchedule, newSchedule key.Key, token AccessToken) (err error) { scheduleRef := &ScheduleRef{ Schedule: newSchedule, } request, response, err := DoRequest(c, "PUT", c.GetAuthService(), fmt.Sprintf("schedules/%v/sound_zones", oldSchedule.Encode()), token, scheduleRef) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } return }
func CountSoundZonesForSchedule(c ServiceConnector, schedule key.Key, token AccessToken) (result int, err error) { request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("schedules/%v/sound_zone_count", schedule.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } container := &CountContainer{} if err = json.NewDecoder(response.Body).Decode(container); err != nil { return } result = container.Count return }
func GetSpotifyAccounts(c ServiceConnector, account key.Key, token AccessToken) (result RemoteSpotifyAccounts, err error) { request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("accounts/%v/payment_method/spotify_accounts", account.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = RemoteSpotifyAccounts{} err = json.NewDecoder(response.Body).Decode(&result) return }
func DeactivateSpotifyAccount(c ServiceConnector, soundZone key.Key, token AccessToken) (err error) { request, response, err := DoRequest(c, "POST", c.GetPaymentService(), fmt.Sprintf("sound_zones/%v/spotify_account/deactivate", soundZone.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } return }
func UpdatePaymentMethodByAccountId(c ServiceConnector, account key.Key, paymentMethod RemotePaymentMethod, token AccessToken) (err error) { request, response, err := DoRequest(c, "PUT", c.GetPaymentService(), fmt.Sprintf("accounts/%v/payment_method", account.Encode()), token, paymentMethod) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } return }
func GetDeviceHierarchy(c ServiceConnector, deviceId key.Key, token AccessToken) (result *DeviceHierarchy, err error) { request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("/device_hierarchy/device/%v", deviceId.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = &DeviceHierarchy{ Device: &RemoteDevice{}, SoundZone: &RemoteSoundZone{}, Location: &RemoteLocation{}, Account: &RemoteAccount{}, } err = json.NewDecoder(response.Body).Decode(&result) return }
func DeactivatePaymentMethodAsync(c ServiceConnector, accountId key.Key, token AccessToken) (err error) { request, response, err := DoRequest(c, "POST", c.GetPaymentService(), fmt.Sprintf("accounts/%v/payment_method/deactivate_async", accountId.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } return }
func CreatePriceModel(c ServiceConnector, paymentMethodId key.Key, isoCountry string, priceModel *RemotePriceModel, token AccessToken) (result *RemotePriceModel, err error) { request, response, err := DoRequest(c, "POST", c.GetPaymentService(), fmt.Sprintf("accounts/%v/payment_method/price_models/%v", paymentMethodId.Encode(), isoCountry), token, priceModel) if err != nil { return } if response.StatusCode != 201 { err = errorFor(request, response) return } result = &RemotePriceModel{} err = json.NewDecoder(response.Body).Decode(result) return }
func GetAccounts(c ServiceConnector, user key.Key, token AccessToken) (result []RemoteAccount, err error) { request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("users/%v/accounts", user.Encode()), token, nil) if err != nil { return } if response.StatusCode != 200 { err = errorFor(request, response) return } result = []RemoteAccount{} err = json.NewDecoder(response.Body).Decode(&result) return }