shutterstock-ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +53 -0
- data/Rakefile +14 -0
- data/lib/shutterstock-ruby.rb +29 -0
- data/lib/shutterstock-ruby/connections.rb +29 -0
- data/lib/shutterstock-ruby/images.rb +11 -0
- data/spec/lib/shutterstock_ruby_spec.rb +28 -0
- data/spec/spec_helper.rb +16 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1101126b2596109a4c85c48056fa9cd787a95a15
|
4
|
+
data.tar.gz: 13240bc37a9d789cfa8ab86b429ded04eb3f870f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2a8583283c6b41cc743dd39c084e2d8d14bdcc5dc74d98d3fa4f5a07624ce405b164290100880a1c61bf96f3b6313ce162e381eab55c2f4ac3212b8aeaa9ef4
|
7
|
+
data.tar.gz: 77d7a8c37993f297dc25e5041d102db23eb6a12c11b87a4e307fde1e4c5886202a092dc559d951db5d2d986d4763c37659e2e33853f91ebd55db4e27da5ee919
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tailor
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
The Shutterstock Ruby API Wrapper
|
2
|
+
===================
|
3
|
+
|
4
|
+
A Ruby API wrapper for [Shutterstock](http://www.shutterstock.com/) [API's](http://developers.shutterstock.com)
|
5
|
+
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/shutterstock-ruby.svg)](http://badge.fury.io/rb/shutterstock-ruby)[![Dependency Status](https://gemnasium.com/TailorBrands/shutterstock-ruby.svg)](https://gemnasium.com/TailorBrands/shutterstock-ruby)
|
7
|
+
[![Circle CI](https://circleci.com/gh/TailorBrands/shutterstock-ruby/tree/master.svg?style=svg)](https://circleci.com/gh/TailorBrands/shutterstock-ruby/tree/master) [![Code Climate](https://codeclimate.com/github/TailorBrands/shutterstock-ruby/badges/gpa.svg)](https://codeclimate.com/github/TailorBrands/shutterstock-ruby) [![Test Coverage](https://codeclimate.com/github/TailorBrands/shutterstock-ruby/badges/coverage.svg)](https://codeclimate.com/github/TailorBrands/shutterstock-ruby)
|
8
|
+
|
9
|
+
```rb
|
10
|
+
gem "shutterstock-ruby", "~> 0.0.1"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Missing
|
14
|
+
|
15
|
+
Current version only wraps the Image search, purchase and download API's. Feel free to send a pull request with more API's wrapped!
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
You need a valid client_id/secret combo to use the Gem, you can get it by signing up [here](http://developers.shutterstock.com)
|
20
|
+
|
21
|
+
*Raises Exception on missing credentials*
|
22
|
+
|
23
|
+
### Configuration
|
24
|
+
You can use an initializer for example if you're on Rails.
|
25
|
+
```rb
|
26
|
+
# initializers/shutterstock.rb
|
27
|
+
ShutterstockRuby.configure do |config|
|
28
|
+
config.api_client = ENV['SHUTTERSTOCK_CLIENT']
|
29
|
+
config.api_secret = ENV['SHUTTERSTOCK_SECRET']
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
### Search for images
|
34
|
+
|
35
|
+
```rb
|
36
|
+
result = ShutterstockRuby::Images.search('Cat') # Returns a hash of the parsed JSON result.
|
37
|
+
```
|
38
|
+
Source [source](https://developers.shutterstock.com/api/v2/image/search)
|
39
|
+
|
40
|
+
## Disclaimer
|
41
|
+
|
42
|
+
This is completely unofficial and is not related to Shutterstock in any way.
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
51
|
+
|
52
|
+
## About Tailor Brands
|
53
|
+
[Check us out!](https://www.tailorbrands.com)
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
$:.unshift 'lib'
|
5
|
+
|
6
|
+
desc 'Default: run unit tests.'
|
7
|
+
task :default => [:spec]
|
8
|
+
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
|
11
|
+
desc 'Run specs'
|
12
|
+
RSpec::Core::RakeTask.new do |t|
|
13
|
+
t.pattern = './spec/**/*_spec.rb'
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'shutterstock-ruby/connections'
|
4
|
+
require 'shutterstock-ruby/images'
|
5
|
+
|
6
|
+
# Top level name space for the entire Gem.
|
7
|
+
module ShutterstockRuby
|
8
|
+
API_BASE = 'api.shutterstock.com/v2'
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
self.configuration ||= Configuration.new
|
16
|
+
yield(configuration) if block_given?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Main configuration class.
|
20
|
+
class Configuration
|
21
|
+
attr_accessor :api_client
|
22
|
+
attr_accessor :api_secret
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@api_client = nil
|
26
|
+
@api_secret = nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ShutterstockRuby
|
2
|
+
module Connections
|
3
|
+
def get(path, params = nil, options = {})
|
4
|
+
ensure_credentials!
|
5
|
+
|
6
|
+
options = { accept: :json }.merge(options)
|
7
|
+
options[:params] = params unless params.nil?
|
8
|
+
|
9
|
+
RestClient.get(build_url(path), options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(path, body, options = {})
|
13
|
+
ensure_credentials!
|
14
|
+
|
15
|
+
RestClient.post(build_url(path), body, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def build_url(path)
|
21
|
+
"https://#{ShutterstockRuby.configuration.api_client}:#{ShutterstockRuby.configuration.api_secret}@#{ShutterstockRuby::API_BASE}#{path}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def ensure_credentials!
|
25
|
+
config = ShutterstockRuby.configuration
|
26
|
+
fail(Exception, 'Missing credentials') if config.api_client.nil? || config.api_secret.nil?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ShutterstockRuby
|
2
|
+
# A class to hold all images related code.
|
3
|
+
class Images
|
4
|
+
extend Connections
|
5
|
+
|
6
|
+
def self.search(query, options = {})
|
7
|
+
query = URI.encode_www_form_component(query)
|
8
|
+
JSON.parse(self.get('/images/search', { query: query }.merge(options)))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ShutterstockRuby do
|
4
|
+
after :each do
|
5
|
+
ShutterstockRuby.configuration.api_client = nil
|
6
|
+
ShutterstockRuby.configuration.api_secret = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'has the correct default' do
|
10
|
+
expect(ShutterstockRuby.configuration.api_client).to be nil
|
11
|
+
expect(ShutterstockRuby.configuration.api_secret).to be nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'sets the correct configuration' do
|
15
|
+
expect(ShutterstockRuby.configuration.api_client).to be nil
|
16
|
+
expect(ShutterstockRuby.configuration.api_secret).to be nil
|
17
|
+
|
18
|
+
key = SecureRandom.uuid
|
19
|
+
secret = SecureRandom.uuid
|
20
|
+
ShutterstockRuby.configure do |config|
|
21
|
+
config.api_client = key
|
22
|
+
config.api_secret = secret
|
23
|
+
end
|
24
|
+
|
25
|
+
expect(ShutterstockRuby.configuration.api_client).to equal(key)
|
26
|
+
expect(ShutterstockRuby.configuration.api_secret).to equal(secret)
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'codeclimate-test-reporter'
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'shutterstock-ruby'
|
6
|
+
require 'pry'
|
7
|
+
require 'faker'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
# require_relative 'support/fakes'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.disable_monkey_patching!
|
14
|
+
config.formatter = 'documentation'
|
15
|
+
config.color = true
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shutterstock-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nadav Shatz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 3.2.0
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.2'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.2.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: faker
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: semver
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: A Gem to expose a wrapping API for the Shutterstock API's
|
90
|
+
email: nadav@tailorbrands.com
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/shutterstock-ruby.rb
|
99
|
+
- lib/shutterstock-ruby/connections.rb
|
100
|
+
- lib/shutterstock-ruby/images.rb
|
101
|
+
- spec/lib/shutterstock_ruby_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/TailorBrands/shutterstock-ruby
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.4.5
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: An API wrapper for the Shutterstock API's
|
127
|
+
test_files:
|
128
|
+
- spec/lib/shutterstock_ruby_spec.rb
|
129
|
+
- spec/spec_helper.rb
|