Class: ZanoxPublisher::ProgramApplication

Inherits:
Base
  • Object
show all
Defined in:
lib/zanox_publisher/program_application.rb

Overview

Program Applications

Apply to advertiser programs, get your applications, end partnerships.

Constant Summary collapse

RESOURCE_PATH =
'/programapplications'
PROGRAM_APPLICATION_STATUS_ENUM =
%w(open confirmed rejected deferred waiting blocked terminated canceled called declined deleted)

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 = {}) ⇒ ProgramApplication



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/zanox_publisher/program_application.rb', line 122

def initialize(data = {})
  @id                 = data.fetch('@id').to_i
  @program            = Program.new(data.fetch('program'))
  @adspace            = AdSpace.new(data.fetch('adspace'))
  @status             = data.fetch('status')
  @created_at         = data.fetch('createDate')
  @allow_tpv          = data.fetch('allowTpv')
  @approved_date      = data.fetch('approvedDate', nil)
  @publisher_comment  = data.fetch('publisherComment', nil)
  @advertiser_comment = data.fetch('advertiserComment', nil)
end

Instance Attribute Details

#adspaceAdSpace

The ad space for which the application is made

Returns:

  • (AdSpace)

    the current value of adspace



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def adspace
  @adspace
end

#advertiser_commentString Also known as: advertiserComment

The advertisers’ comment on the application

Returns:

  • (String)

    the current value of advertiser_comment



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def advertiser_comment
  @advertiser_comment
end

#allow_tpvBoolean Also known as: allowTpv

States if the application allows for tpv tracking links

Returns:

  • (Boolean)

    the current value of allow_tpv



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def allow_tpv
  @allow_tpv
end

#approved_dateDateTime Also known as: approvedDate

The date on which the application was approved

Returns:

  • (DateTime)

    the current value of approved_date



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def approved_date
  @approved_date
end

#created_atDateTime Also known as: createDate

The date on which the application was created at

Returns:

  • (DateTime)

    the current value of created_at



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def created_at
  @created_at
end

#idInteger

The programApplicationItems’s identifer from Zanox

Returns:

  • (Integer)

    the current value of id



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def id
  @id
end

#programProgram

The program for which the application is made

Returns:

  • (Program)

    the current value of program



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def program
  @program
end

#publisher_commentString Also known as: publisherComment

The publishers’ comment on the application

Returns:

  • (String)

    the current value of publisher_comment



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def publisher_comment
  @publisher_comment
end

#statusString

The status of the application

Returns:

  • (String)

    the current value of status



15
16
17
# File 'lib/zanox_publisher/program_application.rb', line 15

def status
  @status
end

Class Method Details

.all(options = {}) ⇒ Array<ProgramApplication>

Retrieves all program applications dependent on search parameters.

NOTE: Program applications are still returned even after the advertiser program has been paused discontinued. The attribute “active” in the “program” element, indicates whether the program is still active.

This is equivalent to the Zanox API method GetProgramApplications. The method documentation can be found under https://developer.zanox.com/web/guest/publisher-api-2011/get-programapplications.

Authentication: Requires signature.

This can require multiple requests, as internally every page is pulled. The ZanoxPublisher::ProgramApplication.page function can be used to better control the requests made.

Parameters:

  • program (Program, Integer)

    Limits results to a particular program.

  • adspace (AdSpace, Integer)

    Limits results to incentives that have tracking links associated with this ad space.

  • status (String)

    Restrict results to program applications with certain status.

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zanox_publisher/program_application.rb', line 39

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

  loop do
    response      = self.page(current_page, options)

    # This break is required as some give 0 elements, but set total value
    break if response.nil? or response.empty?

    retval       += response

    # This is the normal break when all pages have been processed
    break unless ProgramApplication.total > retval.size

    current_page += 1
  end

  retval
end

.connectionConnection

A connection instance with Program Applications’ relative_path

Returns:



115
116
117
# File 'lib/zanox_publisher/program_application.rb', line 115

def connection
  @connection ||= Connection.new(RESOURCE_PATH)
end

.page(page = 0, options = {}) ⇒ Array<ProgramApplication>

Returns a list of programApplicationItems

This is equivalent to the Zanox API method GetProgramApplications. The method documentation can be found under https://developer.zanox.com/web/guest/publisher-api-2011/get-programapplications.

Authentication: Requires signature.

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)

  • program (Program, Integer)

    Limits results to a particular program.

  • adspace (AdSpace, Integer)

    Limits results to incentives that have tracking links associated with this ad space.

  • status (String)

    Restrict results to program applications with certain status.

Returns:



76
77
78
79
80
81
82
83
84
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
# File 'lib/zanox_publisher/program_application.rb', line 76

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 })

  program = options[:program]
  program = program.to_i      unless program.nil?

  adspace = options[:adspace]
  adspace = adspace.to_i      unless adspace.nil?

  status  = options[:status]
  status  = nil               unless PROGRAM_APPLICATION_STATUS_ENUM.include? status

  params[:query].merge!({ program: program })  unless program.nil?
  params[:query].merge!({ adspace: adspace })  unless adspace.nil?
  params[:query].merge!({ status:  status  })  unless status.nil?

  retval = []

  response = self.connection.signature_get(RESOURCE_PATH, params)

  ProgramApplication.total = response.fetch('total')
  program_applications = response.fetch('programApplicationItems', {}).fetch('programApplicationItem', [])

  program_applications.each do |application|
    retval << ProgramApplication.new(application)
  end

  retval
end