shutterstock-ruby 0.3.0 → 0.4.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/lib/shutterstock-ruby.rb +10 -11
- data/lib/shutterstock-ruby/configuration.rb +13 -0
- data/lib/shutterstock-ruby/connections.rb +16 -6
- data/lib/shutterstock-ruby/images.rb +9 -4
- data/lib/shutterstock-ruby/videos.rb +21 -8
- data/spec/lib/shutterstock_ruby_spec.rb +25 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee208d1ecc3c46db667ef7bc689ab76952ccb557
|
4
|
+
data.tar.gz: 5b1aaec166ec632891e7715186576717b0862314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b99eaded4fc7b274a2867a2bbb502a2486ab478e926a2c4877e343197602d0cb957714096f54c47bef15d386ccd55abd77e12987a2c026f9f8c8a2ec4c50e57d
|
7
|
+
data.tar.gz: 6ef64b682f9596a7d169d2e9eee3758c822ebb1f5b41521275a2de3fbe67bdb7d22c942cd490a9182b7d98c7aabf4165c70f550a1ec440a3dfadfd0a00b5b5fb
|
data/lib/shutterstock-ruby.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rest_client'
|
3
|
+
require 'shutterstock-ruby/configuration'
|
3
4
|
require 'shutterstock-ruby/connections'
|
4
5
|
require 'shutterstock-ruby/images'
|
5
6
|
require 'shutterstock-ruby/videos'
|
@@ -9,24 +10,22 @@ module ShutterstockRuby
|
|
9
10
|
API_BASE = 'api.shutterstock.com/v2'
|
10
11
|
|
11
12
|
def self.configuration
|
12
|
-
@configuration ||= Configuration.new
|
13
|
+
@configuration ||= Configuration.new({})
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.configure
|
16
|
-
self.configuration ||= Configuration.new
|
17
|
+
self.configuration ||= Configuration.new({})
|
17
18
|
yield(configuration) if block_given?
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
attr_accessor :access_token
|
23
|
-
attr_accessor :api_client
|
24
|
-
attr_accessor :api_secret
|
21
|
+
class Client
|
22
|
+
attr_reader :configuration, :videos, :images
|
25
23
|
|
26
|
-
def initialize
|
27
|
-
@
|
28
|
-
@
|
29
|
-
@
|
24
|
+
def initialize(args = {})
|
25
|
+
@configuration = Configuration.new(args)
|
26
|
+
@videos = Videos.new(configuration)
|
27
|
+
@images = Images.new(configuration)
|
30
28
|
end
|
29
|
+
|
31
30
|
end
|
32
31
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ShutterstockRuby
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :access_token
|
4
|
+
attr_accessor :api_client
|
5
|
+
attr_accessor :api_secret
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
@access_token = args[:access_token]
|
9
|
+
@api_client = args[:api_client]
|
10
|
+
@api_secret = args[:api_secret]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,5 +1,11 @@
|
|
1
1
|
module ShutterstockRuby
|
2
|
-
|
2
|
+
class Connections
|
3
|
+
attr_reader :configuration
|
4
|
+
|
5
|
+
def initialize(configuration)
|
6
|
+
@configuration = configuration
|
7
|
+
end
|
8
|
+
|
3
9
|
def get(path, params = nil, options = {})
|
4
10
|
ensure_credentials!
|
5
11
|
|
@@ -18,24 +24,28 @@ module ShutterstockRuby
|
|
18
24
|
RestClient.post(build_url(path), body, add_bearer(options))
|
19
25
|
end
|
20
26
|
|
27
|
+
protected
|
28
|
+
def self.client
|
29
|
+
@client ||= new(ShutterstockRuby.configuration)
|
30
|
+
end
|
31
|
+
|
21
32
|
private
|
22
33
|
|
23
34
|
def build_url(path)
|
24
|
-
if
|
35
|
+
if configuration.access_token
|
25
36
|
"https://#{ShutterstockRuby::API_BASE}#{path}"
|
26
37
|
else
|
27
|
-
"https://#{
|
38
|
+
"https://#{configuration.api_client}:#{configuration.api_secret}@#{ShutterstockRuby::API_BASE}#{path}"
|
28
39
|
end
|
29
40
|
end
|
30
41
|
|
31
42
|
def add_bearer(options)
|
32
|
-
options[:authorization] = "Bearer #{
|
43
|
+
options[:authorization] = "Bearer #{configuration.access_token}" if configuration.access_token
|
33
44
|
options
|
34
45
|
end
|
35
46
|
|
36
47
|
def ensure_credentials!
|
37
|
-
|
38
|
-
fail(Exception, 'Missing credentials') if (config.api_client.nil? || config.api_secret.nil?) && config.access_token.nil?
|
48
|
+
fail(Exception, 'Missing credentials') if (configuration.api_client.nil? || configuration.api_secret.nil?) && configuration.access_token.nil?
|
39
49
|
end
|
40
50
|
end
|
41
51
|
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
module ShutterstockRuby
|
2
2
|
# A class to hold all images related code.
|
3
|
-
class Images
|
4
|
-
extend Connections
|
3
|
+
class Images < Connections
|
5
4
|
|
6
|
-
def
|
7
|
-
JSON.parse(
|
5
|
+
def search(query, options = {})
|
6
|
+
JSON.parse(get('/images/search', { query: query }.merge(options)))
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def search(query, options = {})
|
11
|
+
client.search(query, options)
|
12
|
+
end
|
8
13
|
end
|
9
14
|
end
|
10
15
|
end
|
@@ -1,20 +1,33 @@
|
|
1
1
|
module ShutterstockRuby
|
2
2
|
# A class to hold all videos related code.
|
3
|
-
class Videos
|
4
|
-
extend Connections
|
3
|
+
class Videos < Connections
|
5
4
|
|
6
|
-
def
|
7
|
-
JSON.parse(
|
5
|
+
def search(query, options = {})
|
6
|
+
JSON.parse(get('/videos/search', { query: query }.merge(options)))
|
8
7
|
end
|
9
8
|
|
10
|
-
def
|
11
|
-
JSON.parse(
|
9
|
+
def details(id, options = {})
|
10
|
+
JSON.parse(get('/videos', { id: id }.merge(options)))
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
13
|
+
def purchase(id, subscription_id, size, options = {})
|
15
14
|
params = { subscription_id: subscription_id, size: size }
|
16
15
|
body = { videos: [ video_id: id ] }.to_json
|
17
|
-
JSON.parse(
|
16
|
+
JSON.parse(post("/videos/licenses", body, params, options))
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def search(query, options = {})
|
21
|
+
client.search(query, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def details(id, options = {})
|
25
|
+
client.details(id, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def purchase(id, subscription_id, size, options = {})
|
29
|
+
client.purchase(id, subscription_id, size, options)
|
30
|
+
end
|
18
31
|
end
|
19
32
|
end
|
20
33
|
end
|
@@ -1,6 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe ShutterstockRuby do
|
3
|
+
RSpec.describe "ShutterstockRuby instance client" do
|
4
|
+
|
5
|
+
it 'has the correct default' do
|
6
|
+
client = ShutterstockRuby::Client.new
|
7
|
+
|
8
|
+
expect(client.configuration.access_token).to be nil
|
9
|
+
expect(client.configuration.api_client).to be nil
|
10
|
+
expect(client.configuration.api_secret).to be nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'sets the correct configuration' do
|
14
|
+
token = SecureRandom.uuid
|
15
|
+
key = SecureRandom.uuid
|
16
|
+
secret = SecureRandom.uuid
|
17
|
+
|
18
|
+
client = ShutterstockRuby::Client.new(access_token: token, api_client: key, api_secret: secret)
|
19
|
+
|
20
|
+
expect(client.configuration.access_token).to equal(token)
|
21
|
+
expect(client.configuration.api_client).to equal(key)
|
22
|
+
expect(client.configuration.api_secret).to equal(secret)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
RSpec.describe "ShutterstockRuby static client" do
|
4
28
|
after :each do
|
5
29
|
ShutterstockRuby.configuration.access_token = nil
|
6
30
|
ShutterstockRuby.configuration.api_client = nil
|
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.4.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: 2017-
|
11
|
+
date: 2017-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
84
|
- lib/shutterstock-ruby.rb
|
85
|
+
- lib/shutterstock-ruby/configuration.rb
|
85
86
|
- lib/shutterstock-ruby/connections.rb
|
86
87
|
- lib/shutterstock-ruby/images.rb
|
87
88
|
- lib/shutterstock-ruby/videos.rb
|