shutterstock-ruby 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -0
- data/lib/shutterstock-ruby/videos.rb +12 -1
- data/spec/lib/shutterstock_ruby/videos_spec.rb +153 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a95e1ae36a5dd6e7063d5ffc969c65b8ddf3c71
|
4
|
+
data.tar.gz: f98f79dd8b1becabd999cbf4fb505ac0637f08a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 016b42448cdc4e2b2273dbfcab221b5f2589dd90ca48e4244b8b40c36597862e9a859cdc4cb56b0e1bebefb15eda24ed91c5ae221ce8c42435ca23d74e816afd
|
7
|
+
data.tar.gz: ce2ce5016db3367e4bef6d73f538a92e7073f1689e289ff737cc1df04e1e341ad3dd4a6d81b8c6da6a2e21ee2331bd1c98adcac202b16251ab1aad0ab231d979
|
data/README.md
CHANGED
@@ -30,6 +30,13 @@ ShutterstockRuby.configure do |config|
|
|
30
30
|
end
|
31
31
|
```
|
32
32
|
|
33
|
+
If you require multiple clients, you can create an instance:
|
34
|
+
```rb
|
35
|
+
@client ||= ShutterstockRuby::Client.new(access_token: access_token)
|
36
|
+
```
|
37
|
+
|
38
|
+
You must supply either an `api_client` and an `api_secret`, or an `access_token`.
|
39
|
+
|
33
40
|
### Search for images
|
34
41
|
|
35
42
|
```rb
|
@@ -39,11 +46,47 @@ Source [source](https://developers.shutterstock.com/api/v2/images/search)
|
|
39
46
|
|
40
47
|
### Search for videos
|
41
48
|
|
49
|
+
Using the singleton client:
|
42
50
|
```rb
|
43
51
|
result = ShutterstockRuby::Videos.search('Cat') # Returns a hash of the parsed JSON result.
|
44
52
|
```
|
53
|
+
|
54
|
+
Using an instance of the client:
|
55
|
+
```rb
|
56
|
+
result = @client.videos.search('Cat') # Returns a hash of the parsed JSON result.
|
57
|
+
```
|
58
|
+
|
45
59
|
Source [source](https://developers.shutterstock.com/api/v2/videos/search)
|
46
60
|
|
61
|
+
### Details for a video
|
62
|
+
|
63
|
+
```rb
|
64
|
+
result = @client.videos.details(video_id) # Returns a hash of the parsed JSON result.
|
65
|
+
```
|
66
|
+
Source [source](https://developers.shutterstock.com/api/v2/videos/get)
|
67
|
+
|
68
|
+
### Purchase a video
|
69
|
+
|
70
|
+
```rb
|
71
|
+
result = @client.videos.purchase(video_id, subscription_id, size) # Returns a hash of the parsed JSON result.
|
72
|
+
```
|
73
|
+
Source [source](https://developers.shutterstock.com/api/v2/videos/license)
|
74
|
+
|
75
|
+
### Retrieve an existing license for a video
|
76
|
+
|
77
|
+
```rb
|
78
|
+
result = @client.videos.licenses(video_id, license_name) # Returns a hash of the parsed JSON result.
|
79
|
+
```
|
80
|
+
Source [source](https://developers.shutterstock.com/api/v2/videos/licenses)
|
81
|
+
|
82
|
+
### Download a video that has already been purchased
|
83
|
+
|
84
|
+
```rb
|
85
|
+
result = @client.videos.download(license_id) # Returns a hash of the parsed JSON result.
|
86
|
+
```
|
87
|
+
Source [source](https://developers.shutterstock.com/api/v2/videos/download)
|
88
|
+
|
89
|
+
|
47
90
|
## Disclaimer
|
48
91
|
|
49
92
|
This is completely unofficial and is not related to Shutterstock in any way.
|
@@ -12,10 +12,21 @@ module ShutterstockRuby
|
|
12
12
|
|
13
13
|
def purchase(id, subscription_id, size, options = {})
|
14
14
|
params = { subscription_id: subscription_id, size: size }
|
15
|
-
|
15
|
+
metadata = options.delete(:metadata) || {}
|
16
|
+
|
17
|
+
body = { videos: [ { video_id: id }.merge(metadata)] }.to_json
|
16
18
|
JSON.parse(post("/videos/licenses", body, params, options))
|
17
19
|
end
|
18
20
|
|
21
|
+
def licenses(video_id, license, options = {})
|
22
|
+
params = { video_id: video_id, license: license }
|
23
|
+
JSON.parse(get("/videos/licenses", params.merge(options)))
|
24
|
+
end
|
25
|
+
|
26
|
+
def download(licence)
|
27
|
+
JSON.parse(post("/videos/licenses/#{licence}/downloads", {}.to_json))
|
28
|
+
end
|
29
|
+
|
19
30
|
class << self
|
20
31
|
def search(query, options = {})
|
21
32
|
client.search(query, options)
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe "ShutterstockRuby Videos API" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = ShutterstockRuby::Client.new.videos
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can search for videos' do
|
10
|
+
allow(@client).to receive(:get).with("/videos/search", { query: "cats" }).and_return(search_json)
|
11
|
+
expect(@client.search("cats")).to eq(JSON.parse(search_json))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'can search for videos with options' do
|
15
|
+
allow(@client).to receive(:get).with("/videos/search", { query: "cats", per_page: 10 }).and_return(search_json)
|
16
|
+
expect(@client.search("cats", { per_page: 10 })).to eq(JSON.parse(search_json))
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can get the details for a video' do
|
20
|
+
allow(@client).to receive(:get).with("/videos", { id: "1234" }).and_return(video_json)
|
21
|
+
expect(@client.details("1234")).to eq(JSON.parse(video_json))
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'can purchase a video' do
|
25
|
+
allow(@client).to receive(:post).with(
|
26
|
+
"/videos/licenses",
|
27
|
+
{ videos: [ { video_id: "1234" } ]}.to_json,
|
28
|
+
{ subscription_id: "s5678", size: "hd"},
|
29
|
+
{}
|
30
|
+
).and_return(purchase_json)
|
31
|
+
|
32
|
+
expect(@client.purchase("1234", "s5678", "hd")).to eq(JSON.parse(purchase_json))
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can purchase a video with metadata and options' do
|
36
|
+
allow(@client).to receive(:post).with(
|
37
|
+
"/videos/licenses",
|
38
|
+
{ videos: [ { video_id: "1234", price: 20 } ] }.to_json,
|
39
|
+
{ subscription_id: "s5678", size: "hd"},
|
40
|
+
{ my_header: "header" }
|
41
|
+
).and_return(purchase_json)
|
42
|
+
|
43
|
+
expect(@client.purchase("1234", "s5678", "hd", { metadata: { price: 20 }, my_header: "header" })).to eq(JSON.parse(purchase_json))
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'can get an existing license for a video' do
|
47
|
+
allow(@client).to receive(:get).with("/videos/licenses", { video_id: "1234", license: "comp" }).and_return(license_json)
|
48
|
+
expect(@client.licenses("1234", "comp")).to eq(JSON.parse(license_json))
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'can get an download link for an existing license' do
|
52
|
+
allow(@client).to receive(:post).with("/videos/licenses/v5678/downloads", {}.to_json).and_return(download_json)
|
53
|
+
expect(@client.download("v5678")).to eq(JSON.parse(download_json))
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def search_json
|
58
|
+
%Q({
|
59
|
+
"page": 1,
|
60
|
+
"per_page": 1,
|
61
|
+
"total_count": 1,
|
62
|
+
"search_id": "abcd",
|
63
|
+
"data": [
|
64
|
+
#{video_json}
|
65
|
+
]
|
66
|
+
})
|
67
|
+
end
|
68
|
+
|
69
|
+
def purchase_json
|
70
|
+
%q({
|
71
|
+
"data": [
|
72
|
+
{
|
73
|
+
"video_id": "1234",
|
74
|
+
"download": {
|
75
|
+
"url": "http://localhost/1234.mov"
|
76
|
+
},
|
77
|
+
"allotment_charge": 1
|
78
|
+
}
|
79
|
+
]
|
80
|
+
})
|
81
|
+
end
|
82
|
+
|
83
|
+
def download_json
|
84
|
+
%q({
|
85
|
+
"url": "http://localhost/1234.mov"
|
86
|
+
})
|
87
|
+
end
|
88
|
+
|
89
|
+
def video_json
|
90
|
+
%q({
|
91
|
+
"media_type": "video",
|
92
|
+
"id": "1234",
|
93
|
+
"description": "",
|
94
|
+
"aspect": 1.778,
|
95
|
+
"duration": 26,
|
96
|
+
"contributor": {
|
97
|
+
"id": "1234"
|
98
|
+
},
|
99
|
+
"aspect_ratio": "16:9",
|
100
|
+
"assets": {
|
101
|
+
"thumb_webm": {
|
102
|
+
"url": "http://localhost/1234/cats.webm"
|
103
|
+
},
|
104
|
+
"thumb_mp4": {
|
105
|
+
"url": "http://localhost/1234/cats.mp4"
|
106
|
+
},
|
107
|
+
"preview_webm": {
|
108
|
+
"url": "http://localhost/1234/cats.webm"
|
109
|
+
},
|
110
|
+
"preview_mp4": {
|
111
|
+
"url": "http://localhost/1234/cats.mp4"
|
112
|
+
},
|
113
|
+
"thumb_jpg": {
|
114
|
+
"url": "http://localhost/1234/cats7.jpg"
|
115
|
+
},
|
116
|
+
"preview_jpg": {
|
117
|
+
"url": "http://localhost/1234/cats7.jpg"
|
118
|
+
}
|
119
|
+
}
|
120
|
+
})
|
121
|
+
end
|
122
|
+
|
123
|
+
def license_json
|
124
|
+
%q({
|
125
|
+
"data": [
|
126
|
+
{
|
127
|
+
"id": "v5678",
|
128
|
+
"user": {
|
129
|
+
"username": "user"
|
130
|
+
},
|
131
|
+
"license": "comp",
|
132
|
+
"subscription_id": "s1234",
|
133
|
+
"download_time": "2017-10-09T20:31:04-04:00",
|
134
|
+
"metadata": {
|
135
|
+
"client": "",
|
136
|
+
"other": "",
|
137
|
+
"job": "",
|
138
|
+
"purchase_order": ""
|
139
|
+
},
|
140
|
+
"is_downloadable": true,
|
141
|
+
"video": {
|
142
|
+
"id": "1234",
|
143
|
+
"format": {
|
144
|
+
"size": "hd"
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
],
|
149
|
+
"page": 1,
|
150
|
+
"per_page": 1
|
151
|
+
})
|
152
|
+
end
|
153
|
+
end
|
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.5.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-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/shutterstock-ruby/connections.rb
|
87
87
|
- lib/shutterstock-ruby/images.rb
|
88
88
|
- lib/shutterstock-ruby/videos.rb
|
89
|
+
- spec/lib/shutterstock_ruby/videos_spec.rb
|
89
90
|
- spec/lib/shutterstock_ruby_spec.rb
|
90
91
|
- spec/spec_helper.rb
|
91
92
|
homepage: https://github.com/TailorBrands/shutterstock-ruby
|
@@ -113,5 +114,6 @@ signing_key:
|
|
113
114
|
specification_version: 4
|
114
115
|
summary: An API wrapper for the Shutterstock API's
|
115
116
|
test_files:
|
116
|
-
- spec/lib/shutterstock_ruby_spec.rb
|
117
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/lib/shutterstock_ruby_spec.rb
|
119
|
+
- spec/lib/shutterstock_ruby/videos_spec.rb
|