Class: HasOffers::AffiliateBilling

Inherits:
Base
  • Object
show all
Defined in:
lib/hasoffers/affiliate_billing.rb

Constant Summary collapse

Target =
'AffiliateBilling'

Class Method Summary collapse

Methods inherited from Base

api_mode, api_mode=, base_uri, base_uri=, get_request, initialize_credentials, live?, post_request, requires!, test?

Class Method Details

.create_invoice(data, return_object = false) ⇒ Object



53
54
55
56
57
# File 'lib/hasoffers/affiliate_billing.rb', line 53

def create_invoice(data, return_object = false)
  requires!(data, %w[affiliate_id start_date end_date status])
  params = build_data(data, return_object)
  post_request(Target, 'createInvoice', params)
end

.find_all_invoices(params) ⇒ Object

Jon Phenow @ 06/13/12 Switched this to use POST because of some weird issues with sending from behind a proxy



31
32
33
34
35
36
37
38
# File 'lib/hasoffers/affiliate_billing.rb', line 31

def find_all_invoices(params)
  response = post_request(Target, 'findAllInvoices', params)
  if response.success?
    # strip out the clutter
    response.set_data simplify_response_data(response.data)
  end
  response
end

.find_all_invoices_by_ids(ids, params = {}) ⇒ Object

Jon Phenow @ 06/13/12 Switched this to use POST because of some weird issues with sending from behind a proxy



43
44
45
46
47
48
49
50
51
# File 'lib/hasoffers/affiliate_billing.rb', line 43

def find_all_invoices_by_ids(ids, params = {})
  params['ids'] = ids
  response = post_request(Target, 'findAllInvoicesByIds', params)
  if response.success?
    # strip out the clutter
    response.set_data simplify_response_data(response.data)
  end
  response
end

.find_invoice_stats(params) ⇒ Object

Jon Phenow @ 06/13/12 Switched this to use POST because of some weird issues with sending from behind a proxy



12
13
14
15
# File 'lib/hasoffers/affiliate_billing.rb', line 12

def find_invoice_stats(params)
  requires!(params, %w[affiliate_id end_date])
  post_request(Target, 'findInvoiceStats', params)
end

.simplify_response_data(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/hasoffers/affiliate_billing.rb', line 17

def simplify_response_data data
  # Data is returned as a hash like this:
  # {
  #   "1" => {"AffiliateInvoice" => {<what we really want>}, ... },
  #   "2" => {"AffiliateInvoice" => {<what we really want>}, ... }
  # }
  #
  # This function will extract it out.
  data.map { |id, invoice_data| invoice_data["AffiliateInvoice"] }
end

.update_invoice(id, data, return_object = false) ⇒ Object



59
60
61
62
63
# File 'lib/hasoffers/affiliate_billing.rb', line 59

def update_invoice(id, data, return_object = false)
  params = build_data(data, return_object)
  params['id'] = id
  post_request(Target, 'updateInvoice', params)
end