Class: Fex::Service

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fex/service.rb

Overview

This is a wrapper around Savon, with more or less intelligent defaults.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Service

Returns a new instance of Service.



25
26
27
28
29
30
31
# File 'lib/fex/service.rb', line 25

def initialize(options)
  @name           = options.fetch(:name)
  @client_options = options[:client] || {}
  @wsdl           = options[:wsdl]
  @defaults       = options[:defaults] || {}
  @response       = options.fetch(:response)
end

Instance Attribute Details

#defaultsObject (readonly)

Defaults are any values that always exist on this service. Examples are the credentials and the version.



19
20
21
# File 'lib/fex/service.rb', line 19

def defaults
  @defaults
end

#nameObject (readonly)

The name determines the name of the WSDL file located in the wsdl directory in the root of the gem. The full path will be calculated by the WSDL class.



15
16
17
# File 'lib/fex/service.rb', line 15

def name
  @name
end

#responseObject (readonly)

The response is the class that will handle building a response. The default is the generic Response class.



23
24
25
# File 'lib/fex/service.rb', line 23

def response
  @response
end

Instance Method Details

#call(operation, message, options = {}) ⇒ Object



41
42
43
44
45
# File 'lib/fex/service.rb', line 41

def call(operation, message, options = {})
  opts = {message: defaults.deep_merge(message)}.deep_merge(options)
  savon_response = client.call(operation, opts)
  response.new(savon_response)
end

#clientObject



37
38
39
# File 'lib/fex/service.rb', line 37

def client
  Savon.client(client_options)
end

#client_optionsObject



47
48
49
50
51
52
53
54
# File 'lib/fex/service.rb', line 47

def client_options
  default_options = {
    wsdl: wsdl,
    convert_request_keys_to: :camelcase,
    pretty_print_xml: true
  }
  default_options.deep_merge(@client_options)
end

#wsdlObject



33
34
35
# File 'lib/fex/service.rb', line 33

def wsdl
  @wsdl || WSDL.new.path_for(name)
end