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 #233 from seregazhuk/develop
Browse files Browse the repository at this point in the history
fix: Receiving email after business registration
  • Loading branch information
seregazhuk authored Dec 31, 2016
2 parents 7d378c2 + 09d9728 commit 9da0447
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 164 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## [5.1.7] - 2016-12-31
### Fixed:
- Receiving confirmation email after registering business account.

## [5.1.6] - 2016-12-25
### Fixed:
- Feed pagination error
Expand Down
63 changes: 6 additions & 57 deletions src/Api/Providers/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use seregazhuk\PinterestBot\Api\Response;
use seregazhuk\PinterestBot\Helpers\UrlBuilder;
use seregazhuk\PinterestBot\Api\Traits\BusinessAccount;
use seregazhuk\PinterestBot\Api\Traits\SendsRegisterActions;

class Auth extends Provider
{
use SendsRegisterActions;
use SendsRegisterActions, BusinessAccount;

/**
* @var array
Expand All @@ -30,7 +31,7 @@ class Auth extends Provider
*/
public function login($username, $password, $autoLogin = true)
{
if ($this->request->isLoggedIn()) return true;
if ($this->isLoggedIn()) return true;

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

Expand Down Expand Up @@ -86,23 +87,9 @@ public function register($email, $password, $name, $country = 'GB', $age = 18)
*/
public function registerBusiness($email, $password, $businessName, $website = '')
{
$data = [
"email" => $email,
"password" => $password,
"website_url" => $website,
"account_type" => self::ACCOUNT_TYPE_OTHER,
"business_name" => $businessName,
];
$this->register($email, $password, $businessName);

return $this->makeBusinessRegisterCall($data);
}

/**
* @return bool
*/
public function isLoggedIn()
{
return $this->request->isLoggedIn();
return $this->convertToBusiness($businessName, $website);
}

/**
Expand Down Expand Up @@ -162,24 +149,7 @@ protected function makeRegisterCall($data)

if(!$this->execPostRequest($data, UrlBuilder::RESOURCE_CREATE_REGISTER)) return false;

if(!$this->sendPlainRegistrationActions()) return false;

return $this->completeRegistration();
}

/**
* @param array $data
* @return bool|mixed
*/
protected function makeBusinessRegisterCall($data)
{
$this->visitPage('business/create/');

if(!$this->sendBusinessRegistrationInitActions()) return false;

if(!$this->execPostRequest($data, UrlBuilder::RESOURCE_CREATE_REGISTER)) return false;

if(!$this->sendBusinessRegistrationFinishActions()) return false;
if(!$this->sendRegistrationActions()) return false;

return $this->completeRegistration();
}
Expand Down Expand Up @@ -224,25 +194,4 @@ protected function getProfile()
{
return $this->execGetRequest([], UrlBuilder::RESOURCE_GET_USER_SETTINGS);
}

/**
* @return bool
*/
protected function sendRegisterActions()
{
$actions = [
["name" => "multi_step_step_2_complete"],
["name" => "signup_home_page"],
["name" => "signup_referrer.other"],
["name" => "signup_referrer_module.unauth_home_react_page"],
["name" => "unauth.signup_step_2.completed"],
["name" => "setting_new_window_location"],
];

if(!$this->sendRegisterActionRequest($actions)) return false;

if(!$this->sendRegisterActionRequest()) return false;

return true;
}
}
2 changes: 1 addition & 1 deletion src/Api/Providers/Boards.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use seregazhuk\PinterestBot\Api\Traits\SendsMessages;
use seregazhuk\PinterestBot\Api\Contracts\PaginatedResponse;

class Boards extends Provider
class Boards extends EntityProvider
{
use CanBeDeleted, Searchable, Followable, SendsMessages;

Expand Down
14 changes: 14 additions & 0 deletions src/Api/Providers/EntityProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace seregazhuk\PinterestBot\Api\Providers;

class EntityProvider extends Provider
{
/**
* @return string
*/
public function getEntityIdName()
{
return property_exists($this, 'entityIdName') ? $this->entityIdName : '';
}
}
7 changes: 5 additions & 2 deletions src/Api/Providers/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function sendResetLink($user)
public function reset($link, $newPassword)
{
// Visit link to get current reset token, username and token expiration
$this->execGetRequest([], $link);
$this->visitPage($link);
$this->request->clearToken();

$urlData = $this->parseCurrentUrl();
Expand Down Expand Up @@ -77,7 +77,10 @@ public function change($oldPassword, $newPassword)
*/
protected function parseCurrentUrl()
{
$url = $this->request->getHttpClient()->getCurrentUrl();
$url = $this
->request
->getHttpClient()
->getCurrentUrl();

return parse_url($url);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Api/Providers/Pinners.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use seregazhuk\PinterestBot\Api\Traits\Searchable;
use seregazhuk\PinterestBot\Exceptions\WrongFollowingType;

class Pinners extends Provider
class Pinners extends EntityProvider
{
use Searchable, Followable;

Expand Down Expand Up @@ -52,7 +52,7 @@ public function info($username)
* @param string $username
* @param string $type
* @param int $limit
* @return Iterator
* @return Pagination
* @throws WrongFollowingType
*/
public function following($username, $type = UrlBuilder::FOLLOWING_PEOPLE, $limit = Pagination::DEFAULT_LIMIT)
Expand All @@ -72,7 +72,7 @@ public function following($username, $type = UrlBuilder::FOLLOWING_PEOPLE, $limi
*
* @param string $username
* @param int $limit
* @return Iterator
* @return Pagination
*/
public function followingPeople($username, $limit = Pagination::DEFAULT_LIMIT)
{
Expand All @@ -85,7 +85,7 @@ public function followingPeople($username, $limit = Pagination::DEFAULT_LIMIT)
*
* @param string $username
* @param int $limit
* @return Iterator
* @return Pagination
*/
public function followingBoards($username, $limit = Pagination::DEFAULT_LIMIT)
{
Expand All @@ -112,7 +112,7 @@ public function followingInterests($username, $limit = Pagination::DEFAULT_LIMIT
* @param string $username
* @param int $limit
*
* @return Iterator
* @return Pagination
*/
public function pins($username, $limit = Pagination::DEFAULT_LIMIT)
{
Expand All @@ -126,7 +126,7 @@ public function pins($username, $limit = Pagination::DEFAULT_LIMIT)
*
* @param string $username
* @param int $limit
* @return Iterator
* @return Pagination
*/
public function likes($username, $limit = Pagination::DEFAULT_LIMIT)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ public function blockById($userId)
* @param string $url
* @param int $limit
*
* @return \Traversable
* @return Pagination
*/
protected function paginate($username, $url, $limit)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Providers/Pins.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use seregazhuk\PinterestBot\Api\Traits\CanBeDeleted;
use seregazhuk\PinterestBot\Api\Traits\UploadsImages;

class Pins extends Provider
class Pins extends EntityProvider
{
use Searchable, CanBeDeleted, UploadsImages, HasFeed, SendsMessages;

Expand Down Expand Up @@ -188,7 +188,7 @@ public function fromSource($source, $limit = Pagination::DEFAULT_LIMIT)
*
* @param string $pinId
* @param int $limit
* @return Iterator|array
* @return Pagination
*/
public function activity($pinId, $limit = Pagination::DEFAULT_LIMIT)
{
Expand Down
8 changes: 0 additions & 8 deletions src/Api/Providers/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ protected function execute($url, $postString = "")
return $this;
}

/**
* @return string
*/
public function getEntityIdName()
{
return property_exists($this, 'entityIdName') ? $this->entityIdName : '';
}

/**
* Executes pagination GET request.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Providers/ProviderWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ProviderWrapper
/**
* @var Provider
*/
private $provider;
protected $provider;

/**
* @param Provider|object $provider
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Providers/Topics.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use seregazhuk\PinterestBot\Api\Traits\Followable;
use seregazhuk\PinterestBot\Api\Traits\HasRelatedTopics;

class Topics extends Provider
class Topics extends EntityProvider
{
use Followable, HasRelatedTopics, HasFeed;

Expand Down
21 changes: 0 additions & 21 deletions src/Api/Providers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class User extends Provider
'convertToBusiness',
];

const ACCOUNT_TYPE_OTHER = 'other';
const REGISTRATION_COMPLETE_EXPERIENCE_ID = '11:10105';

/**
* Updates or returns user profile info. Gets associative array as a param. Available keys of array are:
* 'last_name', 'first_name', 'username', 'about', 'location' and 'website_url'.
Expand All @@ -47,24 +44,6 @@ public function profile($userInfo = [])
return $this->execPostRequest($userInfo, UrlBuilder::RESOURCE_UPDATE_USER_SETTINGS);
}

/**
* Convert your account to a business one.
*
* @param string $businessName
* @param string $websiteUrl
* @return bool
*/
public function convertToBusiness($businessName, $websiteUrl = '')
{
$data = [
'business_name' => $businessName,
'website_url' => $websiteUrl,
'account_type' => self::ACCOUNT_TYPE_OTHER,
];

return $this->execPostRequest($data, UrlBuilder::RESOURCE_CONVERT_TO_BUSINESS);
}

/**
* Checks if current user is banned
*
Expand Down
28 changes: 28 additions & 0 deletions src/Api/Traits/BusinessAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace seregazhuk\PinterestBot\Api\Traits;

use seregazhuk\PinterestBot\Helpers\UrlBuilder;

trait BusinessAccount
{
use HandlesRequest;

/**
* Convert your account to a business one.
*
* @param string $businessName
* @param string $websiteUrl
* @return bool
*/
public function convertToBusiness($businessName, $websiteUrl = '')
{
$data = [
'business_name' => $businessName,
'website_url' => $websiteUrl,
'account_type' => 'other',
];

return $this->execPostRequest($data, UrlBuilder::RESOURCE_CONVERT_TO_BUSINESS);
}
}
2 changes: 1 addition & 1 deletion src/Api/Traits/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function createSearchQuery($query, $scope, $bookmarks = [])
* @param string $query
* @param int $limit
*
* @return \Traversable
* @return Pagination
*/
public function search($query, $limit = Pagination::DEFAULT_LIMIT)
{
Expand Down
Loading

0 comments on commit 9da0447

Please sign in to comment.