Skip to content

Commit

Permalink
Add documentation for action methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti committed Aug 24, 2014
1 parent e368442 commit 558c62e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
43 changes: 43 additions & 0 deletions src/Antoineaugusti/LaravelEasyrec/Easyrec.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public function getBaseURL()
* ACTIONS
* --------------------
*/

/**
* This action should be raised if a user views an item.
* @param string $itemid An item ID to identify an item on your website. Eg: "POST42"
* @param string $itemdescription An item description that is displayed when showing recommendations on your website.
* @param string $itemurl An item URL that links to the item page. Please give an absolute path.
* @param string $userid A user ID.
* @param string $itemimageurl An optional item image URL that links to an imagine of the item. Please give an absolute path.
* @param string $actiontime An action time parameter that overwrites the current timestamp of the action. The parameter has the format "dd_MM_yyyy_HH_mm_ss".
* @param string $itemtype An item type that denotes the type of the item (`IMAGE`, `BOOK` etc.). If not supplied, the default value `ITEM` will be used.
* @param string $sessionid A session ID of a user.
* @return array The decoded JSON response
*/
public function view($itemid, $itemdescription, $itemurl, $userid = null, $itemimageurl = null, $actiontime = null, $itemtype = null, $sessionid = null)
{
if (is_null($sessionid))
Expand All @@ -56,6 +69,9 @@ public function view($itemid, $itemdescription, $itemurl, $userid = null, $itemi
return $this->sendRequest();
}

/**
* @see view
*/
public function buy($itemid, $itemdescription, $itemurl, $userid = null, $itemimageurl = null, $actiontime = null, $itemtype = null, $sessionid = null)
{
if (is_null($sessionid))
Expand All @@ -70,6 +86,19 @@ public function buy($itemid, $itemdescription, $itemurl, $userid = null, $itemim
return $this->sendRequest();
}

/**
* This action should be raised if a user rates an item.
* @param string $itemid An item ID to identify an item on your website. Eg: "POST42"
* @param integer $ratingvalue The rating value of the item. Must be an integer in the range from 1 to 10.
* @param string $itemdescription An item description that is displayed when showing recommendations on your website.
* @param string $itemurl An item URL that links to the item page. Please give an absolute path.
* @param string $userid A user ID.
* @param string $itemimageurl An optional item image URL that links to an imagine of the item. Please give an absolute path.
* @param string $actiontime An action time parameter that overwrites the current timestamp of the action. The parameter has the format "dd_MM_yyyy_HH_mm_ss".
* @param string $itemtype An item type that denotes the type of the item (`IMAGE`, `BOOK` etc.). If not supplied, the default value `ITEM` will be used.
* @param string $sessionid A session ID of a user.
* @return array The decoded JSON response
*/
public function rate($itemid, $ratingvalue, $itemdescription, $itemurl, $userid = null, $itemimageurl = null, $actiontime = null, $itemtype = null, $sessionid = null)
{
// Check that the $ratingvalue as got the expected format
Expand All @@ -88,6 +117,20 @@ public function rate($itemid, $ratingvalue, $itemdescription, $itemurl, $userid
return $this->sendRequest();
}

/**
* This action can be used to send generic user actions.
* @param string $itemid An item ID to identify an item on your website. Eg: "POST42"
* @param string $itemdescription An item description that is displayed when showing recommendations on your website.
* @param string $itemurl An item URL that links to the item page. Please give an absolute path.
* @param string $actiontype A required action type you want to use to send.
* @param string $actionvalue If your action type uses action values this parameter is required.
* @param string $userid A user ID.
* @param string $itemimageurl An optional item image URL that links to an imagine of the item. Please give an absolute path.
* @param string $actiontime An action time parameter that overwrites the current timestamp of the action. The parameter has the format "dd_MM_yyyy_HH_mm_ss".
* @param string $itemtype An item type that denotes the type of the item (`IMAGE`, `BOOK` etc.). If not supplied, the default value `ITEM` will be used.
* @param string $sessionid A session ID of a user.
* @return array The decoded JSON response
*/
public function sendAction($itemid, $itemdescription, $itemurl, $actiontype, $actionvalue = null, $userid = null, $itemimageurl = null, $actiontime = null, $itemtype = null, $sessionid = null)
{
if (is_null($sessionid))
Expand Down
16 changes: 14 additions & 2 deletions tests/Antoineaugusti/LaravelEasyrec/EasyrecTestActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class EasyrecTestActions extends LaravelEasyrecTestCase {

//
// - view
//
public function testView()
{
Session::shouldReceive('getId')->once()->andReturn(self::SESSION_ID);
Expand All @@ -30,6 +33,9 @@ public function testView()
$this->assertEquals('view', $this->easyrec->getEndpoint());
}

//
// - buy
//
public function testBuy()
{
Session::shouldReceive('getId')->once()->andReturn(self::SESSION_ID);
Expand All @@ -52,7 +58,10 @@ public function testBuy()
// Test the endpoint name
$this->assertEquals('buy', $this->easyrec->getEndpoint());
}


//
// - rate
//
public function testRate()
{
Session::shouldReceive('getId')->once()->andReturn(self::SESSION_ID);
Expand Down Expand Up @@ -83,7 +92,10 @@ public function testRateException()
$this->setExpectedException('InvalidArgumentException');
$this->easyrec->rate(self::ITEM_ID, "not a note", self::ITEM_DESCRIPTION, self::ITEM_URL);
}


//
// - sendAction
//
public function testSendAction()
{
Session::shouldReceive('getId')->once()->andReturn(self::SESSION_ID);
Expand Down

0 comments on commit 558c62e

Please sign in to comment.