Class: Internode::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/internode/client.rb

Defined Under Namespace

Classes: ServerError

Constant Summary collapse

URL =
"https://customer-webtools-api.internode.on.net"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
# File 'lib/internode/client.rb', line 10

def initialize(options = {})
  username = options.fetch(:username){ ENV["INTERNODE_USERNAME"] }
  password = options.fetch(:password){ ENV["INTERNODE_PASSWORD"] }
  @url = options.fetch(:url){ URL }
  @client = HTTPClient.new
  @client.set_auth(@url, username, password)
  @client.cookie_manager = nil
end

Instance Method Details

#get(path, *args) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/internode/client.rb', line 19

def get(path, *args)
  url = "#{@url}#{path}"
  content = @client.get_content(url)

  Oga.parse_xml(content).at_css("internode api")

rescue HTTPClient::BadResponseError => err
  raise ServerError.new("#{err.res.status_code} #{err.res.reason}")
end