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,56 @@
1
+ module Shutterstock
2
+ class ImageAssets < Driver
3
+ attr_reader :hash, :small_jpg, :medium_jpg, :huge_jpg, :supersize_jpg, :huge_tiff, :supersize_tiff, :vector_eps, :small_thumb, :large_thumb,
4
+ :preview, :preview_1000, :preview_1500
5
+
6
+ def initialize(params = {})
7
+ @hash = params
8
+ @small_jpg = ImageSizeDetails.new(params["small_jpg"]) if params["small_jpg"] # (ImageSizeDetails, optional),
9
+ @medium_jpg = ImageSizeDetails.new(params["medium_jpg"]) if params["medium_jpg"] # (ImageSizeDetails, optional),
10
+ @huge_jpg = ImageSizeDetails.new(params["huge_jpg"]) if params["huge_jpg"] # (ImageSizeDetails, optional),
11
+ @supersize_jpg = ImageSizeDetails.new(params["supersize_jpg"]) if params["supersize_jpg"] # (ImageSizeDetails, optional),
12
+ @huge_tiff = ImageSizeDetails.new(params["huge_tiff"]) if params["huge_tiff"] # (ImageSizeDetails, optional),
13
+ @supersize_tiff = ImageSizeDetails.new(params["supersize_tiff"]) if params["supersize_tiff"] # (ImageSizeDetails, optional),
14
+ @vector_eps = ImageSizeDetails.new(params["vector_eps"]) if params["vector_eps"] # (ImageSizeDetails, optional),
15
+ @small_thumb = Thumbnail.new(params["small_thumb"]) if params["small_thumb"] # (Thumbnail, optional),
16
+ @large_thumb = Thumbnail.new(params["large_thumb"]) if params["large_thumb"] # (Thumbnail, optional),
17
+ @preview = Thumbnail.new(params["preview"]) if params["preview"] # (Thumbnail, optional),
18
+ @preview_1000 = Thumbnail.new(params["preview_1000"]) if params["preview_1000"] # (Thumbnail, optional),
19
+ @preview_1500 = Thumbnail.new(params["preview_1500"]) if params["preview_1500"] # (Thumbnail, optional)
20
+ end
21
+
22
+ alias_method :small, :small_jpg
23
+ alias_method :medium, :medium_jpg
24
+ alias_method :huge, :huge_jpg
25
+ alias_method :supersize, :supersize_jpg
26
+
27
+ def count
28
+ @hash.keys.count
29
+ end
30
+
31
+ def largest_preview
32
+ [preview_1500, preview_1000, preview].compact.first
33
+ end
34
+
35
+ def largest_jpg
36
+ [supersize_jpg, huge_jpg, medium_jpg, small_jpg].compact.first
37
+ end
38
+
39
+ def largest_tiff
40
+ [supersize_tiff, huge_tiff].compact.first
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
@@ -0,0 +1,26 @@
1
+ module Shutterstock
2
+ class ImageSizeDetails < Driver
3
+ attr_reader :hash, :height, :width, :file_size, :display_name, :dpi, :format, :is_licensable
4
+
5
+ # {"display_name":"Huge","dpi":300,"file_size":1103872,"format":"jpg","height":5000,"is_licensable":false,"width":5000}
6
+
7
+ def initialize(params = {})
8
+ @hash = params
9
+ @height = params["height"].to_i if params["height"] # (integer, optional),
10
+ @width = params["width"].to_i if params["width"] # (integer, optional),
11
+ @file_size = params["file_size"].to_i if params["file_size"] # (integer, optional),
12
+ @display_name = params["display_name"] # (string, optional),
13
+ @dpi = params["dpi"].to_i if params["dpi"] # (integer, optional),
14
+ @format = params["format"] # (string, optional),
15
+ @is_licensable = json_true? params["is_licensable"] # (boolean, optional)
16
+ end
17
+
18
+ alias_method :name, :display_name
19
+
20
+ def licensable?
21
+ @is_licensable
22
+ end
23
+
24
+
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ module Shutterstock
2
+ class Images < Array
3
+ attr_reader :raw_data, :page, :total_count, :sort_method, :search_id
4
+ def initialize(raw_data)
5
+ @raw_data = raw_data
6
+
7
+ if raw_data.kind_of? Hash
8
+ super(@raw_data["data"].map{ |image| Image.new(image) })
9
+
10
+ @total_count = raw_data["total_count"].to_i
11
+ @page = raw_data["page"].to_i
12
+ # @sort_method = raw_data["sort_method"]
13
+ @search_id = raw_data["search_id"]
14
+ elsif raw_data.kind_of? Array
15
+ super( @raw_data.map{ |image| Image.new(image) } )
16
+ end
17
+
18
+ self
19
+ end
20
+
21
+ # Fill each image in array
22
+ def fill
23
+ self.each {|image| image.fill}
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,67 @@
1
+ module Shutterstock
2
+ class License < Driver
3
+ attr_reader :image_id, :allotment_charge, :price, :download, :error
4
+
5
+ include Equalizer.new(:id)
6
+
7
+ def initialize(params={})
8
+ @hash = params
9
+ @image_id = params["image_id"].to_i # (string),
10
+ @allotment_charge = params["allotment_charge"].to_i if params["allotment_charge"] # (integer, optional),
11
+ @price = SubscriptionPrice.new(params["price"]) if params["price"] # (Price, optional): Wholesale price information, (for rev-share partners only),
12
+ @download = params["download"]["url"] if params["download"] # (Url, optional): Information needed to download the image,
13
+ @error = params["error"] if params["error"] # (string, optional)
14
+ end
15
+
16
+ alias_method :id, :image_id
17
+
18
+ # image_id is an array of either
19
+ # - integer (which is translated to {image_id: "999"} for call)
20
+ # - Image object (which is translated to {image_id: "999"} for call)
21
+ # - hash (passed straight through - used when including metadata: {image_id: "999", metadata: {}}
22
+ def self.license_multiple(subscription_id:, image_id:, format: nil, size: nil, editorial_acknowledgement: nil)
23
+
24
+ raise ArgumentError, "format of 'eps' must correspond with size of 'vector'" if format=='eps' and size != 'vector'
25
+
26
+ params = {}
27
+ params[:subscription_id] = subscription_id
28
+ params[:format] = format if format
29
+ params[:size] = size if size
30
+
31
+ resp = client.request do |r|
32
+ r.path "/v2/images/licenses?subscription_id=#{subscription_id}"
33
+ r.method :post
34
+ r.params params
35
+ r.body ({images: image_ids_to_array_of_hash(image_id, editorial_acknowledgement)})
36
+ end
37
+ Licenses.new(resp.body)
38
+ end
39
+
40
+
41
+ def self.license(subscription_id:, image_id:, format: nil, size: nil, editorial_acknowledgement: nil)
42
+ return license_multiple(subscription_id: subscription_id, image_id: [image_id], format: format, size: size, editorial_acknowledgement: editorial_acknowledgement).first
43
+ end
44
+
45
+
46
+ private
47
+
48
+ # for post request
49
+ # image_id from [1,Image.new("id" => 2), {"image_id" => 3, "metadata": {}}] => [{image_id: "1"},{image_id: "2"},{image_id: "3", metadata: {}}]
50
+ def self.image_ids_to_array_of_hash(image_ids, editorial_acknowledgement)
51
+ Array(image_ids).map do |iid|
52
+ hash = case iid
53
+ when Image
54
+ hash = { "image_id" => iid.id.to_s }
55
+ when Integer
56
+ { "image_id" => iid.to_s }
57
+ when Hash
58
+ iid
59
+ end
60
+ hash["editorial_acknowledgement"] = true if editorial_acknowledgement
61
+ hash
62
+ end
63
+ end
64
+
65
+
66
+ end
67
+ end
@@ -0,0 +1,23 @@
1
+ module Shutterstock
2
+ class Licenses < Array
3
+ attr_reader :raw_data, :total_count, :page, :per_page, :message, :errors
4
+ def initialize(raw_data)
5
+ @raw_data = raw_data
6
+
7
+ if raw_data.kind_of? Hash
8
+ super(@raw_data["data"].map{ |license| License.new(license) })
9
+
10
+ @total_count = raw_data["total_count"].to_i
11
+ @page = raw_data["page"].to_i
12
+ @per_page = raw_data["per_page"].to_i
13
+ @message = raw_data["message"]
14
+ @errors = raw_data["errors"]
15
+
16
+ elsif raw_data.kind_of? Array
17
+ super( @raw_data.map{ |license| License.new(license) } )
18
+ end
19
+
20
+ self
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module Shutterstock
2
+ class Model < Driver
3
+ attr_reader :id
4
+
5
+ include Equalizer.new(:id)
6
+
7
+ def initialize(params={})
8
+ @hash = params
9
+ @id = params["id"].to_i
10
+ end
11
+
12
+ # TODO API calls
13
+
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Shutterstock
2
+ class Models < Array
3
+ attr_reader :raw_data
4
+ def initialize(raw_data)
5
+ @raw_data = raw_data
6
+ super( @raw_data.map{ |model| Model.new(model) } )
7
+ self
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ module Shutterstock
2
+ class Request
3
+
4
+ attr_writer :method, # :post, :get etc
5
+ :path, # request path /v2/images
6
+ :success_status, # response code signifying success. Defaults to 200
7
+ :send_authorization, # default true. Set to false when requesting credentials
8
+ :content_type, # default 'application/json'
9
+ :body, # hash of parameters for request body (usually for :post)
10
+ :params # hash of parameters for url params section (usually for :get or :delete)
11
+
12
+ def initialize(&block)
13
+ @success_status = 200
14
+ @send_authorization = true
15
+ @content_type = 'application/json'
16
+
17
+ # Handle both forms of config:
18
+ # Request.new { |r| r.method=... }
19
+ # Request.new { method=... }
20
+ if block_given?
21
+ if block.arity == 1
22
+ yield self
23
+ else
24
+ instance_eval(&block)
25
+
26
+ end
27
+ end
28
+ end
29
+
30
+ # DSL
31
+ %w[method path success_status params body options send_authorization content_type].each do |method|
32
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
33
+ def #{method}(new_value = nil)
34
+ @#{method} = new_value unless new_value.nil?
35
+ @#{method}
36
+ end
37
+ RUBY
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,35 @@
1
+ require 'date'
2
+
3
+ module Shutterstock
4
+ class Subscription < Driver
5
+ attr_reader :id, :description, :expiration_time, :price_per_download, :license, :allotment, :formats, :metadata
6
+
7
+ include Equalizer.new(:id)
8
+
9
+ def initialize(params={})
10
+ @hash = params
11
+ @id = params["id"] # (string),
12
+ @description = params["description"] if params["description"] # (string, optional),
13
+ @expiration_time = to_date params["expiration_time"] if params["expiration_time"] # (string, optional),
14
+ @price_per_download = SubscriptionPrice.new(params["price_per_download"]) if params["price_per_download"] # (Price, optional),
15
+ @license = params["license"] if params["license"] # (string, optional),
16
+ @allotment = SubscriptionAllotment.new(params["allotment"]) if params["allotment"] # (Allotment, optional),
17
+ @formats = SubscriptionLicenseFormats.new(params["formats"]) if params["formats"] # (LicenseFormat[], optional),
18
+ @metadata = params["metadata"] if params["metadata"] # (SubscriptionMetadata, optional)
19
+ end
20
+
21
+ def expired?
22
+ @expiration_time<DateTime.now
23
+ end
24
+
25
+ # True if this subscription can handle the size passed eg "small"
26
+ def allows_image_size_download?(size)
27
+ !!(!expired? && formats.find {|format| format.size == size})
28
+ end
29
+
30
+ def has_downloads_left?
31
+ allotment && allotment.has_downloads_left?
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ module Shutterstock
2
+ class SubscriptionAllotment < Driver
3
+ attr_reader :downloads_left, :downloads_limit, :start_time, :end_time
4
+
5
+ def initialize(params={})
6
+ @hash = params
7
+
8
+ @downloads_left = params["downloads_left"].to_i if params["downloads_left"] # (integer, optional),
9
+ @downloads_limit = params["downloads_limit"].to_i if params["downloads_limit"] # (integer, optional),
10
+ @start_time = to_date params["start_time"] if params["start_time"] # (string, optional),
11
+ @end_time = to_date params["end_time"] if params["end_time"] # (string, optional)
12
+ end
13
+
14
+ def has_downloads_left?
15
+ @downloads_left>0
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module Shutterstock
2
+ class SubscriptionLicenseFormat < Driver
3
+ attr_reader :description, :min_resolution, :media_type, :format, :size
4
+
5
+ def initialize(params={})
6
+ @hash = params
7
+
8
+ @description = params["description"] if params["description"] # (string, optional),
9
+ @min_resolution = params["min_resolution"].to_i if params["min_resolution"] # (integer, optional),
10
+ @media_type = params["media_type"] if params["media_type"] # (string, optional),
11
+ @format = params["format"] if params["format"] # (string, optional),
12
+ @size = params["size"] if params["size"] # (string, optional)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Shutterstock
2
+ class SubscriptionLicenseFormats < Array
3
+ attr_reader :raw_data
4
+ def initialize(raw_data)
5
+ @raw_data = raw_data
6
+
7
+ super( @raw_data.map{ |slf| SubscriptionLicenseFormat.new(slf) } )
8
+
9
+ self
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Shutterstock
2
+ class SubscriptionPrice < Driver
3
+ attr_reader :local_amount, :local_currency
4
+
5
+ def initialize(params={})
6
+ @hash = params
7
+
8
+ @local_amount = params["local_amount"].to_f if params["local_amount"] # (number, optional),
9
+ @local_currency = params["local_currency"] if params["local_currency"] # (string, optional)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ module Shutterstock
2
+ class Subscriptions < Array
3
+ attr_reader :raw_data, :page, :total_count, :sort_method, :search_id
4
+ def initialize(raw_data)
5
+ @raw_data = raw_data
6
+
7
+ if raw_data.kind_of? Hash
8
+ super(@raw_data["data"].map{ |subscription| Subscription.new(subscription) })
9
+
10
+ @total_count = raw_data["total_count"].to_i
11
+ @page = raw_data["page"].to_i
12
+ elsif raw_data.kind_of? Array
13
+ super( @raw_data.map{ |subscription| Subscription.new(subscription) } )
14
+ end
15
+
16
+ self
17
+ end
18
+
19
+ def find_subscription_for_image_size(size = nil)
20
+ size = "huge" if !size
21
+ self.active.select{|sub| sub.has_downloads_left? && sub.allows_image_size_download?(size)}.first
22
+ end
23
+
24
+ def downloads_left
25
+ self.select{|sub| sub.has_downloads_left?}
26
+ end
27
+
28
+ def expired
29
+ self.select{|sub| sub.expired?}
30
+ end
31
+
32
+ def active
33
+ self.reject{|sub| sub.expired?}
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ module Shutterstock
2
+ class Thumbnail < Driver
3
+ attr_reader :hash, :url, :height, :width
4
+
5
+ include Equalizer.new(:url)
6
+
7
+ # {"display_name":"Huge","dpi":300,"file_size":1103872,"format":"jpg","height":5000,"is_licensable":false,"width":5000}
8
+
9
+ def initialize(params = {})
10
+ @hash = params
11
+ @url = params["url"] # (string),
12
+ @height = params["height"].to_i # (integer),
13
+ @width = params["width"].to_i # (integer)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,68 @@
1
+ module Shutterstock
2
+ class User < Driver
3
+ attr_reader :id, :contributor_id, :customer_id, :email, :first_name, :full_name, :id, :last_name, :language,
4
+ :organization_id, :username, :is_premier, :is_premier_parent, :premier_permissions, :only_sensitive_use,
5
+ :only_enhanced_license
6
+
7
+ include Equalizer.new(:id)
8
+
9
+ def initialize(params={})
10
+ @hash = params
11
+ @contributor_id = params["contributor_id"] if params["contributor_id"] # (string, optional),
12
+ @customer_id = params["customer_id"] if params["customer_id"] # (string, optional),
13
+ @email = params["email"] if params["email"] # (string, optional),
14
+ @first_name = params["first_name"] if params["first_name"] # (string, optional),
15
+ @full_name = params["full_name"] if params["full_name"] # (string, optional),
16
+ @id = params["id"] if params["id"] # (string, optional),
17
+ @last_name = params["last_name"] if params["last_name"] # (string, optional),
18
+ @language = params["language"] if params["language"] # (string, optional),
19
+ @organization_id = params["organization_id"] if params["organization_id"] # (string, optional),
20
+ @username = params["username"] if params["username"] # (string, optional),
21
+ @is_premier = json_true? params["is_premier"] if params["is_premier"] # (boolean, optional),
22
+ @is_premier_parent = json_true? params["is_premier_parent"] if params["is_premier_parent"] # (boolean, optional),
23
+ @premier_permissions = params["premier_permissions"] if params["premier_permissions"] # (string[], optional),
24
+ @only_sensitive_use = json_true? params["only_sensitive_use"] if params["only_sensitive_use"] # (boolean, optional),
25
+ @only_enhanced_license = json_true? params["only_enhanced_license"] if params["only_enhanced_license"] # (boolean, optional)
26
+ end
27
+
28
+ # boolean readers
29
+ def premier?
30
+ @is_premier
31
+ end
32
+
33
+ # boolean readers
34
+ def premier_parent?
35
+ @is_premier_parent
36
+ end
37
+
38
+ # boolean readers
39
+ def sensitive_use?
40
+ @only_sensitive_use
41
+ end
42
+
43
+ # boolean readers
44
+ def enhanced_license?
45
+ @only_enhanced_license
46
+ end
47
+
48
+
49
+ # Currently logged in user
50
+ def self.find
51
+ resp = client.request do
52
+ path "/v2/user"
53
+ method :get
54
+ end
55
+ User.new(resp.body)
56
+ end
57
+
58
+ # Subscriptions for current user
59
+ def self.subscriptions
60
+ resp = client.request do |r|
61
+ r.path "/v2/user/subscriptions"
62
+ r.method :get
63
+ end
64
+ Subscriptions.new(resp.body)
65
+ end
66
+
67
+ end
68
+ end