Module: Translator::Smartling::API::Base
- Included in:
- CreateBatch, CreateJob, DownloadFile, FileStatus, FileUris, UploadFile
- Defined in:
- lib/nexmo_developer/app/services/translator/smartling/api/base.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #build_request ⇒ Object
- #call ⇒ Object
- #cleanup ⇒ Object
- #error ⇒ Object
- #make_request! ⇒ Object
- #response_body ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/nexmo_developer/app/services/translator/smartling/api/base.rb', line 5 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#build_request ⇒ Object
9 10 11 12 13 |
# File 'lib/nexmo_developer/app/services/translator/smartling/api/base.rb', line 9 def build_request request = Net::HTTP::Post.new(uri.path, headers) request.body = request_body.to_json request end |
#call ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nexmo_developer/app/services/translator/smartling/api/base.rb', line 29 def call make_request! raise error unless success? Rails.logger.info("#{self.class} : Success #{self}") return_value rescue StandardError => e Bugsnag.notify(e.) Rails.logger.error(e.) nil ensure cleanup end |
#cleanup ⇒ Object
44 |
# File 'lib/nexmo_developer/app/services/translator/smartling/api/base.rb', line 44 def cleanup; end |
#error ⇒ Object
25 26 27 |
# File 'lib/nexmo_developer/app/services/translator/smartling/api/base.rb', line 25 def error "#{self.class} #{@response.code}: #{response_body['response']['errors'][0]['message']}" end |
#make_request! ⇒ Object
15 16 17 18 19 |
# File 'lib/nexmo_developer/app/services/translator/smartling/api/base.rb', line 15 def make_request! http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true @response = http.request(build_request) end |
#response_body ⇒ Object
21 22 23 |
# File 'lib/nexmo_developer/app/services/translator/smartling/api/base.rb', line 21 def response_body @response_body ||= JSON.parse(@response.body) end |