Class: AstroInsight::HttpClient
- Inherits:
-
Object
- Object
- AstroInsight::HttpClient
- Defined in:
- lib/astroinsight/http_client.rb
Instance Method Summary collapse
- #get(endpoint, params = {}) ⇒ Object
-
#initialize(config) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(endpoint, payload = {}) ⇒ Object
Constructor Details
#initialize(config) ⇒ HttpClient
Returns a new instance of HttpClient.
9 10 11 |
# File 'lib/astroinsight/http_client.rb', line 9 def initialize(config) @config = config end |
Instance Method Details
#get(endpoint, params = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/astroinsight/http_client.rb', line 22 def get(endpoint, params = {}) url = build_url(endpoint) url.query = URI.encode_www_form(params) unless params.empty? request = Net::HTTP::Get.new(url.request_uri, @config.headers) request.basic_auth(@config.client_id, @config.client_secret) execute(url, request) end |
#post(endpoint, payload = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/astroinsight/http_client.rb', line 13 def post(endpoint, payload = {}) url = build_url(endpoint) request = Net::HTTP::Post.new(url.path, @config.headers) request.basic_auth(@config.client_id, @config.client_secret) request.body = payload.respond_to?(:to_h) ? payload.to_h.to_json : payload.to_json execute(url, request) end |