shutterstock-ruby 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/shutterstock-ruby.rb +2 -0
- data/lib/shutterstock-ruby/connections.rb +17 -5
- data/lib/shutterstock-ruby/videos.rb +10 -0
- data/spec/lib/shutterstock_ruby_spec.rb +6 -0
- data/spec/spec_helper.rb +0 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a16a3aea51b0797b15acdf0b796a4b1f318e5333
|
4
|
+
data.tar.gz: 6c60678b9f218c9f4c0129d8db4846b9ee238e9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a868e0f76dcacb6b56b30858b588924596077ab071dd4be3e36851b55d86c220e97d3758cb650305df640174158473a2365736799e9d93d7c9734ddae67fdcd
|
7
|
+
data.tar.gz: 7c867d2f9b4f0c32ef84e723150edf76ba037bcf26988fba2ba03b198e506ab312488fcd037ecc324731a13986dfca4a54ebc94679a7746c692be2d790af20cd
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ The Shutterstock Ruby API Wrapper
|
|
4
4
|
A Ruby API wrapper for [Shutterstock](http://www.shutterstock.com/) [API's](http://developers.shutterstock.com)
|
5
5
|
|
6
6
|
[](http://badge.fury.io/rb/shutterstock-ruby)[](https://gemnasium.com/TailorBrands/shutterstock-ruby)
|
7
|
-
[](https://circleci.com/gh/TailorBrands/shutterstock-ruby/tree/master) [](https://codeclimate.com/github/TailorBrands/shutterstock-ruby)
|
7
|
+
[](https://circleci.com/gh/TailorBrands/shutterstock-ruby/tree/master) [](https://codeclimate.com/github/TailorBrands/shutterstock-ruby)
|
8
8
|
|
9
9
|
```rb
|
10
10
|
gem "shutterstock-ruby"
|
data/lib/shutterstock-ruby.rb
CHANGED
@@ -19,10 +19,12 @@ module ShutterstockRuby
|
|
19
19
|
|
20
20
|
# Main configuration class.
|
21
21
|
class Configuration
|
22
|
+
attr_accessor :access_token
|
22
23
|
attr_accessor :api_client
|
23
24
|
attr_accessor :api_secret
|
24
25
|
|
25
26
|
def initialize
|
27
|
+
@access_token = nil
|
26
28
|
@api_client = nil
|
27
29
|
@api_secret = nil
|
28
30
|
end
|
@@ -6,24 +6,36 @@ module ShutterstockRuby
|
|
6
6
|
options = { accept: :json }.merge(options)
|
7
7
|
options[:params] = params unless params.nil?
|
8
8
|
|
9
|
-
RestClient.get(build_url(path), options)
|
9
|
+
RestClient.get(build_url(path), add_bearer(options))
|
10
10
|
end
|
11
11
|
|
12
|
-
def post(path, body, options = {})
|
12
|
+
def post(path, body, params = nil, options = {})
|
13
13
|
ensure_credentials!
|
14
14
|
|
15
|
-
|
15
|
+
options[:params] = params unless params.nil?
|
16
|
+
options[:content_type] = "application/json"
|
17
|
+
|
18
|
+
RestClient.post(build_url(path), body, add_bearer(options))
|
16
19
|
end
|
17
20
|
|
18
21
|
private
|
19
22
|
|
20
23
|
def build_url(path)
|
21
|
-
|
24
|
+
if ShutterstockRuby.configuration.access_token
|
25
|
+
"https://#{ShutterstockRuby::API_BASE}#{path}"
|
26
|
+
else
|
27
|
+
"https://#{ShutterstockRuby.configuration.api_client}:#{ShutterstockRuby.configuration.api_secret}@#{ShutterstockRuby::API_BASE}#{path}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_bearer(options)
|
32
|
+
options[:authorization] = "Bearer #{ShutterstockRuby.configuration.access_token}" if ShutterstockRuby.configuration.access_token
|
33
|
+
options
|
22
34
|
end
|
23
35
|
|
24
36
|
def ensure_credentials!
|
25
37
|
config = ShutterstockRuby.configuration
|
26
|
-
fail(Exception, 'Missing credentials') if config.api_client.nil? || config.api_secret.nil?
|
38
|
+
fail(Exception, 'Missing credentials') if (config.api_client.nil? || config.api_secret.nil?) && config.access_token.nil?
|
27
39
|
end
|
28
40
|
end
|
29
41
|
end
|
@@ -6,5 +6,15 @@ module ShutterstockRuby
|
|
6
6
|
def self.search(query, options = {})
|
7
7
|
JSON.parse(self.get('/videos/search', { query: query }.merge(options)))
|
8
8
|
end
|
9
|
+
|
10
|
+
def self.details(id, options = {})
|
11
|
+
JSON.parse(self.get('/videos', { id: id }.merge(options)))
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.purchase(id, subscription_id, size, options = {})
|
15
|
+
params = { subscription_id: subscription_id, size: size }
|
16
|
+
body = { videos: [ video_id: id ] }.to_json
|
17
|
+
JSON.parse(self.post("/videos/licenses", body, params, options))
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
@@ -2,26 +2,32 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe ShutterstockRuby do
|
4
4
|
after :each do
|
5
|
+
ShutterstockRuby.configuration.access_token = nil
|
5
6
|
ShutterstockRuby.configuration.api_client = nil
|
6
7
|
ShutterstockRuby.configuration.api_secret = nil
|
7
8
|
end
|
8
9
|
|
9
10
|
it 'has the correct default' do
|
11
|
+
expect(ShutterstockRuby.configuration.access_token).to be nil
|
10
12
|
expect(ShutterstockRuby.configuration.api_client).to be nil
|
11
13
|
expect(ShutterstockRuby.configuration.api_secret).to be nil
|
12
14
|
end
|
13
15
|
|
14
16
|
it 'sets the correct configuration' do
|
17
|
+
expect(ShutterstockRuby.configuration.access_token).to be nil
|
15
18
|
expect(ShutterstockRuby.configuration.api_client).to be nil
|
16
19
|
expect(ShutterstockRuby.configuration.api_secret).to be nil
|
17
20
|
|
21
|
+
token = SecureRandom.uuid
|
18
22
|
key = SecureRandom.uuid
|
19
23
|
secret = SecureRandom.uuid
|
20
24
|
ShutterstockRuby.configure do |config|
|
25
|
+
config.access_token = token
|
21
26
|
config.api_client = key
|
22
27
|
config.api_secret = secret
|
23
28
|
end
|
24
29
|
|
30
|
+
expect(ShutterstockRuby.configuration.access_token).to equal(token)
|
25
31
|
expect(ShutterstockRuby.configuration.api_client).to equal(key)
|
26
32
|
expect(ShutterstockRuby.configuration.api_secret).to equal(secret)
|
27
33
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shutterstock-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nadav Shatz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.6.11
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: An API wrapper for the Shutterstock API's
|