Sha256: 4eb312e7edd702b1dc29f4667fd7d09fd72c148934b682c7965d3edc476d8d91

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

require 'faraday'

module Roar
  module Representer
    module Transport
      # Advanced implementation of the HTTP verbs with the Faraday HTTP library
      # (which can, in turn, use adapters based on Net::HTTP or libcurl)
      #
      # Depending on how the Faraday middleware stack is configured, this
      # Transport can support features such as HTTP error code handling,
      # redirects, etc.
      #
      # @see http://rubydoc.info/gems/faraday/file/README.md Faraday README
      class Faraday

        def get_uri(uri, as, *args)
          build_connection(uri, as).get
        end

        def post_uri(uri, body, as, *args)
          build_connection(uri, as).post(nil, body)
        end

        def put_uri(uri, body, as, *args)
          build_connection(uri, as).put(nil, body)
        end

        def patch_uri(uri, body, as, *args)
          build_connection(uri, as).patch(nil, body)
        end

        def delete_uri(uri, as, *args)
          build_connection(uri, as).delete
        end

        private

        def build_connection(uri, as)
          ::Faraday::Connection.new(
            :url => uri,
            :headers => { :accept => as, :content_type => as }
          ) do |builder|
            builder.use ::Faraday::Response::RaiseError
            builder.adapter ::Faraday.default_adapter
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
roar-0.12.9 lib/roar/representer/transport/faraday.rb
roar-0.12.8 lib/roar/representer/transport/faraday.rb
roar-0.12.7 lib/roar/representer/transport/faraday.rb
roar-0.12.6 lib/roar/representer/transport/faraday.rb
roar-0.12.5 lib/roar/representer/transport/faraday.rb
roar-0.12.4 lib/roar/representer/transport/faraday.rb
roar-0.12.3 lib/roar/representer/transport/faraday.rb