Class: HttpClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret) ⇒ HttpClient

Returns a new instance of HttpClient.



10
11
12
13
14
15
16
17
18
# File 'lib/domain_com_au/http_client.rb', line 10

def initialize(client_id, client_secret)
  @client_id = client_id
  @client_secret = client_secret
  @headers = {
    'content-type': 'application/json'
  }
  # @auth_action = true
  authorize
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



8
9
10
# File 'lib/domain_com_au/http_client.rb', line 8

def auth_token
  @auth_token
end

Instance Method Details

#get(uri, headers = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/domain_com_au/http_client.rb', line 29

def get(uri, headers={})
  authorize if @auth_token && is_token_expired?
  check_uri(uri)
  req = Net::HTTP::Get.new(uri)
  set_headers(req, headers)
  http_response(uri, req)
end

#post(uri, params = {}, headers = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/domain_com_au/http_client.rb', line 20

def post(uri, params={}, headers={})
  authorize if @auth_token && is_token_expired?
  check_uri(uri)
  req = Net::HTTP::Post.new(uri)
  set_headers(req, headers)
  set_body(req, params)
  http_response(uri, req)
end