Skip to content

Commit c6830d4

Browse files
authored
Merge pull request #13 from DripEmail/psr_4
PSR 4 and client refresh
2 parents 38d2928 + c063d68 commit c6830d4

25 files changed

Lines changed: 1261 additions & 609 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Composer files.
2+
/vendor
3+
/composer.lock
4+
/.vscode

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: php
2+
php:
3+
- '5.6'
4+
- '7.0'
5+
- '7.1'
6+
- '7.2'
7+
- 'hhvm'
8+
install:
9+
- 'make install'
10+
script:
11+
- 'make test lint'

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
- Set up composer package
10+
- Make PSR-4 compatible
11+
- Move to namespace `\Drip\Client`
12+
- Pass account_id into client constructor (matches semantics of Ruby API client better)
13+
- Remove some client methods to reduce abstraction leakage:
14+
- `\Drip\Client#make_request`
15+
- `\Drip\Client#get_request_info`
16+
- `\Drip\Client#get_error_message`
17+
- `\Drip\Client#get_error_code`
18+
- `\Drip\Client#_parse_error`
19+
- Switch to Guzzle HTTP Client
20+
- Allow setting of API endpoint
21+
- Return response object instead of array.
22+
- Fairly complete test suite
23+
- Code coverage metrics
24+
- Linter
25+
26+
## 0.0.2
27+
28+
* Introduces Composer
29+
30+
## 0.0.1
31+
32+
* Initial release

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: test lint install
2+
3+
install:
4+
composer install
5+
6+
test:
7+
./vendor/bin/phpunit
8+
9+
lint:
10+
./vendor/bin/phpcs -s

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1-
Drip API Wrapper - PHP
2-
===============
1+
# Drip API Wrapper - PHP
32

