Sha256: 4c6ede25efab2d2c9b89e8bbc5d14bcc9c188327da55f0c58347953190105f79

Contents?: true

Size: 888 Bytes

Versions: 6

Compression:

Stored size: 888 Bytes

Contents

module Fortnox
  module API
    module RequestHandling

      private

        def raise_api_error( error, response )
          message = ( error[ 'message' ] || error[ 'Message' ] || 'Okänt fel' )

          message += "\n\n#{ response.request.inspect }" if Fortnox::API.debugging

          raise Fortnox::API::RemoteServerError, message
        end

        def validate_response( response )
          return if response.code == 200

          api_error = response.parsed_response[ 'ErrorInformation' ]
          raise_api_error( api_error, response ) if api_error
        end

        def validate_and_parse( response )
          validate_response( response )
          response.parsed_response
        end

        def execute
          self.class.set_headers( @headers )
          response = yield( self.class )
          validate_and_parse response
        end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fortnox-api-0.5.2 lib/fortnox/api/request_handling.rb
fortnox-api-0.5.1 lib/fortnox/api/request_handling.rb
fortnox-api-0.5.0 lib/fortnox/api/request_handling.rb
fortnox-api-0.4.0 lib/fortnox/api/request_handling.rb
fortnox-api-0.3.0 lib/fortnox/api/request_handling.rb
fortnox-api-0.2.0 lib/fortnox/api/request_handling.rb