Module: RmsApiRuby::SoapApi

Included in:
Inventory, Order
Defined in:
lib/rms_api_ruby/soap_api.rb,
lib/rms_api_ruby/soap_api/client.rb

Defined Under Namespace

Classes: Client

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



13
14
15
# File 'lib/rms_api_ruby/soap_api.rb', line 13

def method_missing(method, *args)
  api_methods.include?(method) ? call_api(method, args.first) : super
end

Instance Method Details

#api_methodsObject

Raises:

  • (NotImplementedError)


5
6
7
# File 'lib/rms_api_ruby/soap_api.rb', line 5

def api_methods
  raise NotImplementedError, "You must implement #{self}::#{__method__}"
end

#call_api(method, args) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/rms_api_ruby/soap_api.rb', line 21

def call_api(method, args)
  Flow.new.
    chain(response: :response) { soap_client.new(method, args) }.
    on_dam { |error| handle_error(error) }.
    outflow.
    try(:response)
end

#handle_error(error) ⇒ Object



29
30
31
32
33
# File 'lib/rms_api_ruby/soap_api.rb', line 29

def handle_error(error)
  raise error
rescue ServerError, AuthenticationError => e
  RmsApiRuby.configuration.logger.error(e.message)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rms_api_ruby/soap_api.rb', line 17

def respond_to_missing?(method, include_private = false)
  api_methods.include?(method) || super
end

#soap_clientObject

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/rms_api_ruby/soap_api.rb', line 9

def soap_client
  raise NotImplementedError, "You must implement #{self}::#{__method__}"
end