Overview

Namespaces

  • Genetsis
    • core
      • activityid
      • user
  • None

Classes

  • Genetsis\ActivityApi
  • Genetsis\AutoloaderClass
  • Genetsis\Config
  • Genetsis\core\AccessToken
  • Genetsis\core\activityid\Address
  • Genetsis\core\activityid\ContextType
  • Genetsis\core\activityid\Device
  • Genetsis\core\activityid\Location
  • Genetsis\core\activityid\ObjectType
  • Genetsis\core\activityid\Position
  • Genetsis\core\activityid\QualityType
  • Genetsis\core\activityid\Request
  • Genetsis\core\activityid\Response
  • Genetsis\core\activityid\SocialNetwork
  • Genetsis\core\activityid\Verbs
  • Genetsis\core\ClientToken
  • Genetsis\core\Encryption
  • Genetsis\core\FileCache
  • Genetsis\core\LogConfig
  • Genetsis\core\LoginStatus
  • Genetsis\core\LoginStatusType
  • Genetsis\core\OAuth
  • Genetsis\core\OAuthConfig
  • Genetsis\core\OauthTemplate
  • Genetsis\core\RefreshToken
  • Genetsis\core\Request
  • Genetsis\core\StoredToken
  • Genetsis\core\Things
  • Genetsis\core\User
  • Genetsis\core\user\Brand
  • Genetsis\core\user\QueryUserData
  • Genetsis\Identity
  • Genetsis\URLBuilder
  • Genetsis\UserApi
  • Logger
  • LoggerAppender
  • LoggerAppenderConsole
  • LoggerAppenderDailyFile
  • LoggerAppenderDailyRollingFile
  • LoggerAppenderEcho
  • LoggerAppenderFile
  • LoggerAppenderFirePHP
  • LoggerAppenderMail
  • LoggerAppenderMailEvent
  • LoggerAppenderMongoDB
  • LoggerAppenderNull
  • LoggerAppenderPDO
  • LoggerAppenderPhp
  • LoggerAppenderPool
  • LoggerAppenderRollingFile
  • LoggerAppenderSocket
  • LoggerAppenderSyslog
  • LoggerAutoloader
  • LoggerConfigurable
  • LoggerConfigurationAdapterINI
  • LoggerConfigurationAdapterPHP
  • LoggerConfigurationAdapterXML
  • LoggerConfiguratorDefault
  • LoggerFilter
  • LoggerFilterDenyAll
  • LoggerFilterLevelMatch
  • LoggerFilterLevelRange
  • LoggerFilterStringMatch
  • LoggerFormattingInfo
  • LoggerHierarchy
  • LoggerLayout
  • LoggerLayoutHtml
  • LoggerLayoutPattern
  • LoggerLayoutSerialized
  • LoggerLayoutSimple
  • LoggerLayoutTTCC
  • LoggerLayoutXml
  • LoggerLevel
  • LoggerLocationInfo
  • LoggerLoggingEvent
  • LoggerMDC
  • LoggerNDC
  • LoggerOptionConverter
  • LoggerPatternConverter
  • LoggerPatternConverterClass
  • LoggerPatternConverterCookie
  • LoggerPatternConverterDate
  • LoggerPatternConverterEnvironment
  • LoggerPatternConverterFile
  • LoggerPatternConverterLevel
  • LoggerPatternConverterLine
  • LoggerPatternConverterLiteral
  • LoggerPatternConverterLocation
  • LoggerPatternConverterLogger
  • LoggerPatternConverterMDC
  • LoggerPatternConverterMessage
  • LoggerPatternConverterMethod
  • LoggerPatternConverterNDC
  • LoggerPatternConverterNewLine
  • LoggerPatternConverterProcess
  • LoggerPatternConverterRelative
  • LoggerPatternConverterRequest
  • LoggerPatternConverterServer
  • LoggerPatternConverterSession
  • LoggerPatternConverterSessionID
  • LoggerPatternConverterSuperglobal
  • LoggerPatternConverterThrowable
  • LoggerPatternParser
  • LoggerReflectionUtils
  • LoggerRendererDefault
  • LoggerRendererException
  • LoggerRendererMap
  • LoggerRoot
  • LoggerThrowableInformation
  • LoggerUtils

Interfaces

  • Genetsis\core\iTokenTypes
  • LoggerConfigurationAdapter
  • LoggerConfigurator
  • LoggerRenderer

