-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from DripEmail/psr_4
PSR 4 and client refresh
- Loading branch information
Showing
25 changed files
with
1,261 additions
and
609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Composer files. | ||
/vendor | ||
/composer.lock | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: php | ||
php: | ||
- '5.6' | ||
- '7.0' | ||
- '7.1' | ||
- '7.2' | ||
- 'hhvm' | ||
install: | ||
- 'make install' | ||
script: | ||
- 'make test lint' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
- Set up composer package | ||
- Make PSR-4 compatible | ||
- Move to namespace `\Drip\Client` | ||
- Pass account_id into client constructor (matches semantics of Ruby API client better) | ||
- Remove some client methods to reduce abstraction leakage: | ||
- `\Drip\Client#make_request` | ||
- `\Drip\Client#get_request_info` | ||
- `\Drip\Client#get_error_message` | ||
- `\Drip\Client#get_error_code` | ||
- `\Drip\Client#_parse_error` | ||
- Switch to Guzzle HTTP Client | ||
- Allow setting of API endpoint | ||
- Return response object instead of array. | ||
- Fairly complete test suite | ||
- Code coverage metrics | ||
- Linter | ||
|
||
## 0.0.2 | ||
|
||
* Introduces Composer | ||
|
||
## 0.0.1 | ||
|
||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.PHONY: test lint install | ||
|
||
install: | ||
composer install | ||
|
||
test: | ||
./vendor/bin/phpunit | ||
|
||
lint: | ||
./vendor/bin/phpcs -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
Drip API Wrapper - PHP | ||
=============== | ||
# Drip API Wrapper - PHP | ||
|
||
An object-oriented PHP wrapper for Drip's REST API v2.0 | ||
An object-oriented PHP wrapper for Drip's REST API v2.0 | ||
|
||
[![Build Status](https://travis-ci.org/DripEmail/drip-php.svg?branch=master)](https://travis-ci.org/DripEmail/drip-php) | ||
|
||
## Installation | ||
|
||
Run `composer require dripemail/drip-php` | ||
|
||
## Authentication | ||
|
||
For private integrations, you may use your personal API Token (found | ||
[here](https://www.getdrip.com/user/edit)) via the `api_key` setting: | ||
|
||
```php | ||
$client = new \Drip\Client("YOUR_API_KEY", "YOUR_ACCOUNT_ID"); | ||
``` | ||
|
||
For public integrations, pass in the user's OAuth token via the `access_token` | ||
setting: | ||
|
||
```php | ||
$client = new \Drip\Client("YOUR_ACCESS_TOKEN", "YOUR_ACCOUNT_ID"); | ||
``` | ||
|
||
Your account ID can be found [here](https://www.getdrip.com/settings/site). | ||
Most API actions require an account ID, with the exception of methods like | ||
the "list accounts" endpoint. | ||
|
||
|
||
## PHP version support | ||
|
||
We attempt to support versions of PHP that are supported upstream: http://php.net/supported-versions.php | ||
|
||
For the actual supported list, see `.travis.yml`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Drip"> | ||
<description>The coding standard for Drip.</description> | ||
|
||
<file>src/</file> | ||
<file>tests/</file> | ||
|
||
<exclude-pattern>*/Standards/*/Tests/*\.(inc|css|js)</exclude-pattern> | ||
|
||
<arg name="basepath" value="."/> | ||
<arg name="colors" /> | ||
<arg name="parallel" value="75" /> | ||
<arg value="np"/> | ||
|
||
<rule ref="PSR2"> | ||
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" /> | ||
</rule> | ||
|
||
<rule ref="Generic.PHP.ClosingPHPTag.Found"/> | ||
<rule ref="Generic.Files.EndFileNoNewline.NotFound"/> | ||
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent.TabsUsed"/> | ||
<rule ref="Generic.PHP.DeprecatedFunctions"/> | ||
<rule ref="Generic.PHP.LowerCaseKeyword"/> | ||
<rule ref="Generic.Strings.UnnecessaryStringConcat"/> | ||
<rule ref="Generic.Commenting.Todo"/> | ||
<rule ref="Generic.ControlStructures.InlineControlStructure"/> | ||
<rule ref="Generic.Formatting.DisallowMultipleStatements"/> | ||
<rule ref="Generic.Formatting.SpaceAfterCast"/> | ||
<rule ref="Generic.NamingConventions.ConstructorName"/> | ||
<rule ref="Squiz.Arrays.ArrayBracketSpacing" /> | ||
<rule ref="Squiz.ControlStructures.ControlSignature" /> | ||
<rule ref="Squiz.ControlStructures.ElseIfDeclaration" /> | ||
<rule ref="Squiz.Commenting.BlockComment" /> | ||
<rule ref="Squiz.Commenting.DocCommentAlignment" /> | ||
<rule ref="Squiz.Commenting.EmptyCatchComment" /> | ||
<rule ref="Squiz.Commenting.LongConditionClosingComment" /> | ||
<rule ref="Squiz.Commenting.VariableComment" /> | ||
<rule ref="Squiz.Formatting.OperatorBracket" /> | ||
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing" /> | ||
<rule ref="Squiz.Scope.MethodScope" /> | ||
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing" /> | ||
<rule ref="Squiz.WhiteSpace.OperatorSpacing" /> | ||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" /> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
> | ||
|
||
<php> | ||
<includePath>./tests/support</includePath> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Drip PHP API Client Tests"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./</directory> | ||
<exclude> | ||
<directory>./tests</directory> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
|
||
<logging> | ||
<!-- <log type="coverage-html" target="/tmp/report" lowUpperBound="35" highLowerBound="70"/> --> | ||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" showOnlySummary="true"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Drip; | ||
|
||
/** | ||
* Base response class | ||
*/ | ||
abstract class AbstractResponse implements ResponseInterface | ||
{ | ||
/** @var string */ | ||
protected $url; | ||
/** @var array */ | ||
protected $params; | ||
/** @var \Psr\Http\Message\ResponseInterface */ | ||
protected $response; | ||
/** @var array */ | ||
protected $body; | ||
|
||
public function __construct($url, $params, \Psr\Http\Message\ResponseInterface $response) | ||
{ | ||
$this->url = $url; | ||
$this->params = $params; | ||
$this->response = $response; | ||
$this->body = json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* Whether the response is successfull. | ||
* | ||
* @return boolean | ||
*/ | ||
public function is_success() | ||
{ | ||
return $this->get_http_code() >= 200 && $this->get_http_code() <= 299; | ||
} | ||
|
||
/** | ||
* The url of the request. | ||
* | ||
* @return string | ||
*/ | ||
public function get_url() | ||
{ | ||
return $this->url; | ||
} | ||
|
||
/** | ||
* The parameters of the request. | ||
* | ||
* @return array | ||
*/ | ||
public function get_params() | ||
{ | ||
return $this->params; | ||
} | ||
|
||
/** | ||
* The http response code | ||
* | ||
* @return integer | ||
*/ | ||
public function get_http_code() | ||
{ | ||
return $this->response->getStatusCode(); | ||
} | ||
|
||
/** | ||
* The http response message | ||
* | ||
* @return string | ||
*/ | ||
public function get_http_message() | ||
{ | ||
return $this->response->getReasonPhrase(); | ||
} | ||
} |
Oops, something went wrong.