/** * {@inheritdoc} */ public function jsonSerialize() { // The 'auth' parameter must have been set if (!isset($this->auth)) { throw new PushwooshException('The \'auth\' property is not set !'); } $json = ['auth' => $this->auth]; // Mandatory parameters $json['ignore_user_timezone'] = $this->ignoreUserTimezone; $json['send_date'] = is_string($this->sendDate) ? $this->sendDate : $this->sendDate->format('Y-m-d H:i'); // Optional parameters isset($this->content) ? $json['content'] = $this->content : false; isset($this->data) ? $json['data'] = $this->data : false; isset($this->devicesFilter) ? $json['devices_filter'] = $this->devicesFilter : false; isset($this->filter) ? $json['filter'] = $this->filter : false; isset($this->link) ? $json['link'] = $this->link : false; isset($this->minimizeLink) ? $json['minimize_link'] = $this->minimizeLink->getValue() : false; isset($this->pageId) ? $json['page_id'] = $this->pageId : false; isset($this->remotePage) ? $json['remote_page'] = $this->remotePage : false; isset($this->richPageId) ? $json['rich_page_id'] = $this->richPageId : false; isset($this->sendRate) ? $json['send_rate'] = $this->sendRate : false; isset($this->timezone) ? $json['timezone'] = $this->timezone : false; return $json; }
/** * Test method for the <tt>toJSON()</tt> function. */ public function testToJSON() { $array = Notification::create()->setSendDate('now')->setIgnoreUserTimezone(true)->setContent(array('en' => 'English', 'ru' => 'Русский', 'de' => 'Deutsch'))->setPageId(39)->setLink('http://google.com')->setMinimizeLink(MinimizeLink::none())->setData(array('custom' => 'json data'))->setPlatforms(array(Platform::iOS(), Platform::blackBerry(), Platform::android(), Platform::nokia(), Platform::windowsPhone7(), Platform::maxOSX(), Platform::windows8(), Platform::amazon(), Platform::safari()))->setDevices(array('dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41'))->setFilter('FILTER_NAME')->setConditions(array(IntCondition::create('intTag')->gte(10), StringCondition::create('stringTag')->eq('stringValue'), ListCondition::create('listTag')->in(array('value0', 'value1', 'value2'))))->setADM(ADM::create()->setBanner('http://example.com/banner.png')->setCustomIcon('http://example.com/image.png')->setHeader('Header')->setIcon('icon')->setRootParams(array('key' => 'value'))->setSound('push.mp3')->setTtl(3600))->setAndroid(Android::create()->setBanner('http://example.com/banner.png')->setCustomIcon('http://example.com/image.png')->setGcmTtl(3600)->setHeader('Header')->setIcon('icon')->setRootParams(array('key' => 'value'))->setSound('push.mp3'))->setBlackBerry(BlackBerry::create()->setHeader('header'))->setIOS(IOS::create()->setApnsTrimContent(true)->setBadges(5)->setRootParams(array('aps' => array('content-available' => '1')))->setSound('sound file.wav')->setTtl(3600)->setTrimContent(true))->setMac(Mac::create()->setBadges(3)->setRootParams(array('content-available' => '1'))->setSound('sound.caf')->setTtl(3600))->setSafari(Safari::create()->setAction('Click here')->setTitle('Title')->setTtl(3600)->setUrlArgs(array('firstArgument', 'secondArgument')))->setWNS(WNS::create()->setContent(array('en' => 'ENENENEN', 'de' => 'DEDEDEDE'))->setTag('myTag')->setType('Badge'))->setWP(WP::create()->setBackbackground('/Resources/Green.jpg')->setBackcontent('back content')->setBackground('/Resources/Red.jpg')->setBacktitle('back title')->setCount(3)->setType('Tile'))->toJSON(); // Test the generic properties $this->assertCount(49, $array); $this->assertEquals('now', $array['send_date']); $this->assertTrue($array['ignore_user_timezone']); $this->assertCount(3, $array['content']); $this->assertEquals('English', $array['content']['en']); $this->assertEquals('Русский', $array['content']['ru']); $this->assertEquals('Deutsch', $array['content']['de']); $this->assertEquals(39, $array['page_id']); $this->assertEquals('http://google.com', $array['link']); $this->assertEquals(0, $array['minimize_link']); $this->assertCount(1, $array['data']); $this->assertEquals('json data', $array['data']['custom']); $this->assertCount(9, $array['platforms']); $this->assertEquals(1, $array['platforms'][0]); $this->assertEquals(2, $array['platforms'][1]); $this->assertEquals(3, $array['platforms'][2]); $this->assertEquals(4, $array['platforms'][3]); $this->assertEquals(5, $array['platforms'][4]); $this->assertEquals(7, $array['platforms'][5]); $this->assertEquals(8, $array['platforms'][6]); $this->assertEquals(9, $array['platforms'][7]); $this->assertEquals(10, $array['platforms'][8]); $this->assertCount(1, $array['devices']); $this->assertEquals('dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41', $array['devices'][0]); $this->assertEquals('FILTER_NAME', $array['filter']); $this->assertCount(3, $array['conditions']); $this->assertEquals('intTag', $array['conditions'][0][0]); $this->assertEquals('GTE', $array['conditions'][0][1]); $this->assertEquals(10, $array['conditions'][0][2]); $this->assertEquals('stringTag', $array['conditions'][1][0]); $this->assertEquals('EQ', $array['conditions'][1][1]); $this->assertEquals('stringValue', $array['conditions'][1][2]); $this->assertEquals('listTag', $array['conditions'][2][0]); $this->assertEquals('IN', $array['conditions'][2][1]); $this->assertCount(3, $array['conditions'][2][2]); $this->assertEquals('value0', $array['conditions'][2][2][0]); $this->assertEquals('value1', $array['conditions'][2][2][1]); $this->assertEquals('value2', $array['conditions'][2][2][2]); // Test the ADM parameters $this->assertEquals('http://example.com/banner.png', $array['adm_banner']); $this->assertEquals('http://example.com/image.png', $array['adm_custom_icon']); $this->assertEquals('Header', $array['adm_header']); $this->assertEquals('icon', $array['adm_icon']); $this->assertEquals(array('key' => 'value'), $array['adm_root_params']); $this->assertEquals('push.mp3', $array['adm_sound']); $this->assertEquals(3600, $array['adm_ttl']); // Test Android parameters $this->assertEquals('http://example.com/banner.png', $array['android_banner']); $this->assertEquals('http://example.com/image.png', $array['android_custom_icon']); $this->assertEquals(3600, $array['android_gcm_ttl']); $this->assertEquals('Header', $array['android_header']); $this->assertEquals('icon', $array['android_icon']); $this->assertEquals(array('key' => 'value'), $array['android_root_params']); $this->assertEquals('push.mp3', $array['android_sound']); // Test BlackBerry parameters $this->assertEquals('header', $array['blackberry_header']); // Test IOS parameters $this->assertEquals(1, $array['apns_trim_content']); $this->assertEquals(5, $array['ios_badges']); $this->assertEquals(array('aps' => array('content-available' => '1')), $array['ios_root_params']); $this->assertEquals('sound file.wav', $array['ios_sound']); $this->assertEquals(3600, $array['ios_ttl']); $this->assertEquals(1, $array['ios_trim_content']); // Test Mac parameters $this->assertEquals(3, $array['mac_badges']); $this->assertEquals(array('content-available' => '1'), $array['mac_root_params']); $this->assertEquals('sound.caf', $array['mac_sound']); $this->assertEquals(3600, $array['mac_ttl']); // Test Safari parameters $this->assertEquals('Click here', $array['safari_action']); $this->assertEquals('Title', $array['safari_title']); $this->assertEquals(3600, $array['safari_ttl']); $this->assertEquals(array('firstArgument', 'secondArgument'), $array['safari_url_args']); // Test WNS parameters $this->assertEquals(array('en' => 'ENENENEN', 'de' => 'DEDEDEDE'), $array['wns_content']); $this->assertEquals('myTag', $array['wns_tag']); $this->assertEquals('Badge', $array['wns_type']); // Test WP parameters $this->assertEquals('/Resources/Green.jpg', $array['wp_backbackground']); $this->assertEquals('back content', $array['wp_backcontent']); $this->assertEquals('/Resources/Red.jpg', $array['wp_background']); $this->assertEquals('back title', $array['wp_backtitle']); $this->assertEquals(3, $array['wp_count']); $this->assertEquals('Tile', $array['wp_type']); }
/** * Creates a JSON representation of this request. * * @return array a PHP which can be passed to the 'json_encode' PHP method. */ public function jsonSerialize() { $json = []; // Mandatory parameters $json['ignore_user_timezone'] = $this->ignoreUserTimezone; $json['send_date'] = is_string($this->sendDate) ? $this->sendDate : $this->sendDate->format('Y-m-d H:i'); // Optional parameters isset($this->sendRate) ? $json['send_rate'] = $this->sendRate : false; isset($this->content) ? $json['content'] = $this->content : false; isset($this->data) ? $json['data'] = $this->data : false; isset($this->devices) ? $json['devices'] = $this->devices : false; isset($this->filter) ? $json['filter'] = $this->filter : false; isset($this->link) ? $json['link'] = $this->link : false; isset($this->minimizeLink) ? $json['minimize_link'] = $this->minimizeLink->getValue() : false; isset($this->pageId) ? $json['page_id'] = $this->pageId : false; if (isset($this->conditions)) { $conditionsArray = []; foreach ($this->conditions as $condition) { $conditionsArray[] = $condition->jsonSerialize(); } $json['conditions'] = $conditionsArray; } if (isset($this->platforms)) { $platformsArray = []; foreach ($this->platforms as $platform) { $platformsArray[] = $platform->getValue(); } $json['platforms'] = $platformsArray; } // Merge specific platforms informations return JsonUtils::mergeJsonSerializables($json, $this->aDM, $this->android, $this->blackBerry, $this->chrome, $this->iOS, $this->mac, $this->safari, $this->wNS, $this->wP); }
/** * Creates a JSON representation of this request. * * @return array a PHP which can be passed to the 'json_encode' PHP method. */ public function toJSON() { $json = array(); // Mandatory parameters $json['ignore_user_timezone'] = $this->ignoreUserTimezone; $json['send_date'] = is_string($this->sendDate) ? $this->sendDate : $this->sendDate->format('Y-m-d H:i'); // Optional parameters isset($this->content) ? $json['content'] = $this->content : false; isset($this->data) ? $json['data'] = $this->data : false; isset($this->devices) ? $json['devices'] = $this->devices : false; isset($this->filter) ? $json['filter'] = $this->filter : false; isset($this->link) ? $json['link'] = $this->link : false; isset($this->minimizeLink) ? $json['minimize_link'] = $this->minimizeLink->getValue() : false; isset($this->pageId) ? $json['page_id'] = $this->pageId : false; if (isset($this->conditions)) { $conditionsArray = array(); foreach ($this->conditions as $condition) { $conditionsArray[] = $condition->toJSON(); } $json['conditions'] = $conditionsArray; } if (isset($this->platforms)) { $platformsArray = array(); foreach ($this->platforms as $platform) { $platformsArray[] = $platform->getValue(); } $json['platforms'] = $platformsArray; } // Amazon Device Messaging specific informations if (isset($this->aDM)) { foreach ($this->aDM->toJSON() as $key => $value) { $json[$key] = $value; } } // Android specific informations if (isset($this->android)) { foreach ($this->android->toJSON() as $key => $value) { $json[$key] = $value; } } // BlackBerry specific informations if (isset($this->blackBerry)) { foreach ($this->blackBerry->toJSON() as $key => $value) { $json[$key] = $value; } } // iOS specific informations if (isset($this->iOS)) { foreach ($this->iOS->toJSON() as $key => $value) { $json[$key] = $value; } } // Mac specific informations if (isset($this->mac)) { foreach ($this->mac->toJSON() as $key => $value) { $json[$key] = $value; } } // Safari specific informations if (isset($this->safari)) { foreach ($this->safari->toJSON() as $key => $value) { $json[$key] = $value; } } // Windows Notification Service specific informations if (isset($this->wNS)) { foreach ($this->wNS->toJSON() as $key => $value) { $json[$key] = $value; } } // Windows Phone specific informations if (isset($this->wP)) { foreach ($this->wP->toJSON() as $key => $value) { $json[$key] = $value; } } return $json; }