Class: EnomRuby::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/enom-ruby/client.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/enom-ruby/client.rb', line 9

def password
  @password
end

.test_modeObject Also known as: test?

Returns the value of attribute test_mode.



9
10
11
# File 'lib/enom-ruby/client.rb', line 9

def test_mode
  @test_mode
end

.usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/enom-ruby/client.rb', line 9

def username
  @username
end

Class Method Details

.base_uriObject

Enom has a test platform and a production platform. Both are configured to use HTTPS at all times. Don’t forget to configure permitted IPs (in both environments) or you’ll get InterfaceErrors.



25
26
27
28
# File 'lib/enom-ruby/client.rb', line 25

def base_uri
  subdomain = test? ? 'resellertest' : 'reseller'
  "https://#{subdomain}.enom.com/interface.asp"
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
# File 'lib/enom-ruby/client.rb', line 12

def configure
  yield self
  self
end

.default_paramsObject

All requests must contain the UID, PW, and ResponseType query parameters



18
19
20
# File 'lib/enom-ruby/client.rb', line 18

def default_params
  { "UID" => self.username, "PW" => self.password, "ResponseType" => "xml" }
end

.request(params = {}) ⇒ Object

All requests to Enom are GET requests, even when we’re changing data. Unfortunately, Enom also does not provide HTTP status codes to alert for authentication failures or other helpful statuses – everything comes back as a 200.



33
34
35
36
37
38
39
40
# File 'lib/enom-ruby/client.rb', line 33

def request(params = {})
  response = get(base_uri, query: params.merge(default_params))
  if Integer(response["interface_response"]["ErrCount"]).zero?
    return response["interface_response"]
  else
    raise response["interface_response"]["errors"].values.join(", ")
  end
end