Class: TranslationIO::API::Request
- Inherits:
-
Object
- Object
- TranslationIO::API::Request
- Defined in:
- lib/translation_io/api/request.rb
Overview
An HTTP request
Instance Method Summary collapse
-
#get(uri, data) ⇒ TranslationIO::API::Response
Get request.
-
#initialize(api_key:) ⇒ TranslationIO::API::Request
constructor
Constructor.
-
#post(uri, data) ⇒ TranslationIO::API::Response
Post request.
Constructor Details
#initialize(api_key:) ⇒ TranslationIO::API::Request
Constructor
16 17 18 |
# File 'lib/translation_io/api/request.rb', line 16 def initialize(api_key:) @api_key = api_key end |
Instance Method Details
#get(uri, data) ⇒ TranslationIO::API::Response
Get request
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/translation_io/api/request.rb', line 27 def get(uri, data) uri = URI.parse(uri) req = Net::HTTP::Get.new(uri) req["Content-Type"] = "application/json" req["X-api-key"] = @api_key req.body = data.to_json res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(req) end Response.new(res) end |
#post(uri, data) ⇒ TranslationIO::API::Response
Post request
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/translation_io/api/request.rb', line 49 def post(uri, data) uri = URI.parse(uri) req = Net::HTTP::Post.new(uri) req["Content-Type"] = "application/json" req["X-api-key"] = @api_key req.body = data.to_json res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(req) end Response.new(res) end |