Skip to content

Commit

Permalink
Merge pull request #13 from DripEmail/psr_4
Browse files Browse the repository at this point in the history
PSR 4 and client refresh
  • Loading branch information
will-in-wi authored Jun 6, 2018
2 parents 38d2928 + c063d68 commit c6830d4
Show file tree
Hide file tree
Showing 25 changed files with 1,261 additions and 609 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Composer files.
/vendor
/composer.lock
/.vscode
11 changes: 11 additions & 0 deletions .travis.yml
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'
32 changes: 32 additions & 0 deletions CHANGELOG.md
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
10 changes: 10 additions & 0 deletions Makefile
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
38 changes: 35 additions & 3 deletions README.md
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`.
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
"name": "dripemail/drip-php",
"description": "An object-oriented PHP wrapper for Drip's REST API v2.0",
"homepage": "https://github.com/DripEmail/drip-php",
"license": "MIT",
"autoload": {
"classmap": [
"src/"
]
"psr-4": { "Drip\\": "src" }
},
"require-dev": {
"phpunit/phpunit": "^5",
"squizlabs/php_codesniffer": "3.*"
},
"require": {
"guzzlehttp/guzzle": "^6.3"
}
}
}
44 changes: 44 additions & 0 deletions phpcs.xml
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>
36 changes: 36 additions & 0 deletions phpunit.xml
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>
76 changes: 76 additions & 0 deletions src/AbstractResponse.php
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();
}
}
Loading

0 comments on commit c6830d4

Please sign in to comment.