Sha256: 88dc8b60307d71c7d2c89efb14ac106bbf46616a1c599517270c5e9486dfbd66

Contents?: true

Size: 1.18 KB

Versions: 94

Compression:

Stored size: 1.18 KB

Contents

module Translator
  module Smartling
    module API
      module Base
        def self.included(base)
          base.extend ClassMethods
        end

        def build_request
          request = Net::HTTP::Post.new(uri.path, headers)
          request.body = request_body.to_json
          request
        end

        def make_request!
          http = Net::HTTP.new(uri.host, uri.port)
          http.use_ssl = true
          @response = http.request(build_request)
        end

        def response_body
          @response_body ||= JSON.parse(@response.body)
        end

        def error
          "#{self.class} #{@response.code}: #{response_body['response']['errors'][0]['message']}"
        end

        def call
          make_request!

          raise error unless success?

          Rails.logger.info("#{self.class} : Success #{self}")
          return_value
        rescue StandardError => e
          Bugsnag.notify(e.message)
          Rails.logger.error(e.message)
          nil
        ensure
          cleanup
        end

        def cleanup; end

        module ClassMethods
          def call(attrs = {})
            new(attrs).call
          end
        end
      end
    end
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.15 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.14 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.13 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.12 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.11 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.10 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.9 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.8 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.7 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.6 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.5 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.4 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.3 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.2 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.1 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.5.0 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.4.9 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.4.8 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.4.7 lib/nexmo_developer/app/services/translator/smartling/api/base.rb