Class: HttpClient
- Inherits:
-
Object
- Object
- HttpClient
- Defined in:
- lib/domain_com_au/http_client.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
Instance Method Summary collapse
- #get(uri, headers = {}) ⇒ Object
-
#initialize(client_id, client_secret) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(uri, params = {}, headers = {}) ⇒ Object
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 end |
Instance Attribute Details
#auth_token ⇒ Object
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={}) 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={}) 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 |