Exceptions

  • Genetsis\core\InvalidGrantException
  • LoggerException
  • Overview
  • Namespace
  • Class
   1: <?php
   2: namespace Genetsis;
   3: 
   4: use Exception;
   5: use Genetsis\core\activityid\Location;
   6: use Genetsis\core\activityid\ObjectType;
   7: use Genetsis\core\activityid\Request;
   8: use Genetsis\core\activityid\Response;
   9: use Genetsis\core\activityid\SocialNetwork;
  10: use Genetsis\core\activityid\Verbs;
  11: use Genetsis\core\OAuthConfig;
  12: use Genetsis\core\Request as IDRequest;
  13: 
  14: /**
  15:  * This is a statistical REST service populated from user-generated web content.
  16:  *
  17:  * This service will be consumable only by those client applications that are and will be integrated with,
  18:  * regardless of ownership or platform. The enrollment process to use this service is part of the ID service.
  19:  *
  20:  * Finally, the core of the project for representing potential and completed activities and names and syntax conventions
  21:  * using JSON format is based on the effort of the JSON Activity Streams 2.0 model. Also, the core objectTypes and verbs used
  22:  * in these services are related to the Activity Streams - Base Schema
  23:  *
  24:  * {@link UserApi} makes calls internally to the Coca-Cola.es API to
  25:  * request user data Activity
  26:  *
  27:  * @package   Genetsis
  28:  * @category  Bean
  29:  * @version   2.0
  30:  * @access    public
  31:  * @author    Javier Ferrero
  32:  * @revision  Israel Dominguez
  33:  * @see       http://docs.cocacola.es
  34:  * @todo      Review source code.
  35:  */
  36: class ActivityApi
  37: {
  38: 
  39:     /**
  40:      * Genetsis ID user participate actively in a promotion.
  41:      * This interaction is generated by an application after verify that the requirements for participation in the promotion are met.
  42:      * Indicates that Genetsis ID user has requested the object. It is very important for the agency to call this method when the agency has successfully registered the participation in its application, to avoid method calls that do not correspond with real participations
  43:      *
  44:      * @param Request $request
  45:      *  $request->setUserId: (optional) Id of Genetsis ID user (ckusid) who participates in the promotion, if ckusid is not specified, the user logged is sent, but you must check if an user is connected.
  46:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
  47:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
  48:      *
  49:      * @return Response Return a list of InteractionsObject. The list contains one object corresponding to each object created or used in the interaction. Each object contains the object id and the object type. In this case is the object id of the promotion associated to the section
  50:      * @throws \Exception If there is an error in the response.
  51:      */
  52:     public static function Participate($request)
  53:     {
  54:         try {
  55:             self::setSecured($request);
  56: 
  57:             $params = array(
  58:                 'actor' => array(
  59:                     'id' => $request->getUserId(),
  60:                     'objectType' => ObjectType::PERSON
  61:                 ),
  62:                 'verb' => Verbs::REQUEST,
  63:                 'object' => array(
  64:                     'objectType' => ObjectType::GAME,
  65:                     'id' => $request->getObjectId()
  66:                 )
  67:             );
  68: 
  69:             self::checkSource($params, $request->getSource());
  70: 
  71:             $response = IDRequest::execute(
  72:                 self::getUrlRequest('participate'),
  73:                 $params,
  74:                 IDRequest::HTTP_POST,
  75:                 IDRequest::NOT_SECURED,
  76:                 self::setHeaders($request->getSectionName())
  77:             );
  78: 
  79:             return self::checkStatus($response);
  80:         } catch (Exception $e) {
  81:             Identity::getLogger()->error($e->getMessage());
  82:             throw $e;
  83:         }
  84:     }
  85: 
  86:     /**
  87:      * An administrator rejects the participation of a user that not fulfilled a condition of participation in a promotion.
  88:      * Indicates that the administrator has rejected the participation in the promotion. Its commonly used for promotions that require a vertification of the participation (i.e: a consumer must upload a photo to participate, and a moderator must deny it in because is invalid for the promotion
  89:      *
  90:      * @param Request $request
  91:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
  92:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
  93:      *
  94:      * @return Response Return a list of InteractionsObject. The list contains one object corresponding to each object created or used in the interaction. Each object contains the object id and the object type. In this case is the object id of the promotion associated to the section
  95:      * @throws \Exception If there is an error in the response.
  96:      */
  97:     public static function rejectParticipation($request)
  98:     {
  99:         try {
 100:             self::setSecured($request, false);
 101: 
 102:             $params = array(
 103:                 'actor' => array(
 104:                     'id' => $request->getUserId(),
 105:                     'objectType' => ObjectType::APPLICATION
 106:                 ),
 107:                 'verb' => Verbs::REJECT,
 108:                 'object' => array(
 109:                     'id' => $request->getObjectId(),
 110:                     'objectType' => ObjectType::GAME
 111:                 )
 112:             );
 113: 
 114:             self::checkSource($params, $request->getSource());
 115: 
 116:             $response = IDRequest::execute(
 117:                 self::getUrlRequest('reject_participation'),
 118:                 $params,
 119:                 IDRequest::HTTP_POST,
 120:                 IDRequest::NOT_SECURED,
 121:                 self::setHeaders($request->getSectionName())
 122:             );
 123: 
 124:             return self::checkStatus($response);
 125:         } catch (Exception $e) {
 126:             Identity::getLogger()->error($e->getMessage());
 127:             throw $e;
 128:         }
 129:     }
 130: 
 131:     /**
 132:      * Genetsis ID user wins a prize from a promotion.
 133:      * Indicates that Genetsis ID user has won the prize. This verb is typically applicable only when the object represents some form of promotion.
 134:      * The prize MUST be registered in your configuration by an administrator during the activity on boarding proccess
 135:      *
 136:      * @param Request $request
 137:      *  $request->setUserId: (optional) Id of Genetsis ID user (ckusid) who participates in the promotion, if ckusid is not specified, the user logged is sent, but previously you must check if an user is connected.
 138:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
 139:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
 140:      *  $request->
 141:      *
 142:      * @return Response Return a list of InteractionsObject. The list contains one object corresponding to each object created or used in the interaction. Each object contains the object id and the object type. In this case is the object id of the unit prize contained by the prize, and used in the interaction
 143:      * @throws \Exception If there is an error in the response.
 144:      */
 145:     public static function winPrize($request)
 146:     {
 147:         try {
 148:             self::setSecured($request);
 149: 
 150:             if (self::checkParam($request->getObjectId())) {
 151:                 throw new Exception('A valid Prize Key is mandatory');
 152:             }
 153: 
 154:             $params = array(
 155:                 'actor' => array(
 156:                     'id' => $request->getUserId(),
 157:                     'objectType' => ObjectType::PERSON
 158:                 ),
 159:                 'verb' => Verbs::WIN,
 160:                 'object' => array(
 161:                     'objectType' => ObjectType::PRODUCT,
 162:                     'prize' => array(
 163:                         'key' => $request->getObjectId()
 164:                     )
 165:                 )
 166:             );
 167: 
 168:             self::checkSource($params, $request->getSource());
 169: 
 170:             $response = IDRequest::execute(
 171:                 self::getUrlRequest('win_prize_content'),
 172:                 $params,
 173:                 IDRequest::HTTP_POST,
 174:                 IDRequest::NOT_SECURED,
 175:                 self::setHeaders($request->getSectionName())
 176:             );
 177: 
 178:             return self::checkStatus($response);
 179:         } catch (Exception $e) {
 180:             Identity::getLogger()->error($e->getMessage());
 181:             throw $e;
 182:         }
 183:     }
 184: 
 185:     /**
 186:      * Genetsis ID user share content on social networks or through other digital media.
 187:      * Indicates that Genetsis ID user has called out the object to readers.
 188:      * In most cases, Genetsis ID user did not create the object being shared, but is instead drawing attention to it.
 189:      * The activityObject can be an object of type Video, Image, Audio, Comment, Article or Note.
 190:      * The interaction is considered done by the logged user
 191:      *
 192:      * @param Request $request
 193:      *  $request->setUserId: (optional) Id of Genetsis ID user (ckusid) who participates in the promotion, if ckusid is not specified, the user logged is sent, but previously you must check if an user is connected.
 194:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
 195:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
 196:      *
 197:      * @return Response Return a list of InteractionsObject. The list contains one object corresponding to each object created or used in the interaction. Each object contains the object id and the object type. The id of the objects must be persisted in the agency database in order to generate future interactions that refers this objects (i.e: report a content)
 198:      * @throws \Exception If there is an error in the response.
 199:      */
 200:     public static function share($request)
 201:     {
 202:         try {
 203:             self::setSecured($request);
 204: 
 205:             $params = array(
 206:                 'actor' => array(
 207:                     'id' => $request->getUserId(),
 208:                     'objectType' => ObjectType::PERSON
 209:                 ),
 210:                 'verb' => Verbs::SHARE,
 211:                 'object' => array(
 212:                     'id' => '1',
 213:                     'objectType' => $request->getObjectType(),
 214:                     'displayName' => $request->getDisplayName(),
 215:                     'url' => $request->getUrl()
 216:                 ),
 217:                 'target' => array(
 218:                     'id' => $request->getTargetId(),
 219:                     'objectType' => ObjectType::APPLICATION
 220:                 )
 221:             );
 222: 
 223:             self::checkSource($params, $request->getSource());
 224: 
 225:             $response = IDRequest::execute(
 226:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('share')),
 227:                 $params,
 228:                 IDRequest::HTTP_POST,
 229:                 IDRequest::NOT_SECURED,
 230:                 self::setHeaders($request->getSectionName())
 231:             );
 232: 
 233:             return self::checkStatus($response);
 234:         } catch (Exception $e) {
 235:             Identity::getLogger()->error($e->getMessage());
 236:             throw $e;
 237:         }
 238:     }
 239: 
 240:     /**
 241:      * Genetsis ID user has completed a question or a poll.
 242:      *
 243:      * @param Request $request
 244:      *  $request->setUserId: (optional) Id of Genetsis ID user (ckusid) who participates in the promotion, if ckusid is not specified, the user logged is sent, but previously you must check if an user is connected.
 245:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
 246:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
 247:      *
 248:      * @return Response
 249:      * @throws \Exception  If there is an error in the response.
 250:      */
 251:     public static function fillSurvey($request)
 252:     {
 253:         try {
 254:             self::setSecured($request);
 255: 
 256:             if (self::checkParam($request->getObjectId())) {
 257:                 $request->setObjectId('1');
 258:             }
 259: 
 260:             $params = array(
 261:                 'actor' => array(
 262:                     'id' => $request->getUserId(),
 263:                     'objectType' => ObjectType::PERSON
 264:                 ),
 265:                 'verb' => Verbs::COMPLETE,
 266:                 'object' => array(
 267:                     'id' => $request->getObjectId(),
 268:                     'objectType' => ObjectType::QUESTION,
 269:                     'displayName' => $request->getDisplayName(),
 270:                     'url' => $request->getUrl()
 271:                 )
 272:             );
 273: 
 274:             self::checkSource($params, $request->getSource());
 275: 
 276:             $response = IDRequest::execute(
 277:                 self::getUrlRequest('fill_survey'),
 278:                 $params,
 279:                 IDRequest::HTTP_POST,
 280:                 IDRequest::NOT_SECURED,
 281:                 self::setHeaders($request->getSectionName())
 282:             );
 283: 
 284:             return self::checkStatus($response);
 285:         } catch (Exception $e) {
 286:             Identity::getLogger()->error($e->getMessage());
 287:             throw $e;
 288:         }
 289:     }
 290: 
 291:     /**
 292:      * Genetsis ID user upload a content of type: video, image or audio. Indicates that Genetsis ID user has created the object.
 293:      *
 294:      * @param Request $request
 295:      *  $request->setUserId: (optional) Id of Genetsis ID user (ckusid) who participates in the promotion, if ckusid is not specified, the user logged is sent, but previously you must check if an user is connected.
 296:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
 297:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
 298:      *
 299:      * @return Response
 300:      * @throws \Exception If there is an error in the response.
 301:      */
 302:     public static function uploadUGC($request)
 303:     {
 304:         try {
 305:             self::setSecured($request);
 306: 
 307:             if (self::checkParam($request->getObjectType())) {
 308:                 throw new Exception('Object Type is mandatory');
 309:             }
 310: 
 311:             $params = array(
 312:                 'actor' => array(
 313:                     'id' => $request->getUserId(),
 314:                     'objectType' => ObjectType::PERSON
 315:                 ),
 316:                 'verb' => Verbs::CREATE,
 317:                 'object' => array(
 318:                     'objectType' => $request->getObjectType(),
 319:                     'displayName' => $request->getDisplayName(),
 320:                     'url' => $request->getUrl()
 321:                 )
 322:             );
 323: 
 324:             self::checkSource($params, $request->getSource());
 325: 
 326:             $response = IDRequest::execute(
 327:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('upload_ugc')),
 328:                 $params,
 329:                 IDRequest::HTTP_POST,
 330:                 IDRequest::NOT_SECURED,
 331:                 self::setHeaders($request->getSectionName())
 332:             );
 333: 
 334:             return self::checkStatus($response);
 335:         } catch (Exception $e) {
 336:             Identity::getLogger()->error($e->getMessage());
 337:             throw $e;
 338:         }
 339:     }
 340: 
 341:     /**
 342:      * Genetsis ID user delete a previously uploaded content of type: video, image or audio. Indicates that Genetsis ID user has deleted the object.
 343:      *
 344:      * @param Request $request
 345:      *  $request->setUserId: (optional) Id of Genetsis ID user (ckusid) who participates in the promotion, if ckusid is not specified, the user logged is sent, but previously you must check if an user is connected.
 346:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
 347:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
 348:      *
 349:      * @return Response
 350:      * @throws \Exception If there is an error in the response.
 351:      */
 352:     public static function deleteUGC($request)
 353:     {
 354:         try {
 355:             self::setSecured($request);
 356: 
 357:             if (self::checkParam($request->getObjectId())) {
 358:                 throw new Exception('Object Id is mandatory');
 359:             }
 360: 
 361:             if (self::checkParam($request->getObjectType())) {
 362:                 throw new Exception('Object Type is mandatory');
 363:             }
 364: 
 365:             $params = array(
 366:                 'actor' => array(
 367:                     'id' => $request->getUserId(),
 368:                     'objectType' => ObjectType::PERSON
 369:                 ),
 370:                 'verb' => Verbs::DELETE,
 371:                 'object' => array(
 372:                     'id' => $request->getObjectId(),
 373:                     'objectType' => $request->getObjectType(),
 374:                 )
 375:             );
 376: 
 377:             self::checkSource($params, $request->getSource());
 378: 
 379:             $response = IDRequest::execute(
 380:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('delete_ugc')),
 381:                 $params,
 382:                 IDRequest::HTTP_POST,
 383:                 IDRequest::NOT_SECURED,
 384:                 self::setHeaders($request->getSectionName())
 385:             );
 386: 
 387:             return self::checkStatus($response);
 388:         } catch (Exception $e) {
 389:             Identity::getLogger()->error($e->getMessage());
 390:             throw $e;
 391:         }
 392:     }
 393: 
 394:     /**
 395:      * Genetsis ID user (system moderator) reject a previously uploaded content of type: video, image or audio.
 396:      *
 397:      * @param Request $request
 398:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
 399:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
 400:      *
 401:      * @return Response
 402:      * @throws \Exception If there is an error in the response.
 403:      */
 404:     public static function rejectUGC($request)
 405:     {
 406:         try {
 407:             self::setSecured($request, false);
 408: 
 409:             if (self::checkParam($request->getObjectType())) {
 410:                 throw new Exception('Object Type is mandatory');
 411:             }
 412: 
 413:             $params = array(
 414:                 'actor' => array(
 415:                     'id' => $request->getUserId(),
 416:                     'objectType' => ObjectType::APPLICATION
 417:                 ),
 418:                 'verb' => Verbs::REJECT,
 419:                 'object' => array(
 420:                     'id' => $request->getObjectId(),
 421:                     'objectType' => $request->getObjectType()
 422:                 )
 423:             );
 424: 
 425:             self::checkSource($params, $request->getSource());
 426: 
 427:             $response = IDRequest::execute(
 428:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('reject_ugc')),
 429:                 $params,
 430:                 IDRequest::HTTP_POST,
 431:                 IDRequest::NOT_SECURED,
 432:                 self::setHeaders($request->getSectionName())
 433:             );
 434: 
 435:             return self::checkStatus($response);
 436:         } catch (Exception $e) {
 437:             Identity::getLogger()->error($e->getMessage());
 438:             throw $e;
 439:         }
 440:     }
 441: 
 442:     /**
 443:      * The actor votes for a user-generated content.
 444:      * Related to an objectType Rating, given as a number between 1.0 and 5.0 inclusive with one decimal place of precision.
 445:      *
 446:      * @param Request $request
 447:      *  $request->setUserId: (optional) Id of Genetsis ID user (ckusid) who participates in the promotion, if ckusid is not specified, the user logged is sent, but previously you must check if an user is connected.
 448:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
 449:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
 450:      *
 451:      * @return Response
 452:      * @throws \Exception If there is an error in the response.
 453:      */
 454:     public static function voteUGC($request)
 455:     {
 456:         try {
 457:             self::setSecured($request);
 458: 
 459:             if (self::checkParam($request->getRating())) {
 460:                 throw new Exception('Rating is mandatory');
 461:             } else {
 462:                 if ($request->getRating() < 1 || $request->getRating() > 5) {
 463:                     throw new Exception('Rating value is not valid');
 464:                 }
 465:             }
 466: 
 467:             if (self::checkParam($request->getTargetObjectType())) {
 468:                 throw new Exception('Target Object Type is mandatory');
 469:             }
 470: 
 471:             if (self::checkParam($request->getTargetId())) {
 472:                 $request->setTargetId('1');
 473:             }
 474: 
 475:             $params = array(
 476:                 'actor' => array(
 477:                     'id' => $request->getUserId(),
 478:                     'objectType' => ObjectType::PERSON
 479:                 ),
 480:                 'verb' => Verbs::CREATE,
 481:                 'object' => array(
 482:                     'objectType' => ObjectType::REVIEW,
 483:                     'rating' => $request->getRating()
 484:                 ),
 485:                 'target' => array(
 486:                     'objectType' => $request->getTargetObjectType(),
 487:                     'id' => $request->getTargetId()
 488:                 )
 489:             );
 490: 
 491:             self::checkSource($params, $request->getSource());
 492: 
 493:             $response = IDRequest::execute(
 494:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('vote_ugc')),
 495:                 $params,
 496:                 IDRequest::HTTP_POST,
 497:                 IDRequest::NOT_SECURED,
 498:                 self::setHeaders($request->getSectionName())
 499:             );
 500: 
 501:             return self::checkStatus($response);
 502:         } catch (Exception $e) {
 503:             Identity::getLogger()->error($e->getMessage());
 504:             throw $e;
 505:         }
 506:     }
 507: 
 508:     /**
 509:      * The actor has updated or modified the object. The use of the update verb is generally reserved to indicate modifications
 510:      * to existing objects or data such as changing an existing user's profile information.
 511:      *
 512:      * @param Request $request
 513:      * @return Response
 514:      * @throws \Exception If there is an error in the response.
 515:      */
 516:     public static function editUGC($request)
 517:     {
 518:         try {
 519:             self::setSecured($request);
 520: 
 521:             $params = array(
 522:                 'actor' => array(
 523:                     'id' => $request->getUserId(),
 524:                     'objectType' => ObjectType::PERSON
 525:                 ),
 526:                 'verb' => Verbs::UPDATE,
 527:                 'object' => array(
 528:                     'id' => $request->getObjectId(),
 529:                     'objectType' => $request->getObjectType(),
 530:                     'displayName' => $request->getDisplayName(),
 531:                     'url' => $request->getUrl()
 532:                 )
 533:             );
 534: 
 535:             self::checkSource($params, $request->getSource());
 536: 
 537:             $response = IDRequest::execute(
 538:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('edit_ugc')),
 539:                 $params,
 540:                 IDRequest::HTTP_POST,
 541:                 IDRequest::NOT_SECURED,
 542:                 self::setHeaders($request->getSectionName())
 543:             );
 544: 
 545:             return self::checkStatus($response);
 546:         } catch (Exception $e) {
 547:             Identity::getLogger()->error($e->getMessage());
 548:             throw $e;
 549:         }
 550:     }
 551: 
 552:     /**
 553:      * The actor has consumed the object. The object.objectType property may take the value: video, image or audio.
 554:      * The specific meaning is dependent largely on the object's type.
 555:      * For instance, an actor may "consume" an audio object, indicating that the actor has listened to it;
 556:      * or an actor may "consume" a video, indicating that the video has been watched.
 557:      *
 558:      * @param Request $request
 559:      * @return Response
 560:      * @throws \Exception If there is an error in the response.
 561:      */
 562:     public static function viewUGC($request)
 563:     {
 564:         try {
 565:             self::setSecured($request);
 566: 
 567:             if (self::checkParam($request->getObjectId())) {
 568:                 $request->setObjectId('1');
 569:             }
 570: 
 571:             if (self::checkParam($request->getObjectType())) {
 572:                 throw new Exception('Object Type is mandatory');
 573:             }
 574: 
 575:             $params = array(
 576:                 'actor' => array(
 577:                     'id' => $request->getUserId(),
 578:                     'objectType' => ObjectType::PERSON
 579:                 ),
 580:                 'verb' => Verbs::CONSUME,
 581:                 'object' => array(
 582:                     'id' => $request->getObjectId(),
 583:                     'objectType' => $request->getObjectType(),
 584:                     'displayName' => $request->getDisplayName(),
 585:                     'url' => $request->getUrl()
 586:                 )
 587:             );
 588: 
 589:             self::checkSource($params, $request->getSource());
 590: 
 591:             $response = IDRequest::execute(
 592:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('view_ugc')),
 593:                 $params,
 594:                 IDRequest::HTTP_POST,
 595:                 IDRequest::NOT_SECURED,
 596:                 self::setHeaders($request->getSectionName())
 597:             );
 598: 
 599:             return self::checkStatus($response);
 600:         } catch (Exception $e) {
 601:             Identity::getLogger()->error($e->getMessage());
 602:             throw $e;
 603:         }
 604:     }
 605: 
 606:     /**
 607:      * Genetsis ID user has created a comment. It must contains an additional property: quality, to give a “revised” rating of the review.
 608:      * This property may have the values NEGATIVE, POSITIVE or NEUTRAL, refering the sentimenal meaning of the comment associated with brand values.
 609:      * Represents a textual response to another object. Comment of this type MUST contain an additional activity object for which is to be considered a response.
 610:      *
 611:      * @param Request $request
 612:      *  $request->setUserId: (optional) Id of Genetsis ID user (ckusid) who participates in the promotion, if ckusid is not specified, the user logged is sent, but previously you must check if an user is connected.
 613:      *  $request->setSectionName: (optional) If you have only one section or is the default section, you do not need pass it. The section received is located in oauthconf.xml file.
 614:      *  $request->setSource: (optional) You can set the Device (pc, tablet, mobile,...) origin of the interaction, If source is not specified by default UserAgent is sent.
 615:      *
 616:      * @return Response
 617:      * @throws \Exception If there is an error in the response.
 618:      */
 619:     public static function comment($request)
 620:     {
 621:         try {
 622:             self::setSecured($request);
 623: 
 624:             if (self::checkParam($request->getQuality())) {
 625:                 throw new Exception('Type of comment is mandatory');
 626:             }
 627:             if (self::checkParam($request->getInReplyToId())) {
 628:                 throw new Exception('Object Id replay To is mandatory');
 629:             }
 630:             if (self::checkParam($request->getInReplyToObjectType())) {
 631:                 throw new Exception('Object Type replay To is mandatory');
 632:             }
 633:             if (self::checkParam($request->getContent())) {
 634:                 throw new Exception('Comment content is mandatory');
 635:             }
 636: 
 637:             $params = array(
 638:                 'actor' => array(
 639:                     'id' => $request->getUserId(),
 640:                     'objectType' => ObjectType::PERSON
 641:                 ),
 642:                 'verb' => Verbs::CREATE,
 643:                 'object' => array(
 644:                     'id' => $request->getObjectId(),
 645:                     'objectType' => ObjectType::COMMENT,
 646:                     'url' => $request->getUrl(),
 647:                     'content' => $request->getContent(),
 648:                     'quality' => $request->getQuality(),
 649:                     'inReplyTo' => array(
 650:                         'id' => $request->getInReplyToId(),
 651:                         'objectType' => $request->getInReplyToObjectType(),
 652:                         'url' => $request->getInReplyToUrl(),
 653:                         'displayName' => $request->getInReplyToDisplayName()
 654:                     )
 655:                 )
 656:             );
 657: 
 658:             self::checkSource($params, $request->getSource());
 659: 
 660:             $response = IDRequest::execute(
 661:                 self::getUrlRequest('negative_comment'),
 662:                 $params,
 663:                 IDRequest::HTTP_POST,
 664:                 IDRequest::NOT_SECURED,
 665:                 self::setHeaders($request->getSectionName())
 666:             );
 667: 
 668:             return self::checkStatus($response);
 669:         } catch (Exception $e) {
 670:             Identity::getLogger()->error($e->getMessage());
 671:             throw $e;
 672:         }
 673:     }
 674: 
 675:     /**
 676:      * The actor report a violation of privacy or terms and conditions of a content.
 677:      * Indicates that the actor has flagged the object as being inappropriate for some reason.
 678:      * The context property can be used to provide additional detail about why the object has been flagged.
 679:      * Related to an objectType: issue, that represents a report about a problem or situation that needs to be resolved.
 680:      *
 681:      * The context property is defined in the Context section of the Activity Streams Schema.
 682:      * The context.type property CAN use one of the following values: advertisingContent, violentAbusiveOffensive,
 683:      * sexualInappropriateProhibited, meWithoutPermission, sendMeAdvertising, sendMeInappropriateProhibited or threateningHarassingInsultingMe
 684:      *
 685:      * @param Request $request
 686:      * @return Response
 687:      * @throws \Exception If there is an error in the response.
 688:      */
 689:     public static function report($request)
 690:     {
 691:         try {
 692:             self::setSecured($request);
 693: 
 694:             if (self::checkParam($request->getObjectType())) {
 695:                 throw new Exception('Object Type is mandatory');
 696:             }
 697: 
 698:             if (self::checkParam($request->getContextType())) {
 699:                 throw new Exception('Context Type is mandatory');
 700:             }
 701: 
 702:             $params = array(
 703:                 'actor' => array(
 704:                     'id' => $request->getUserId(),
 705:                     'objectType' => ObjectType::PERSON
 706:                 ),
 707:                 'verb' => Verbs::FLAG_AS_INAPPROPRIATE,
 708:                 'object' => array(
 709:                     'id' => $request->getObjectId(),
 710:                     'objectType' => $request->getObjectType(),
 711:                     'displayName' => $request->getDisplayName()
 712:                 ),
 713:                 'context' => array(
 714:                     'objectType' => ObjectType::ISSUE,
 715:                     'displayName' => $request->getContextDisplayName(),
 716:                     'type' => $request->getContextType()
 717:                 )
 718:             );
 719: 
 720:             self::checkSource($params, $request->getSource());
 721: 
 722:             $response = IDRequest::execute(
 723:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('report')),
 724:                 $params,
 725:                 IDRequest::HTTP_POST,
 726:                 IDRequest::NOT_SECURED,
 727:                 self::setHeaders($request->getSectionName())
 728:             );
 729: 
 730:             return self::checkStatus($response);
 731:         } catch (Exception $e) {
 732:             Identity::getLogger()->error($e->getMessage());
 733:             throw $e;
 734:         }
 735:     }
 736: 
 737:     /**
 738:      * The actor forward a generated content by TCCC on Twitter.
 739:      * The objectType note, represents a short-form text message.
 740:      * The object.id property is the Id of shared content generated by content owner (TCCC)
 741:      *
 742:      * @param Request $request
 743:      * @return Response
 744:      * @throws \Exception If there is an error in the response.
 745:      */
 746:     public static function retweet($request)
 747:     {
 748:         try {
 749:             self::setSecured($request);
 750: 
 751:             if (self::checkParam($request->getObjectId())) {
 752:                 $request->setObjectId('1');
 753:             }
 754: 
 755:             $params = array(
 756:                 'actor' => array(
 757:                     'id' => $request->getUserId(),
 758:                     'objectType' => ObjectType::PERSON
 759:                 ),
 760:                 'verb' => Verbs::SHARE,
 761:                 'object' => array(
 762:                     'id' => $request->getObjectId(),
 763:                     'objectType' => ObjectType::NOTE,
 764:                     'displayName' => $request->getDisplayName(),
 765:                     'url' => $request->getUrl()
 766:                 ),
 767:                 'target' => array(
 768:                     'id' => SocialNetwork::TWITTER,
 769:                     'objectType' => ObjectType::APPLICATION
 770:                 )
 771:             );
 772: 
 773:             self::checkSource($params, $request->getSource());
 774: 
 775:             $response = IDRequest::execute(
 776:                 self::getUrlRequest('retweet'),
 777:                 $params,
 778:                 IDRequest::HTTP_POST,
 779:                 IDRequest::NOT_SECURED,
 780:                 self::setHeaders($request->getSectionName())
 781:             );
 782: 
 783:             return self::checkStatus($response);
 784:         } catch (Exception $e) {
 785:             Identity::getLogger()->error($e->getMessage());
 786:             throw $e;
 787:         }
 788:     }
 789: 
 790:     /**
 791:      * The actor follow an account managed by TCCC on Twitter.
 792:      * The object.objectType person, represents an account managed by TCCC.
 793:      * Indicates that the actor began following the activity of the object.
 794:      *
 795:      * @param Request $request
 796:      * @return Response
 797:      * @throws \Exception If there is an error in the response.
 798:      */
 799:     public static function follow($request)
 800:     {
 801:         try {
 802:             self::setSecured($request);
 803: 
 804:             if (self::checkParam($request->getObjectId())) {
 805:                 $request->setObjectId('1');
 806:             }
 807: 
 808:             $params = array(
 809:                 'actor' => array(
 810:                     'id' => $request->getUserId(),
 811:                     'objectType' => ObjectType::PERSON
 812:                 ),
 813:                 'verb' => Verbs::FOLLOW,
 814:                 'object' => array(
 815:                     'id' => $request->getObjectId(),
 816:                     'objectType' => ObjectType::PERSON,
 817:                 )
 818:             );
 819: 
 820:             self::checkSource($params, $request->getSource());
 821: 
 822:             $response = IDRequest::execute(
 823:                 self::getUrlRequest('follow'),
 824:                 $params,
 825:                 IDRequest::HTTP_POST,
 826:                 IDRequest::NOT_SECURED,
 827:                 self::setHeaders($request->getSectionName())
 828:             );
 829: 
 830:             return self::checkStatus($response);
 831:         } catch (Exception $e) {
 832:             Identity::getLogger()->error($e->getMessage());
 833:             throw $e;
 834:         }
 835:     }
 836: 
 837:     /**
 838:      * The actor has marked in a positive way a content. Indicates that the actor marked the object as an item of special interest.
 839:      *
 840:      * @param Request $request
 841:      * @return Response
 842:      * @throws \Exception If there is an error in the response.
 843:      */
 844:     public static function like($request)
 845:     {
 846:         try {
 847:             self::setSecured($request);
 848: 
 849:             if (self::checkParam($request->getObjectId())) {
 850:                 $request->setObjectId('1');
 851:             }
 852: 
 853:             if (self::checkParam($request->getObjectType())) {
 854:                 throw new Exception('Object Type is mandatory');
 855:             }
 856: 
 857:             if (self::checkParam($request->getTargetId())) {
 858:                 throw new Exception('Social Network destiny is mandatory');
 859:             }
 860: 
 861:             $params = array(
 862:                 'actor' => array(
 863:                     'id' => $request->getUserId(),
 864:                     'objectType' => ObjectType::PERSON
 865:                 ),
 866:                 'verb' => Verbs::LIKE,
 867:                 'object' => array(
 868:                     'id' => $request->getObjectId(),
 869:                     'objectType' => $request->getObjectType()
 870:                 ),
 871:                 'target' => array(
 872:                     'id' => $request->getTargetId(),
 873:                     'objectType' => ObjectType::APPLICATION
 874:                 )
 875:             );
 876: 
 877:             self::checkSource($params, $request->getSource());
 878: 
 879:             $response = IDRequest::execute(
 880:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('like')),
 881:                 $params,
 882:                 IDRequest::HTTP_POST,
 883:                 IDRequest::NOT_SECURED,
 884:                 self::setHeaders($request->getSectionName())
 885:             );
 886: 
 887:             return self::checkStatus($response);
 888:         } catch (Exception $e) {
 889:             Identity::getLogger()->error($e->getMessage());
 890:             throw $e;
 891:         }
 892:     }
 893: 
 894:     /**
 895:      * The actor stopped marking positively a content. Indicates that the actor has removed the object from the collection of liked items
 896:      *
 897:      * @param Request $request
 898:      * @return Response
 899:      * @throws \Exception If there is an error in the response.
 900:      */
 901:     public static function unlike($request)
 902:     {
 903:         try {
 904:             self::setSecured($request);
 905: 
 906:             if (self::checkParam($request->getObjectId())) {
 907:                 $request->setObjectId('1');
 908:             }
 909: 
 910:             if (self::checkParam($request->getObjectType())) {
 911:                 throw new Exception('Object Type is mandatory');
 912:             }
 913: 
 914:             if (self::checkParam($request->getTargetId())) {
 915:                 throw new Exception('Social Network destiny is mandatory');
 916:             }
 917: 
 918:             $params = array(
 919:                 'actor' => array(
 920:                     'id' => $request->getUserId(),
 921:                     'objectType' => ObjectType::PERSON
 922:                 ),
 923:                 'verb' => Verbs::UNLIKE,
 924:                 'object' => array(
 925:                     'id' => $request->getObjectId(),
 926:                     'objectType' => $request->getObjectType()
 927:                 ),
 928:                 'target' => array(
 929:                     'id' => $request->getTargetId(),
 930:                     'objectType' => ObjectType::APPLICATION
 931:                 )
 932:             );
 933: 
 934:             self::checkSource($params, $request->getSource());
 935: 
 936:             $response = IDRequest::execute(
 937:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('unlike')),
 938:                 $params,
 939:                 IDRequest::HTTP_POST,
 940:                 IDRequest::NOT_SECURED,
 941:                 self::setHeaders($request->getSectionName())
 942:             );
 943: 
 944:             return self::checkStatus($response);
 945:         } catch (Exception $e) {
 946:             Identity::getLogger()->error($e->getMessage());
 947:             throw $e;
 948:         }
 949:     }
 950: 
 951:     /**
 952:      * Same as Vote UGC, except that the content was generated by TCCC, referred by the target property.
 953:      * Indicates that the actor votes for a Brand-generated content.
 954:      * Related to an objectType Rating, given as a number between 1.0 and 5.0 inclusive with one decimal place of precision.
 955:      *
 956:      * @param Request $request
 957:      * @throws \Exception If there is an error in the response.
 958:      * @return Response
 959:      */
 960:     public static function voteBrandContent($request)
 961:     {
 962:         try {
 963:             self::setSecured($request);
 964: 
 965:             if (self::checkParam($request->getRating())) {
 966:                 throw new Exception('Rating is mandatory');
 967:             } else {
 968:                 if ($request->getRating() < 1 || $request->getRating() > 5) {
 969:                     throw new Exception('Rating value is not valid');
 970:                 }
 971:             }
 972: 
 973:             if (self::checkParam($request->getTargetId())) {
 974:                 $request->setTargetId('1');
 975:             }
 976: 
 977:             if (self::checkParam($request->getTargetObjectType())) {
 978:                 throw new Exception('Target Type is mandatory');
 979:             }
 980: 
 981:             $params = array(
 982:                 'actor' => array(
 983:                     'id' => $request->getUserId(),
 984:                     'objectType' => ObjectType::PERSON
 985:                 ),
 986:                 'verb' => Verbs::CREATE,
 987:                 'object' => array(
 988:                     'objectType' => ObjectType::REVIEW,
 989:                     'rating' => $request->getRating()
 990:                 ),
 991:                 'target' => array(
 992:                     'objectType' => $request->getTargetObjectType(),
 993:                     'id' => $request->getTargetId()
 994:                 )
 995:             );
 996: 
 997:             self::checkSource($params, $request->getSource());
 998: 
 999:             $response = IDRequest::execute(
1000:                 self::getUrlRequest('vote_brand_content'),
1001:                 $params,
1002:                 IDRequest::HTTP_POST,
1003:                 IDRequest::NOT_SECURED,
1004:                 self::setHeaders($request->getSectionName())
1005:             );
1006: 
1007:             return self::checkStatus($response);
1008:         } catch (Exception $e) {
1009:             Identity::getLogger()->error($e->getMessage());
1010:             throw $e;
1011:         }
1012:     }
1013: 
1014:     /**
1015:      * Same as View UGC, except that the content was generated by TCCC, referred by the target property.
1016:      * Indicates that the actor has consumed the object.
1017:      * The object.objectType property may take the value: video, image or audio
1018:      *
1019:      * @param Request $request
1020:      * @throws \Exception If there is an error in the response.
1021:      * @return Response
1022:      */
1023:     public static function viewBrandContent($request)
1024:     {
1025:         try {
1026:             self::setSecured($request);
1027: 
1028:             if (self::checkParam($request->getObjectType())) {
1029:                 throw new Exception('Object Type is mandatory');
1030:             }
1031: 
1032:             $params = array(
1033:                 'actor' => array(
1034:                     'id' => $request->getUserId(),
1035:                     'objectType' => ObjectType::PERSON
1036:                 ),
1037:                 'verb' => Verbs::CONSUME,
1038:                 'object' => array(
1039:                     'id' => $request->getObjectId(),
1040:                     'objectType' => $request->getObjectType(),
1041:                     'displayName' => $request->getDisplayName()
1042:                 )
1043:             );
1044: 
1045:             self::checkSource($params, $request->getSource());
1046: 
1047:             $response = IDRequest::execute(
1048:                 str_replace('{objectType}', $request->getObjectType(), self::getUrlRequest('view_brand_content')),
1049:                 $params,
1050:                 IDRequest::HTTP_POST,
1051:                 IDRequest::NOT_SECURED,
1052:                 self::setHeaders($request->getSectionName())
1053:             );
1054: 
1055:             return self::checkStatus($response);
1056:         } catch (Exception $e) {
1057:             Identity::getLogger()->error($e->getMessage());
1058:             throw $e;
1059:         }
1060:     }
1061: 
1062:     /**
1063:      * Register a "Acceptance"
1064:      * @param Request $request
1065:      * @throws \Exception If there is an error in the response.
1066:      * @return Response
1067:      */
1068:     public static function acceptance($request)
1069:     {
1070:         try {
1071:             self::setSecured($request);
1072: 
1073:             $params = array(
1074:                 'actor' => array(
1075:                     'id' => $request->getUserId(),
1076:                     'objectType' => ObjectType::PERSON
1077:                 ),
1078:                 'verb' => Verbs::ACCEPT,
1079:                 'object' => array(
1080:                     'id' => $request->getObjectId(),
1081:                     'objectType' => ObjectType::PRODUCT,
1082:                     'displayName' => $request->getDisplayName(),
1083:                     'url' => $request->getUrl()
1084:                 )
1085:             );
1086: 
1087:             self::checkSource($params, $request->getSource());
1088: 
1089:             $response = IDRequest::execute(
1090:                 self::getUrlRequest('acceptance'),
1091:                 $params,
1092:                 IDRequest::HTTP_POST,
1093:                 IDRequest::NOT_SECURED,
1094:                 self::setHeaders($request->getSectionName())
1095:             );
1096: 
1097:             return self::checkStatus($response);
1098:         } catch (Exception $e) {
1099:             Identity::getLogger()->error($e->getMessage());
1100:             throw $e;
1101:         }
1102:     }
1103: 
1104:     /**
1105:      * The actor has participate in a physical or digital event generated by TCCC and is not in POS (Point of Sale).
1106:      * Indicates that the actor has attended the object
1107:      *
1108:      * @param Request $request
1109:      * @throws \Exception If there is an error in the response.
1110:      * @return Response
1111:      */
1112:     public static function eventAttendance($request)
1113:     {
1114:         try {
1115:             self::setSecured($request);
1116: 
1117:             $params = array(
1118:                 'actor' => array(
1119:                     'id' => $request->getUserId(),
1120:                     'objectType' => ObjectType::PERSON
1121:                 ),
1122:                 'verb' => Verbs::ATTEND,
1123:                 'object' => array(
1124:                     'id' => $request->getObjectId(),
1125:                     'objectType' => ObjectType::EVENT
1126:                 )
1127:             );
1128: 
1129:             self::checkSource($params, $request->getSource());
1130: 
1131:             $response = IDRequest::execute(
1132:                 self::getUrlRequest('event_attendance'),
1133:                 $params,
1134:                 IDRequest::HTTP_POST,
1135:                 IDRequest::NOT_SECURED,
1136:                 self::setHeaders($request->getSectionName())
1137:             );
1138: 
1139:             return self::checkStatus($response);
1140:         } catch (Exception $e) {
1141:             Identity::getLogger()->error($e->getMessage());
1142:             throw $e;
1143:         }
1144:     }
1145: 
1146:     /**
1147:      * The actor has created a friendship that is reciprocated by the object. Since this verb implies an
1148:      * activity on the part of its object, processors MUST NOT accept activities with this verb unless they
1149:      * are able to verify through some external means that there is in fact a reciprocated connection.
1150:      * For example, a processor may have received a guarantee from a particular publisher that the publisher
1151:      * will only use this Verb in cases where a reciprocal relationship exists.
1152:      *
1153:      * @param Request $request
1154:      * @throws \Exception If there is an error in the response.
1155:      * @return Response
1156:      */
1157:     public static function makeFriend($request)
1158:     {
1159:         try {
1160:             self::setSecured($request);
1161: 
1162:             if (self::checkParam($request->getObjectId())) {
1163:                 throw new Exception('Friend ID is mandatory');
1164:             }
1165: 
1166:             $params = array(
1167:                 'actor' => array(
1168:                     'id' => $request->getUserId(),
1169:                     'objectType' => ObjectType::PERSON
1170:                 ),
1171:                 'verb' => Verbs::MAKE_FRIEND,
1172:                 'object' => array(
1173:                     'id' => $request->getObjectId(),
1174:                     'objectType' => ObjectType::PERSON
1175:                 )
1176:             );
1177: 
1178:             self::checkSource($params, $request->getSource());
1179: 
1180:             $response = IDRequest::execute(
1181:                 self::getUrlRequest('make_a_friend'),
1182:                 $params,
1183:                 IDRequest::HTTP_POST,
1184:                 IDRequest::NOT_SECURED,
1185:                 self::setHeaders($request->getSectionName())
1186:             );
1187: 
1188:             return self::checkStatus($response);
1189:         } catch (Exception $e) {
1190:             Identity::getLogger()->error($e->getMessage());
1191:             throw $e;
1192:         }
1193:     }
1194: 
1195:     /**
1196:      * The actor has downloaded a free coupon from TCCC.
1197:      * Indicates that the actor is receiving an object.
1198:      * The object identifies the object being received.
1199:      *
1200:      * @param Request $request objectd
1201:      * @throws \Exception If there is an error in the response.
1202:      * @return Response
1203:      */
1204:     public static function downloadCoupon($request)
1205:     {
1206:         try {
1207:             self::setSecured($request);
1208: 
1209:             $params = array(
1210:                 'actor' => array(
1211:                     'id' => $request->getUserId(),
1212:                     'objectType' => ObjectType::PERSON
1213:                 ),
1214:                 'verb' => Verbs::RECEIVE,
1215:                 'object' => array(
1216:                     'id' => $request->getObjectId(),
1217:                     'objectType' => ObjectType::COUPON,
1218:                     'displayName' => $request->getDisplayName(),
1219:                     'url' => $request->getUrl()
1220:                 )
1221:             );
1222: 
1223:             self::checkSource($params, $request->getSource());
1224: 
1225:             $response = IDRequest::execute(
1226:                 self::getUrlRequest('download_coupon'),
1227:                 $params,
1228:                 IDRequest::HTTP_POST,
1229:                 IDRequest::NOT_SECURED,
1230:                 self::setHeaders($request->getSectionName())
1231:             );
1232: 
1233:             return self::checkStatus($response);
1234:         } catch (Exception $e) {
1235:             Identity::getLogger()->error($e->getMessage());
1236:             throw $e;
1237:         }
1238:     }
1239: 
1240:     /**
1241:      * Same as Download Coupon, except that the location property MUST be fulfilled.
1242:      * The actor has downloaded a free coupon from TCCC.
1243:      * Indicates that the actor is receiving an object. The object identifies the object being received.
1244:      * The location property is defined in the Location section of the Activity Stream Schema.
1245:      *
1246:      * @param Request $request
1247:      * @throws \Exception If there is an error in the response.
1248:      * @return Response
1249:      */
1250:     public static function downloadCouponPOS($request)
1251:     {
1252:         try {
1253:             self::setSecured($request);
1254: 
1255:             $location = Location::checkLocation($request->getLocation());
1256: 
1257:             $params = array(
1258:                 'actor' => array(
1259:                     'id' => $request->getUserId(),
1260:                     'objectType' => ObjectType::PERSON
1261:                 ),
1262:                 'verb' => Verbs::RECEIVE,
1263:                 'object' => array(
1264:                     'id' => $request->getObjectId(),
1265:                     'objectType' => ObjectType::COUPON,
1266:                     'displayName' => $request->getDisplayName(),
1267:                     'url' => $request->getUrl()
1268:                 ),
1269:                 'location' => $location
1270:             );
1271: 
1272:             self::checkSource($params, $request->getSource());
1273: 
1274:             $response = IDRequest::execute(
1275:                 self::getUrlRequest('download_coupon'),
1276:                 $params,
1277:                 IDRequest::HTTP_POST,
1278:                 IDRequest::NOT_SECURED,
1279:                 self::setHeaders($request->getSectionName())
1280:             );
1281: 
1282:             return self::checkStatus($response);
1283:         } catch (Exception $e) {
1284:             Identity::getLogger()->error($e->getMessage());
1285:             throw $e;
1286:         }
1287:     }
1288: 
1289:     /**
1290:      * The actor has Redeem a Coupon purchased or Downloaded at the Point of Sale of TCCC.
1291:      * Indicates that the actor has consumed the object from a Geo-Location.
1292:      * The location property MUST be fulfilled as defined in the Location section of the Activity Stream Schema.
1293:      * The object.id CAN be an id created as a result of an previously Downloaded / Redeemed Coupon or any other id from their own POS system.
1294:      * In Location info, an Address OR a Position are mandatory
1295:      *
1296:      * @param Request $request
1297:      * @throws \Exception If there is an error in the response.
1298:      * @return Response
1299:      */
1300:     public static function redeemCouponPOS($request)
1301:     {
1302:         try {
1303:             self::setSecured($request);
1304: 
1305:             $location = Location::checkLocation($request->getLocation());
1306: 
1307:             $params = array(
1308:                 'actor' => array(
1309:                     'id' => $request->getUserId(),
1310:                     'objectType' => ObjectType::PERSON
1311:                 ),
1312:                 'verb' => Verbs::CONSUME,
1313:                 'object' => array(
1314:                     'id' => $request->getObjectId(),
1315:                     'objectType' => ObjectType::COUPON,
1316:                     'displayName' => $request->getDisplayName(),
1317:                     'url' => $request->getUrl()
1318:                 ),
1319:                 'location' => $location
1320:             );
1321: 
1322:             self::checkSource($params, $request->getSource());
1323: 
1324:             $response = IDRequest::execute(
1325:                 self::getUrlRequest('redeem_coupon_in_pos'),
1326:                 $params,
1327:                 IDRequest::HTTP_POST,
1328:                 IDRequest::NOT_SECURED,
1329:                 self::setHeaders($request->getSectionName())
1330:             );
1331: 
1332:             return self::checkStatus($response);
1333:         } catch (Exception $e) {
1334:             Identity::getLogger()->error($e->getMessage());
1335:             throw $e;
1336:         }
1337:     }
1338: 
1339:     /**
1340:      * The actor has checked-in to the object. For instance, a person checking-in to a Place.
1341:      * Indicates that the actor share branded user's geographical location at a POS.
1342:      * The place property MUST be fulfilled as defined in the Place section of the Activity Stream Schema.
1343:      *
1344:      * @param Request $request
1345:      * @throws \Exception If there is an error in the response.
1346:      * @return Response
1347:      */
1348:     public static function checkIn($request)
1349:     {
1350:         try {
1351:             self::setSecured($request);
1352: 
1353:             $location = Location::checkLocation($request->getLocation());
1354: 
1355:             $params = array(
1356:                 'actor' => array(
1357:                     'id' => $request->getUserId(),
1358:                     'objectType' => ObjectType::PERSON
1359:                 ),
1360:                 'verb' => Verbs::CHECKIN,
1361:                 'object' => $location
1362:             );
1363: 
1364:             self::checkSource($params, $request->getSource());
1365: 
1366:             $response = IDRequest::execute(
1367:                 self::getUrlRequest('check_in'),
1368:                 $params,
1369:                 IDRequest::HTTP_POST,
1370:                 IDRequest::NOT_SECURED,
1371:                 self::setHeaders($request->getSectionName())
1372:             );
1373: 
1374:             return self::checkStatus($response);
1375:         } catch (Exception $e) {
1376:             Identity::getLogger()->error($e->getMessage());
1377:             throw $e;
1378:         }
1379:     }
1380: 
1381:     /**
1382:      * Set Actor.id for request to ActivityID. Set section of promotion too.
1383:      *
1384:      * @param Request $request
1385:      * @param bool $secured if true, Actor.id is ckusid from User logged, if false is Client ID.
1386:      * @throws \Exception
1387:      */
1388:     private static function setSecured(&$request, $secured = true)
1389:     {
1390:         if ($secured) {
1391:             if (self::checkParam($request->getUserId())) {
1392:                 if (Identity::isConnected()) {
1393:                     $request->setUserId(Identity::getThings()->getLoginStatus()->getCkusid());
1394:                 }
1395:             }
1396:         } else {
1397:             $request->setUserId(OAuthConfig::getClientId());
1398:         }
1399: 
1400:         if ($request->getUserId() === null) {
1401:             throw new Exception('Not user logged');
1402:         }
1403: 
1404:         if ($request->getSectionName() === null) {
1405:             $request->setSectionName(OAuthConfig::getDefaultSection());
1406:         }
1407:     }
1408: 
1409:     /**
1410:      * Check if param is null or empty or blank
1411:      *
1412:      * @param $param string Parameter to validate
1413:      * @return bool True if is null, empty or blank, False in other case
1414:      */
1415:     private static function checkParam($param)
1416:     {
1417:         return empty($param);
1418:     }
1419: 
1420:     /**
1421:      * @param $params
1422:      * @param $source
1423:      */
1424:     private static function checkSource(&$params, $source)
1425:     {
1426:         if (!self::checkParam($source)) {
1427:             $params['source'] = array(
1428:                 'id' => $source,
1429:                 'objectType' => ObjectType::DEVICE
1430:             );
1431:         }
1432:     }
1433: 
1434:     /**
1435:      * Returns the url of ActivityApi from the specified request
1436:      *
1437:      * @param string $request The type of request
1438:      * @return string The url
1439:      */
1440:     private static function getUrlRequest($request)
1441:     {
1442:         return OAuthConfig::getApiUrl('api.activityid' , 'base_url') . OAuthConfig::getApiUrl('api.activityid' , $request);
1443:     }
1444: 
1445:     /**
1446:      * Set Headers Params to de Request
1447:      *
1448:      * @param string $from Section Name
1449:      * @return array
1450:      */
1451:     private static function setHeaders($from)
1452:     {
1453:         $httpHeaders = array(
1454:             'Authorization' => 'Bearer ' . Identity::getThings()->getClientToken()->getValue(),
1455:             'Content-Type' => 'application/json',
1456:             'From' => $from
1457:         );
1458: 
1459:         return $httpHeaders;
1460:     }
1461: 
1462:     /**
1463:      * Check response and if http request is success return Activity ID Response object
1464:      *
1465:      * @param array $response
1466:      * @throws \Exception If there is an error in the response.
1467:      * @return Response
1468:      */
1469:     private static function checkStatus($response)
1470:     {
1471:         $gid_response = new Response();
1472: 
1473:         // Check if response has a code
1474:         if (isset($response['code'])) {
1475:             $gid_response->setStatus($response['code']);
1476: 
1477:             if ($response['code'] == Response::RESPONSE_SUCCESS) {
1478:                 if (isset($response['result']->request)) {
1479:                     $gid_response->setObjectId($response['result']->request->object->id);
1480:                 }
1481:                 return $gid_response;
1482:             } else {
1483:                 if (isset($response['result']->result) && ($response['result']->result->status != Response::RESPONSE_SUCCESS)) {
1484:                     $gid_response->setErrorMessage($response['result']->result->errors[0]->message);
1485:                     if (isset($response['result']->result->errors[0]->reason)) {
1486:                         $gid_response->setErrorReason($response['result']->result->errors[0]->reason);
1487:                     }
1488:                     throw new Exception($gid_response->getErrorReason());
1489:                 } else {
1490:                     throw new Exception('Unknown error');
1491:                 }
1492:             }
1493:         } else {
1494:             throw new Exception('Server error');
1495:         }
1496:     }
1497: }
1498: 
1499: 
API documentation generated by ApiGen