shutterstock-v2 0.0.1

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.
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,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Category do
4
+ # before do
5
+ # client
6
+ # end
7
+
8
+ context 'initialize' do
9
+ it 'initializes with ID and Name from params' do
10
+ category = Category.new("id" => 1234, "name" => "dog")
11
+ expect(category.id).to be 1234
12
+ expect(category.name).to eq "dog"
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Client do
4
+
5
+ context "#initialize" do
6
+ it "should require a block" do
7
+ expect { Client.instance.configure }.to raise_error(AppNotConfigured)
8
+ end
9
+ end
10
+
11
+ context 'basic auth' do
12
+ it 'should raise an exception when client_id is not provided' do
13
+ expect do
14
+ Client.instance.configure do |config|
15
+ config.client_secret = "67890"
16
+ config.access_token = "abcde"
17
+ config.api_url = "https://api.shutterstock.com/v2"
18
+ end
19
+ end.to raise_error(AppNotConfigured)
20
+ end
21
+
22
+ it 'should raise an exception when client_secret is not provided' do
23
+ expect do
24
+ Client.instance.configure do |config|
25
+ config.client_id = "12345"
26
+ end
27
+ end.to raise_error(AppNotConfigured)
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ describe Collection do
4
+ $new_collection_id = nil
5
+
6
+ before do
7
+ client
8
+ end
9
+
10
+ context 'find' do
11
+ let(:id) { 23_712_632 }
12
+ let(:image_id) { 88_028_233 }
13
+ let(:new_image_id) { 550_104_544 }
14
+ subject(:collection) { Collection.find(id) }
15
+
16
+ it 'finds a collection, given an id' do
17
+ expect(Collection).to respond_to(:find)
18
+
19
+ expect(collection).to_not be_nil
20
+ expect(collection.id).to eql id
21
+ expect(collection.name.size).to be > 2
22
+ expect(collection.total_count).to be > 0
23
+ expect(collection.items_updated).to be_a DateTime
24
+ expect(collection.cover_item).to be_a Image
25
+ expect(collection.cover_item.id).to eq new_image_id
26
+ end
27
+
28
+ it 'converts list to images' do
29
+ items = collection.items
30
+ expect(items).to be_kind_of Images
31
+ expect(items[0]).to be_kind_of Image
32
+ end
33
+
34
+ it 'raises error for invalid collection id' do
35
+ test_id = 12_345_678
36
+ expect { Collection.find(test_id) }.to raise_error(FailedResponse)
37
+ end
38
+
39
+ it 'adds an image' do
40
+ expect { collection.add_image(new_image_id) }.not_to raise_error
41
+ end
42
+
43
+ it 'removes an image' do
44
+ expect { collection.remove_image(new_image_id) }.not_to raise_error
45
+ end
46
+ end
47
+
48
+ context do
49
+
50
+ context 'create' do
51
+
52
+ it 'raises ArgumentError if no collection_name' do
53
+ expect { Collection.create() }.to raise_error(ArgumentError)
54
+ end
55
+
56
+ it 'creates a collection' do
57
+ collection = Collection.create('test_collection')
58
+ expect(collection).to be_an_instance_of(Collection)
59
+ expect(collection.id).to be_an Integer
60
+ $new_collection_id = collection.id
61
+ expect(collection.name).to eql 'test_collection'
62
+ end
63
+
64
+ end
65
+
66
+ context 'list' do
67
+ it 'returns all collections for the current user' do
68
+ result = Collection.list
69
+ expect(result).to_not be_nil
70
+ expect(result).to be_kind_of Array
71
+ expect(result).to be_kind_of Collections
72
+ expect(result[0]).to be_kind_of Collection
73
+ end
74
+
75
+ it 'raises error on unsuccessful update' do
76
+
77
+ test_id = 99999 # creates error in mock
78
+ expect { Collection.update(id: test_id, name: 'test_collection_new_name') }.to raise_error(FailedResponse)
79
+ end
80
+ end
81
+
82
+ context 'update' do
83
+ it 'raises ArgumentError if no collection_name' do
84
+ expect { Collection.update() }.to raise_error(ArgumentError)
85
+ end
86
+
87
+ it 'changes the name of a collection' do
88
+ expect { Collection.update(id: $new_collection_id, name: 'test_collection_new_name') }.not_to raise_error
89
+ expect(Collection.find($new_collection_id).name).to eq 'test_collection_new_name'
90
+ end
91
+
92
+ it 'raises error on unsuccessful update' do
93
+
94
+ test_id = 99999 # creates error in mock
95
+ expect { Collection.update(id: test_id, name: 'test_collection_new_name') }.to raise_error(FailedResponse)
96
+ end
97
+ end
98
+
99
+ context 'destroy' do
100
+ it 'destroys a collection' do
101
+ expect { Collection.destroy($new_collection_id) }.not_to raise_error
102
+ expect { Collection.find($new_collection_id) }.to raise_error(FailedResponse)
103
+ end
104
+
105
+ it 'raises error on unsucessful delete' do
106
+ test_id = 99999
107
+ expect { Collection.destroy(test_id) }.to raise_error(FailedResponse)
108
+ end
109
+ end
110
+
111
+ context 'add_image' do
112
+ let(:id) { 23_712_632 }
113
+ let(:bad_collection_id) { 54_321 }
114
+ let(:image_id) { 123_456_987_654_321 }
115
+ context 'error' do
116
+ it 'raises ArgumentError if no collection_id or image_id' do
117
+ expect { Collection.add_image(image_id: image_id) }.to raise_error(ArgumentError)
118
+ expect { Collection.add_image(id: bad_collection_id) }.to raise_error(ArgumentError)
119
+ end
120
+
121
+ it 'raises error if collection does not exist' do
122
+ expect { Collection.add_image(id: bad_collection_id, image_id: image_id) }.to raise_error(FailedResponse)
123
+ end
124
+
125
+ end
126
+
127
+ it 'adds image using id' do
128
+ expect { Collection.add_image(id: id, image_id: image_id) }.not_to raise_error
129
+ end
130
+
131
+ it 'adds image using Image.new' do
132
+ expect { Collection.add_image(id: id, image_id: Image.new("id" => image_id)) }.not_to raise_error
133
+ end
134
+ end
135
+
136
+ context 'remove_image' do
137
+ let(:id) { 23_712_632 }
138
+ let(:image_id) { 987_654_321 }
139
+
140
+ context 'error' do
141
+ it 'raises ArgumentError if no collection_id or image_id' do
142
+ expect { Collection.remove_image(image_id: image_id) }.to raise_error(ArgumentError)
143
+ expect { Collection.remove_image(id: id) }.to raise_error(ArgumentError)
144
+ end
145
+
146
+ end
147
+
148
+ it 'removes image using id' do
149
+ expect { Collection.remove_image(id: id, image_id: image_id) }.not_to raise_error
150
+ end
151
+
152
+ it 'removes image using Image.new' do
153
+ expect { Collection.remove_image(id: id, image_id: Image.new("id" => image_id)) }.not_to raise_error
154
+ end
155
+ end
156
+
157
+ end
158
+
159
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Collections do
4
+ before do
5
+ client
6
+ end
7
+
8
+ subject(:collections) { Collection.list }
9
+
10
+ it 'returns all collections for current user' do
11
+ expect(collections).to_not be_nil
12
+ expect(collections).to be_kind_of Array
13
+ expect(collections).to be_kind_of Collections
14
+ expect(collections[0]).to be_kind_of Collection
15
+ expect(collections.raw_data).to be_kind_of Hash
16
+ end
17
+
18
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Configuration do
4
+ subject { Configuration.new }
5
+
6
+ it 'should return api_url when set' do
7
+ subject.api_url = 'https://api.shutterstock.com/newurl'
8
+ expect(subject.api_url).to eql('https://api.shutterstock.com/newurl')
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Contributor do
4
+ # before do
5
+ # client
6
+ # end
7
+
8
+ context 'initialize' do
9
+ it 'initializes with ID from params' do
10
+ expect(Contributor.new("id" => 1234).id).to be 1234
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Driver do
4
+ describe "#json_true?" do
5
+ it "returns true for any truthy json value" do
6
+ Driver::TRUTHY_JSON_VALUES.each do |value|
7
+ expect(subject.json_true?(value)).to be true
8
+ end
9
+ end
10
+
11
+ it "returns false for null" do
12
+ expect(subject.json_true?(nil)).to be false
13
+ end
14
+
15
+ it "return false for non-truthy values" do
16
+ expect(subject.json_true?("FALSE")).to be false
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe ImageAssets do
4
+ before do
5
+ client
6
+ end
7
+
8
+ let(:id) { 402_160_099 }
9
+ subject(:assets) { Image.find(id).assets }
10
+
11
+ describe "find" do
12
+ it 'places image data into correct fields' do
13
+ # Test variables from this specific API call.
14
+ # Might break if vcr recording is deleted. If so, use new values
15
+
16
+ expect(assets.small_jpg).to be_a ImageSizeDetails
17
+ expect(assets.small_jpg.height).to eq 375
18
+ expect(assets.medium_jpg).to be_a ImageSizeDetails
19
+ expect(assets.huge_jpg).to be_a ImageSizeDetails
20
+ expect(assets.supersize_jpg).to be_a ImageSizeDetails
21
+ expect(assets.huge_tiff).to be_a ImageSizeDetails
22
+ expect(assets.supersize_tiff).to be_a ImageSizeDetails
23
+ expect(assets.vector_eps).to be nil
24
+ expect(assets.small_thumb).to be_a Thumbnail
25
+ expect(assets.large_thumb).to be_a Thumbnail
26
+ expect(assets.preview).to be_a Thumbnail
27
+ expect(assets.preview_1000).to be nil
28
+ expect(assets.preview_1500).to be nil
29
+
30
+ expect(assets.count).to be 9
31
+
32
+ end
33
+
34
+ it 'calculates fields correctly' do
35
+
36
+ # Test variables from this specific API call.
37
+ # Might break if vcr recording is deleted. If so, use new values
38
+
39
+ expect(assets.small).to eq assets.small_jpg
40
+ expect(assets.medium).to eq assets.medium_jpg
41
+ expect(assets.huge).to eq assets.huge_jpg
42
+ expect(assets.supersize).to eq assets.supersize_jpg
43
+
44
+ expect(assets.largest_jpg).to eq assets.supersize
45
+ expect(assets.largest_tiff).to eq assets.supersize_tiff
46
+ expect(assets.largest_preview).to eq assets.preview
47
+
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe ImageSizeDetails do
4
+ # before do
5
+ # client
6
+ # end
7
+
8
+ context 'initialize' do
9
+ it 'initializes params correctly' do
10
+ isd = ImageSizeDetails.new({"display_name" => "Huge","dpi" => 300,"file_size" => 1103872,"format" => "jpg","height" => 5000,"is_licensable" => false,"width" => 5000})
11
+
12
+ expect(isd.name).to eq "Huge"
13
+ expect(isd.display_name).to eq "Huge"
14
+ expect(isd.dpi).to eq 300
15
+ expect(isd.file_size).to eq 1103872
16
+ expect(isd.format).to eq "jpg"
17
+ expect(isd.height).to eq 5000
18
+ expect(isd.is_licensable).to eq false
19
+ expect(isd.licensable?).to eq false
20
+ expect(isd.width).to eq 5000
21
+ end
22
+
23
+ it 'initializes correctly when some params missing' do
24
+ isd = ImageSizeDetails.new({"display_name" => "Huge","file_size" => 1103872,"format" => "jpg","is_licensable" => false})
25
+
26
+ expect(isd.display_name).to eq "Huge"
27
+ expect(isd.dpi).to be nil
28
+ expect(isd.height).to be nil
29
+ expect(isd.width).to be nil
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe Image do
4
+ before do
5
+ client
6
+ end
7
+
8
+ let(:id) { 118_139_110 }
9
+ subject(:image) { Image.find(id) }
10
+
11
+ describe "find" do
12
+ it 'returns an Image object' do
13
+ expect(Image).to respond_to(:find)
14
+ expect(image).to_not be_nil
15
+
16
+ expect(image.id).to eql id
17
+ expect(image.assets).to be_a ImageAssets
18
+ end
19
+
20
+ it 'places image data into correct fields' do
21
+ # Test variables from this specific API call.
22
+ # Might break if vcr recording is deleted. If so, use new values
23
+ expect(image.added).to eq DateTime.parse("2012-11-09T00:00:00+00:00")
24
+ expect(image.adult?).to eq false
25
+ expect(image.aspect).to eq 1.5
26
+ expect(image.assets.count).to eq 9
27
+ expect(image.assets.preview).to be_a Thumbnail
28
+ expect(image.assets.small).to be_a ImageSizeDetails
29
+ expect(image.assets.preview.url).to match /118139110/
30
+ expect(image.categories).to be_a Categories
31
+ expect(image.categories[0]).to be_a Category
32
+ expect(image.categories[0].id).to eq 1
33
+ expect(image.contributor).to be_a Contributor
34
+ expect(image.contributor.id).to eq 1306729
35
+ expect(image.description).to eq "Adorable Labrador Puppy Playing with a Chew Toy on White Backdrop"
36
+ expect(image.editorial?).to eq false
37
+ expect(image.illustration?).to eq false
38
+ expect(image.image_type).to eq "photo"
39
+ expect(image.keywords).to be_a Array
40
+ expect(image.keywords.count).to eq 20
41
+ expect(image.media_type).to eq "image"
42
+ expect(image.model_release?).to eq false
43
+ expect(image.model_releases).to eq nil
44
+ expect(image.models).to eq nil
45
+ expect(image.property_release?).to eq false
46
+ end
47
+
48
+ it 'places more image data into correct fields' do
49
+ # Tests model releases
50
+ # Might break if vcr recording is deleted. If so, use new values
51
+ another = Image.find(356308322)
52
+ expect(another.model_release?).to eq true
53
+ expect(another.model_releases).to eq nil
54
+ expect(another.models).to be_a Models
55
+ expect(another.models[0]).to be_a Model
56
+ expect(another.models[0].id).to eq 17856134
57
+ end
58
+
59
+ end
60
+
61
+ describe "similar" do
62
+ it 'returns similar images' do
63
+ result = Image.similar(id)
64
+ expect(result).to_not be_nil
65
+ expect(result).to be_kind_of Array
66
+ expect(result).to be_kind_of Images
67
+ expect(result[0]).to be_kind_of Image
68
+ expect(result.raw_data).to be_kind_of Hash
69
+ expect(result.page).to be 1
70
+ expect(result.total_count).to eq 200
71
+ expect(result.search_id).to_not be_nil
72
+
73
+ # ["count", "page", "sort_method", "search_id", "data"]
74
+ end
75
+
76
+ it 'finds similar images, given an image' do
77
+ expect(image.similar).to be_kind_of Images
78
+ end
79
+ end
80
+
81
+ describe "search" do
82
+ it 'searches for images based on searchterm' do
83
+ results = Image.search('purple cat')
84
+ expect(results).to be_kind_of Images
85
+ expect(results.size).to be > 1
86
+ end
87
+
88
+ it 'searches using more than one parameter' do
89
+ results = Image.search({query: 'laughing', people_age: 'teenagers', sort: 'popular'})
90
+ expect(results).to be_kind_of Images
91
+ expect(results.size).to be > 1
92
+ end
93
+ end
94
+
95
+ describe "fill" do
96
+ it 'fills all details of current image' do
97
+ unfilled = Image.new("id" => 118_139_110)
98
+ unfilled.fill
99
+ expect(unfilled.description).to eq subject.description
100
+ end
101
+ end
102
+ end