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.1.5 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.1.4 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.1.3 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.1.2 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.1.1 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.1.0 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.145 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.144 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.143 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.142 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.141 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.140 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.139 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.138 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.137 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.136 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.135 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.134 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.133 lib/nexmo_developer/app/services/translator/smartling/api/base.rb
station-0.0.132 lib/nexmo_developer/app/services/translator/smartling/api/base.rb