-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b68420c
Showing
16 changed files
with
2,492 additions
and
0 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,17 @@ | ||
--- | ||
engines: | ||
duplication: | ||
enabled: true | ||
config: | ||
languages: | ||
- php | ||
fixme: | ||
enabled: true | ||
phpcodesniffer: | ||
enabled: true | ||
phpmd: | ||
enabled: true | ||
ratings: | ||
paths: | ||
- src/** | ||
- tests/** |
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,5 @@ | ||
/build | ||
/vendor | ||
codeclimate.json | ||
composer.phar | ||
coverage.xml |
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,14 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7 | ||
|
||
install: | ||
- composer self-update | ||
- composer install --dev --no-interaction | ||
|
||
script: phpunit --tap --coverage-clover build/logs/clover.xml | ||
|
||
after_script: | ||
- bash bin/codeclimate.sh |
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,13 @@ | ||
Copyright 2016 Shutterstock Images, LLC | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
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,66 @@ | ||
# Demo Client for Shutterstock API | ||
|
||
PHP client that utilizes Guzzle to interact with the [Shutterstock API](https://developers.shutterstock.com/). | ||
|
||
[![Build Status](https://travis-ci.org/jacobemerick/php-shutterstock-api.svg)](https://travis-ci.org/jacobemerick/php-shutterstock-api) | ||
[![Code Climate](https://codeclimate.com/github/jacobemerick/php-shutterstock-api/badges/gpa.svg)](https://codeclimate.com/github/jacobemerick/php-shutterstock-api) | ||
[![Test Coverage](https://codeclimate.com/github/jacobemerick/php-shutterstock-api/badges/coverage.svg)](https://codeclimate.com/github/jacobemerick/php-shutterstock-api/coverage) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jacobemerick/php-shutterstock-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jacobemerick/php-shutterstock-api/?branch=master) | ||
|
||
## Installation | ||
|
||
Use [Composer](https://getcomposer.org/) to install the dependencies. | ||
|
||
```bash | ||
$ composer require shutterstock/php-shutterstock-api | ||
``` | ||
|
||
## Usage | ||
|
||
Instantiating the client requires passing in your client id and secret, which you can register for on the [Shutterstock Developers site](https://developers.shutterstock.com/). | ||
|
||
```php | ||
<?php | ||
|
||
require_once __DIR__ . '/vendor/autoload.php'; | ||
|
||
$client = new Shutterstock\Api\Client($clientId, $clientSecret); | ||
``` | ||
|
||
Interacting with the different endpoints is as simple as reading the [API documentation](https://developers.shutterstock.com/api/v2). There are two main methods of the client to deal with - `Client::get` and `Client::post` - which take an endpoint as their first argument and the client parameters as the second. | ||
|
||
```php | ||
// perform an image search for puppies | ||
$client->get('images/search', array('query' => 'puppies')); | ||
|
||
// retrieve details for a handful of image ids | ||
$client->get('images', array('id' => array(1, 2, 3))); | ||
|
||
// create a lightbox | ||
$client->post('images/collections', array('name' => 'Lightbox Name Here')); | ||
``` | ||
|
||
Each request will return a PSR-7 response object, which you can read about on the [Guzzle/PSR7 repo](https://github.com/guzzle/psr7). The response object bodies have been decorated with a JsonSerializable interface to allow easier handling of the default API responses. | ||
|
||
```php | ||
$imageResponse = $client->get('images', array('id' => array(1, 2, 3))); | ||
if ($imageResponse->getStatusCode() != 200) { | ||
// error handler | ||
} | ||
$images = $imageResponse->getBody()->jsonSerialize()['data']; | ||
// etc | ||
``` | ||
|
||
If your application is setup to handle async CURL requests, you can also make `Client::getAsync` and `Client::postAsync` calls, which return [Guzzle Promises](https://github.com/guzzle/promises). | ||
|
||
For more examples and a demo application using this client, see [LINK HERE]. | ||
|
||
## License | ||
|
||
Copyright 2016 Shutterstock Images, LLC | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
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 @@ | ||
#!/usr/bin/env sh | ||
|
||
php vendor/bin/test-reporter --stdout > codeclimate.json | ||
curl -X POST -d @codeclimate.json -H 'Content-Type: application/json' -H 'User-Agent: Code Climate (PHP Test Reporter v0.1.1)' https://codeclimate.com/test_reports |
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,23 @@ | ||
{ | ||
"name": "shutterstock/api", | ||
"license": "Apache-2.0", | ||
"require": { | ||
"php": ">=5.6", | ||
"guzzlehttp/guzzle": "^6.1", | ||
"psr/log": "^1.0" | ||
}, | ||
"require-dev": { | ||
"codeclimate/php-test-reporter": "dev-master", | ||
"phpunit/phpunit": "^5.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Shutterstock\\Api\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Shutterstock\\Api\\": "tests/" | ||
} | ||
} | ||
} |
Oops, something went wrong.