Class: SoapyCake::Request

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

Constant Summary collapse

DATE_CLASSES =
[Date, Time, DateTime, ActiveSupport::TimeWithZone].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role, service, method, opts = {}) ⇒ Request

Returns a new instance of Request.



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

def initialize(role, service, method, opts = {})
  @role = role.to_s
  @service = service.to_s
  @method = method.to_s
  @opts = opts
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/soapy_cake/request.rb', line 7

def api_key
  @api_key
end

#methodObject (readonly)

Returns the value of attribute method.



8
9
10
# File 'lib/soapy_cake/request.rb', line 8

def method
  @method
end

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/soapy_cake/request.rb', line 8

def opts
  @opts
end

#roleObject (readonly)

Returns the value of attribute role.



8
9
10
# File 'lib/soapy_cake/request.rb', line 8

def role
  @role
end

#serviceObject (readonly)

Returns the value of attribute service.



8
9
10
# File 'lib/soapy_cake/request.rb', line 8

def service
  @service
end

#time_converterObject

Returns the value of attribute time_converter.



7
8
9
# File 'lib/soapy_cake/request.rb', line 7

def time_converter
  @time_converter
end

Instance Method Details

#pathObject



17
18
19
# File 'lib/soapy_cake/request.rb', line 17

def path
  "#{api_path}/#{service}.asmx"
end

#read_only?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/soapy_cake/request.rb', line 42

def read_only?
  (API_CONFIG.dig('read_only', role, service) || []).include?(method)
end

#short_response?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/soapy_cake/request.rb', line 34

def short_response?
  %w[addedit track signup].include?(service)
end

#to_sObject



38
39
40
# File 'lib/soapy_cake/request.rb', line 38

def to_s
  "#{role}:#{service}:#{method}:#{version} #{opts.to_json}"
end

#xmlObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/soapy_cake/request.rb', line 21

def xml
  Nokogiri::XML::Builder.new do |xml|
    xml['env'].Envelope(xml_namespaces) do
      xml.Header
      xml.Body do
        xml['cake'].public_send(method.camelize.to_sym) do
          xml_params(xml)
        end
      end
    end
  end.to_xml
end