Class: Fex::ServiceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/fex/service_factory.rb

Constant Summary collapse

PRODUCTION_ENDPOINT =
"https://ws.fedex.com:443/web-services"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ ServiceFactory

Returns a new instance of ServiceFactory.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fex/service_factory.rb', line 15

def initialize(name, options)
  @name           = name
  @mode           = options.fetch(:mode) { "test" }
  @version        = options.fetch(:version)  {{}}
  @client_options = options.fetch(:client)   {{}}
  @defaults       = options.fetch(:defaults) {{}}

  @credentials    = options.fetch(:credentials)
  @key            = @credentials.fetch(:key)
  @password       = @credentials.fetch(:password)
  @account_number = @credentials.fetch(:account_number)
  @meter_number   = @credentials.fetch(:meter_number)

  @wsdl = options[:wsdl]

  @response = options[:response] || "Response"
end

Instance Attribute Details

#account_numberObject (readonly)

credentials



13
14
15
# File 'lib/fex/service_factory.rb', line 13

def 
  @account_number
end

#client_optionsObject (readonly)

Returns the value of attribute client_options.



10
11
12
# File 'lib/fex/service_factory.rb', line 10

def client_options
  @client_options
end

#defaultsObject (readonly)

Returns the value of attribute defaults.



10
11
12
# File 'lib/fex/service_factory.rb', line 10

def defaults
  @defaults
end

#keyObject (readonly)

credentials



13
14
15
# File 'lib/fex/service_factory.rb', line 13

def key
  @key
end

#meter_numberObject (readonly)

credentials



13
14
15
# File 'lib/fex/service_factory.rb', line 13

def meter_number
  @meter_number
end

#modeObject (readonly)

Returns the value of attribute mode.



10
11
12
# File 'lib/fex/service_factory.rb', line 10

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/fex/service_factory.rb', line 10

def name
  @name
end

#passwordObject (readonly)

credentials



13
14
15
# File 'lib/fex/service_factory.rb', line 13

def password
  @password
end

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/fex/service_factory.rb', line 10

def response
  @response
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/fex/service_factory.rb', line 10

def version
  @version
end

#wsdlObject (readonly)

Returns the value of attribute wsdl.



10
11
12
# File 'lib/fex/service_factory.rb', line 10

def wsdl
  @wsdl
end

Instance Method Details

#authenticationObject



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

def authentication
  {
    web_authentication_detail: {
      user_credential: { key: key, password: password }
    },
    client_detail: { account_number: , meter_number: meter_number }
  }
end

#endpoint_optionsObject



60
61
62
63
64
65
66
# File 'lib/fex/service_factory.rb', line 60

def endpoint_options
  if mode.to_s == "production"
    { endpoint: PRODUCTION_ENDPOINT }
  else
    {}
  end
end

#merged_client_optionsObject



56
57
58
# File 'lib/fex/service_factory.rb', line 56

def merged_client_options
  endpoint_options.deep_merge(client_options)
end

#merged_defaultsObject



43
44
45
# File 'lib/fex/service_factory.rb', line 43

def merged_defaults
  authentication.deep_merge(version: version).deep_merge(defaults)
end

#serviceObject



33
34
35
36
37
38
39
40
41
# File 'lib/fex/service_factory.rb', line 33

def service
  Service.new(
    name:       name,
    client:     merged_client_options,
    wsdl:       wsdl,
    defaults:   merged_defaults,
    response:   Fex.const_get(response)
  )
end