Class: ServiceProxy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/service_proxy/base.rb

Constant Summary collapse

VERSION =
'0.2.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ Base

Returns a new instance of Base.



22
23
24
25
# File 'lib/service_proxy/base.rb', line 22

def initialize(endpoint)
  self.endpoint = endpoint
  self.setup
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



111
112
113
114
115
116
# File 'lib/service_proxy/base.rb', line 111

def method_missing(method, *args)
  method_name = method.to_s
  options = args.pop || {}
  super unless self.service_methods.include?(method_name)
  call_service(options.update(:method => method_name))
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



19
20
21
# File 'lib/service_proxy/base.rb', line 19

def debug
  @debug
end

#endpointObject

Returns the value of attribute endpoint.



19
20
21
# File 'lib/service_proxy/base.rb', line 19

def endpoint
  @endpoint
end

#httpObject

Returns the value of attribute http.



19
20
21
# File 'lib/service_proxy/base.rb', line 19

def http
  @http
end

#service_methodsObject

Returns the value of attribute service_methods.



19
20
21
# File 'lib/service_proxy/base.rb', line 19

def service_methods
  @service_methods
end

#soap_actionsObject

Returns the value of attribute soap_actions.



19
20
21
# File 'lib/service_proxy/base.rb', line 19

def soap_actions
  @soap_actions
end

#target_namespaceObject

Returns the value of attribute target_namespace.



19
20
21
# File 'lib/service_proxy/base.rb', line 19

def target_namespace
  @target_namespace
end

#uriObject

Returns the value of attribute uri.



19
20
21
# File 'lib/service_proxy/base.rb', line 19

def uri
  @uri
end

#wsdlObject

Returns the value of attribute wsdl.



19
20
21
# File 'lib/service_proxy/base.rb', line 19

def wsdl
  @wsdl
end

Instance Method Details

#call_service(options) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/service_proxy/base.rb', line 27

def call_service(options)
  method   = options[:method]
  headers  = { 'content-type' => 'text/xml; charset=utf-8', 'SOAPAction' => self.soap_actions[method] }
  body     = build_request(method, options)
  response = self.http.request_post(self.uri.path, body, headers)
  parse_response(method, response)
end