Sha256: 40f12891af83f9efd6aa8e3ee5ada933a098ea05b255bfde33c20687826d393f

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module GnipApi
  module Adapters
    class HTTPartyAdapter < GnipApi::Adapters::BaseAdapter
      def post request
        data = HTTParty.post request.uri, :basic_auth => auth, :body => request.payload, :timeout => default_timeout
        return response(request, data)
      end
      
      def delete request
        data = HTTParty.post request.uri, :basic_auth => auth, :body => request.payload, :timeout => default_timeout
        return response(request, data)
      end
      
      def get request
        data = HTTParty.get request.uri, :basic_auth => auth, :timeout => default_timeout
        return response(request, data)
      end

      def stream_get request
        HTTParty.get request.uri, :headers => request.headers, :stream_body => true, :basic_auth => auth do |data|
          yield(data)
        end
      end

      def auth
        {
          :username => username,
          :password => password
        }
      end
      
      def response request, data
        create_response request, data.code, data.body, data.headers
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gnip_api-1.0.1 lib/gnip_api/adapters/httparty_adapter.rb
gnip_api-1.0.0 lib/gnip_api/adapters/httparty_adapter.rb