Class: ZanoxPublisher::Program

Inherits:
Base
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#adrankFixnum

The adrank of the advertiser

Returns:

  • (Fixnum)

    the current value of adrank



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def adrank
  @adrank
end

#application_requiredBoolean Also known as: applicationRequired, application_required?

States whether a direct application is required

Returns:

  • (Boolean)

    the current value of application_required



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def application_required
  @application_required
end

#categoriesArray<Category>

The categories of the advertiser

Returns:

  • (Array<Category>)

    the current value of categories



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def categories
  @categories
end

#currencyString

The currency of the program

Returns:

  • (String)

    the current value of currency



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def currency
  @currency
end

#descriptionString

The description from the advertiser

Returns:

  • (String)

    the current value of description



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def description
  @description
end

#description_localString Also known as: descriptionLocal

The description from the advertiser in connect ID language

Returns:

  • (String)

    the current value of description_local



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def description_local
  @description_local
end

#idInteger

The programItem’s identifer from Zanox

Returns:

  • (Integer)

    the current value of id



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def id
  @id
end

#imageString

The image for the program

Returns:

  • (String)

    the current value of image



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def image
  @image
end

#nameString

The name of the advertiser

Returns:

  • (String)

    the current value of name



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def name
  @name
end

#policiesArray<Policy>

The policies to follow for the program

Returns:

  • (Array<Policy>)

    the current value of policies



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def policies
  @policies
end

#productsInteger

The number of products from the advertiser

Returns:

  • (Integer)

    the current value of products



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def products
  @products
end

#regionsArray<String>

The regions the advertiser is active in

Returns:

  • (Array<String>)

    the current value of regions



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def regions
  @regions
end

#return_time_leadsString Also known as: returnTimeLeads

The return time in which a lead is given

Returns:

  • (String)

    the current value of return_time_leads



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def return_time_leads
  @return_time_leads
end

#return_time_salesString Also known as: returnTimeSales

The return time in which a sale is given

Returns:

  • (String)

    the current value of return_time_sales



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def return_time_sales
  @return_time_sales
end

#start_dateDateTime Also known as: startDate

The start date of the program

Returns:

  • (DateTime)

    the current value of start_date



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def start_date
  @start_date
end

#statusString

The status of the program, with active stating the program is still a live

Returns:

  • (String)

    the current value of status



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def status
  @status
end

#termsString

The terms of the program

Returns:

  • (String)

    the current value of terms



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def terms
  @terms
end

#terms_urlString Also known as: termsUrl

The terms url

Returns:

  • (String)

    the current value of terms_url



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def terms_url
  @terms_url
end

#urlString

The url for the program

Returns:

  • (String)

    the current value of url



26
27
28
# File 'lib/zanox_publisher/program.rb', line 26

def url
  @url
end

#verticalVertical

The vertical of the advertiser

Returns:

  • (Vertical)

    the current value of vertical



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.

Parameters:

  • query (String)

    Limits results to programs associated with this search string (API equivalent is q).

  • q (String)

    Limits results to programs associated with this search string (API name).

  • start_date (Date)

    Limits results to programs activated after this date (API equivalent is startdate).

  • startdate (Date)

    Limits results to programs activated after this date (API name).

  • region (String)

    Limits results to a particular region.

  • partnership (String)

    Limits results to programs with mandatory direct applications (“DIRECT”) or not requiring direct application (“INDIRECT”).

  • has_products (Boolean)

    Limits results to programs with products (API equivalent is hasproducts).

  • hasproducts (Boolean)

    Limits results to programs with products (API name).

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/zanox_publisher/program.rb', line 52

def all(options = {})
  retval = []
  current_page = 0
  options.merge!({ per_page: maximum_per_page })

  begin
    retval       += self.page(current_page, options)
    current_page += 1
  end while Program.total > retval.size

  retval
end

.categoriesArray<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.

Returns:



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

.connectionConnection

A connection instance with Programs’ relative_path

Returns:



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.

Parameters:

  • id (Program, Integer)

    the ID of the program you want to get.

Returns:



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.

Parameters:

  • page (Integer) (defaults to: 0)

    the page position

  • per_page (Integer)

    number of items in the result set (API equivalent is items)

  • items (Integer)

    number of items in the result set (API name)

  • query (String)

    Limits results to programs associated with this search string (API equivalent is q).

  • q (String)

    Limits results to programs associated with this search string (API name).

  • start_date (Date)

    Limits results to programs activated after this date (API equivalent is startdate).

  • startdate (Date)

    Limits results to programs activated after this date (API name).

  • region (String)

    Limits results to a particular region.

  • partnership (String)

    Limits results to programs with mandatory direct applications (“DIRECT”) or not requiring direct application (“INDIRECT”).

  • has_products (Boolean)

    Limits results to programs with products (API equivalent is hasproducts).

  • hasproducts (Boolean)

    Limits results to programs with products (API name).

Returns:



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, options = {})
  params = { query: { page: page } }

  per_page = nil
  per_page = options[:per_page] if per_page.nil?
  per_page = options[:items]    if per_page.nil?
  per_page = Program.per_page   if per_page.nil?
  params[:query].merge!({ items: per_page })

  q = options[:query]
  q = options[:q]     if q.nil?

  start_date = options[:start_date]
  start_date = options[: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 = options[:region]

  partnership = options[:partnership]

  has_products = options[:has_products]
  has_products = options[: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_categoriesArray<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.

Returns:



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_iInteger

Returns the programItems’ ID as integer representation

Returns:

  • (Integer)


227
228
229
# File 'lib/zanox_publisher/program.rb', line 227

def to_i
  @id
end