getty 0.0.1 → 0.0.2
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 +34 -9
- data/VERSION +1 -1
- data/getty.gemspec +1 -1
- data/lib/getty/images.rb +56 -0
- data/lib/getty/sessions.rb +2 -2
- data/test/test_client.rb +28 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5be612e803b67928db231eac256c022b849ff07
|
4
|
+
data.tar.gz: d4dbf24bdc8a2984c3dd7da3d2f56a1e19a95308
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7afdf0bc61d8b8f1f4b14780cdabaf4e56c69e6c7e173272644a67fde1ab29262e0289e92d5cec6d9ab7ed072796c7a18b6d9f5ce8e5087be9785ea8d74f7686
|
7
|
+
data.tar.gz: beb490c5d9c818a9899ad86c8c0d91c707f31db77a18d6b6594d752218382e728de76ad8edd76662574f9d7a10f307617a415ec9c3e8cb36668085ea8e5b3fe6
|
data/README.md
CHANGED
@@ -1,17 +1,42 @@
|
|
1
1
|
# Getty API DRY mode
|
2
2
|
Example usage:
|
3
3
|
|
4
|
+
# SETUP GETTY API
|
4
5
|
Getty.configure do |config|
|
5
|
-
config.system_id = '
|
6
|
-
config.system_pwd = '
|
7
|
-
config.user_name = "
|
8
|
-
config.user_pwd = "
|
6
|
+
config.system_id = '10799'
|
7
|
+
config.system_pwd = 'vMK8LPFBcaA0JWug3VReKcN45TtzCVtqWjnuLcHbyF0='
|
8
|
+
config.user_name = "seedhacklon_api"
|
9
|
+
config.user_pwd = "HJARZH1p7awxi68"
|
9
10
|
end
|
11
|
+
|
12
|
+
# CREATE SESSION
|
10
13
|
@client = Getty::Client.new
|
11
14
|
session = @client.create_session
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
token = session.SecureToken
|
16
|
+
|
17
|
+
# SEARCH RESULTS
|
18
|
+
search_results = @client.search(token, :query => "soccer", :limit => 1)
|
19
|
+
|
20
|
+
image_ids = []
|
21
|
+
search_results.Images.each do |sr|
|
22
|
+
puts "#{sr.ImageId} #{sr.Artist} #{sr.Caption}"
|
23
|
+
image_ids << sr.ImageId
|
24
|
+
end
|
25
|
+
|
26
|
+
# AUTHORIZE DOWNLOADS
|
27
|
+
authorizations = @client.largest_image_authorizations(token, :image_ids => image_ids)
|
28
|
+
|
29
|
+
download_tokens = []
|
30
|
+
authorizations.Images.each do |image|
|
31
|
+
image.Authorizations.each do |auth|
|
32
|
+
download_tokens << auth.DownloadToken
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# PRINT DOWNLOAD STRING
|
37
|
+
download = @client.download_image(token, :download_tokens => download_tokens)
|
38
|
+
download.DownloadUrls.each do |url|
|
39
|
+
system "open \"#{url.UrlAttachment}\""
|
17
40
|
end
|
41
|
+
|
42
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/getty.gemspec
CHANGED
data/lib/getty/images.rb
CHANGED
@@ -20,6 +20,62 @@ module Getty
|
|
20
20
|
return_error_or_body(response, response.body)
|
21
21
|
end
|
22
22
|
|
23
|
+
def largest_image_authorizations(token, options={})
|
24
|
+
image_ids = options[:image_ids] || []
|
25
|
+
response = connection.post do |req|
|
26
|
+
req.url "download/GetLargestImageDownloadAuthorizations"
|
27
|
+
req.body = {
|
28
|
+
:RequestHeader => {
|
29
|
+
:Token => token,
|
30
|
+
# :CoordinationId => ""
|
31
|
+
},
|
32
|
+
:GetLargestImageDownloadAuthorizationsRequestBody => {
|
33
|
+
:Images => image_ids.collect { |ii| { :ImageId => ii } }
|
34
|
+
# :Images => image_ids
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
end
|
39
|
+
return_error_or_body(response, response.body.GetLargestImageDownloadAuthorizationsResult)
|
40
|
+
end
|
41
|
+
|
42
|
+
def download_image(token, options={})
|
43
|
+
download_tokens = options[:download_tokens] || []
|
44
|
+
response = connection.post do |req|
|
45
|
+
req.url "download/CreateDownloadRequest"
|
46
|
+
req.body = {
|
47
|
+
:RequestHeader => {
|
48
|
+
:Token => token,
|
49
|
+
# :CoordinationId => "MyUniqueId"
|
50
|
+
},
|
51
|
+
:CreateDownloadRequestBody =>
|
52
|
+
{ :DownloadItems =>
|
53
|
+
download_tokens.collect { |dt| { :DownloadToken => dt } }
|
54
|
+
}
|
55
|
+
}
|
56
|
+
end
|
57
|
+
return_error_or_body(response, response.body.CreateDownloadRequestResult)
|
58
|
+
end
|
59
|
+
|
60
|
+
def search(token, options={})
|
61
|
+
query = options[:query] || ""
|
62
|
+
limit = options[:limit] || 25
|
63
|
+
response = connection.post do |req|
|
64
|
+
req.url "search/SearchForImages"
|
65
|
+
req.body = {
|
66
|
+
:RequestHeader => { :Token => token},
|
67
|
+
:SearchForImages2RequestBody => {
|
68
|
+
:Query => { :SearchPhrase => query},
|
69
|
+
:ResultOptions => {
|
70
|
+
:ItemCount => limit,
|
71
|
+
:ItemStartNumber => 1
|
72
|
+
},
|
73
|
+
:Filter => { :ImageFamilies => ["creative"] }
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
return_error_or_body(response, response.body.SearchForImagesResult)
|
78
|
+
end
|
23
79
|
end
|
24
80
|
end
|
25
81
|
|
data/lib/getty/sessions.rb
CHANGED
@@ -18,7 +18,7 @@ module Getty
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
end
|
21
|
-
return_error_or_body(response, response.body)
|
21
|
+
return_error_or_body(response, response.body.CreateSessionResult)
|
22
22
|
end
|
23
23
|
|
24
24
|
def renew_session(token)
|
@@ -36,7 +36,7 @@ module Getty
|
|
36
36
|
}
|
37
37
|
}
|
38
38
|
end
|
39
|
-
return_error_or_body(response, response.body)
|
39
|
+
return_error_or_body(response, response.body.RenewSessionResult)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/test/test_client.rb
CHANGED
@@ -25,6 +25,13 @@ class TestClient < Test::Unit::TestCase
|
|
25
25
|
end
|
26
26
|
|
27
27
|
should "create session" do
|
28
|
+
# session = @client.renew_session session.CreateSessionResult.SecureToken
|
29
|
+
# token = session.RenewSessionResult.Token
|
30
|
+
# details = @client.image_details(token, :image_ids => image_ids)
|
31
|
+
# details.GetImageDetailsResult.Images.each do |image_result|
|
32
|
+
# puts "#{image_result.Artist} #{image_result.Caption}"
|
33
|
+
# end
|
34
|
+
|
28
35
|
Getty.configure do |config|
|
29
36
|
config.system_id = '10799'
|
30
37
|
config.system_pwd = 'vMK8LPFBcaA0JWug3VReKcN45TtzCVtqWjnuLcHbyF0='
|
@@ -33,11 +40,27 @@ class TestClient < Test::Unit::TestCase
|
|
33
40
|
end
|
34
41
|
@client = Getty::Client.new
|
35
42
|
session = @client.create_session
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
token = session.SecureToken
|
44
|
+
search_results = @client.search(token, :query => "hello", :limit => 1)
|
45
|
+
|
46
|
+
image_ids = []
|
47
|
+
search_results.Images.each do |sr|
|
48
|
+
puts "#{sr.ImageId} #{sr.Artist} #{sr.Caption}"
|
49
|
+
image_ids << sr.ImageId
|
50
|
+
end
|
51
|
+
|
52
|
+
authorizations = @client.largest_image_authorizations(token, :image_ids => image_ids)
|
53
|
+
|
54
|
+
download_tokens = []
|
55
|
+
authorizations.Images.each do |image|
|
56
|
+
image.Authorizations.each do |auth|
|
57
|
+
download_tokens << auth.DownloadToken
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
download = @client.download_image(token, :download_tokens => download_tokens)
|
62
|
+
download.DownloadUrls.each do |url|
|
63
|
+
system "open \"#{url.UrlAttachment}\""
|
41
64
|
end
|
42
65
|
end
|
43
66
|
end
|