Class: IletimerkeziSdk::Http::NetHttpClient

Inherits:
HttpClient show all
Defined in:
lib/iletimerkezi_sdk/http/net_http_client.rb

Constant Summary

Constants inherited from HttpClient

HttpClient::BASE_URL, HttpClient::USER_AGENT, HttpClient::VERSION

Instance Method Summary collapse

Methods inherited from HttpClient

#get_body, #get_payload, #get_status_code, #initialize

Methods inherited from HttpClientInterface

#get_body, #get_payload, #get_status_code

Constructor Details

This class inherits a constructor from IletimerkeziSdk::Http::HttpClient

Instance Method Details

#get(endpoint, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/iletimerkezi_sdk/http/net_http_client.rb', line 23

def get(endpoint, options = {})
  uri = URI(build_url(endpoint))
  uri.query = URI.encode_www_form(options[:params]) if options[:params]
  
  request = Net::HTTP::Get.new(uri)
  request['Content-Type'] = 'application/json'

  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
    http.request(request)
  end

  handle_response(response)
end

#post(endpoint, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/iletimerkezi_sdk/http/net_http_client.rb', line 8

def post(endpoint, options = {})
  uri = URI(build_url(endpoint))
  request = Net::HTTP::Post.new(uri)
  request['Content-Type'] = 'application/json'
  request.body = options[:json].to_json if options[:json]

  store_request_payload(request.body)

  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
    http.request(request)
  end

  handle_response(response)
end