protected function resolve(array $data)
 {
     $resolver = new OptionsResolver();
     $resolver->setDefined('contents')->setAllowedTypes('contents', 'array')->setDefined('headings')->setAllowedTypes('headings', 'array')->setDefined('isIos')->setAllowedTypes('isIos', 'bool')->setDefined('isAndroid')->setAllowedTypes('isAndroid', 'bool')->setDefined('isWP')->setAllowedTypes('isWP', 'bool')->setDefined('isAdm')->setAllowedTypes('isAdm', 'bool')->setDefined('isChrome')->setAllowedTypes('isChrome', 'bool')->setDefined('isChromeWeb')->setAllowedTypes('isChromeWeb', 'bool')->setDefined('isSafari')->setAllowedTypes('isSafari', 'bool')->setDefined('isAnyWeb')->setAllowedTypes('isAnyWeb', 'bool')->setDefined('included_segments')->setAllowedTypes('included_segments', 'array')->setDefined('excluded_segments')->setAllowedTypes('excluded_segments', 'array')->setDefined('include_player_ids')->setAllowedTypes('include_player_ids', 'array')->setDefined('include_ios_tokens')->setAllowedTypes('include_ios_tokens', 'array')->setDefined('include_android_reg_ids')->setAllowedTypes('include_android_reg_ids', 'array')->setDefined('include_wp_uris')->setAllowedTypes('include_wp_uris', 'array')->setDefined('include_wp_wns_uris')->setAllowedTypes('include_wp_wns_uris', 'array')->setDefined('include_amazon_reg_ids')->setAllowedTypes('include_amazon_reg_ids', 'array')->setDefined('include_chrome_reg_ids')->setAllowedTypes('include_chrome_reg_ids', 'array')->setDefined('include_chrome_web_reg_ids')->setAllowedTypes('include_chrome_web_reg_ids', 'array')->setDefined('app_ids')->setAllowedTypes('app_ids', 'array')->setDefined('tags')->setAllowedTypes('tags', 'array')->setNormalizer('tags', function (Options $options, array $value) {
         $tags = [];
         foreach ($value as $tag) {
             if (isset($tag['key'], $tag['relation'], $tag['value'])) {
                 $tags[] = ['key' => (string) $tag['key'], 'relation' => (string) $tag['relation'], 'value' => (string) $tag['value']];
             } elseif (isset($tag['operator'])) {
                 $tags[] = ['operator' => 'OR'];
             }
         }
         return $tags;
     })->setDefined('ios_badgeType')->setAllowedTypes('ios_badgeType', 'string')->setAllowedValues('ios_badgeType', ['None', 'SetTo', 'Increase'])->setDefined('ios_badgeCount')->setAllowedTypes('ios_badgeCount', 'int')->setDefined('ios_sound')->setAllowedTypes('ios_sound', 'string')->setDefined('android_sound')->setAllowedTypes('android_sound', 'string')->setDefined('adm_sound')->setAllowedTypes('adm_sound', 'string')->setDefined('wp_sound')->setAllowedTypes('wp_sound', 'string')->setDefined('wp_wns_sound')->setAllowedTypes('wp_wns_sound', 'string')->setDefined('data')->setAllowedTypes('data', 'array')->setDefined('buttons')->setAllowedTypes('buttons', 'array')->setNormalizer('buttons', function (Options $options, array $value) {
         $buttons = [];
         foreach ($value as $button) {
             if (!isset($button['text'])) {
                 continue;
             }
             $buttons[] = ['id' => isset($button['id']) ? $button['id'] : mt_rand(), 'text' => $button['text'], 'icon' => isset($button['icon']) ? $button['icon'] : null];
         }
         return $buttons;
     })->setDefined('small_icon')->setAllowedTypes('small_icon', 'string')->setDefined('large_icon')->setAllowedTypes('large_icon', 'string')->setDefined('big_picture')->setAllowedTypes('big_picture', 'string')->setDefined('adm_small_icon')->setAllowedTypes('adm_small_icon', 'string')->setDefined('adm_large_icon')->setAllowedTypes('adm_large_icon', 'string')->setDefined('adm_big_picture')->setAllowedTypes('adm_big_picture', 'string')->setDefined('chrome_icon')->setAllowedTypes('chrome_icon', 'string')->setDefined('chrome_big_picture')->setAllowedTypes('chrome_big_picture', 'string')->setDefined('chrome_web_icon')->setAllowedTypes('chrome_web_icon', 'string')->setDefined('url')->setAllowedTypes('url', 'string')->setAllowedValues('url', function ($value) {
         // https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/UrlValidator.php
         $pattern = '~^(http|https)://(([\\pL\\pN-]+:)?([\\pL\\pN-]+)@)?(([\\pL\\pN\\pS-\\.])+(\\.?([\\pL]|xn\\-\\-[\\pL\\pN-]+)+\\.?)|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\[(?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))\\])(:[0-9]+)?(/?|/\\S+)$~ixu';
         return (bool) preg_match($pattern, $value);
     })->setDefined('send_after')->setAllowedTypes('send_after', '\\DateTime')->setNormalizer('send_after', function (Options $options, \DateTime $value) {
         //Fri May 02 2014 00:00:00 GMT-0700 (PDT)
         return $value->format('D M d Y H:i:s eO (T)');
     })->setDefined('delayed_option')->setAllowedTypes('delayed_option', 'string')->setAllowedValues('delayed_option', ['timezone', 'last-active'])->setDefined('delivery_time_of_day')->setAllowedTypes('delivery_time_of_day', '\\DateTime')->setNormalizer('delivery_time_of_day', function (Options $options, \DateTime $value) {
         return $value->format('g:iA');
     })->setDefined('android_led_color')->setAllowedTypes('android_led_color', 'string')->setDefined('android_accent_color')->setAllowedTypes('android_accent_color', 'string')->setDefined('android_visibility')->setAllowedTypes('android_visibility', 'int')->setAllowedValues('android_visibility', [-1, 0, 1])->setDefined('content_available')->setAllowedTypes('content_available', 'bool')->setDefined('android_background_data')->setAllowedTypes('android_background_data', 'bool')->setDefined('amazon_background_data')->setAllowedTypes('amazon_background_data', 'bool')->setDefined('template_id')->setAllowedTypes('template_id', 'string')->setDefined('android_group')->setAllowedTypes('android_group', 'string')->setDefined('android_group_message')->setAllowedTypes('android_group_message', 'array')->setDefined('adm_group')->setAllowedTypes('adm_group', 'string')->setDefined('adm_group_message')->setAllowedTypes('adm_group_message', 'array')->setDefault('app_id', $this->api->getConfig()->getApplicationId());
     return $resolver->resolve($data);
 }
