Class: ZanoxPublisher::Program
- Defined in:
- lib/zanox_publisher/program.rb
Overview
Programs
Get advertiser programs
Constant Summary collapse
- RESOURCE_PATH =
'/programs'- PROGRAM_STATUS_ENUM =
%w(active inactive)
Instance Attribute Summary collapse
-
#adrank ⇒ Fixnum
The adrank of the advertiser.
-
#application_required ⇒ Boolean
(also: #applicationRequired, #application_required?)
States whether a direct application is required.
-
#categories ⇒ Array<Category>
The categories of the advertiser.
-
#currency ⇒ String
The currency of the program.
-
#description ⇒ String
The description from the advertiser.
-
#description_local ⇒ String
(also: #descriptionLocal)
The description from the advertiser in connect ID language.
-
#id ⇒ Integer
The programItem’s identifer from Zanox.
-
#image ⇒ String
The image for the program.
-
#name ⇒ String
The name of the advertiser.
-
#policies ⇒ Array<Policy>
The policies to follow for the program.
-
#products ⇒ Integer
The number of products from the advertiser.
-
#regions ⇒ Array<String>
The regions the advertiser is active in.
-
#return_time_leads ⇒ String
(also: #returnTimeLeads)
The return time in which a lead is given.
-
#return_time_sales ⇒ String
(also: #returnTimeSales)
The return time in which a sale is given.
-
#start_date ⇒ DateTime
(also: #startDate)
The start date of the program.
-
#status ⇒ String
The status of the program, with active stating the program is still a live.
-
#terms ⇒ String
The terms of the program.
-
#terms_url ⇒ String
(also: #termsUrl)
The terms url.
-
#url ⇒ String
The url for the program.
-
#vertical ⇒ Vertical
The vertical of the advertiser.
Class Method Summary collapse
-
.all(options = {}) ⇒ Array<Program>
Retrieves all programs dependent on search parameters.
-
.categories ⇒ Array<Category>
Get all program categories, including names and IDs, associated to the connect ID.
-
.connection ⇒ Connection
A connection instance with Programs’ relative_path.
-
.find(id) ⇒ <Program>?
Request an programItem by its ID.
-
.page(page = 0, options = {}) ⇒ Array<Program>
Returns a list of programItems.
Instance Method Summary collapse
-
#admedia_categories ⇒ Array<Category>
Retrieve AdMedia categories for this program.
-
#initialize(data = {}) ⇒ Program
constructor
A new instance of Program.
-
#to_i ⇒ Integer
Returns the programItems’ ID as integer representation.
Methods inherited from Base
maximum_per_page, per_page, per_page=, total, total=
Constructor Details
#initialize(data = {}) ⇒ Program
Returns a new instance of Program.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/zanox_publisher/program.rb', line 191 def initialize(data = {}) @id = data.fetch('@id').to_i # Depending on short or long representation of object if data.fetch('$', nil).nil? @name = data.fetch('name') @adrank = data.fetch('adrank') @application_required = data.fetch('applicationRequired') @description = data.fetch('description') @description_local = data.fetch('descriptionLocal', nil) @products = data.fetch('products') @vertical = data.fetch('vertical', nil) @vertical = Vertical.new(@vertical) unless @vertical.nil? @regions = data.fetch('regions', []).first @regions = @regions.fetch('region') unless @regions.nil? @regions = [@regions] if @regions.is_a? String @categories = data.fetch('categories', nil) @categories = Category.fetch(@categories) unless @categories.nil? @start_date = Date.strptime(data.fetch('startDate'), "%Y-%m-%dT%H:%M:%S%z") @url = data.fetch('url') @image = data.fetch('image') @currency = data.fetch('currency') @status = data.fetch('status') @terms = data.fetch('terms', nil) @terms_url = data.fetch('termsUrl', nil) @policies = Policy.fetch(data['policies']) @return_time_leads = data.fetch('returnTimeLeads', nil) @return_time_sales = data.fetch('returnTimeSales', nil) else @name = data.fetch('$') end end |
Instance Attribute Details
#adrank ⇒ Fixnum
The adrank of the advertiser
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def adrank @adrank end |
#application_required ⇒ Boolean Also known as: applicationRequired, application_required?
States whether a direct application is required
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def application_required @application_required end |
#categories ⇒ Array<Category>
The categories of the advertiser
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def categories @categories end |
#currency ⇒ String
The currency of the program
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def currency @currency end |
#description ⇒ String
The description from the advertiser
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def description @description end |
#description_local ⇒ String Also known as: descriptionLocal
The description from the advertiser in connect ID language
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def description_local @description_local end |
#id ⇒ Integer
The programItem’s identifer from Zanox
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def id @id end |
#image ⇒ String
The image for the program
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def image @image end |
#name ⇒ String
The name of the advertiser
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def name @name end |
#policies ⇒ Array<Policy>
The policies to follow for the program
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def policies @policies end |
#products ⇒ Integer
The number of products from the advertiser
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def products @products end |
#regions ⇒ Array<String>
The regions the advertiser is active in
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def regions @regions end |
#return_time_leads ⇒ String Also known as: returnTimeLeads
The return time in which a lead is given
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def return_time_leads @return_time_leads end |
#return_time_sales ⇒ String Also known as: returnTimeSales
The return time in which a sale is given
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def return_time_sales @return_time_sales end |
#start_date ⇒ DateTime Also known as: startDate
The start date of the program
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def start_date @start_date end |
#status ⇒ String
The status of the program, with active stating the program is still a live
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def status @status end |
#terms ⇒ String
The terms of the program
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def terms @terms end |
#terms_url ⇒ String Also known as: termsUrl
The terms url
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def terms_url @terms_url end |
#url ⇒ String
The url for the program
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def url @url end |
#vertical ⇒ Vertical
The vertical of the advertiser
26 27 28 |
# File 'lib/zanox_publisher/program.rb', line 26 def vertical @vertical end |
Class Method Details
.all(options = {}) ⇒ Array<Program>
Retrieves all programs dependent on search parameters.
This is equivalent to the Zanox API method SearchPrograms. The method documentation can be found under https://developer.zanox.com/web/guest/publisher-api-2011/get-programs.
Authentication: Requires connect ID.
This can require multiple requests, as internally every page is pulled. The ZanoxPublisher::Program.page function can be used to better control the requests made.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zanox_publisher/program.rb', line 52 def all( = {}) retval = [] current_page = 0 .merge!({ per_page: maximum_per_page }) begin retval += self.page(current_page, ) current_page += 1 end while Program.total > retval.size retval end |
.categories ⇒ Array<Category>
Get all program categories, including names and IDs, associated to the connect ID.
This is equivalent to the Zanox API method GetProgramCategories. The method documentation can be found under https://developer.zanox.com/web/guest/publisher-api-2011/get-programs-categories.
NOTE: These categories are different than ZanoxPublisher::Product::categories
Authentication: Requires connect ID.
160 161 162 163 |
# File 'lib/zanox_publisher/program.rb', line 160 def categories response = self.connection.get(RESOURCE_PATH + '/categories') Category.fetch(response['categories']) end |
.connection ⇒ Connection
A connection instance with Programs’ relative_path
168 169 170 |
# File 'lib/zanox_publisher/program.rb', line 168 def connection @connection ||= Connection.new(RESOURCE_PATH) end |
.find(id) ⇒ <Program>?
Request an programItem by its ID.
This is equivalent to the Zanox API method GetProgram. The method documentation can be found under https://developer.zanox.com/web/guest/publisher-api-2011/get-programs-program.
Authentication: Requires connect ID.
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/zanox_publisher/program.rb', line 139 def find(id) response = self.connection.get(RESOURCE_PATH + "/program/#{id.to_i}") program = response.fetch('programItem', []).first if program.nil? or program.empty? return nil end Program.new(program) end |
.page(page = 0, options = {}) ⇒ Array<Program>
Returns a list of programItems
This is equivalent to the Zanox API method SearchPrograms. The method documentation can be found under https://developer.zanox.com/web/guest/publisher-api-2011/get-programs.
Authentication: Requires connect ID.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/zanox_publisher/program.rb', line 85 def page(page = 0, = {}) params = { query: { page: page } } per_page = nil per_page = [:per_page] if per_page.nil? per_page = [:items] if per_page.nil? per_page = Program.per_page if per_page.nil? params[:query].merge!({ items: per_page }) q = [:query] q = [:q] if q.nil? start_date = [:start_date] start_date = [:startdate] if start_date.nil? start_date = nil unless start_date.respond_to? :strftime start_date = start_date.strftime('%Y-%m-%d') unless start_date.nil? region = [:region] partnership = [:partnership] has_products = [:has_products] has_products = [:hasproducts] if has_products.nil? params[:query].merge!({ q: q }) unless q.nil? params[:query].merge!({ startdate: start_date }) unless start_date.nil? params[:query].merge!({ region: region }) unless region.nil? params[:query].merge!({ partnership: partnership }) unless partnership.nil? params[:query].merge!({ hasproducts: has_products }) unless has_products.nil? retval = [] response = self.connection.get(RESOURCE_PATH, params) Program.total = response.fetch('total') programs = response.fetch('programItems', []).fetch('programItem', []) programs.each do |program| retval << Program.new(program) end retval end |
Instance Method Details
#admedia_categories ⇒ Array<Category>
Retrieve AdMedia categories for this program.
Returns a list of the advertiser-defined, program-specific ad media categories.
This is equivalent to the Zanox API method GetAdmediumCategories. The method documentation can be found under https://developer.zanox.com/web/guest/publisher-api-2011/get-admedia-categories-program.
NOTE: The returned ad media categories are different from progam categories
Authentication: Requires connect ID.
185 186 187 188 189 |
# File 'lib/zanox_publisher/program.rb', line 185 def admedia_categories response = Program.connection.get("/admedia/categories/program/#{@id}") Category.fetch(response['categories']) end |
#to_i ⇒ Integer
Returns the programItems’ ID as integer representation
227 228 229 |
# File 'lib/zanox_publisher/program.rb', line 227 def to_i @id end |