Class: EasyTranslate::Request
- Inherits:
-
Object
- Object
- EasyTranslate::Request
- Defined in:
- lib/easy_translate/request.rb
Direct Known Subclasses
Detection::DetectionRequest, Translation::TranslationRequest, TranslationTarget::TranslationTargetRequest
Instance Attribute Summary collapse
-
#http_options ⇒ Object
Returns the value of attribute http_options.
Instance Method Summary collapse
-
#body ⇒ String
Body, blank by default.
-
#initialize(options = {}, http_options = {}) ⇒ Request
constructor
A new instance of Request.
-
#params ⇒ Hash
The base params for a request.
-
#path ⇒ String
The path for the request.
-
#perform_raw ⇒ String
Perform the given request.
Constructor Details
#initialize(options = {}, http_options = {}) ⇒ Request
Returns a new instance of Request.
10 11 12 13 |
# File 'lib/easy_translate/request.rb', line 10 def initialize( = {}, = {}) = = end |
Instance Attribute Details
#http_options ⇒ Object
Returns the value of attribute http_options.
8 9 10 |
# File 'lib/easy_translate/request.rb', line 8 def end |
Instance Method Details
#body ⇒ String
Body, blank by default
17 18 19 |
# File 'lib/easy_translate/request.rb', line 17 def body '' end |
#params ⇒ Hash
The base params for a request
29 30 31 32 33 34 |
# File 'lib/easy_translate/request.rb', line 29 def params params = {} params[:key] = EasyTranslate.api_key if EasyTranslate.api_key params[:prettyPrint] = 'false' # eliminate unnecessary overhead params end |
#path ⇒ String
The path for the request
23 24 25 |
# File 'lib/easy_translate/request.rb', line 23 def path raise NotImplementedError.new('path is not implemented') end |
#perform_raw ⇒ String
Perform the given request
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/easy_translate/request.rb', line 38 def perform_raw # Construct the request request = Net::HTTP::Post.new(uri.request_uri) request.add_field('X-HTTP-Method-Override', 'GET') request.body = body # Fire and return response = http.request(request) unless response.code == '200' err = JSON.parse(response.body)['error']['errors'].first['message'] raise EasyTranslateException.new(err) end response.body end |