zanox_publisher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +178 -0
  7. data/Rakefile +10 -0
  8. data/lib/zanox_publisher/ad_medium.rb +232 -0
  9. data/lib/zanox_publisher/ad_space.rb +159 -0
  10. data/lib/zanox_publisher/base.rb +69 -0
  11. data/lib/zanox_publisher/category.rb +57 -0
  12. data/lib/zanox_publisher/connection.rb +291 -0
  13. data/lib/zanox_publisher/exclusive_incentive.rb +135 -0
  14. data/lib/zanox_publisher/format.rb +19 -0
  15. data/lib/zanox_publisher/incentive.rb +135 -0
  16. data/lib/zanox_publisher/incentive_base.rb +89 -0
  17. data/lib/zanox_publisher/policy.rb +42 -0
  18. data/lib/zanox_publisher/prize.rb +18 -0
  19. data/lib/zanox_publisher/product.rb +263 -0
  20. data/lib/zanox_publisher/profile.rb +123 -0
  21. data/lib/zanox_publisher/program.rb +241 -0
  22. data/lib/zanox_publisher/program_application.rb +135 -0
  23. data/lib/zanox_publisher/tracking_link.rb +42 -0
  24. data/lib/zanox_publisher/version.rb +3 -0
  25. data/lib/zanox_publisher/vertical.rb +19 -0
  26. data/lib/zanox_publisher.rb +39 -0
  27. data/spec/config/credentials.example.yml +2 -0
  28. data/spec/lib/requirements_spec.rb +9 -0
  29. data/spec/lib/zanox_publisher/ad_medium_spec.rb +162 -0
  30. data/spec/lib/zanox_publisher/ad_space_spec.rb +56 -0
  31. data/spec/lib/zanox_publisher/base_spec.rb +35 -0
  32. data/spec/lib/zanox_publisher/connection_spec.rb +68 -0
  33. data/spec/lib/zanox_publisher/exclusive_incentive_spec.rb +104 -0
  34. data/spec/lib/zanox_publisher/incentive_spec.rb +112 -0
  35. data/spec/lib/zanox_publisher/product_spec.rb +223 -0
  36. data/spec/lib/zanox_publisher/profile_spec.rb +26 -0
  37. data/spec/lib/zanox_publisher/program_application_spec.rb +51 -0
  38. data/spec/lib/zanox_publisher/program_spec.rb +192 -0
  39. data/spec/lib/zanox_ruby_spec.rb +17 -0
  40. data/spec/spec_helper.rb +21 -0
  41. data/spec/support/credentials.rb +3 -0
  42. data/spec/support/vcr.rb +8 -0
  43. data/spec/vcr_cassettes/.gitignore +4 -0
  44. data/zanox_publisher.gemspec +27 -0
  45. metadata +203 -0
