Class: SoapyCake::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/soapy_cake/client.rb

Direct Known Subclasses

Admin, AdminAddedit, AdminTrack, Affiliate

Constant Summary collapse

HEADERS =
{ 'Content-Type' => 'application/soap+xml;charset=UTF-8' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
# File 'lib/soapy_cake/client.rb', line 9

def initialize(opts = {})
  @opts = opts
  @domain = fetch_opt(:domain) || raise(Error, 'Cake domain missing')
  @api_key = fetch_opt(:api_key) || raise(Error, 'Cake API key missing')
  @retry_count = fetch_opt(:retry_count, 4)
  @write_enabled = ['yes', true].include?(fetch_opt(:write_enabled))
  @time_converter = TimeConverter.new(fetch_opt(:time_zone), fetch_opt(:time_offset))
end

Instance Method Details

#read_only?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/soapy_cake/client.rb', line 22

def read_only?
  !write_enabled
end

#run(request) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/soapy_cake/client.rb', line 26

def run(request)
  check_write_enabled!(request)
  request.api_key = api_key
  request.time_converter = time_converter

  with_retries do
    response = Response.new(response_body(request), request.short_response?, time_converter)
    xml_response? ? response.to_xml : response.to_enum
  end
end

#xml_response?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/soapy_cake/client.rb', line 18

def xml_response?
  opts[:xml_response] == true
end