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 #296 from seregazhuk/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
seregazhuk authored Jul 2, 2017
2 parents f5e3e57 + 81fffef commit f7ddb0b
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

## v5.5.0 - 2017-07-01
### Added:
- User `id()` helper to get current user id
- Boards `sendInvite`, `acceptInvite`, `ignoreInvite` and `removeInvite`
- Contact requests

## v5.4.5 - 2017-06-27
### Fixed:
- Boards invites
Expand Down
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ if you don't use such operations as creating pins, writing comments or sending m
- [Topics](#topics)
- [Search](#search)
- [Inbox](#inbox)
- [News](#news)
- [Notifications](#notifications)
- [Conversations](#conversations)
- [Write a message](#write-a-message)
- [Send email](#send-email)
- [Contact requests](#contact-requests)
- [Keywords](#keywords)
- [Errors handling](#errors-handling)
- [Use proxy](#use-proxy)
Expand Down Expand Up @@ -260,6 +266,11 @@ Get your current username:
$username = $bot->user->username();
```

Get your current user id:
```php
$userId = $bot->user->id();
```

Check if your account is banned:
```php
if ($bot->user->isBanned() {
Expand Down Expand Up @@ -382,11 +393,44 @@ $bot->boards->sendWithEmail($boardId, 'Message', '[email protected]'); // One e
$bot->boards->sendWithEmail($boardId, 'Message', ['[email protected]', '[email protected]']); // many
```

### Invites

Get your boards invites:
```php
$invites = $bot->boards->invites();
```

Invite someone to your board:
```php
// to a user by email
$bot->boards->sendInvite($boardId, '[email protected]');

// to a user by user id
$bot->boards->sendInvite($boardId, $userId);

// to users by email
$bot->boards->sendInvite($boardId, ['[email protected]', '[email protected]']);
// to users by user id
$bot->boards->sendInvite($boardId, [$user1Id, $user2Id]);
```

Accept an invite to a board:
```php
$bot->boards->acceptInvite($boardId);
```

Ignore an invite to a board:
```php
$bot->boards->ignoreInvite($boardId);
```

Delete invite. Removes from the board collaborators, requires an id of the user, you want to remove from the board:
```php
$bot->boards->deleteInvite($boardId, $userId);
// also you can ban a user specifying third argument as true
$bot->boards->deleteInvite($boardId, $userId, true);
```

## Pins

Notice! Try not to be very aggressive when pinning or commenting pins, or Pinterest will gonna ban you.
Expand Down Expand Up @@ -877,6 +921,27 @@ Attach pin to email:
$bot->inbox->sendEmail('[email protected]', 'message text', $pindId);
```

### Contact requests
When someone at first sends you an invitation to a board, you receive a contact request.
Get a list of contact requests:

```php
$requests = $bot->inbox->contactRequests();
```

To accept or to ignore a request you need to specify a request ID. This ID can be received from the array
returned in `$bot->inbox->contactRequests()` method.

Accept a request:
```php
$bot->inbox->acceptContactRequest($requestId);
```

Ignore a request:
```php
$bot->inbox->ignoreContactRequest($requestId);
```

## Keywords
Get recommended keywords for the query:

Expand Down
2 changes: 1 addition & 1 deletion src/Api/Contracts/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

interface HttpClient
{
const COOKIE_PREFIX = 'pinterest_cookie_';
const COOKIE_PREFIX = 'pinterest_bot_cookie';

/**
* Executes curl request.
Expand Down
20 changes: 7 additions & 13 deletions src/Api/Providers/Boards.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
use seregazhuk\PinterestBot\Helpers\UrlBuilder;
use seregazhuk\PinterestBot\Api\Traits\Searchable;
use seregazhuk\PinterestBot\Api\Traits\CanBeDeleted;
use seregazhuk\PinterestBot\Api\Traits\BoardsInvites;
use seregazhuk\PinterestBot\Api\Traits\SendsMessages;
use seregazhuk\PinterestBot\Api\Traits\ResolvesCurrentUsername;
use seregazhuk\PinterestBot\Api\Providers\Core\FollowableProvider;

class Boards extends FollowableProvider
{
use CanBeDeleted, Searchable, SendsMessages, ResolvesCurrentUsername;
use CanBeDeleted, Searchable, SendsMessages, ResolvesCurrentUsername, BoardsInvites;

const BOARD_PRIVACY_PUBLIC = 'public';
const BOARD_PRIVACY_PRIVATE = 'secret';
Expand All @@ -28,6 +29,11 @@ class Boards extends FollowableProvider
'follow',
'invites',
'unFollow',
'sendInvite',
'sendInviteByEmail',
'sendInviteByUserId',
'deleteInvite',
'acceptInvite',
];

protected $searchScope = 'boards';
Expand Down Expand Up @@ -187,17 +193,5 @@ public function titleSuggestionsFor($pinId)
return $this->get(['pin_id' => $pinId], UrlBuilder::RESOURCE_TITLE_SUGGESTIONS);
}

/**
* Get boards invites
* @return array
*/
public function invites()
{
$data = [
'current_user' => true,
'field_set_key' => 'news',
];

return $this->get($data, UrlBuilder::RESOURCE_BOARDS_INVITES);
}
}
39 changes: 39 additions & 0 deletions src/Api/Providers/Inbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,43 @@ public function sendEmail($emails, $text, $pinId = null)
{
return $this->send($pinId, $text, [], $emails);
}

public function contactRequests()
{
$requests = $this->get([], UrlBuilder::RESOURCE_CONTACTS_REQUESTS);

return !$requests ? [] : $requests;
}

/**
* @param string $requestId
* @return bool
*/
public function acceptContactRequest($requestId)
{
$data = [
'contact_request' => [
"type" => "contactrequest",
"id" => $requestId,
],
];

return $this->post($data, UrlBuilder::RESOURCE_CONTACT_REQUEST_ACCEPT);
}

/**
* @param string $requestId
* @return bool
*/
public function ignoreContactRequests($requestId)
{
$data = [
'contact_request' => [
"type" => "contactrequest",
"id" => $requestId,
],
];

return $this->post($data, UrlBuilder::RESOURCE_CONTACT_REQUEST_IGNORE);
}
}
24 changes: 22 additions & 2 deletions src/Api/Providers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class User extends Provider
* @var array
*/
protected $loginRequiredFor = [
'id',
'invite',
'profile',
'username',
Expand Down Expand Up @@ -63,9 +64,17 @@ public function isBanned()
*/
public function username()
{
$profile = $this->profile();
return $this->getProfileData('username');
}

return isset($profile['username']) ? $profile['username'] : '';
/**
* Returns current user id
*
* @return string
*/
public function id()
{
return $this->getProfileData('id');
}

/**
Expand Down Expand Up @@ -185,4 +194,15 @@ protected function updateProfile($userInfo)

return $this->post($userInfo, UrlBuilder::RESOURCE_UPDATE_USER_SETTINGS);
}

/**
* @param string $key
* @return mixed|string
*/
protected function getProfileData($key)
{
$profile = $this->profile();

return isset($profile[$key]) ? $profile[$key] : '';
}
}
1 change: 1 addition & 0 deletions src/Api/ProvidersContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace seregazhuk\PinterestBot\Api;

use seregazhuk\PinterestBot\Api\Providers\ContactRequests;
use seregazhuk\PinterestBot\Api\Providers\Pins;
use seregazhuk\PinterestBot\Api\Providers\User;
use seregazhuk\PinterestBot\Api\Providers\Auth;
Expand Down
120 changes: 120 additions & 0 deletions src/Api/Traits/BoardsInvites.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace seregazhuk\PinterestBot\Api\Traits;

use seregazhuk\PinterestBot\Helpers\UrlBuilder;

trait BoardsInvites
{
use HandlesRequest;

/**
* Get boards invites
* @return array
*/
public function invites()
{
$data = [
'current_user' => true,
'field_set_key' => 'news',
];

$invites = $this->get($data, UrlBuilder::RESOURCE_BOARDS_INVITES);

return !$invites ? [] : $invites;
}

/**
* @param string $boardId
* @param string|array $emails
* @return bool
*/
public function sendInviteByEmail($boardId, $emails)
{
$emails = is_array($emails) ? $emails : [$emails];
$data = [
"board_id" => $boardId,
"emails" => $emails,
];

return $this->post($data, UrlBuilder::RESOURCE_CREATE_EMAIL_INVITE);
}

/**
* @param string $boardId
* @param string|array $users
* @return bool
*/
public function sendInvite($boardId, $users)
{
$users = is_array($users) ? $users : [$users];

$isEmail = filter_var($users[0], FILTER_VALIDATE_EMAIL);

return $isEmail ?
$this->sendInviteByEmail($boardId, $users) :
$this->sendInviteByUserId($boardId, $users);
}

/**
* @param string $boardId
* @param string|array $userIds
* @return bool
*/
public function sendInviteByUserId($boardId, $userIds)
{
$userIds = is_array($userIds) ? $userIds : [$userIds];
$data = [
"board_id" => $boardId,
"invited_user_ids" => $userIds,
];

return $this->post($data, UrlBuilder::RESOURCE_CREATE_USER_ID_INVITE);
}

/**
* @param string $boardId
* @param string $userId
* @param bool $ban
* @return bool
*/
public function deleteInvite($boardId, $userId, $ban = false)
{
$data = [
'ban' => $ban,
'board_id' => $boardId,
'field_set_key' => 'boardEdit',
'invited_user_id' => $userId,
];

return $this->post($data, UrlBuilder::RESOURCE_DELETE_INVITE);
}

/**
* @param string $boardId
* @return bool
*/
public function ignoreInvite($boardId)
{
$data = [
'board_id' => $boardId,
'invited_user_id' => $this->container->user->id(),
];

return $this->post($data, UrlBuilder::RESOURCE_DELETE_INVITE);
}

/**
* @param string $boardId
* @return bool
*/
public function acceptInvite($boardId)
{
$data = [
'board_id' => $boardId,
'invited_user_id' => $this->container->user->id(),
];

return $this->post($data, UrlBuilder::RESOURCE_ACCEPT_INVITE);
}
}
Loading

0 comments on commit f7ddb0b

Please sign in to comment.