zanox_publisher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +178 -0
- data/Rakefile +10 -0
- data/lib/zanox_publisher/ad_medium.rb +232 -0
- data/lib/zanox_publisher/ad_space.rb +159 -0
- data/lib/zanox_publisher/base.rb +69 -0
- data/lib/zanox_publisher/category.rb +57 -0
- data/lib/zanox_publisher/connection.rb +291 -0
- data/lib/zanox_publisher/exclusive_incentive.rb +135 -0
- data/lib/zanox_publisher/format.rb +19 -0
- data/lib/zanox_publisher/incentive.rb +135 -0
- data/lib/zanox_publisher/incentive_base.rb +89 -0
- data/lib/zanox_publisher/policy.rb +42 -0
- data/lib/zanox_publisher/prize.rb +18 -0
- data/lib/zanox_publisher/product.rb +263 -0
- data/lib/zanox_publisher/profile.rb +123 -0
- data/lib/zanox_publisher/program.rb +241 -0
- data/lib/zanox_publisher/program_application.rb +135 -0
- data/lib/zanox_publisher/tracking_link.rb +42 -0
- data/lib/zanox_publisher/version.rb +3 -0
- data/lib/zanox_publisher/vertical.rb +19 -0
- data/lib/zanox_publisher.rb +39 -0
- data/spec/config/credentials.example.yml +2 -0
- data/spec/lib/requirements_spec.rb +9 -0
- data/spec/lib/zanox_publisher/ad_medium_spec.rb +162 -0
- data/spec/lib/zanox_publisher/ad_space_spec.rb +56 -0
- data/spec/lib/zanox_publisher/base_spec.rb +35 -0
- data/spec/lib/zanox_publisher/connection_spec.rb +68 -0
- data/spec/lib/zanox_publisher/exclusive_incentive_spec.rb +104 -0
- data/spec/lib/zanox_publisher/incentive_spec.rb +112 -0
- data/spec/lib/zanox_publisher/product_spec.rb +223 -0
- data/spec/lib/zanox_publisher/profile_spec.rb +26 -0
- data/spec/lib/zanox_publisher/program_application_spec.rb +51 -0
- data/spec/lib/zanox_publisher/program_spec.rb +192 -0
- data/spec/lib/zanox_ruby_spec.rb +17 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/credentials.rb +3 -0
- data/spec/support/vcr.rb +8 -0
- data/spec/vcr_cassettes/.gitignore +4 -0
- data/zanox_publisher.gemspec +27 -0
- metadata +203 -0
@@ -0,0 +1,241 @@
|
|
1
|
+
module ZanoxPublisher
|
2
|
+
# Programs
|
3
|
+
#
|
4
|
+
# Get advertiser programs
|
5
|
+
#
|
6
|
+
# @attr [Integer] id The programItem's identifer from Zanox
|
7
|
+
# @attr [String] name The name of the advertiser
|
8
|
+
# @attr [Fixnum] adrank The adrank of the advertiser
|
9
|
+
# @attr [Boolean] application_required States whether a direct application is required
|
10
|
+
# @attr [String] description The description from the advertiser
|
11
|
+
# @attr [String] description_local The description from the advertiser in connect ID language
|
12
|
+
# @attr [Integer] products The number of products from the advertiser
|
13
|
+
# @attr [Vertical] vertical The vertical of the advertiser
|
14
|
+
# @attr [Array<String>] regions The regions the advertiser is active in
|
15
|
+
# @attr [Array<Category>] categories The categories of the advertiser
|
16
|
+
# @attr [DateTime] start_date The start date of the program
|
17
|
+
# @attr [String] url The url for the program
|
18
|
+
# @attr [String] image The image for the program
|
19
|
+
# @attr [String] currency The currency of the program
|
20
|
+
# @attr [String] status The status of the program, with active stating the program is still a live
|
21
|
+
# @attr [String] terms The terms of the program
|
22
|
+
# @attr [String] terms_url The terms url
|
23
|
+
# @attr [Array<Policy>] policies The policies to follow for the program
|
24
|
+
# @attr [String] return_time_leads The return time in which a lead is given
|
25
|
+
# @attr [String] return_time_sales The return time in which a sale is given
|
26
|
+
class Program < Base
|
27
|
+
RESOURCE_PATH = '/programs'
|
28
|
+
|
29
|
+
PROGRAM_STATUS_ENUM = %w(active inactive)
|
30
|
+
|
31
|
+
class << self
|
32
|
+
# Retrieves all programs dependent on search parameters.
|
33
|
+
#
|
34
|
+
# This is equivalent to the Zanox API method SearchPrograms.
|
35
|
+
# The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-programs}.
|
36
|
+
#
|
37
|
+
# Authentication: Requires connect ID.
|
38
|
+
#
|
39
|
+
# This can require multiple requests, as internally every page is pulled.
|
40
|
+
# The ZanoxPublisher::Program.page function can be used to better control the requests made.
|
41
|
+
#
|
42
|
+
# @param query [String] Limits results to programs associated with this search string (API equivalent is q).
|
43
|
+
# @param q [String] Limits results to programs associated with this search string (API name).
|
44
|
+
# @param start_date [Date] Limits results to programs activated after this date (API equivalent is startdate).
|
45
|
+
# @param startdate [Date] Limits results to programs activated after this date (API name).
|
46
|
+
# @param region [String] Limits results to a particular region.
|
47
|
+
# @param partnership [String] Limits results to programs with mandatory direct applications ("DIRECT") or not requiring direct application ("INDIRECT").
|
48
|
+
# @param has_products [Boolean] Limits results to programs with products (API equivalent is hasproducts).
|
49
|
+
# @param hasproducts [Boolean] Limits results to programs with products (API name).
|
50
|
+
#
|
51
|
+
# @return [Array<Program>]
|
52
|
+
def all(options = {})
|
53
|
+
retval = []
|
54
|
+
current_page = 0
|
55
|
+
options.merge!({ per_page: maximum_per_page })
|
56
|
+
|
57
|
+
begin
|
58
|
+
retval += self.page(current_page, options)
|
59
|
+
current_page += 1
|
60
|
+
end while Program.total > retval.size
|
61
|
+
|
62
|
+
retval
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns a list of programItems
|
66
|
+
#
|
67
|
+
# This is equivalent to the Zanox API method SearchPrograms.
|
68
|
+
# The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-programs}.
|
69
|
+
#
|
70
|
+
# Authentication: Requires connect ID.
|
71
|
+
#
|
72
|
+
# @param page [Integer] the page position
|
73
|
+
# @param per_page [Integer] number of items in the result set (API equivalent is items)
|
74
|
+
# @param items [Integer] number of items in the result set (API name)
|
75
|
+
# @param query [String] Limits results to programs associated with this search string (API equivalent is q).
|
76
|
+
# @param q [String] Limits results to programs associated with this search string (API name).
|
77
|
+
# @param start_date [Date] Limits results to programs activated after this date (API equivalent is startdate).
|
78
|
+
# @param startdate [Date] Limits results to programs activated after this date (API name).
|
79
|
+
# @param region [String] Limits results to a particular region.
|
80
|
+
# @param partnership [String] Limits results to programs with mandatory direct applications ("DIRECT") or not requiring direct application ("INDIRECT").
|
81
|
+
# @param has_products [Boolean] Limits results to programs with products (API equivalent is hasproducts).
|
82
|
+
# @param hasproducts [Boolean] Limits results to programs with products (API name).
|
83
|
+
#
|
84
|
+
# @return [Array<Program>]
|
85
|
+
def page(page = 0, options = {})
|
86
|
+
params = { query: { page: page } }
|
87
|
+
|
88
|
+
per_page = nil
|
89
|
+
per_page = options[:per_page] if per_page.nil?
|
90
|
+
per_page = options[:items] if per_page.nil?
|
91
|
+
per_page = Program.per_page if per_page.nil?
|
92
|
+
params[:query].merge!({ items: per_page })
|
93
|
+
|
94
|
+
q = options[:query]
|
95
|
+
q = options[:q] if q.nil?
|
96
|
+
|
97
|
+
start_date = options[:start_date]
|
98
|
+
start_date = options[:startdate] if start_date.nil?
|
99
|
+
start_date = nil unless start_date.respond_to? :strftime
|
100
|
+
start_date = start_date.strftime('%Y-%m-%d') unless start_date.nil?
|
101
|
+
|
102
|
+
region = options[:region]
|
103
|
+
|
104
|
+
partnership = options[:partnership]
|
105
|
+
|
106
|
+
has_products = options[:has_products]
|
107
|
+
has_products = options[:hasproducts] if has_products.nil?
|
108
|
+
|
109
|
+
params[:query].merge!({ q: q }) unless q.nil?
|
110
|
+
params[:query].merge!({ startdate: start_date }) unless start_date.nil?
|
111
|
+
params[:query].merge!({ region: region }) unless region.nil?
|
112
|
+
params[:query].merge!({ partnership: partnership }) unless partnership.nil?
|
113
|
+
params[:query].merge!({ hasproducts: has_products }) unless has_products.nil?
|
114
|
+
|
115
|
+
retval = []
|
116
|
+
|
117
|
+
response = self.connection.get(RESOURCE_PATH, params)
|
118
|
+
|
119
|
+
Program.total = response.fetch('total')
|
120
|
+
programs = response.fetch('programItems', []).fetch('programItem', [])
|
121
|
+
|
122
|
+
programs.each do |program|
|
123
|
+
retval << Program.new(program)
|
124
|
+
end
|
125
|
+
|
126
|
+
retval
|
127
|
+
end
|
128
|
+
|
129
|
+
# Request an programItem by its ID.
|
130
|
+
#
|
131
|
+
# This is equivalent to the Zanox API method GetProgram.
|
132
|
+
# The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-programs-program}.
|
133
|
+
#
|
134
|
+
# Authentication: Requires connect ID.
|
135
|
+
#
|
136
|
+
# @param id [Program, Integer] the ID of the program you want to get.
|
137
|
+
#
|
138
|
+
# @return [<Program>]
|
139
|
+
def find(id)
|
140
|
+
response = self.connection.get(RESOURCE_PATH + "/program/#{id.to_i}")
|
141
|
+
progam = response.fetch('programItem', []).first
|
142
|
+
|
143
|
+
Program.new(progam)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Get all program categories, including names and IDs, associated to the connect ID.
|
147
|
+
#
|
148
|
+
# This is equivalent to the Zanox API method GetProgramCategories.
|
149
|
+
# The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-programs-categories}.
|
150
|
+
#
|
151
|
+
# NOTE: These categories are different than ZanoxPublisher::Product::categories
|
152
|
+
#
|
153
|
+
# Authentication: Requires connect ID.
|
154
|
+
#
|
155
|
+
# @return [Array<Category>]
|
156
|
+
def categories
|
157
|
+
response = self.connection.get(RESOURCE_PATH + '/categories')
|
158
|
+
Category.fetch(response['categories'])
|
159
|
+
end
|
160
|
+
|
161
|
+
# A connection instance with Programs' relative_path
|
162
|
+
#
|
163
|
+
# @return [Connection]
|
164
|
+
def connection
|
165
|
+
@connection ||= Connection.new(RESOURCE_PATH)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Retrieve AdMedia categories for this program.
|
170
|
+
#
|
171
|
+
# Returns a list of the advertiser-defined, program-specific ad media categories.
|
172
|
+
#
|
173
|
+
# This is equivalent to the Zanox API method GetAdmediumCategories.
|
174
|
+
# The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-admedia-categories-program}.
|
175
|
+
#
|
176
|
+
# NOTE: The returned ad media categories are different from progam categories
|
177
|
+
#
|
178
|
+
# Authentication: Requires connect ID.
|
179
|
+
#
|
180
|
+
# @return [Array<Category>]
|
181
|
+
def admedia_categories
|
182
|
+
response = Program.connection.get("/admedia/categories/program/#{@id}")
|
183
|
+
|
184
|
+
Category.fetch(response['categories'])
|
185
|
+
end
|
186
|
+
|
187
|
+
def initialize(data = {})
|
188
|
+
@id = data.fetch('@id').to_i
|
189
|
+
|
190
|
+
# Depending on short or long representation of object
|
191
|
+
if data.fetch('$', nil).nil?
|
192
|
+
@name = data.fetch('name')
|
193
|
+
@adrank = data.fetch('adrank')
|
194
|
+
@application_required = data.fetch('applicationRequired')
|
195
|
+
@description = data.fetch('description')
|
196
|
+
@description_local = data.fetch('descriptionLocal', nil)
|
197
|
+
@products = data.fetch('products')
|
198
|
+
@vertical = data.fetch('vertical', nil)
|
199
|
+
@vertical = Vertical.new(@vertical) unless @vertical.nil?
|
200
|
+
@regions = data.fetch('regions', []).first
|
201
|
+
@regions = @regions.fetch('region') unless @regions.nil?
|
202
|
+
@regions = [@regions] if @regions.is_a? String
|
203
|
+
@categories = data.fetch('categories', nil)
|
204
|
+
@categories = Category.fetch(@categories) unless @categories.nil?
|
205
|
+
@start_date = Date.strptime(data.fetch('startDate'), "%Y-%m-%dT%H:%M:%S%z")
|
206
|
+
@url = data.fetch('url')
|
207
|
+
@image = data.fetch('image')
|
208
|
+
@currency = data.fetch('currency')
|
209
|
+
@status = data.fetch('status')
|
210
|
+
@terms = data.fetch('terms', nil)
|
211
|
+
@terms_url = data.fetch('termsUrl', nil)
|
212
|
+
@policies = Policy.fetch(data['policies'])
|
213
|
+
@return_time_leads = data.fetch('returnTimeLeads', nil)
|
214
|
+
@return_time_sales = data.fetch('returnTimeSales', nil)
|
215
|
+
else
|
216
|
+
@name = data.fetch('$')
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# Returns the programItems' ID as integer representation
|
221
|
+
#
|
222
|
+
# @return [Integer]
|
223
|
+
def to_i
|
224
|
+
@id
|
225
|
+
end
|
226
|
+
|
227
|
+
attr_accessor :id, :name, :adrank, :application_required, :description,
|
228
|
+
:description_local, :products, :vertical, :regions, :categories,
|
229
|
+
:start_date, :url, :image, :currency, :status, :terms, :terms_url,
|
230
|
+
:policies, :return_time_leads, :return_time_sales
|
231
|
+
|
232
|
+
# make API names available
|
233
|
+
alias applicationRequired application_required
|
234
|
+
alias application_required? application_required
|
235
|
+
alias descriptionLocal description_local
|
236
|
+
alias startDate start_date
|
237
|
+
alias termsUrl terms_url
|
238
|
+
alias returnTimeLeads return_time_leads
|
239
|
+
alias returnTimeSales return_time_sales
|
240
|
+
end
|
241
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module ZanoxPublisher
|
2
|
+
# Program Applications
|
3
|
+
#
|
4
|
+
# Apply to advertiser programs, get your applications, end partnerships.
|
5
|
+
#
|
6
|
+
# @attr [Integer] id The programApplicationItems's identifer from Zanox
|
7
|
+
# @attr [Program] program The program for which the application is made
|
8
|
+
# @attr [AdSpace] adspace The ad space for which the application is made
|
9
|
+
# @attr [String] status The status of the application
|
10
|
+
# @attr [DateTime] created_at The date on which the application was created at
|
11
|
+
# @attr [Boolean] allow_tpv States if the application allows for tpv tracking links
|
12
|
+
# @attr [DateTime] approved_date The date on which the application was approved
|
13
|
+
# @attr [String] publisher_comment The publishers' comment on the application
|
14
|
+
# @attr [String] advertiser_comment The advertisers' comment on the application
|
15
|
+
class ProgramApplication < Base
|
16
|
+
RESOURCE_PATH = '/programapplications'
|
17
|
+
|
18
|
+
PROGRAM_APPLICATION_STATUS_ENUM = %w(open confirmed rejected deferred waiting blocked terminated canceled called declined deleted)
|
19
|
+
|
20
|
+
class << self
|
21
|
+
# Retrieves all program applications dependent on search parameters.
|
22
|
+
#
|
23
|
+
# NOTE: Program applications are still returned even after the advertiser program has been paused discontinued.
|
24
|
+
# The attribute "active" in the "program" element, indicates whether the program is still active.
|
25
|
+
#
|
26
|
+
# This is equivalent to the Zanox API method GetProgramApplications.
|
27
|
+
# The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-programapplications}.
|
28
|
+
#
|
29
|
+
# Authentication: Requires signature.
|
30
|
+
#
|
31
|
+
# This can require multiple requests, as internally every page is pulled.
|
32
|
+
# The ZanoxPublisher::ProgramApplication.page function can be used to better control the requests made.
|
33
|
+
#
|
34
|
+
# @param program [Program, Integer] Limits results to a particular program.
|
35
|
+
# @param adspace [AdSpace, Integer] Limits results to incentives that have tracking links associated with this ad space.
|
36
|
+
# @param status [String] Restrict results to program applications with certain status.
|
37
|
+
#
|
38
|
+
# @return [Array<ProgramApplication>]
|
39
|
+
def all(options = {})
|
40
|
+
retval = []
|
41
|
+
current_page = 0
|
42
|
+
options.merge!({ per_page: maximum_per_page })
|
43
|
+
|
44
|
+
begin
|
45
|
+
retval += self.page(current_page, options)
|
46
|
+
current_page += 1
|
47
|
+
end while ProgramApplication.total > retval.size
|
48
|
+
|
49
|
+
retval
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns a list of programApplicationItems
|
53
|
+
#
|
54
|
+
# This is equivalent to the Zanox API method GetProgramApplications.
|
55
|
+
# The method documentation can be found under {https://developer.zanox.com/web/guest/publisher-api-2011/get-programapplications}.
|
56
|
+
#
|
57
|
+
# Authentication: Requires signature.
|
58
|
+
#
|
59
|
+
# @param page [Integer] the page position
|
60
|
+
# @param per_page [Integer] number of items in the result set (API equivalent is items)
|
61
|
+
# @param items [Integer] number of items in the result set (API name)
|
62
|
+
# @param program [Program, Integer] Limits results to a particular program.
|
63
|
+
# @param adspace [AdSpace, Integer] Limits results to incentives that have tracking links associated with this ad space.
|
64
|
+
# @param status [String] Restrict results to program applications with certain status.
|
65
|
+
#
|
66
|
+
# @return [Array<ProgramApplication>]
|
67
|
+
def page(page = 0, options = {})
|
68
|
+
params = { query: { page: page } }
|
69
|
+
|
70
|
+
per_page = nil
|
71
|
+
per_page = options[:per_page] if per_page.nil?
|
72
|
+
per_page = options[:items] if per_page.nil?
|
73
|
+
per_page = Program.per_page if per_page.nil?
|
74
|
+
params[:query].merge!({ items: per_page })
|
75
|
+
|
76
|
+
program = options[:program]
|
77
|
+
program = program.to_i unless program.nil?
|
78
|
+
|
79
|
+
adspace = options[:adspace]
|
80
|
+
adspace = adspace.to_i unless adspace.nil?
|
81
|
+
|
82
|
+
status = options[:status]
|
83
|
+
status = nil unless PROGRAM_APPLICATION_STATUS_ENUM.include? status
|
84
|
+
|
85
|
+
params[:query].merge!({ program: program }) unless program.nil?
|
86
|
+
params[:query].merge!({ adspace: adspace }) unless adspace.nil?
|
87
|
+
params[:query].merge!({ status: status }) unless status.nil?
|
88
|
+
|
89
|
+
retval = []
|
90
|
+
|
91
|
+
response = self.connection.signature_get(RESOURCE_PATH, params)
|
92
|
+
|
93
|
+
ProgramApplication.total = response.fetch('total')
|
94
|
+
program_applications = response.fetch('programApplicationItems', {}).fetch('programApplicationItem', [])
|
95
|
+
|
96
|
+
program_applications.each do |application|
|
97
|
+
retval << ProgramApplication.new(application)
|
98
|
+
end
|
99
|
+
|
100
|
+
retval
|
101
|
+
end
|
102
|
+
|
103
|
+
# A connection instance with Program Applications' relative_path
|
104
|
+
#
|
105
|
+
# @return [Connection]
|
106
|
+
def connection
|
107
|
+
@connection ||= Connection.new(RESOURCE_PATH)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# TODO: {https://developer.zanox.com/web/guest/publisher-api-2011/post-programapplications-program-adspace}
|
112
|
+
# TODO: {https://developer.zanox.com/web/guest/publisher-api-2011/delete-programapplications-program-adspace}
|
113
|
+
def initialize(data = {})
|
114
|
+
@id = data.fetch('@id').to_i
|
115
|
+
@program = Program.new(data.fetch('program'))
|
116
|
+
@adspace = AdSpace.new(data.fetch('adspace'))
|
117
|
+
@status = data.fetch('status')
|
118
|
+
@created_at = data.fetch('createDate')
|
119
|
+
@allow_tpv = data.fetch('allowTpv')
|
120
|
+
@approved_date = data.fetch('approvedDate', nil)
|
121
|
+
@publisher_comment = data.fetch('publisherComment', nil)
|
122
|
+
@advertiser_comment = data.fetch('advertiserComment', nil)
|
123
|
+
end
|
124
|
+
|
125
|
+
attr_accessor :id, :program, :adspace, :status, :created_at, :allow_tpv,
|
126
|
+
:approved_date, :publisher_comment, :advertiser_comment
|
127
|
+
|
128
|
+
# make API names available
|
129
|
+
alias createDate created_at
|
130
|
+
alias allowTpv allow_tpv
|
131
|
+
alias approvedDate approved_date
|
132
|
+
alias publisherComment publisher_comment
|
133
|
+
alias advertiserComment advertiser_comment
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ZanoxPublisher
|
2
|
+
# @attr [Integer] adspace The adspaces' ID for which the tracking link is set
|
3
|
+
# @attr [String] ppv The Pay Per View tracking link
|
4
|
+
# @attr [String] ppc The Pay Per Click tracking link
|
5
|
+
# @attr [String] tpv The True Post View tracking link
|
6
|
+
class TrackingLink
|
7
|
+
class << self
|
8
|
+
# Fetch all tracking links from Zanox API Response
|
9
|
+
#
|
10
|
+
# @param data [Array] the value of the 'trackingLinks' element
|
11
|
+
#
|
12
|
+
# @return [Array<TrackingLink>, nil]
|
13
|
+
def fetch(data = nil)
|
14
|
+
# To support API of picking categories of hash with [] notation
|
15
|
+
return nil if data.nil? or not data.respond_to? :each
|
16
|
+
|
17
|
+
retval = []
|
18
|
+
|
19
|
+
data.each do |tracking_link|
|
20
|
+
retval << TrackingLink.new(tracking_link)
|
21
|
+
end
|
22
|
+
|
23
|
+
retval
|
24
|
+
end
|
25
|
+
end
|
26
|
+
attr_reader :adspace, :ppv, :ppc
|
27
|
+
|
28
|
+
def initialize(data = {})
|
29
|
+
@adspace = data.fetch('@adspaceId').to_i
|
30
|
+
@ppv = data.fetch('ppv')
|
31
|
+
@ppc = data.fetch('ppc')
|
32
|
+
@tpv = data.fetch('tpv', nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the adspaceItems' ID as integer representation
|
36
|
+
#
|
37
|
+
# @return [Integer]
|
38
|
+
def to_i
|
39
|
+
@adspace
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ZanoxPublisher
|
2
|
+
# Wrapper for the vertical response from Zanox API
|
3
|
+
class Vertical
|
4
|
+
attr_reader :id, :name
|
5
|
+
|
6
|
+
def initialize(data = {})
|
7
|
+
@id = data.fetch('@id').to_i
|
8
|
+
@name = data.fetch('$')
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
@name
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_i
|
16
|
+
@id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'zanox_publisher/version'
|
2
|
+
|
3
|
+
module ZanoxPublisher
|
4
|
+
autoload :Connection, 'zanox_publisher/connection'
|
5
|
+
autoload :Base, 'zanox_publisher/base'
|
6
|
+
autoload :Category, 'zanox_publisher/category'
|
7
|
+
autoload :Format, 'zanox_publisher/format'
|
8
|
+
autoload :Vertical, 'zanox_publisher/vertical'
|
9
|
+
autoload :Policy, 'zanox_publisher/policy'
|
10
|
+
autoload :Prize, 'zanox_publisher/prize'
|
11
|
+
autoload :TrackingLink, 'zanox_publisher/tracking_link'
|
12
|
+
autoload :Profile, 'zanox_publisher/profile'
|
13
|
+
autoload :AdSpace, 'zanox_publisher/ad_space'
|
14
|
+
autoload :AdMedium, 'zanox_publisher/ad_medium'
|
15
|
+
autoload :Product, 'zanox_publisher/product'
|
16
|
+
autoload :Program, 'zanox_publisher/program'
|
17
|
+
autoload :ProgramApplication, 'zanox_publisher/program_application'
|
18
|
+
autoload :IncentiveBase, 'zanox_publisher/incentive_base'
|
19
|
+
autoload :Incentive, 'zanox_publisher/incentive'
|
20
|
+
autoload :ExclusiveIncentive, 'zanox_publisher/exclusive_incentive'
|
21
|
+
|
22
|
+
class << self
|
23
|
+
attr_accessor :connect_id, :secret_key
|
24
|
+
|
25
|
+
# Setup connect ID and secret key for ZanoxPublisher.
|
26
|
+
# The connect ID and secret key will be used for all subsequent requests.
|
27
|
+
#
|
28
|
+
# @param connect_id [String] The connect ID of your account for authentication
|
29
|
+
# @param secret_key [String] The secret key of your account for authentication
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
# ZanoxPublisher::authenticate("<your_client_id>", "<your_client_secret>")
|
33
|
+
# ZanoxPublisher::Profile.first #=> <Profile>
|
34
|
+
#
|
35
|
+
def authenticate(connect_id, secret_key)
|
36
|
+
@connect_id, @secret_key = connect_id, secret_key
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
describe "Test requirement", :focus do
|
2
|
+
it "a connect ID in spec/config/credentials.yml" do
|
3
|
+
expect(credentials['connect_id']).to be_kind_of String
|
4
|
+
end
|
5
|
+
|
6
|
+
it "a secret key in spec/config/credentials.yml" do
|
7
|
+
expect(credentials['secret_key']).to be_kind_of String
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZanoxPublisher::AdMedium do
|
4
|
+
before(:all) { ZanoxPublisher::authenticate(credentials['connect_id'], credentials['secret_key']) }
|
5
|
+
after(:all) { ZanoxPublisher::authenticate(nil, nil) }
|
6
|
+
|
7
|
+
let(:program) { ZanoxPublisher::Program.page.first }
|
8
|
+
let(:category) { program.admedia_categories.first }
|
9
|
+
let(:region) { 'DE' }
|
10
|
+
let(:format) { 4 }
|
11
|
+
let(:type) { ZanoxPublisher::AdMedium.admedia_types.first }
|
12
|
+
let(:purpose_supported) { ZanoxPublisher::AdMedium.admedia_purposes[1] }
|
13
|
+
let(:purpose_unsupported) { ZanoxPublisher::AdMedium.admedia_purposes.last }
|
14
|
+
let(:partnership_direct) { 'DIRECT' }
|
15
|
+
let(:partnership_indirect) { 'INDIRECT' }
|
16
|
+
let(:adspace) { ZanoxPublisher::AdSpace.page.first }
|
17
|
+
let(:admedium_total) do
|
18
|
+
ZanoxPublisher::AdMedium.page
|
19
|
+
ZanoxPublisher::AdMedium.total
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '::page', :vcr do
|
23
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page }
|
24
|
+
|
25
|
+
it { is_expected.to be_kind_of Array }
|
26
|
+
it { expect(admedia.first).to be_kind_of ZanoxPublisher::AdMedium }
|
27
|
+
|
28
|
+
it { expect(admedia.count).to be > 0 }
|
29
|
+
it 'to set the AdMedium total count' do
|
30
|
+
ZanoxPublisher::AdMedium.total = nil
|
31
|
+
admedia
|
32
|
+
expect(ZanoxPublisher::AdMedium.total).to be > 0
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with program', vcr: { record: :new_episodes } do
|
36
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, { program: program }) }
|
37
|
+
|
38
|
+
it { expect(admedia.all? { |admedium| admedium.program.id == program.id }).to be true }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with region', vcr: { record: :new_episodes } do
|
42
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, { region: region }) }
|
43
|
+
|
44
|
+
it 'limits results to programs from a particular region' do
|
45
|
+
programs = []
|
46
|
+
|
47
|
+
admedia.each do |admedium|
|
48
|
+
program = ZanoxPublisher::Program.find(admedium.program.id)
|
49
|
+
programs << program
|
50
|
+
end
|
51
|
+
|
52
|
+
expect(programs.all? { |program| program.regions.include? region }).to be true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with format' do
|
57
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0 , { format: format }) }
|
58
|
+
|
59
|
+
it { expect(admedia.all? { |admedium| admedium.format.id == format }).to be true }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'with admedium_type' do
|
63
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, { admedium_type: type }) }
|
64
|
+
|
65
|
+
it { expect(admedia.all? { |admedium| admedium.admedium_type == type }).to be true }
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'with admediumtype' do
|
69
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, { admediumtype: type }) }
|
70
|
+
|
71
|
+
it { expect(admedia.all? { |admedium| admedium.admedium_type == type }).to be true }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with purpose' do
|
75
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, { purpose: purpose_supported }) }
|
76
|
+
|
77
|
+
# The response seems to nil purpose but does not error with unallowed request
|
78
|
+
it { expect(admedia.all? { |admedium| admedium.purpose == purpose_supported or admedium.purpose.nil? }).to be true}
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'with unsupported purpose' do
|
82
|
+
subject { ZanoxPublisher::AdMedium.page(0, { purpose: purpose_unsupported }) }
|
83
|
+
|
84
|
+
it { expect{ subject }.to raise_error(ZanoxPublisher::BadRequest) }
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with partnership direct' do
|
88
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, { partnership: partnership_direct }) }
|
89
|
+
|
90
|
+
# Seems to be effectless
|
91
|
+
it 'limits results to admedia with mandatory application' do
|
92
|
+
admedia
|
93
|
+
expect(ZanoxPublisher::AdMedium.total).to be <= admedium_total
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'with partnership indirect' do
|
98
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, { partnership: partnership_indirect }) }
|
99
|
+
|
100
|
+
# Seems to be effectless
|
101
|
+
it 'limits results to admedia without required application' do
|
102
|
+
admedia
|
103
|
+
expect(ZanoxPublisher::AdMedium.total).to be <= admedium_total
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with category' do
|
108
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, { category: category })}
|
109
|
+
|
110
|
+
it { expect(admedia.all? { |admedium| admedium.category.id == category.id }).to be true }
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'with adspace' do
|
114
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.page(0, {adspace: adspace}) }
|
115
|
+
|
116
|
+
it 'incentives have tracking link associated with this AdSpace' do
|
117
|
+
expect(admedia.all? { |admedium| admedium.tracking_links.first.adspace == adspace.id}).to be true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '::all', :vcr do
|
123
|
+
subject(:admedia) { ZanoxPublisher::AdMedium.all region: region, admedium_type: type }
|
124
|
+
|
125
|
+
it { is_expected.to be_kind_of Array }
|
126
|
+
it { expect(admedia.first).to be_kind_of ZanoxPublisher::AdMedium }
|
127
|
+
|
128
|
+
it { expect(admedia.count).to be == ZanoxPublisher::AdMedium.total }
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '::find', vcr: { record: :new_episodes } do
|
132
|
+
let(:first) do
|
133
|
+
ZanoxPublisher::AdMedium.page.first
|
134
|
+
end
|
135
|
+
|
136
|
+
subject(:find) { ZanoxPublisher::AdMedium.find(first.id) }
|
137
|
+
|
138
|
+
it { is_expected.to be_kind_of ZanoxPublisher::AdMedium }
|
139
|
+
|
140
|
+
it { expect(find.id).to be == first.id }
|
141
|
+
it { expect(find.name).to be == first.name }
|
142
|
+
it { expect(find.adrank).to be == first.adrank }
|
143
|
+
it { expect(find.admedium_type).to be == first.admedium_type }
|
144
|
+
it { expect(find.program.id).to be == first.program.id }
|
145
|
+
|
146
|
+
context 'with adspace' do
|
147
|
+
subject(:find) { ZanoxPublisher::AdMedium.find(first.id, adspace: adspace)}
|
148
|
+
|
149
|
+
it 'ad medium has tracking link associated with this AdSpace' do
|
150
|
+
expect(find.tracking_links.first.adspace).to be == adspace.id
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'item', :vcr do
|
156
|
+
subject(:admedium) { ZanoxPublisher::AdMedium.page.first }
|
157
|
+
|
158
|
+
it 'responds to to_i with its ID' do
|
159
|
+
expect(admedium.to_i).to be == admedium.id
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|