4-
An object-oriented PHP wrapper for Drip's REST API v2.0
3+
An object-oriented PHP wrapper for Drip's REST API v2.0
4+
5+
[![Build Status](https://travis-ci.org/DripEmail/drip-php.svg?branch=master)](https://travis-ci.org/DripEmail/drip-php)
6+
7+
## Installation
8+
9+
Run `composer require dripemail/drip-php`
10+
11+
## Authentication
12+
13+
For private integrations, you may use your personal API Token (found
14+
[here](https://www.getdrip.com/user/edit)) via the `api_key` setting:
15+
16+
```php
17+
$client = new \Drip\Client("YOUR_API_KEY", "YOUR_ACCOUNT_ID");
18+
```
19+
20+
For public integrations, pass in the user's OAuth token via the `access_token`
21+
setting:
22+
23+
```php
24+
$client = new \Drip\Client("YOUR_ACCESS_TOKEN", "YOUR_ACCOUNT_ID");
25+
```
26+
27+
Your account ID can be found [here](https://www.getdrip.com/settings/site).
28+
Most API actions require an account ID, with the exception of methods like
29+
the "list accounts" endpoint.
30+
31+
32+
## PHP version support
33+
34+
We attempt to support versions of PHP that are supported upstream: http://php.net/supported-versions.php
35+
36+
For the actual supported list, see `.travis.yml`.

composer.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
"name": "dripemail/drip-php",
33
"description": "An object-oriented PHP wrapper for Drip's REST API v2.0",
44
"homepage": "https://github.com/DripEmail/drip-php",
5+
"license": "MIT",
56
"autoload": {
6-
"classmap": [
7-
"src/"
8-
]
7+
"psr-4": { "Drip\\": "src" }
8+
},
9+
"require-dev": {
10+
"phpunit/phpunit": "^5",
11+
"squizlabs/php_codesniffer": "3.*"
12+
},
13+
"require": {
14+
"guzzlehttp/guzzle": "^6.3"
915
}
10-
}
16+
}

phpcs.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Drip">
3+
<description>The coding standard for Drip.</description>
4+
5+
<file>src/</file>
6+
<file>tests/</file>
7+
8+
<exclude-pattern>*/Standards/*/Tests/*\.(inc|css|js)</exclude-pattern>
9+
10+
<arg name="basepath" value="."/>
11+
<arg name="colors" />
12+
<arg name="parallel" value="75" />
13+
<arg value="np"/>
14+
15+
<rule ref="PSR2">
16+
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
17+
</rule>
18+
19+
<rule ref="Generic.PHP.ClosingPHPTag.Found"/>
20+
<rule ref="Generic.Files.EndFileNoNewline.NotFound"/>
21+
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent.TabsUsed"/>
22+
<rule ref="Generic.PHP.DeprecatedFunctions"/>
23+
<rule ref="Generic.PHP.LowerCaseKeyword"/>
24+
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
25+
<rule ref="Generic.Commenting.Todo"/>
26+
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
27+
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
28+
<rule ref="Generic.Formatting.SpaceAfterCast"/>
29+
<rule ref="Generic.NamingConventions.ConstructorName"/>
30+
<rule ref="Squiz.Arrays.ArrayBracketSpacing" />
31+
<rule ref="Squiz.ControlStructures.ControlSignature" />
32+
<rule ref="Squiz.ControlStructures.ElseIfDeclaration" />
33+
<rule ref="Squiz.Commenting.BlockComment" />
34+
<rule ref="Squiz.Commenting.DocCommentAlignment" />
35+
<rule ref="Squiz.Commenting.EmptyCatchComment" />
36+
<rule ref="Squiz.Commenting.LongConditionClosingComment" />
37+
<rule ref="Squiz.Commenting.VariableComment" />
38+
<rule ref="Squiz.Formatting.OperatorBracket" />
39+
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing" />
40+
<rule ref="Squiz.Scope.MethodScope" />
41+
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing" />
42+
<rule ref="Squiz.WhiteSpace.OperatorSpacing" />
43+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace" />
44+
</ruleset>

phpunit.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
failOnRisky="true"
9+
failOnWarning="true"
10+
>
11+
12+
<php>
13+
<includePath>./tests/support</includePath>
14+
</php>
15+
16+
<testsuites>
17+
<testsuite name="Drip PHP API Client Tests">
18+
<directory>./tests/</directory>
19+
</testsuite>
20+
</testsuites>
21+
22+
<filter>
23+
<whitelist>
24+
<directory>./</directory>
25+
<exclude>
26+
<directory>./tests</directory>
27+
<directory>./vendor</directory>
28+
</exclude>
29+
</whitelist>
30+
</filter>
31+
32+
<logging>
33+
<!-- <log type="coverage-html" target="/tmp/report" lowUpperBound="35" highLowerBound="70"/> -->
34+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" showOnlySummary="true"/>
35+
</logging>
36+
</phpunit>

src/AbstractResponse.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace Drip;
4+
5+
/**
6+
* Base response class
7+
*/
8+
abstract class AbstractResponse implements ResponseInterface
9+
{
10+
/** @var string */
11+
protected $url;
12+
/** @var array */
13+
protected $params;
14+
/** @var \Psr\Http\Message\ResponseInterface */
15+
protected $response;
16+
/** @var array */
17+
protected $body;
18+
19+
public function __construct($url, $params, \Psr\Http\Message\ResponseInterface $response)
20+
{
21+
$this->url = $url;
22+
$this->params = $params;
23+
$this->response = $response;
24+
$this->body = json_decode($response->getBody(), true);
25+
}
26+
27+
/**
28+
* Whether the response is successfull.
29+
*
30+
* @return boolean
31+
*/
32+
public function is_success()
33+
{
34+
return $this->get_http_code() >= 200 && $this->get_http_code() <= 299;
35+
}
36+
37+
/**
38+
* The url of the request.
39+
*
40+
* @return string
41+
*/
42+
public function get_url()
43+
{
44+
return $this->url;
45+
}
46+
47+
/**
48+
* The parameters of the request.
49+
*
50+
* @return array
51+
*/
52+
public function get_params()
53+
{
54+
return $this->params;
55+
}
56+
57+
/**
58+
* The http response code
59+
*
60+
* @return integer
61+
*/
62+
public function get_http_code()
63+
{
64+
return $this->response->getStatusCode();
65+
}
66+
67+
/**
68+
* The http response message
69+
*
70+
* @return string
71+
*/
72+
public function get_http_message()
73+
{
74+
return $this->response->getReasonPhrase();
75+
}
76+
}

0 commit comments

Comments
 (0)