Class: ServiceProxy::Base

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

Constant Summary collapse

VERSION =
'0.1.4'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ Base

Returns a new instance of Base.



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

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)



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/service_proxy/base.rb', line 134

def method_missing(method, *args)
  method_name = method.to_s
  case method_name
  when /_uri$/
    sp_name = method_name.gsub(/_uri$/, '')
    super unless self.service_ports.has_key?(sp_name)
    URI.parse(self.service_ports[sp_name])
  else
    options = args.pop || {}
    super unless self.service_methods.include?(method_name)
    call_service(options.update(:method => method_name))
  end
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def debug
  @debug
end

#endpointObject

Returns the value of attribute endpoint.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def endpoint
  @endpoint
end

#httpObject

Returns the value of attribute http.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def http
  @http
end

#service_http=(value) ⇒ Object

Sets the attribute service_http

Parameters:

  • value

    the value to set the attribute service_http to.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def service_http=(value)
  @service_http = value
end

#service_methodsObject

Returns the value of attribute service_methods.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def service_methods
  @service_methods
end

#service_portsObject

Returns the value of attribute service_ports.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def service_ports
  @service_ports
end

#service_uri=(value) ⇒ Object

Sets the attribute service_uri

Parameters:

  • value

    the value to set the attribute service_uri to.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def service_uri=(value)
  @service_uri = value
end

#soap_actionsObject

Returns the value of attribute soap_actions.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def soap_actions
  @soap_actions
end

#target_namespaceObject

Returns the value of attribute target_namespace.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def target_namespace
  @target_namespace
end

#uriObject

Returns the value of attribute uri.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def uri
  @uri
end

#wsdlObject

Returns the value of attribute wsdl.



16
17
18
# File 'lib/service_proxy/base.rb', line 16

def wsdl
  @wsdl
end

Instance Method Details

#call_service(options) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/service_proxy/base.rb', line 23

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.service_http.request_post(self.service_uri.path, body, headers)    
  parse_response(method, response)
end