shutterstock-v2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +6 -0
  5. data/.travis.yml +6 -0
  6. data/Dockerfile +17 -0
  7. data/Gemfile +3 -0
  8. data/Guardfile +9 -0
  9. data/README.md +377 -0
  10. data/Rakefile +19 -0
  11. data/lib/client/auth.rb +48 -0
  12. data/lib/client/categories.rb +11 -0
  13. data/lib/client/category.rb +16 -0
  14. data/lib/client/client.rb +72 -0
  15. data/lib/client/collection.rb +151 -0
  16. data/lib/client/collections.rb +16 -0
  17. data/lib/client/configuration.rb +20 -0
  18. data/lib/client/contributor.rb +15 -0
  19. data/lib/client/driver.rb +38 -0
  20. data/lib/client/error.rb +20 -0
  21. data/lib/client/image.rb +139 -0
  22. data/lib/client/image_assets.rb +56 -0
  23. data/lib/client/image_size_details.rb +26 -0
  24. data/lib/client/images.rb +27 -0
  25. data/lib/client/license.rb +67 -0
  26. data/lib/client/licenses.rb +23 -0
  27. data/lib/client/model.rb +15 -0
  28. data/lib/client/models.rb +11 -0
  29. data/lib/client/request.rb +41 -0
  30. data/lib/client/subscription.rb +35 -0
  31. data/lib/client/subscription_allotment.rb +19 -0
  32. data/lib/client/subscription_license_format.rb +16 -0
  33. data/lib/client/subscription_license_formats.rb +12 -0
  34. data/lib/client/subscription_price.rb +13 -0
  35. data/lib/client/subscriptions.rb +37 -0
  36. data/lib/client/thumbnail.rb +17 -0
  37. data/lib/client/user.rb +68 -0
  38. data/lib/client/version.rb +3 -0
  39. data/lib/shutterstock-v2.rb +31 -0
  40. data/shutterstock-v2.gemspec +30 -0
  41. data/spec/cassettes/Shutterstock_Auth_get_access_token/returns_hash_with_access_token.yml +86 -0
  42. data/spec/cassettes/Shutterstock_Auth_get_authorize_url/returns_URL_to_redirect_user_to_passing_redirect_url_an.yml +48 -0
  43. data/spec/cassettes/Shutterstock_Categories/parses_params_correctly.yml +53 -0
  44. data/spec/cassettes/Shutterstock_Categories/returns_all_cats_for_an_image.yml +53 -0
  45. data/spec/cassettes/Shutterstock_Collection/add_image_adds_image_using_Image_new.yml +48 -0
  46. data/spec/cassettes/Shutterstock_Collection/add_image_adds_image_using_id.yml +48 -0
  47. data/spec/cassettes/Shutterstock_Collection/add_image_error_raises_error_if_collection_does_not_exist.yml +52 -0
  48. data/spec/cassettes/Shutterstock_Collection/create_creates_a_collection.yml +52 -0
  49. data/spec/cassettes/Shutterstock_Collection/destroy_destroys_a_collection.yml +93 -0
  50. data/spec/cassettes/Shutterstock_Collection/find_adds_an_image.yml +97 -0
  51. data/spec/cassettes/Shutterstock_Collection/find_converts_list_to_images.yml +101 -0
  52. data/spec/cassettes/Shutterstock_Collection/find_finds_a_collection_given_an_id.yml +52 -0
  53. data/spec/cassettes/Shutterstock_Collection/find_raises_error_for_invalid_collection_id.yml +50 -0
  54. data/spec/cassettes/Shutterstock_Collection/find_removes_an_image.yml +95 -0
  55. data/spec/cassettes/Shutterstock_Collection/list_returns_all_collections_for_the_current_user.yml +53 -0
  56. data/spec/cassettes/Shutterstock_Collection/remove_image_removes_image_using_Image_new.yml +46 -0
  57. data/spec/cassettes/Shutterstock_Collection/remove_image_removes_image_using_id.yml +46 -0
  58. data/spec/cassettes/Shutterstock_Collection/update_changes_the_name_of_a_collection.yml +97 -0
  59. data/spec/cassettes/Shutterstock_Collections/returns_all_collections_for_current_user.yml +53 -0
  60. data/spec/cassettes/Shutterstock_Image/fill_fills_all_details_of_current_image.yml +109 -0
  61. data/spec/cassettes/Shutterstock_Image/fills_all_details_of_current_image.yml +109 -0
  62. data/spec/cassettes/Shutterstock_Image/find_places_image_data_into_correct_fields.yml +56 -0
  63. data/spec/cassettes/Shutterstock_Image/find_places_more_image_data_into_correct_fields.yml +53 -0
  64. data/spec/cassettes/Shutterstock_Image/find_returns_an_Image_object.yml +56 -0
  65. data/spec/cassettes/Shutterstock_Image/finds_similar_images_given_an_image.yml +125 -0
  66. data/spec/cassettes/Shutterstock_Image/returns_an_Image_object.yml +56 -0
  67. data/spec/cassettes/Shutterstock_Image/returns_similar_images.yml +72 -0
  68. data/spec/cassettes/Shutterstock_Image/search_searches_for_images_based_on_searchterm.yml +73 -0
  69. data/spec/cassettes/Shutterstock_Image/search_searches_using_more_than_one_parameter.yml +77 -0
  70. data/spec/cassettes/Shutterstock_Image/searches_for_images_based_on_searchterm.yml +73 -0
  71. data/spec/cassettes/Shutterstock_Image/searches_using_more_than_one_parameter.yml +77 -0
  72. data/spec/cassettes/Shutterstock_Image/similar_finds_similar_images_given_an_image.yml +125 -0
  73. data/spec/cassettes/Shutterstock_Image/similar_returns_similar_images.yml +72 -0
  74. data/spec/cassettes/Shutterstock_ImageAssets/find_calculates_fields_correctly.yml +53 -0
  75. data/spec/cassettes/Shutterstock_ImageAssets/find_places_image_data_into_correct_fields.yml +53 -0
  76. data/spec/cassettes/Shutterstock_Images/fill_fills_details_of_all_images_in_list_all_images_now_have_keywords.yml +1144 -0
  77. data/spec/cassettes/Shutterstock_Images/returns_similar_images.yml +126 -0
  78. data/spec/cassettes/Shutterstock_License/license_editorial_acknowledgement_returns_error_if_requesting_an_image.yml +53 -0
  79. data/spec/cassettes/Shutterstock_License/license_editorial_acknowledgement_returns_licenced_image_if_ed_ack_is_.yml +52 -0
  80. data/spec/cassettes/Shutterstock_License/license_license_from_image_object_sends_editorial_acknowledgement_when.yml +160 -0
  81. data/spec/cassettes/Shutterstock_License/license_license_from_image_object_using_found_subscription.yml +108 -0
  82. data/spec/cassettes/Shutterstock_License/license_license_from_image_object_vector_image.yml +108 -0
  83. data/spec/cassettes/Shutterstock_License/license_multiple_licenses_multiple_images.yml +52 -0
  84. data/spec/cassettes/Shutterstock_License/license_multiple_licenses_multiple_images_from_Image_new.yml +52 -0
  85. data/spec/cassettes/Shutterstock_License/license_multiple_returns_error_in_Licenses_when_incorrect_image_used.yml +53 -0
  86. data/spec/cassettes/Shutterstock_License/license_single_licencing_same_image_twice_does_not_give_error.yml +101 -0
  87. data/spec/cassettes/Shutterstock_License/license_single_license_fails_when_subscription_doesn_t_allow.yml +49 -0
  88. data/spec/cassettes/Shutterstock_License/license_single_licenses_single_image.yml +52 -0
  89. data/spec/cassettes/Shutterstock_License/license_single_licenses_single_image_from_Image_new.yml +52 -0
  90. data/spec/cassettes/Shutterstock_License/license_single_licenses_single_image_from_hash.yml +52 -0
  91. data/spec/cassettes/Shutterstock_License/license_single_licenses_single_image_with_smaller_size.yml +52 -0
  92. data/spec/cassettes/Shutterstock_License/license_single_licenses_vector_image.yml +52 -0
  93. data/spec/cassettes/Shutterstock_License/license_single_licensing_same_image_twice_does_not_give_error.yml +101 -0
  94. data/spec/cassettes/Shutterstock_License/license_single_returns_error_when_incorrect_image_used.yml +103 -0
  95. data/spec/cassettes/Shutterstock_License/license_single_returns_error_when_incorrect_subscription_used.yml +53 -0
  96. data/spec/cassettes/Shutterstock_Models/parses_params_correctly.yml +53 -0
  97. data/spec/cassettes/Shutterstock_Models/returns_all_models_for_an_image.yml +53 -0
  98. data/spec/cassettes/Shutterstock_Subscription/allows_image_size_download_correctly_finds_if_image_size_is_possi.yml +59 -0
  99. data/spec/cassettes/Shutterstock_Subscription/new_parses_info_on_user_correctly.yml +59 -0
  100. data/spec/cassettes/Shutterstock_Subscription/new_returns_a_subscription_for_current_user.yml +59 -0
  101. data/spec/cassettes/Shutterstock_SubscriptionLicenseFormat/new_parses_info_correctly.yml +59 -0
  102. data/spec/cassettes/Shutterstock_SubscriptionLicenseFormat/new_returns_a_subscription_license_format_for_curren.yml +59 -0
  103. data/spec/cassettes/Shutterstock_Subscriptions/subscriptions_active_expired_total_subscriptions.yml +59 -0
  104. data/spec/cassettes/Shutterstock_Subscriptions/subscriptions_active_returns_only_active_subscriptions.yml +59 -0
  105. data/spec/cassettes/Shutterstock_Subscriptions/subscriptions_downloads_left_only_subscriptions_with_downloads_l.yml +59 -0
  106. data/spec/cassettes/Shutterstock_Subscriptions/subscriptions_expired_returns_only_expired_subscriptions.yml +59 -0
  107. data/spec/cassettes/Shutterstock_Subscriptions/subscriptions_find_subscription_for_image_size_finds_subs_to_use.yml +59 -0
  108. data/spec/cassettes/Shutterstock_Subscriptions/subscriptions_returns_all_subscriptions_for_current_user.yml +59 -0
  109. data/spec/cassettes/Shutterstock_User/find_parses_info_on_user_correctly.yml +52 -0
  110. data/spec/cassettes/Shutterstock_User/find_returns_object_for_current_user.yml +52 -0
  111. data/spec/client/auth_spec.rb +36 -0
  112. data/spec/client/categories_spec.rb +26 -0
  113. data/spec/client/category_spec.rb +16 -0
  114. data/spec/client/client_spec.rb +32 -0
  115. data/spec/client/collection_spec.rb +159 -0
  116. data/spec/client/collections_spec.rb +18 -0
  117. data/spec/client/configuration_spec.rb +10 -0
  118. data/spec/client/contributor_spec.rb +14 -0
  119. data/spec/client/driver_spec.rb +20 -0
  120. data/spec/client/image_assets_spec.rb +51 -0
  121. data/spec/client/image_size_details_spec.rb +33 -0
  122. data/spec/client/image_spec.rb +102 -0
  123. data/spec/client/images_spec.rb +31 -0
  124. data/spec/client/license_spec.rb +234 -0
  125. data/spec/client/model_spec.rb +14 -0
  126. data/spec/client/models_spec.rb +23 -0
  127. data/spec/client/request_spec.rb +79 -0
  128. data/spec/client/subscription_allotment_spec.rb +25 -0
  129. data/spec/client/subscription_license_format_spec.rb +29 -0
  130. data/spec/client/subscription_price_spec.rb +17 -0
  131. data/spec/client/subscription_spec.rb +60 -0
  132. data/spec/client/subscriptions_spec.rb +54 -0
  133. data/spec/client/thumbnail_spec.rb +21 -0
  134. data/spec/client/user_spec.rb +37 -0
  135. data/spec/spec_helper.rb +88 -0
  136. metadata +467 -0
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Images do
4
+ before do
5
+ client
6
+ end
7
+
8
+ let(:id) { 32_329_852 }
9
+ subject(:images) { Image.find(id).similar }
10
+
11
+ it 'returns similar images' do
12
+ expect(images).to_not be_nil
13
+ expect(images).to be_kind_of Array
14
+ expect(images).to be_kind_of Images
15
+ expect(images[0]).to be_kind_of Image
16
+ expect(images.raw_data).to be_kind_of Hash
17
+ expect(images.page).to be 1
18
+ expect(images.total_count).to eq 200
19
+ expect(images.search_id).to_not be_nil
20
+ end
21
+
22
+ describe "fill" do
23
+ it 'fills details of all images in list: all images now have keywords' do
24
+ similar = images
25
+ expect(similar.select{|img| img.keywords.class == Array}.count).to eq 0
26
+ similar.fill
27
+ expect(similar.select{|img| img.keywords.class != Array}.count).to eq 0
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,234 @@
1
+ require 'spec_helper'
2
+
3
+ describe License do
4
+
5
+ before do
6
+ client
7
+ end
8
+
9
+ context 'params' do
10
+
11
+ it 'stores params correctly' do
12
+ subject = License.new("image_id" =>"42194962",
13
+ "download" =>{"url" =>"https://download.shutterstock.com/shutterstock_42194962.jpg"},
14
+ "allotment_charge" => 1)
15
+
16
+
17
+ expect(License).to respond_to(:license)
18
+
19
+ expect(subject).to_not be_nil
20
+ expect(subject.image_id).to eq 42194962
21
+ expect(subject.download).to eq "https://download.shutterstock.com/shutterstock_42194962.jpg"
22
+ expect(subject.allotment_charge).to eq 1
23
+ end
24
+
25
+ end
26
+
27
+ context 'license' do
28
+
29
+
30
+ let(:subscription_id) { "s30187600" }
31
+ let(:bad_image_id) { 509_205_923_049 }
32
+
33
+ context 'single' do
34
+
35
+ let(:bad_subscription_id) { "s987654" }
36
+ let(:image_id) { 138_869_051 }
37
+ let(:image2) { Image.new("id" => "145104193") }
38
+ let(:image3) { { "image_id" => "157910507" } }
39
+ let(:vector_image_id) { 109675343 }
40
+
41
+
42
+ it 'returns error when neither image or subscription id passed' do
43
+ expect { License.license(subscription_id: subscription_id) }.to raise_error(ArgumentError)
44
+ expect { License.license(image_id: image_id) }.to raise_error(ArgumentError)
45
+ end
46
+
47
+ it 'returns error when incorrect image used' do
48
+ license = License.license(subscription_id: subscription_id, image_id: bad_image_id)
49
+ expect( license.error ).to eq "Media unavailable"
50
+ end
51
+
52
+ it 'returns error when incorrect subscription used' do
53
+ license = License.license(subscription_id: bad_subscription_id, image_id: image_id)
54
+ expect( license.error ).to eq "Subscription is unusable"
55
+ end
56
+
57
+ it 'licenses single image' do
58
+ license = License.license(subscription_id: subscription_id, image_id: image_id, format: "jpg", size: "huge")
59
+ expect( license ).to be_a License
60
+ expect( license.image_id ).to eq image_id
61
+ expect( license.error ).to be nil
62
+ expect( license.allotment_charge ).to be 1
63
+ expect( license.download ).to be_a String
64
+ expect( license.download ).to match /download\.shutterstock/
65
+ end
66
+
67
+ it 'licenses single image from Image.new' do
68
+ license = License.license(subscription_id: subscription_id, image_id: image2, format: "jpg", size: "huge")
69
+ expect( license ).to be_a License
70
+ expect( license.image_id ).to eq image2.id
71
+ expect( license.error ).to be nil
72
+ expect( license.allotment_charge ).to be 1
73
+ expect( license.download ).to be_a String
74
+ expect( license.download ).to match /download\.shutterstock/
75
+ end
76
+
77
+ it 'licenses single image from hash' do
78
+ license = License.license(subscription_id: subscription_id, image_id: image3, format: "jpg", size: "huge")
79
+ expect( license ).to be_a License
80
+ expect( license.image_id ).to eq image3["image_id"].to_i
81
+ expect( license.error ).to be nil
82
+ expect( license.allotment_charge ).to be 1
83
+ expect( license.download ).to be_a String
84
+ expect( license.download ).to match /download\.shutterstock/
85
+ end
86
+
87
+ it 'error when format is eps but size is not vector' do
88
+ expect { License.license(subscription_id: subscription_id, image_id: vector_image_id, format: "eps") }.to raise_error(ArgumentError)
89
+ end
90
+
91
+ it 'licenses vector image' do
92
+ license = License.license(subscription_id: subscription_id, image_id: vector_image_id, format: "eps", size: "vector")
93
+ expect( license ).to be_a License
94
+ expect( license.image_id ).to eq vector_image_id
95
+ expect( license.error ).to be nil
96
+ expect( license.allotment_charge ).to be 1
97
+ expect( license.download ).to be_a String
98
+ expect( license.download ).to match /download\.shutterstock/
99
+ end
100
+
101
+ it 'licenses single image with smaller size' do
102
+ license = License.license(subscription_id: subscription_id, image_id: image3, format: "jpg", size: "small")
103
+ expect( license ).to be_a License
104
+ expect( license.image_id ).to eq image3["image_id"].to_i
105
+ expect( license.error ).to be nil
106
+ expect( license.download ).to be_a String
107
+ expect( license.download ).to match /download\.shutterstock/
108
+ end
109
+
110
+ it 'license fails when subscription doesn\'t allow' do
111
+ expect { License.license(subscription_id: subscription_id, image_id: image3, format: "tiff", size: "small") }.to raise_error(FailedResponse)
112
+ end
113
+
114
+ it 'licencing same image twice does not give error' do
115
+ license = License.license(subscription_id: subscription_id, image_id: image3, format: "jpg", size: "huge")
116
+ expect( license ).to be_a License
117
+ license = License.license(subscription_id: subscription_id, image_id: image3, format: "jpg", size: "huge")
118
+ expect( license.allotment_charge ).to eq 0
119
+ end
120
+
121
+
122
+ end
123
+
124
+ context 'multiple' do
125
+
126
+ let(:image_ids) { [312464573, 313292420, 314250722] }
127
+ let(:image_ids_as_images) { [431616757, 461729398, 94306576].map{|id| Image.new("id" => id)} }
128
+
129
+ it 'returns error when neither image or subscription id passed' do
130
+ expect { License.license_multiple(subscription_id: subscription_id) }.to raise_error(ArgumentError)
131
+ expect { License.license_multiple(image_id: image_ids) }.to raise_error(ArgumentError)
132
+ end
133
+
134
+ it 'licenses multiple images' do
135
+ licenses = License.license_multiple(subscription_id: subscription_id, image_id: image_ids, format: "jpg", size: "huge")
136
+ expect( licenses ).to be_a Licenses
137
+ expect( licenses.count ).to eq 3
138
+ expect( licenses.errors ).to be nil
139
+
140
+ first_license = licenses.first
141
+ expect( first_license ).to be_a License
142
+ expect( first_license.image_id ).to eq image_ids.first
143
+ expect( first_license.error ).to be nil
144
+ expect( first_license.allotment_charge ).to be 1
145
+ expect( first_license.download ).to be_a String
146
+ expect( first_license.download ).to match /download\.shutterstock/
147
+ end
148
+
149
+ it 'licenses multiple images from Image.new' do
150
+ licenses = License.license_multiple(subscription_id: subscription_id, image_id: image_ids_as_images, format: "jpg", size: "small")
151
+ expect( licenses ).to be_a Licenses
152
+ expect( licenses.count ).to eq 3
153
+ expect( licenses.errors ).to be nil
154
+
155
+ first_license = licenses.first
156
+ expect( first_license ).to be_a License
157
+ expect( first_license.image_id ).to eq image_ids_as_images.first.id
158
+ expect( first_license.error ).to be nil
159
+ expect( first_license.allotment_charge ).to be 1
160
+ expect( first_license.download ).to be_a String
161
+ expect( first_license.download ).to match /download\.shutterstock/
162
+ end
163
+
164
+ it 'returns error in Licenses when incorrect image used' do
165
+ licenses = License.license_multiple(subscription_id: subscription_id, image_id: [bad_image_id])
166
+ expect( licenses.errors ).to be_a Array
167
+ expect( licenses.errors.first["message"] ).to eq "Failed to license 1 image"
168
+ expect( licenses.first.error ).to eq "Media unavailable"
169
+ end
170
+ end
171
+
172
+ context 'editorial_acknowledgement' do
173
+
174
+ let(:image_id_needing_ed_ack) { 204_501_694 }
175
+
176
+
177
+ it 'returns error if requesting an image that needs editorial acknowledgement' do
178
+ license = License.license(subscription_id: subscription_id, image_id: image_id_needing_ed_ack)
179
+ expect( license ).to be_a License
180
+ expect( license.image_id ).to eq image_id_needing_ed_ack
181
+ expect( license.error ).to eq "Editorial status must be acknowledged"
182
+ end
183
+
184
+ it 'returns licenced image if ed ack is sent' do
185
+ license = License.license(subscription_id: subscription_id, image_id: image_id_needing_ed_ack, editorial_acknowledgement: true)
186
+ expect( license ).to be_a License
187
+ expect( license.image_id ).to eq image_id_needing_ed_ack
188
+ expect( license.error ).to be nil
189
+ expect( license.allotment_charge ).to be 1
190
+ expect( license.download ).to be_a String
191
+ expect( license.download ).to match /download\.shutterstock/
192
+ end
193
+
194
+
195
+ end
196
+ context 'license from image object' do
197
+
198
+ let(:image) { Image.new("id" => "42194962") }
199
+
200
+ it 'using found subscription' do
201
+ license = image.license
202
+ expect( license ).to be_a License
203
+ expect( license.image_id ).to eq image.id
204
+ expect( license.error ).to be nil
205
+ expect( license.allotment_charge ).to be 1
206
+ expect( license.download ).to be_a String
207
+ expect( license.download ).to match /download\.shutterstock/
208
+ end
209
+
210
+ it 'vector image' do
211
+ image = Image.new("id" => "110641004")
212
+ license = image.license(format: "eps", size: "vector")
213
+ expect( license ).to be_a License
214
+ expect( license.image_id ).to eq image.id
215
+ expect( license.error ).to be nil
216
+ expect( license.allotment_charge ).to be 1
217
+ expect( license.download ).to be_a String
218
+ expect( license.download ).to match /download\.shutterstock/
219
+ end
220
+
221
+ it 'sends editorial_acknowledgement when image needs it' do
222
+ license = Image.new("id" => "204501694").fill.license
223
+ expect( license ).to be_a License
224
+ expect( license.image_id ).to eq 204501694
225
+ expect( license.error ).to be nil
226
+ expect( license.download ).to be_a String
227
+ expect( license.download ).to match /download\.shutterstock/
228
+ end
229
+
230
+ end
231
+
232
+ end
233
+
234
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Model do
4
+ # before do
5
+ # client
6
+ # end
7
+
8
+ context 'initialize' do
9
+ it 'initializes with ID from params' do
10
+ expect(Model.new("id" => 1234).id).to be 1234
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Models do
4
+ before do
5
+ client
6
+ end
7
+
8
+ subject(:models) { Image.find(356308322).models }
9
+
10
+ it 'returns all models for an image' do
11
+ expect(models).to_not be_nil
12
+ expect(models).to be_kind_of Array
13
+ expect(models).to be_kind_of Models
14
+ expect(models[0]).to be_kind_of Model
15
+ expect(models.raw_data).to be_kind_of Array
16
+ end
17
+
18
+ it 'parses params correctly' do
19
+ expect(models[0].id).to eq 17856134
20
+ expect(models[1].id).to eq 15233887
21
+ end
22
+
23
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Request do
4
+
5
+ describe ".new" do
6
+ it 'vars set in block are retained' do
7
+ result = Shutterstock::Request.new do |r|
8
+ r.method ('method')
9
+ r.path ('path')
10
+ r.success_status (123)
11
+ r.send_authorization (false)
12
+ r.content_type ('type')
13
+ r.body ('body')
14
+ r.params ('params')
15
+ end
16
+
17
+ expect(result.method).to eq 'method'
18
+ expect(result.path).to eq 'path'
19
+ expect(result.success_status).to eq 123
20
+ expect(result.send_authorization).to eq false
21
+ expect(result.content_type).to eq 'type'
22
+ expect(result.body).to eq 'body'
23
+ expect(result.params).to eq 'params'
24
+
25
+ end
26
+
27
+ it 'can use DSL' do
28
+ result = Shutterstock::Request.new do
29
+ method ('method')
30
+ path ('path')
31
+ success_status (123)
32
+ send_authorization (false)
33
+ content_type ('type')
34
+ body ('body')
35
+ params ('params')
36
+ end
37
+
38
+ expect(result.method).to eq 'method'
39
+ expect(result.path).to eq 'path'
40
+ expect(result.success_status).to eq 123
41
+ expect(result.send_authorization).to eq false
42
+ expect(result.content_type).to eq 'type'
43
+ expect(result.body).to eq 'body'
44
+ expect(result.params).to eq 'params'
45
+
46
+ end
47
+
48
+ it 'can use equals to set' do
49
+
50
+ result = Shutterstock::Request.new do |r|
51
+ r.method = 'method'
52
+ r.path = 'path'
53
+ r.success_status = 123
54
+ r.send_authorization = false
55
+ r.content_type = 'type'
56
+ r.body = 'body'
57
+ r.params = 'params'
58
+ end
59
+
60
+ expect(result.method).to eq 'method'
61
+ expect(result.path).to eq 'path'
62
+ expect(result.success_status).to eq 123
63
+ expect(result.send_authorization).to eq false
64
+ expect(result.content_type).to eq 'type'
65
+ expect(result.body).to eq 'body'
66
+ expect(result.params).to eq 'params'
67
+
68
+ end
69
+
70
+ it 'sets sensible defaults' do
71
+ result = Shutterstock::Request.new
72
+
73
+ expect(result.success_status).to eq 200
74
+ expect(result.send_authorization).to eq true
75
+ expect(result.content_type).to eq 'application/json'
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe SubscriptionAllotment do
4
+ # before do
5
+ # client
6
+ # end
7
+
8
+ context 'initialize' do
9
+ it 'initializes with data from params' do
10
+ subject = SubscriptionAllotment.new("downloads_left" => 10, "downloads_limit" => 30, "start_time" => "2016-12-28T09:36:49-05:00", "end_time" => "2017-12-28T09:36:49-10:00")
11
+ expect(subject.downloads_left).to eq 10
12
+ expect(subject.downloads_limit).to eq 30
13
+ expect(subject.start_time).to eq DateTime.parse("2016-12-28T09:36:49-05:00")
14
+ expect(subject.end_time).to eq DateTime.parse("2017-12-28T09:36:49-10:00")
15
+ end
16
+
17
+ it '.has_downloads_left?' do
18
+ subject = SubscriptionAllotment.new("downloads_left" => 10, "downloads_limit" => 30)
19
+ expect(subject.has_downloads_left?).to be true
20
+ subject = SubscriptionAllotment.new("downloads_left" => 0, "downloads_limit" => 30)
21
+ expect(subject.has_downloads_left?).to be false
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe SubscriptionLicenseFormat do
4
+ before do
5
+ client
6
+ end
7
+
8
+ context 'new' do
9
+
10
+ subject { User.subscriptions.first.formats.first }
11
+
12
+ it 'returns a subscription license format for current user' do
13
+ expect(subject).to_not be_nil
14
+ expect(subject).to be_a SubscriptionLicenseFormat
15
+ end
16
+
17
+ it 'parses info correctly' do
18
+ # Test variables from this specific API call.
19
+ # Might break if vcr recording is deleted. If so, use new values
20
+ expect(subject.description).to eq "Huge"
21
+ expect(subject.min_resolution).to eq 4000000
22
+ expect(subject.media_type).to eq "image"
23
+ expect(subject.format).to eq "jpg"
24
+ expect(subject.size).to eq "huge"
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe SubscriptionPrice do
4
+ # before do
5
+ # client
6
+ # end
7
+
8
+ context 'initialize' do
9
+ it 'initializes with data from params' do
10
+ subject = SubscriptionPrice.new("local_amount" => 10.40, "local_currency" => "USD")
11
+ expect(subject.local_amount).to eq 10.40
12
+ expect(subject.local_currency).to eq "USD"
13
+ end
14
+
15
+ end
16
+
17
+ end