@@ -0,0 +1,135 @@
1
+ module ZanoxPublisher
2
+ # Incentives - Get coupons and other incentives
3
+ #
4
+ # The Zanox API cannot retrieve both exclusive and non-exclusive incentives, so each has its own class.
5
+ class Incentive < IncentiveBase
6
+ RESOURCE_PATH = '/incentives'
7
+
8
+ # Set the exclusive attribute
9
+ @@exclusive = false
10
+
11
+ class << self
12
+ # Retrieves all incentive's dependent on search parameters.
13
+ #
14
+ # This is equivalent to the Zanox API method SearchIncentives.
15
+ # The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-incentives}.
16
+ #
17
+ # Authentication: Requires connect ID.
18
+ #
19
+ # This can require multiple requests, as internally every page is pulled.
20
+ # The ZanoxPublisher::AdMedium.page function can be used to better control the requests made.
21
+ #
22
+ # @param program [Program, Integer] limits results to a particular program ID.
23
+ # @param adspace [AdSpace, Integer] limits results to incentives that have tracking links associated with this AdSpace.
24
+ # @param incentive_type [String] limits results to one of the following incentive types (API equivalent is incentiveType).
25
+ # @param incentiveType [String] limits results to one of the following incentive types (API name).
26
+ # @param region [String] limits results to a region.
27
+ #
28
+ # @return [Array<Incentive>]
29
+ def all(options = {})
30
+ retval = []
31
+ current_page = 0
32
+ options.merge!({ per_page: maximum_per_page })
33
+
34
+ begin
35
+ retval += self.page(current_page, options)
36
+ current_page += 1
37
+ end while Incentive.total > retval.size
38
+
39
+ retval
40
+ end
41
+
42
+ # Retrieves a list of publicly available, non-exclusive incentiveItems dependent on search parameter.
43
+ #
44
+ # This is equivalent to the Zanox API method SearchIncentives.
45
+ # The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-incentives}.
46
+ #
47
+ # Authentication: Requires connect ID.
48
+ #
49
+ # @param page [Integer] the page position.
50
+ # @param per_page [Integer] number of items in the result set (API equivalent is items).
51
+ # @param items [Integer] number of items in the result set (API name).
52
+ # @param program [Program, Integer] limits results to a particular program ID.
53
+ # @param adspace [AdSpace, Integer] limits results to incentives that have tracking links associated with this AdSpace.
54
+ # @param incentive_type [String] limits results to one of the following incentive types (API equivalent is incentiveType).
55
+ # @param incentiveType [String] limits results to one of the following incentive types (API name).
56
+ # @param region [String] limits results to a region.
57
+ #
58
+ # @return [Array<Incentive>]
59
+ def page(page = 0, options = {})
60
+ params = { query: { page: page } }
61
+
62
+ per_page = nil
63
+ per_page = options[:per_page] if per_page.nil?
64
+ per_page = options[:items] if per_page.nil?
65
+ per_page = AdMedium.per_page if per_page.nil?
66
+ params[:query].merge!({ items: per_page })
67
+
68
+ program = options[:program]
69
+ program = program.to_i unless program.nil?
70
+
71
+ adspace = options[:adspace]
72
+ adspace = adspace.to_i unless adspace.nil?
73
+
74
+ incentive_type = options[:incentive_type]
75
+ incentive_type = options[:incentiveType] if incentive_type.nil?
76
+ incentive_type = nil unless @@incentive_types.include? incentive_type
77
+
78
+ region = options[:region]
79
+
80
+ # Build the query on hand of the options received
81
+ params[:query].merge!({ program: program }) unless program.nil?
82
+ params[:query].merge!({ adspace: adspace }) unless adspace.nil?
83
+ params[:query].merge!({ incentiveType: incentive_type }) unless incentive_type.nil?
84
+ params[:query].merge!({ region: region }) unless region.nil?
85
+
86
+ retval = []
87
+
88
+ response = self.connection.get(RESOURCE_PATH, params)
89
+
90
+ Incentive.total = response.fetch('total')
91
+
92
+ incentives = []
93
+ incentives = response.fetch('incentiveItems', {}).fetch('incentiveItem', []) if Incentive.total > 0
94
+ incentives = [incentives] unless incentives.is_a? Array
95
+
96
+ incentives.each do |incentive|
97
+ retval << Incentive.new(incentive, @@exclusive)
98
+ end
99
+
100
+ retval
101
+ end
102
+
103
+ # Returns a single incentiveItem, as queried by its ID.
104
+ #
105
+ # This is equivalent to the Zanox API method GetIncentive.
106
+ # The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-incentives-incentive}.
107
+ #
108
+ # Authentication: Requires connect ID.
109
+ #
110
+ # @param id [Integer] the ID of the adspace you want to get.
111
+ # @param adspace [AdSpace, Integer] if you would like tracking links for only one of your publisher ad spaces, pass its ID in this parameter.
112
+ #
113
+ # @return [<Incentive>]
114
+ def find(id, options = {})
115
+ params = {}
116
+
117
+ adspace = options[:adspace]
118
+ adspace = adspace.to_i unless adspace.nil?
119
+
120
+ params = { query: { adspace: adspace } } unless adspace.nil?
121
+
122
+ response = self.connection.get(RESOURCE_PATH + "/incentive/#{id.to_i}", params)
123
+
124
+ Incentive.new(response.fetch('incentiveItem'), @@exclusive)
125
+ end
126
+
127
+ # A connection instance with Incentives' relative_path
128
+ #
129
+ # @return [Connection]
130
+ def connection
131
+ @connection ||= Connection.new(RESOURCE_PATH)
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,89 @@
1
+ module ZanoxPublisher
2
+ # Base class to hold the incentive attributes
3
+ #
4
+ # @attr [Integer] id The incentiveItem's identifer from Zanox
5
+ # @attr [String] name The name for the incentive
6
+ # @attr [Program] program The program to which the incentive belongs
7
+ # @attr [Array<AdMedium>] admedium The ad medium that can be used for the incentive
8
+ # @attr [String] incentive_type The type of incentive
9
+ # @attr [Array<String>] regions The regions for the incentive
10
+ # @attr [DateTime] created_at The date the incentive is created at
11
+ # @attr [DateTime] modified_at The date the incentive is modified at
12
+ # @attr [DateTime] start_date The date the incentive will start
13
+ # @attr [DateTime] end_date The date the incentive will end
14
+ # @attr [String] info_for_publisher The information for the publisher
15
+ # @attr [String] info_for_customer The information for the customer
16
+ # @attr [String] coupon_code The coupon code assigned to the incentive
17
+ # @attr [Fixnum] total The total amount saved through the incentive
18
+ # @attr [String] currency The currency of money amounts
19
+ # @attr [Fixnum] percentage The rebate percentage given through the incentive
20
+ # @attr [String] restrictions Any restrictions associated with the incentive
21
+ # @attr [Boolean] new_customer_only States if the incentive is only for new customers
22
+ # @attr [Fixnum] minimum_basket_value The minimum basket value to trigger the incentive
23
+ # @attr [Array<Prize>] prizes The prizes given during the incentive
24
+ class IncentiveBase < Base
25
+ @@incentive_types = %w(coupons samples bargains freeProducts noShippingCosts lotteries)
26
+
27
+ # Returns the Zanox API incentiveTypeEnum datatype
28
+ #
29
+ # @return [Array<String>]
30
+ def self.incentive_types
31
+ @@incentive_types
32
+ end
33
+
34
+ def initialize(data = {}, exclusive = false)
35
+ @id = data.fetch('@id')
36
+ @name = data.fetch('name')
37
+ @program = Program.new(data.fetch('program'))
38
+ @admedium = AdMedium.new(data.fetch('admedia').fetch('admediumItem'))
39
+ @incentive_type = data.fetch('incentiveType')
40
+ @regions = data.fetch('regions', []).first
41
+ @regions = @regions.fetch('region') unless @regions.nil?
42
+ @regions = [@regions] if @regions.is_a? String
43
+ @created_at = data.fetch('createDate')
44
+ @modified_at = data.fetch('modifiedDate')
45
+ @start_date = data.fetch('startDate')
46
+ @end_date = data.fetch('endDate', nil)
47
+ @info_for_publisher = data.fetch('info4publisher', nil)
48
+ @info_for_customer = data.fetch('info4customer')
49
+ @coupon_code = data.fetch('couponCode', nil)
50
+ @total = data.fetch('total', nil)
51
+ @currency = data.fetch('currency', nil)
52
+ @percentage = data.fetch('percentage', nil)
53
+ @restrictions = data.fetch('restrictions', nil)
54
+ @new_customer_only = data.fetch('newCustomerOnly')
55
+ @minimum_basket_value = data.fetch('minimumBasketValue', nil)
56
+ @prizes = data.fetch('prizes', '')
57
+ @prizes = nil if @prizes == ''
58
+ @prizes = @prizes.fetch('prize') unless @prizes.nil?
59
+ @prizes = @prizes.map{ |hash| Prize.new(hash) } unless @prizes.nil?
60
+ @exclusive = exclusive
61
+ end
62
+
63
+ # Returns the incentiveItems' ID as integer representation
64
+ #
65
+ # @return [Integer]
66
+ def to_i
67
+ @id
68
+ end
69
+
70
+ attr_accessor :id, :name, :program, :admedium, :incentive_type,
71
+ :regions, :created_at, :modified_at, :start_date,
72
+ :end_date, :info_for_publisher, :info_for_customer,
73
+ :coupon_code, :total, :currency, :percentage, :restrictions,
74
+ :new_customer_only, :minimum_basket_value, :prizes, :exclusive
75
+
76
+ # make API names available
77
+ alias admedia admedium
78
+ alias incentiveType incentive_type
79
+ alias createDate created_at
80
+ alias modifiedDate modified_at
81
+ alias startDate start_date
82
+ alias endDate end_date
83
+ alias info4publisher info_for_publisher
84
+ alias info4customer info_for_customer
85
+ alias couponCode coupon_code
86
+ alias newCustomerOnly new_customer_only
87
+ alias minimumBasketValue minimum_basket_value
88
+ end
89
+ end
@@ -0,0 +1,42 @@
1
+ module ZanoxPublisher
2
+ class Policy
3
+ class << self
4
+ def fetch(data = nil)
5
+ # To support API of picking categories of hash with [] notation
6
+ return nil if data.nil?
7
+
8
+ # Try to fetch policy else make data it an array
9
+ policies = data.fetch('policy', nil)
10
+ policies = [data] if policies.nil?
11
+ policies = [policies] if policies.is_a? Hash
12
+
13
+ # Build the return value
14
+ retval = []
15
+
16
+ policies.each do |policy|
17
+ retval << Policy.new(policy)
18
+ end
19
+
20
+ retval
21
+ end
22
+ end
23
+
24
+ attr_reader :id, :name
25
+
26
+ def initialize(data = {})
27
+ @id = data.fetch('@id').to_i
28
+ @name = data.fetch('$', nil)
29
+ end
30
+
31
+ def to_s
32
+ @name
33
+ end
34
+
35
+ # Returns the policy ID as integer representation
36
+ #
37
+ # @return [Integer]
38
+ def to_i
39
+ @id
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ module ZanoxPublisher
2
+ # Wrapper for the prizes response from Zanox API
3
+ class Prize
4
+ attr_reader :id, :name, :description, :count, :rank
5
+
6
+ def initialize(data = {})
7
+ @id = data.fetch('@id')
8
+ @name = data.fetch('name')
9
+ @description = data.fetch('description')
10
+ @count = data.fetch('count')
11
+ @rank = data.fetch('rank')
12
+ end
13
+
14
+ def to_i
15
+ @id
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,263 @@
1
+ module ZanoxPublisher
2
+ # Products
3
+ #
4
+ # Get products, including their tracking links
5
+ #
6
+ # @attr [String] id The productItem's identifer from Zanox
7
+ # @attr [String] name The name for the product
8
+ # @attr [DateTime] modified_at The date the incentive is modified at
9
+ # @attr [Program] program The program to which the product belongs
10
+ # @attr [Fixnum] price The price of the product
11
+ # @attr [String] currency The currency of the price
12
+ # @attr [Array<TrackingLink>] tracking_links The tracking links of the product for each ad space
13
+ # @attr [String] description The product description
14
+ # @attr [String] description_long The long version of the product description
15
+ # @attr [String] manufacturer The products' manufacturer
16
+ # @attr [String] ean The products' EAN
17
+ # @attr [String] delivery_time The delivery time for the product
18
+ # @attr [String] terms The terms and conditions of the product
19
+ # @attr [Category] category The advertisers' given category to the product
20
+ # @attr [Hash] image The product image's
21
+ # @attr [Fixnum] price_old The old price of the product
22
+ # @attr [String] shipping_costs The shipping costs for the product
23
+ # @attr [String] shipping The shipping costs for the product
24
+ # @attr [String] merchant_category The merchants' category for the product
25
+ # @attr [String] merchant_product_id The merchants' product ID
26
+ class Product < Base
27
+ RESOURCE_PATH = '/products'
28
+
29
+ class << self
30
+ # Retrieves all products dependent on search parameters.
31
+ #
32
+ # This is equivalent to the Zanox API method SearchProducts.
33
+ # The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-products}.
34
+ #
35
+ # Authentication: Requires connect ID.
36
+ #
37
+ # This can require multiple requests, as internally every page is pulled.
38
+ # The ZanoxPublisher::Product.page function can be used to better control the requests made.
39
+ #
40
+ # @param query [String] Limits results to programs associated with this search string (API equivalent is q).
41
+ # @param q [String] Limits results to programs associated with this search string (API name).
42
+ # @param region [String] Limits results to a particular region.
43
+ # @param minimum_price [Integer] Limits results to products with a minimum, currency-independent price (API equivalent is minprice).
44
+ # @param minprice [Integer] Limits results to products with a minimum, currency-independent price (API name).
45
+ # @param maximum_price [Integer] Limits results to products with a maximum, currency-independent price (API equivalent is maxprice).
46
+ # @param maxprice [Integer] Limits results to products with a maximum, currency-independent price (API name).
47
+ # @param programs [Program, Integer, Array<Program>, Array<Integer>] Limits results to particular program ID(s).
48
+ # @param has_images [Boolean] Limits results to products with images (API equivalent is hasimages).
49
+ # @param hasimages [Boolean] Limits results to products with images (API name).
50
+ # @param adspace [AdSpace, Integer] limits results to incentives that have tracking links associated with this AdSpace.
51
+ # @param partnership [String] Enables search in all product data regardless of whether you are confirmed by the advertiser or not.
52
+ # @param ean [Integer, String] Limit on hand of the international article number.
53
+ # @param merchant_category [String, Array<String>] Limits results to the specified merchant category/categories.
54
+ # @param merchantcategory [String, Array<String>] Limits results to the specified merchant category/categories.
55
+ #
56
+ # @return [Array<Product>]
57
+ def all(options = {})
58
+ retval = []
59
+ current_page = 0
60
+ options.merge!({ per_page: maximum_per_page })
61
+
62
+ begin
63
+ retval += self.page(current_page, options)
64
+ current_page += 1
65
+ end while Product.total > retval.size
66
+
67
+ retval
68
+ end
69
+
70
+ # Retrieves the requested page of product items dependent on search parameters.
71
+ #
72
+ # This is equivalent to the Zanox API method SearchProducts.
73
+ # The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-products}.
74
+ #
75
+ # Authentication: Requires connect ID.
76
+ #
77
+ # @param page [Integer] the page position
78
+ # @param per_page [Integer] number of items in the result set (API equivalent is items)
79
+ # @param items [Integer] number of items in the result set (API name)
80
+ # @param query [String] Limits results to programs associated with this search string (API equivalent is q).
81
+ # @param q [String] Limits results to programs associated with this search string (API name).
82
+ # @param region [String] Limits results to a particular region.
83
+ # @param minimum_price [Integer] Limits results to products with a minimum, currency-independent price (API equivalent is minprice).
84
+ # @param minprice [Integer] Limits results to products with a minimum, currency-independent price (API name).
85
+ # @param maximum_price [Integer] Limits results to products with a maximum, currency-independent price (API equivalent is maxprice).
86
+ # @param maxprice [Integer] Limits results to products with a maximum, currency-independent price (API name).
87
+ # @param programs [Program, Integer, Array<Program>, Array<Integer>] Limits results to particular program ID(s).
88
+ # @param has_images [Boolean] Limits results to products with images (API equivalent is hasimages).
89
+ # @param hasimages [Boolean] Limits results to products with images (API name).
90
+ # @param adspace [AdSpace, Integer] limits results to incentives that have tracking links associated with this AdSpace.
91
+ # @param partnership [String] Enables search in all product data regardless of whether you are confirmed by the advertiser or not.
92
+ # @param ean [Integer, String] Limit on hand of the international article number.
93
+ # @param merchant_category [String, Array<String>] Limits results to the specified merchant category/categories.
94
+ # @param merchantcategory [String, Array<String>] Limits results to the specified merchant category/categories.
95
+ #
96
+ # @return [Array<Product>]
97
+ def page(page = 0, options = {})
98
+ params = { query: { page: page } }
99
+
100
+ per_page = nil
101
+ per_page = options[:per_page] if per_page.nil?
102
+ per_page = options[:items] if per_page.nil?
103
+ per_page = Product.per_page if per_page.nil?
104
+ params[:query].merge!({ items: per_page })
105
+
106
+ query = options[:query]
107
+ query = options[:q] if query.nil?
108
+
109
+ if not query.nil?
110
+ if query.length <= 25
111
+ searchtype = 'phrase'
112
+ else
113
+ searchtype = 'contextual'
114
+ end
115
+ end
116
+
117
+ region = options[:region]
118
+
119
+ minimum_price = options[:minimum_price]
120
+ minimum_price = options[:minprice] if minimum_price.nil?
121
+ minimum_price = minimum_price.to_i unless minimum_price.nil?
122
+
123
+ maximum_price = options[:maximum_price]
124
+ maximum_price = options[:maxprice] if maximum_price.nil?
125
+ maximum_price = maximum_price.to_i unless maximum_price.nil?
126
+
127
+ programs = options[:programs]
128
+
129
+ unless programs.nil?
130
+ programs = programs.map(&:to_i).join(',') if programs.is_a? Array
131
+ programs = programs.to_i if programs.is_a? Program or programs.is_a? Integer
132
+ end
133
+
134
+ has_images = options[:has_images]
135
+ has_images = options[:hasimages] if has_images.nil?
136
+
137
+ adspace = options[:adspace]
138
+ adspace = adspace.to_i unless adspace.nil?
139
+
140
+ partnership = options[:partnership]
141
+ partnership = nil unless ['all', 'confirmed'].include? partnership
142
+
143
+ ean = options[:ean]
144
+
145
+ merchant_category = options[:merchant_category]
146
+ merchant_category = options[:merchantcategory] if merchant_category.nil?
147
+
148
+ unless merchant_category.nil?
149
+ if merchant_category.is_a? Array
150
+ merchant_category.each { |category| params[:query].merge!({ merchantcategory: category }) }
151
+ else
152
+ params[:query].merge!({ merchantcategory: merchant_category })
153
+ end
154
+ end
155
+
156
+ params[:query].merge!({ q: query }) unless query.nil?
157
+ params[:query].merge!({ searchtype: searchtype }) unless query.nil?
158
+ params[:query].merge!({ region: region }) unless region.nil?
159
+ params[:query].merge!({ minprice: minimum_price }) unless minimum_price.nil?
160
+ params[:query].merge!({ maxprice: maximum_price }) unless maximum_price.nil?
161
+ params[:query].merge!({ programs: programs }) unless programs.nil?
162
+ params[:query].merge!({ hasimages: has_images }) unless has_images.nil?
163
+ params[:query].merge!({ adspace: adspace }) unless adspace.nil?
164
+ params[:query].merge!({ partnership: partnership }) unless partnership.nil?
165
+ params[:query].merge!({ ean: ean }) unless ean.nil?
166
+
167
+ retval = []
168
+
169
+ response = self.connection.get(RESOURCE_PATH, params)
170
+
171
+ Product.total = response.fetch('total')
172
+
173
+ products = []
174
+ products = response.fetch('productItems', {}) if Product.total > 0
175
+ products = {} unless products.is_a? Hash
176
+ products = products.fetch('productItem', [])
177
+
178
+ products.each do |product|
179
+ retval << Product.new(product)
180
+ end
181
+
182
+ retval
183
+ end
184
+
185
+ # Returns a single productItem, as queried by its ID.
186
+ #
187
+ # This is equivalent to the Zanox API method GetProduct.
188
+ # The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-products-product}.
189
+ #
190
+ # Authentication: Requires connect ID.
191
+ #
192
+ # @param id [Integer] the ID of the adspace you want to get.
193
+ # @param adspace [AdSpace, Integer] if you would like tracking links for only one of your publisher ad spaces, pass its ID in this parameter.
194
+ #
195
+ # @return [<Product>]
196
+ def find(id, options = {})
197
+ params = {}
198
+
199
+ adspace = options[:adspace]
200
+ adspace = adspace.to_i unless adspace.nil?
201
+
202
+ params = { query: { adspace: adspace } } unless adspace.nil?
203
+
204
+ response = self.connection.get(RESOURCE_PATH + "/product/#{id.to_i}", params)
205
+
206
+ Product.new(response.fetch('productItem').first)
207
+ end
208
+
209
+ # A connection instance with Products' relative_path
210
+ #
211
+ # @return [Connection]
212
+ def connection
213
+ @connection ||= Connection.new(RESOURCE_PATH)
214
+ end
215
+ end
216
+
217
+ def initialize(data = {})
218
+ @id = data.fetch('@id')
219
+ @name = data.fetch('name')
220
+ @modified_at = data.fetch('modified')
221
+ @program = Program.new(data.fetch('program'))
222
+ @price = data.fetch('price')
223
+ @currency = data.fetch('currency')
224
+ @tracking_links = TrackingLink.fetch(data.fetch('trackingLinks', {})['trackingLink'])
225
+ @description = data.fetch('description', nil)
226
+ @description_long = data.fetch('descriptionLong', nil)
227
+ @manufacturer = data.fetch('manufacturer', nil)
228
+ @ean = data.fetch('ean', nil)
229
+ @delivery_time = data.fetch('deliveryTime', nil)
230
+ @terms = data.fetch('terms', nil)
231
+ @category = data.fetch('category', nil)
232
+ @category = Category.new(@category) unless @category.nil?
233
+ @image = data.fetch('image', nil)
234
+ @price_old = data.fetch('priceOld', nil)
235
+ @shipping_costs = data.fetch('shippingCosts', nil)
236
+ @shipping = data.fetch('shipping', nil)
237
+ @merchant_category = data.fetch('merchantCategory', nil)
238
+ @merchant_product_id = data.fetch('merchantProductId', nil)
239
+ end
240
+
241
+ # Returns the productItems' ID as integer representation
242
+ #
243
+ # @return [Integer]
244
+ def to_i
245
+ @id
246
+ end
247
+
248
+ attr_accessor :id, :name, :modified_at, :program, :price, :currency, :tracking_links,
249
+ :description, :description_long, :manufacturer, :ean, :delivery_time,
250
+ :terms, :category, :image, :price_old, :shipping_costs, :shipping,
251
+ :merchant_category, :merchant_product_id
252
+
253
+ # make API names available
254
+ alias modified modified_at
255
+ alias trackingLinks tracking_links
256
+ alias descriptionLong description_long
257
+ alias deliveryTime delivery_time
258
+ alias priceOld price_old
259
+ alias shippingCosts shipping_costs
260
+ alias merchantCategory merchant_category
261
+ alias merchantProductId merchant_product_id
262
+ end
263
+ end
@@ -0,0 +1,123 @@
1
+ module ZanoxPublisher
2
+ # Profile information
3
+ #
4
+ # Get and update your profile information
5
+ #
6
+ # @attr [Integer] id The profileItem's identifer from Zanox
7
+ # @attr [Fixnum] adrank The adrank
8
+ # @attr [String] first_name The first name of the profile holder
9
+ # @attr [String] last_name The last name of the profile holder
10
+ # @attr [String] email The email address of the profile
11
+ # @attr [String] country The country of the profile
12
+ # @attr [String] street1 The first adress line
13
+ # @attr [String] city The city of the profile
14
+ # @attr [String] zipcode The zip code of the profile
15
+ # @attr [String] login_name The login name of the profile
16
+ # @attr [String] user_name The user name of the profile
17
+ # @attr [String] title The title of the profile holder
18
+ # @attr [String] currency The currency of the account
19
+ # @attr [String] language The language setting of the account
20
+ # @attr [String] fax The fax number of the profile holder
21
+ # @attr [String] mobile The mobile number of the profile holder
22
+ # @attr [String] phone The phone number of the profile holder
23
+ # @attr [String] street2 The second adress line
24
+ # @attr [String] company The company to which the profile belongs
25
+ # @attr [Boolean] is_advertiser The account is an advertiser account
26
+ # @attr [Boolean] is_sublogin The account is a sublogin of a main account
27
+ class Profile
28
+ RESOURCE_PATH = '/profiles'
29
+
30
+ class << self
31
+ # Get all profiles associated to the connect ID.
32
+ #
33
+ # This is equivalent to the Zanox API method getProfiles.
34
+ # The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-profiles}.
35
+ #
36
+ # Authentication: Requires signature.
37
+ #
38
+ # @return [Array<Profile>]
39
+ #
40
+ # @example
41
+ # profiles = ZanoxPublisher::Profile.all #=> [#<Profile ...>]
42
+ # profile = profiles.first #=> #<Profile ...>
43
+ def all
44
+ response = self.connection.signature_get()
45
+ data = response.fetch('profileItem')
46
+ profiles = []
47
+
48
+ data.each do |profile|
49
+ profiles << Profile.new(profile)
50
+ end
51
+
52
+ profiles
53
+ end
54
+
55
+ # Get the first profiles' information.
56
+ #
57
+ # This gives convenient access to your main profile,
58
+ # as often the Zanox API getProfiles method will only return
59
+ # one profileItem.
60
+ #
61
+ # @return [Profile]
62
+ #
63
+ # @example
64
+ # my_profile = ZanoxPublisher::Profile.first #=> #<Profile ...>
65
+ def first
66
+ Profile.all.first
67
+ end
68
+
69
+ # A connection instance with Profiles' relative_path
70
+ #
71
+ # @return [Connection]
72
+ def connection
73
+ @connection ||= Connection.new(RESOURCE_PATH)
74
+ end
75
+ end
76
+
77
+ # TODO: PUT {https://developer.zanox.com/web/guest/publisher-api-2011/put-profiles}
78
+ #
79
+ def initialize(data = {})
80
+ @id = data.fetch('@id').to_i
81
+ @adrank = data.fetch('adrank')
82
+ @firstName = data.fetch('firstName')
83
+ @lastName = data.fetch('lastName')
84
+ @email = data.fetch('email')
85
+ @country = data.fetch('country')
86
+ @street1 = data.fetch('street1')
87
+ @city = data.fetch('city')
88
+ @zipcode = data.fetch('zipcode')
89
+ @loginName = data.fetch('loginName')
90
+ @userName = data.fetch('userName')
91
+ @isAdvertiser = data.fetch('isAdvertiser')
92
+ @isSublogin = data.fetch('isSublogin')
93
+ # Optionally returned data
94
+ @title = data.fetch('title', nil)
95
+ @currency = data.fetch('currency', nil)
96
+ @language = data.fetch('language', nil)
97
+ @fax = data.fetch('fax', nil)
98
+ @mobile = data.fetch('mobile', nil)
99
+ @phone = data.fetch('phone', nil)
100
+ @street2 = data.fetch('street2', nil)
101
+ @company = data.fetch('company', nil)
102
+ end
103
+
104
+ # Returns the profileItems' ID as integer representation
105
+ #
106
+ # @return [Integer]
107
+ def to_i
108
+ @id
109
+ end
110
+
111
+ attr_accessor :id, :adrank, :first_name, :last_name, :email, :country, :street1, :city,
112
+ :zipcode, :login_name, :user_name, :is_advertiser, :is_sublogin,
113
+ :title, :currency, :language, :fax, :mobile, :phone, :street2, :company
114
+
115
+ # make API names available
116
+ alias firstName first_name
117
+ alias lastName last_name
118
+ alias loginName login_name
119
+ alias userName user_name
120
+ alias isAdvertiser is_advertiser
121
+ alias isSublogin is_sublogin
122
+ end
123
+ end