Skip to content

Commit b68420c

Browse files
committed
initial release
0 parents  commit b68420c

16 files changed

+2492
-0
lines changed

.codeclimate.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
engines:
3+
duplication:
4+
enabled: true
5+
config:
6+
languages:
7+
- php
8+
fixme:
9+
enabled: true
10+
phpcodesniffer:
11+
enabled: true
12+
phpmd:
13+
enabled: true
14+
ratings:
15+
paths:
16+
- src/**
17+
- tests/**

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/build
2+
/vendor
3+
codeclimate.json
4+
composer.phar
5+
coverage.xml

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: php
2+
3+
php:
4+
- 5.6
5+
- 7
6+
7+
install:
8+
- composer self-update
9+
- composer install --dev --no-interaction
10+
11+
script: phpunit --tap --coverage-clover build/logs/clover.xml
12+
13+
after_script:
14+
- bash bin/codeclimate.sh

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2016 Shutterstock Images, LLC
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Demo Client for Shutterstock API
2+
3+
PHP client that utilizes Guzzle to interact with the [Shutterstock API](https://developers.shutterstock.com/).
4+
5+
[![Build Status](https://travis-ci.org/jacobemerick/php-shutterstock-api.svg)](https://travis-ci.org/jacobemerick/php-shutterstock-api)
6+
[![Code Climate](https://codeclimate.com/github/jacobemerick/php-shutterstock-api/badges/gpa.svg)](https://codeclimate.com/github/jacobemerick/php-shutterstock-api)
7+
[![Test Coverage](https://codeclimate.com/github/jacobemerick/php-shutterstock-api/badges/coverage.svg)](https://codeclimate.com/github/jacobemerick/php-shutterstock-api/coverage)
8+
[![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)
9+
10+
## Installation
11+
12+
Use [Composer](https://getcomposer.org/) to install the dependencies.
13+
14+
```bash
15+
$ composer require shutterstock/php-shutterstock-api
16+
```
17+
18+
## Usage
19+
20+
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/).
21+
22+
```php
23+
<?php
24+
25+
require_once __DIR__ . '/vendor/autoload.php';
26+
27+
$client = new Shutterstock\Api\Client($clientId, $clientSecret);
28+
```
29+
30+
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.
31+
32+
```php
33+
// perform an image search for puppies
34+
$client->get('images/search', array('query' => 'puppies'));
35+
36+
// retrieve details for a handful of image ids
37+
$client->get('images', array('id' => array(1, 2, 3)));
38+
39+
// create a lightbox
40+
$client->post('images/collections', array('name' => 'Lightbox Name Here'));
41+
```
42+
43+
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.
44+
45+
```php
46+
$imageResponse = $client->get('images', array('id' => array(1, 2, 3)));
47+
if ($imageResponse->getStatusCode() != 200) {
48+
// error handler
49+
}
50+
$images = $imageResponse->getBody()->jsonSerialize()['data'];
51+
// etc
52+
```
53+
54+
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).
55+
56+
For more examples and a demo application using this client, see [LINK HERE].
57+
58+
## License
59+
60+
Copyright 2016 Shutterstock Images, LLC
61+
62+
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
63+
64+
http://www.apache.org/licenses/LICENSE-2.0
65+
66+
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.

bin/codeclimate.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
3+
php vendor/bin/test-reporter --stdout > codeclimate.json
4+
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

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "shutterstock/api",
3+
"license": "Apache-2.0",
4+
"require": {
5+
"php": ">=5.6",
6+
"guzzlehttp/guzzle": "^6.1",
7+
"psr/log": "^1.0"
8+
},
9+
"require-dev": {
10+
"codeclimate/php-test-reporter": "dev-master",
11+
"phpunit/phpunit": "^5.0"
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"Shutterstock\\Api\\": "src/"
16+
}
17+
},
18+
"autoload-dev": {
19+
"psr-4": {
20+
"Shutterstock\\Api\\": "tests/"
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)