Class: SignalWire::REST::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/signalwire/rest/http_client.rb

Overview

Thin wrapper around Net::HTTP with Basic Auth and JSON handling.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_id, token, space, base_url: nil) ⇒ HttpClient

base_url overrides the derived https://{space} value when set, which is how the audit fixture and tests point the client at a loopback server. Pass either space (“acme”) / a host (“acme.signalwire.com”) OR an explicit base_url (“127.0.0.1:NNNN”).



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/signalwire/rest/http_client.rb', line 31

def initialize(project_id, token, space, base_url: nil)
  if base_url && !base_url.empty?
    @base_url = base_url.sub(/\/$/, '')
  else
    host       = space.include?('.') ? space : "#{space}.signalwire.com"
    @base_url  = "https://#{host}"
  end
  @project_id  = project_id
  @token       = token
  @auth_header = 'Basic ' + Base64.strict_encode64("#{project_id}:#{token}")
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



25
26
27
# File 'lib/signalwire/rest/http_client.rb', line 25

def base_url
  @base_url
end

Instance Method Details

#delete(path) ⇒ Object



63
64
65
# File 'lib/signalwire/rest/http_client.rb', line 63

def delete(path)
  _request('DELETE', path)
end

#get(path, params = nil) ⇒ Object



47
48
49
# File 'lib/signalwire/rest/http_client.rb', line 47

def get(path, params = nil)
  _request('GET', path, params: params)
end

#patch(path, body = nil) ⇒ Object



59
60
61
# File 'lib/signalwire/rest/http_client.rb', line 59

def patch(path, body = nil)
  _request('PATCH', path, body: body)
end

#post(path, body = nil, params: nil) ⇒ Object



51
52
53
# File 'lib/signalwire/rest/http_client.rb', line 51

def post(path, body = nil, params: nil)
  _request('POST', path, body: body, params: params)
end

#project_idObject



43
44
45
# File 'lib/signalwire/rest/http_client.rb', line 43

def project_id
  @project_id
end

#put(path, body = nil) ⇒ Object



55
56
57
# File 'lib/signalwire/rest/http_client.rb', line 55

def put(path, body = nil)
  _request('PUT', path, body: body)
end