Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #125 from seregazhuk/develop
Browse files Browse the repository at this point in the history
Registration add
  • Loading branch information
seregazhuk authored Jun 27, 2016
2 parents 3687321 + 9d333a8 commit 0870add
Show file tree
Hide file tree
Showing 36 changed files with 468 additions and 393 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Change Log
All notable changes to this project will be documented in this file.

## [4.3.0] - 2016-06-27

### Added:
- User *register* method
### Fixed:
- Pins *edit* method returns bool value
### Changed:
- *login*, *isLoggedIn* and *logout* methods move to User provider
- Bot *login*, *isLoggedIn* and *logout* methods are deprecated
- removed *RequestInterface* and *ResponseInterface*


## [4.2.2] - 2016-06-19
### Fixed:
- keywords *recommendedFor* method returns an empty array if no results
Expand Down Expand Up @@ -50,7 +62,7 @@ All notable changes to this project will be documented in this file.
- Better exception messages in ProviderLoginCheckWrapper

## [3.2.3] - 2016-06-09
### Fixes:
### Fixed:
- Pins like/dislike
- Response error check

Expand Down Expand Up @@ -78,7 +90,7 @@ All notable changes to this project will be documented in this file.
- News *latest* method renamed to *last*
- Request and providers refactoring

### Fixes:
### Fixed:
- Boards follow/unfollow request

## [2.6.0] - 2016-05-28
Expand Down
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use seregazhuk\PinterestBot\Factories\PinterestBot;
$bot = PinterestBot::create();

// login
$bot->login('mypinterestlogin', 'mypinterestpassword');
$bot->user->login('mypinterestlogin', 'mypinterestpassword');

// get lists of your boards
$boards = $bot->boards->forUser('yourUserName');
Expand All @@ -69,19 +69,31 @@ Or you may skip login, if you want. It is only required for such operations as l
You can get your current logged in status via *isLoggedIn* method:

```php
if($bot->isLoggedIn()) {
if($bot->user->isLoggedIn()) {
// ...
}
```
To logout use *logout* method:

```php
$bot->logout();
$bot->user->logout();
```

*Note*: Some functions use pinterest navigation through results, for example,
get user followers or search queries. These functions return a generator object with api results. By default functions
return all pinterest results, but you can pass a limit num as the second argument. For example,
To register a new user:

```php
$bot->user->register('[email protected]', 'password', 'Name');
```

You can specify additional parameters with registration: age and country. By default they are: 18, "UK":

```php
$bot->user->register('[email protected]', 'password', 'Name', 40, "DE");
```

