Class: Twizo::NetHttpClient
- Defined in:
- lib/twizo/client/net_http_client.rb
Constant Summary
Constants inherited from Client
Client::API_USERNAME, Client::API_VERSION, Client::LIB_NAME, Client::LIB_VERSION
Instance Method Summary collapse
Methods inherited from Client
Constructor Details
This class inherits a constructor from Twizo::Client
Instance Method Details
#send_request(method, location, post_params) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/twizo/client/net_http_client.rb', line 16 def send_request(method, location, post_params) uri = URI.parse("https://#{@api_host}/#{Client::API_VERSION}/#{location}") case method when 'GET' request = Net::HTTP::Get.new(uri) when 'POST' request = Net::HTTP::Post.new(uri) when 'PUT' request = Net::HTTP::Put.new(uri) when 'DELETE' request = Net::HTTP::Delete.new(uri) else raise RuntimeError.new('No method provided') end request.add_field('user-agent', user_agent) request.basic_auth(API_USERNAME, @api_key) request.content_type = 'application/json; charset=utf8' request['accept'] = 'application/json' request.body = post_params unless post_params.nil? https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.request(request) end |