public function testFromArray()
 {
     $str = '
     {
         "AdsResponse": {
             "Ads": {
                 "Type": "thirdparty",
                     "ClickUrl": "http://att.com",
                     "TrackUrl": "http://att.com",
                     "Text": "",
                     "Content":"fds"
             }
         }
     }  
     ';
     $arr = json_decode($str, true);
     $r = ADSResponse::fromArray($arr);
     $this->assertEquals($r->getClickUrl(), 'http://att.com');
     $this->assertEquals($r->getADSType(), 'thirdparty');
     $this->assertTrue($r->getImageUrl() == null);
     $this->assertEquals($r->getTrackUrl(), 'http://att.com');
     $this->assertEquals($r->getContent(), 'fds');
 }
Beispiel #2
0
 /**
  * Sends a request to the API for getting an advertisement. 
  * 
  * @param string       $category  category of this app.
  * @param string       $userAgent user agent string to send to API.
  * @param string       $udid      specifies a universially unique
  *                                identifier, which must be at least 30
  *                                characters in length.
  * @param OptArgs|null $optArgs   any optional values.
  *
  * @return null|ADSResponse null if no ads were returned, 
  *                          otherwise an ADSResponse object
  * @throws ServiceException if API request was not successful
  */
 public function getAdvertisement($category, $userAgent, $udid, OptArgs $optArgs = null, $raw_response = false)
 {
     $endpoint = $this->getFqdn() . '/rest/1/ads';
     $req = new RestfulRequest($endpoint);
     $req->setAuthorizationHeader($this->getToken())->setHeader('User-agent', $userAgent)->setHeader('Udid', $udid);
     $httpGet = new HttpGet();
     $httpGet->setParam('Category', $category);
     if ($optArgs != null) {
         $this->_appendOptArgs($httpGet, $optArgs);
     }
     $result = $req->sendHttpGet($httpGet);
     // no ads returned
     if ($result->getResponseCode() == 204) {
         if ($raw_response) {
             return $result->getResponseBody();
         }
         return null;
     }
     if ($raw_response) {
         return Service::parseApiResposeBody($result);
     }
     // response as json array
     $jarr = Service::parseJson($result);
     return ADSResponse::fromArray($jarr);
 }