예제 #2
0
 protected function resolve(array $data, callable $callback = null)
 {
     $resolver = new OptionsResolver();
     if (is_callable($callback)) {
         $callback($resolver);
     }
     $resolver->setDefined('identifier')->setAllowedTypes('identifier', 'string')->setDefined('language')->setAllowedTypes('language', 'string')->setDefined('timezone')->setAllowedTypes('timezone', 'int')->setDefined('game_version')->setAllowedTypes('game_version', 'string')->setDefined('device_model')->setAllowedTypes('device_model', 'string')->setDefined('device_os')->setAllowedTypes('device_os', 'string')->setDefined('ad_id')->setAllowedTypes('ad_id', 'string')->setDefined('sdk')->setAllowedTypes('sdk', 'string')->setDefined('session_count')->setAllowedTypes('session_count', 'int')->setDefined('tags')->setAllowedTypes('tags', 'array')->setDefined('amount_spent')->setAllowedTypes('amount_spent', 'float')->setDefined('created_at')->setAllowedTypes('created_at', 'int')->setDefined('playtime')->setAllowedTypes('playtime', 'int')->setDefined('badge_count')->setAllowedTypes('badge_count', 'int')->setDefined('last_active')->setAllowedTypes('last_active', 'int')->setDefault('app_id', $this->api->getConfig()->getApplicationId());
     return $resolver->resolve($data);
 }
 public function testClient()
 {
     $this->assertInstanceOf('GuzzleHttp\\Client', $this->api->getClient());
 }
예제 #4
0
 /**
  * Update application with provided data.
  *
  * User authentication key must be set.
  *
  * @param string $id   ID of your application
  * @param array  $data New application data
  *
  * @return \GuzzleHttp\Message\Response
  */
 public function update($id, array $data)
 {
     $data = $this->resolve($data);
     return $this->api->request('PUT', '/apps/' . $id, ['headers' => ['Authorization' => 'Basic ' . $this->api->getConfig()->getUserAuthKey(), 'Content-Type' => 'application/json'], 'json' => $data]);
 }