*Note*: Some functions use pinterest navigation through results, for example, get user followers or search queries.
These functions return a generator object with api results. By default functions return all pinterest results,
but you can pass a limit num as a second argument. For example,
```php
foreach($bot->pins->search('query', 2) as $pin) {
// ...
Expand Down
8 changes: 4 additions & 4 deletions src/Api/Providers/Boards.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class Boards extends Provider
*/
public function forUser($username)
{
return $this->execGetRequest(['username' => $username], UrlHelper::RESOURCE_GET_BOARDS);
return $this->execGetRequest(
['username' => $username], UrlHelper::RESOURCE_GET_BOARDS
);
}

/**
Expand All @@ -58,9 +60,7 @@ public function info($username, $board)
'field_set_key' => 'detailed',
];

return $this->execGetRequest(
$requestOptions, UrlHelper::RESOURCE_GET_BOARDS
);
return $this->execGetRequest($requestOptions, UrlHelper::RESOURCE_GET_BOARDS);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Api/Providers/Interests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Interests extends Provider
{
use Followable;

/**
* @var array
*/
protected $loginRequiredFor = ['follow', 'unFollow'];

protected $followUrl = UrlHelper::RESOURCE_FOLLOW_INTEREST;
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Providers/Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function recommendedFor($query)

/**
* @param array $response
* @return array
* @return bool|array
*/
protected function parseKeywordsFromRequest($response)
{
Expand Down
48 changes: 0 additions & 48 deletions src/Api/Providers/Pinners.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,54 +70,6 @@ public function pins($username, $limit = 0)
);
}

/**
* Login as pinner.
*
* @param string $username
* @param string $password
*
* @throws AuthException
*
* @return bool
*/
public function login($username, $password)
{
if ($this->request->isLoggedIn()) {
return true;
}

$this->checkCredentials($username, $password);

$postString = PinnerHelper::createLoginQuery($username, $password);
$this->request->clearToken();

$response = $this->request->exec(UrlHelper::RESOURCE_LOGIN, $postString);
if ($this->response->hasErrors($response)) {
throw new AuthException($this->response->getLastError()['message']);
}
$this->request->login();

return true;
}

public function logout()
{
$this->request->logout();
}

/**
* Validates password and login.
*
* @param string $username
* @param string $password
*/
protected function checkCredentials($username, $password)
{
if (!$username || !$password) {
throw new LogicException('You must set username and password to login.');
}
}

/**
* @param string $username
* @param string $url
Expand Down
10 changes: 5 additions & 5 deletions src/Api/Providers/Pins.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function create($imageUrl, $boardId, $description = '', $link = '')
* @param string $description
* @param string $link
* @param int|null $boardId
* @return mixed
* @return bool
*/
public function edit($pindId, $description = '', $link = '', $boardId = null)
{
Expand All @@ -123,15 +123,15 @@ public function edit($pindId, $description = '', $link = '', $boardId = null)
'board_id' => $boardId,
];

return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_UPDATE_PIN, true);
return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_UPDATE_PIN);
}

/**
* Moves pin to a new board
*
* @param int $pindId
* @param int $boardId
* @return mixed
* @return bool
*/
public function moveToBoard($pindId, $boardId)
{
Expand Down Expand Up @@ -196,9 +196,9 @@ public function fromSource($source, $limit = 0)
}

/**
* @param $pinId
* @param int $pinId
* @param int $limit
* @return Iterator
* @return Iterator|null
*/
public function activity($pinId, $limit = 0)
{
Expand Down
27 changes: 13 additions & 14 deletions src/Api/Providers/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace seregazhuk\PinterestBot\Api\Providers;

use seregazhuk\PinterestBot\Api\Request;
use seregazhuk\PinterestBot\Contracts\RequestInterface;
use seregazhuk\PinterestBot\Contracts\ResponseInterface;
use seregazhuk\PinterestBot\Api\Response;

/**
* Class Provider.
Expand All @@ -20,24 +19,24 @@ abstract class Provider
protected $loginRequiredFor = [];

/**
* Instance of the API RequestInterface.
* Instance of the API Request.
*
* @var RequestInterface
* @var Request
*/
protected $request;

/**
* Instance of the API ResponseInterface.
* Instance of the API Response.
*
* @var ResponseInterface
* @var Response
*/
protected $response;

/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @param Request $request
* @param Response $response
*/
public function __construct(RequestInterface $request, ResponseInterface $response)
public function __construct(Request $request, Response $response)
{
$this->request = $request;
$this->response = $response;
Expand All @@ -54,7 +53,7 @@ public function __construct(RequestInterface $request, ResponseInterface $respon
*/
protected function execPostRequest($requestOptions, $resourceUrl, $returnData = false)
{
$postString = Request::createQuery(['options' => $requestOptions]);
$postString = Request::createQuery($requestOptions);
$response = $this->request->exec($resourceUrl, $postString);

if ($returnData) {
Expand All @@ -73,7 +72,7 @@ protected function execPostRequest($requestOptions, $resourceUrl, $returnData =
*/
protected function execGetRequest(array $requestOptions, $resourceUrl)
{
$query = Request::createQuery(['options' => $requestOptions]);
$query = Request::createQuery($requestOptions);
$response = $this->request->exec($resourceUrl . "?{$query}");

return $this->response->getData($response);
Expand All @@ -89,7 +88,7 @@ protected function execGetRequest(array $requestOptions, $resourceUrl)
*/
protected function execGetRequestWithPagination(array $requestOptions, $resourceUrl, $bookmarks = [])
{
$query = Request::createQuery(['options' => $requestOptions], $bookmarks);
$query = Request::createQuery($requestOptions, $bookmarks);
$response = $this->request->exec($resourceUrl . "?{$query}");

return $this->response->getPaginationData($response);
Expand Down Expand Up @@ -124,15 +123,15 @@ public function checkMethodRequiresLogin($method)
}

/**
* @return RequestInterface
* @return Request
*/
public function getRequest()
{
return $this->request;
}

/**
* @return ResponseInterface
* @return Response
*/
public function getResponse()
{
Expand Down
Loading

0 comments on commit 0870add

Please sign in to comment.