Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge tag 'vv0.1.0' into develop
Browse files Browse the repository at this point in the history
Tagging version v0.1.0 vv0.1.0
  • Loading branch information
mickadoo committed Jan 19, 2015
2 parents 441358c + 72f3312 commit 200aadd
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ config/
vendor/
composer.lock
tests/LooplineSystems/CloseIoApi/Api/LiveApiTest.php
tests/build/logs/
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -28,7 +28,7 @@ Require via [Composer](https://github.com/composer/composer)<br />
Usage
------------
```php
// optionally pass in close.io api endpoint as init argument
// you can optionally pass in close.io api endpoint as init argument (it defaults to 'https://app.close.io/api/v1')
$closeIoConfig = new CloseIoConfig();
$closeIoConfig->setApiKey('yourApiKey');

Expand All @@ -37,9 +37,9 @@ $leadsApi = $closeIoApiWrapper->getLeadApi();

// create lead
$lead = new Lead();
$lead->setName('Dynamic Test');
$lead->setDescription('Dynamic lead test description');
$lead->setUrl('www.dynamic-lead-test.com');
$lead->setName('Test Company');
$lead->setDescription('Company description');
$lead->setUrl('www.test-company.com');

// address
$address = new Address();
Expand All @@ -50,19 +50,19 @@ $address->setAddress2('Mitte');

// contacts
$contact = new Contact();
$contact->setName('Dynamic Testcontact');
$contact->setTitle('Dynamic Contact Test Title');
$contact->setName('Testy Testersson');
$contact->setTitle('Chief Tester');

// emails
$email = new Email();
$email->setEmail('testcontactemail@dynamic-lead-test.com');
$email->setType('work');
$email->setEmail('testy-testersson@test-company.com');
$email->setType(Email::EMAIL_TYPE_OFFICE);
$contact->addEmail($email);

// phones
$phone = new Phone();
$phone->setPhone('01244349656');
$phone->setType('mobile');
$phone->setPhone('+491234567890');
$phone->setType(Phone::PHONE_TYPE_MOBILE);
$contact->addPhone($phone);

$lead->addAddress($address);
Expand Down
1 change: 1 addition & 0 deletions src/LooplineSystems/CloseIoApiWrapper/Api/LeadApi.php
Expand Up @@ -49,6 +49,7 @@ public function getAllLeads()

if ($result->getReturnCode() == 200) {
$rawData = $result->getData()[CloseIoResponse::GET_ALL_RESPONSE_LEADS_KEY];

foreach ($rawData as $lead) {
$leads[] = new Lead($lead);
}
Expand Down
8 changes: 7 additions & 1 deletion src/LooplineSystems/CloseIoApiWrapper/Library/Curl/Curl.php
Expand Up @@ -14,8 +14,14 @@
use LooplineSystems\CloseIoApiWrapper\Library\Exception\BadApiRequestException;
use LooplineSystems\CloseIoApiWrapper\Library\Exception\UrlNotSetException;

class Curl implements CurlConstantsInterface
class Curl
{
const METHOD_POST = 'POST';
const METHOD_GET = 'GET';
const METHOD_PUT = 'PUT';
const METHOD_DELETE = 'DELETE';
const METHOD_PATCH = 'PATCH';

/**
* @param CloseIoRequest $request
* @return resource
Expand Down

This file was deleted.

Expand Up @@ -11,6 +11,13 @@

class JsonDecodingException extends \RuntimeException
{
const JSON_ERROR_DEPTH_MESSAGE = 'The maximum stack depth has been exceeded';
const JSON_ERROR_STATE_MISMATCH_MESSAGE = 'Invalid or malformed JSON';
const JSON_ERROR_CTRL_CHAR_MESSAGE = 'Control character error, possibly incorrectly encoded';
const JSON_ERROR_UTF8_MESSAGE = 'Malformed UTF-8 characters, possibly incorrectly encoded';
const JSON_ERROR_SYNTAX_MESSAGE = 'JSON syntax is malformed';
const JSON_ERROR_DEFAULT_MESSAGE = 'Syntax error';

/**
* @param int|string $code
* @param \Exception $previous
Expand All @@ -19,22 +26,22 @@ public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null
{
switch ($code) {
case JSON_ERROR_DEPTH:
$message = 'The maximum stack depth has been exceeded';
$message = self::JSON_ERROR_DEPTH_MESSAGE;
break;
case JSON_ERROR_STATE_MISMATCH:
$message = 'Invalid or malformed JSON';
$message = self::JSON_ERROR_STATE_MISMATCH_MESSAGE;
break;
case JSON_ERROR_CTRL_CHAR:
$message = 'Control character error, possibly incorrectly encoded';
$message = self::JSON_ERROR_CTRL_CHAR_MESSAGE;
break;
case JSON_ERROR_UTF8:
$message = 'Malformed UTF-8 characters, possibly incorrectly encoded';
$message = self::JSON_ERROR_UTF8_MESSAGE;
break;
case JSON_ERROR_SYNTAX:
$message = 'JSON syntax is malformed';
$message = self::JSON_ERROR_SYNTAX_MESSAGE;
break;
default:
$message = 'Syntax error';
$message = self::JSON_ERROR_DEFAULT_MESSAGE;
}
parent::__construct($message, $code, $previous);
}
Expand Down
4 changes: 0 additions & 4 deletions src/LooplineSystems/CloseIoApiWrapper/Model/Task.php
Expand Up @@ -82,10 +82,6 @@ class Task implements \JsonSerializable
* */
private $id;

/**
* @var string
* */

/**
* @var string
*/
Expand Down
80 changes: 80 additions & 0 deletions tests/LooplineSystems/CloseIoApi/Api/ExceptionsTest.php
@@ -0,0 +1,80 @@
<?php
/**
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems
*
* @link https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
*/

namespace LooplineSystems\CloseIoApiWrapper\Tests;

use LooplineSystems\CloseIoApiWrapper\Library\Exception\JsonDecodingException;

class ExceptionsTest extends \PHPUnit_Framework_TestCase
{
/**
* @param $data
* @throws JsonDecodingException
* @dataProvider badJsonProvider
*/
public function testJsonDecodeException($data, $expectedMessage)
{
$this->setExpectedException('LooplineSystems\CloseIoApiWrapper\Library\Exception\JsonDecodingException');
json_decode($data);
if (json_last_error() !== JSON_ERROR_NONE) {
$exception = new JsonDecodingException(json_last_error());
$this->assertTrue($exception->getMessage() === $expectedMessage);
throw $exception;
}
}

/**
* @param $data
* @throws JsonDecodingException
* @dataProvider badDataProvider
*/
public function testJsonEncodeException($data, $expectedMessage)
{
$this->setExpectedException('LooplineSystems\CloseIoApiWrapper\Library\Exception\JsonDecodingException');
json_encode($data);
if (json_last_error() !== JSON_ERROR_NONE) {
$exception = new JsonDecodingException(json_last_error());
$this->assertTrue($exception->getMessage() === $expectedMessage);
throw $exception;
}
}


public function badJsonProvider()
{
return [
[
"{'Organization': 'PHP Documentation Team'}",
JsonDecodingException::JSON_ERROR_SYNTAX_MESSAGE
],
[
'{ bar: "baz" }',
JsonDecodingException::JSON_ERROR_SYNTAX_MESSAGE
],
[
"{ 'bar': 'baz' }",
JsonDecodingException::JSON_ERROR_SYNTAX_MESSAGE
],
[
'{ bar: "baz", }',
JsonDecodingException::JSON_ERROR_SYNTAX_MESSAGE
]
];
}

public function badDataProvider()
{
return [
[
"\xB1\x31",
JsonDecodingException::JSON_ERROR_UTF8_MESSAGE
],
];
}
}
35 changes: 29 additions & 6 deletions tests/LooplineSystems/CloseIoApi/Api/LeadTest.php
Expand Up @@ -9,8 +9,10 @@

namespace LooplineSystems\CloseIoApiWrapper\Tests;

use LooplineSystems\CloseIoApiWrapper\Model\Email;
use LooplineSystems\CloseIoApiWrapper\Model\Lead;
use LooplineSystems\CloseIoApiWrapper\Model\Opportunity;
use LooplineSystems\CloseIoApiWrapper\Model\Phone;

class LeadTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -122,33 +124,54 @@ public function fullLeadProvider()
'addresses' => [
[
'city' => 'Test City',
'country' => 'de'
'country' => 'de',
'zipcode' => '90210',
'label' => 'office',
'state' => 'Test State',
'address_1' => 'Test Street',
'address_2' => 'Test Building'
],
],
'organization' => 'Test Organization',
'created_by' => 'Test Creator',
'url' => 'http://www.test-url.com',
'tasks' => [
[
'text' => 'Test Task Text'
'due_date' => '01-01-2016',
'text' => 'Test Task Text',
'assigned_to' => 'dfaslk2324',
'completed' => 'false',
'lead_name' => 'Test Lead',
'updated_by' => 'dfaslk2324',
'date_updated' => '01-01-2015',
'created_by' => 'dfaslk2324',
'organization_id' => 'AFSl23lkjs0',
'updated_by_name' => 'Test User',
'assigned_to_name' => 'Test User',
'created_by_name' => 'Test User',
'lead_id' => 'dsfalkj23',
'date_created' => '01-01-2014'
]
],
'name' => 'Test Name',
'contacts' => [
[
'name' => 'Test Contact',
'title' => 'Test Title',
'date_updated' => '01-01-2015',
'created_by' => 'dasflkj32lkjs',
'organization_id' => 'sdalfkj2l2jk',
'phones' => [
[
'phone' => '23211434332323',
'type' => 'office'
'phone' => '23211434332',
'phone_formatted' => '+49 23 21 1434 332',
'type' => Phone::PHONE_TYPE_OFFICE,
]
],
'emails' => [
[
'email' => 'testemail@mail.com',
'type' => 'office'
]
'type' => Email::EMAIL_TYPE_DIRECT ]
],
'urls' => [
[
Expand Down
58 changes: 33 additions & 25 deletions tests/LooplineSystems/CloseIoApi/Api/LeadsApiTest.php
Expand Up @@ -70,38 +70,18 @@ public function testGetLead($lead)
}

/**
* @dataProvider leadProvider
* @param Lead $lead
* @dataProvider leadArrayProvider
* @param Lead[] $leadsArray
*/
public function testGetAllLeads($lead)
public function testGetAllLeads($leadsArray)
{
// set up leads to be returned
$leadOne = clone $lead;
$leadTwo = clone $lead;
$leadThree = clone $lead;

$leadOne->setId('TestIdOne');
$leadTwo->setId('TestIdTwo');
$leadThree->setId('TestIdThree');

$leadsArray = [
$leadOne,
$leadTwo,
$leadThree
];

$responseBody = [
CloseIoResponse::GET_ALL_RESPONSE_HAS_MORE_KEY => false,
CloseIoResponse::GET_ALL_RESPONSE_TOTAL_RESULTS_KEY => '3',
CloseIoResponse::GET_ALL_RESPONSE_LEADS_KEY => $leadsArray
];

// init wrapper
$closeIoConfig = new CloseIoConfig();
$closeIoConfig->setApiKey('test-api-key');
$closeIoApiWrapper = new CloseIoApiWrapper($closeIoConfig);
$leadsApi = $closeIoApiWrapper->getLeadApi();

$leadsApi = $this->getLeadsApi();

$expectedResponse = new CloseIoResponse();
$expectedResponse->setReturnCode(200);
Expand All @@ -117,7 +97,6 @@ public function testGetAllLeads($lead)
foreach ($returnedLeads as $key => $lead){
$this->assertTrue($lead == $leadsArray[$key]);
}

}

/**
Expand Down Expand Up @@ -219,5 +198,34 @@ public function leadProvider()
]
];
}

/**
* @return array
*/
public function leadArrayProvider()
{
$lead = new Lead(['name'=>'Test Name', 'description' => 'Test Description']);

// set up leads to be returned
$leadOne = clone $lead;
$leadTwo = clone $lead;
$leadThree = clone $lead;

$leadOne->setId('TestIdOne');
$leadTwo->setId('TestIdTwo');
$leadThree->setId('TestIdThree');

$leadsArray = [
$leadOne,
$leadTwo,
$leadThree
];

return [
[
$leadsArray
],
];
}
}

0 comments on commit 200aadd

Please sign in to comment.