Sha256: cd467b87100689d231f973580449449e1437c7233b62340617e7cff300f8e7c0

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 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)
          build_connection(uri, as).get
        end

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

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

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

        def delete_uri(uri, as)
          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

16 entries across 16 versions & 1 rubygems

Version Path
roar-0.12.0 lib/roar/representer/transport/faraday.rb
roar-0.11.19 lib/roar/representer/transport/faraday.rb
roar-0.11.18 lib/roar/representer/transport/faraday.rb
roar-0.11.17 lib/roar/representer/transport/faraday.rb
roar-0.11.16 lib/roar/representer/transport/faraday.rb
roar-0.11.15 lib/roar/representer/transport/faraday.rb
roar-0.11.14 lib/roar/representer/transport/faraday.rb
roar-0.11.13 lib/roar/representer/transport/faraday.rb
roar-0.11.12 lib/roar/representer/transport/faraday.rb
roar-0.11.11 lib/roar/representer/transport/faraday.rb
roar-0.11.10 lib/roar/representer/transport/faraday.rb
roar-0.11.9 lib/roar/representer/transport/faraday.rb
roar-0.11.8 lib/roar/representer/transport/faraday.rb
roar-0.11.7 lib/roar/representer/transport/faraday.rb
roar-0.11.6 lib/roar/representer/transport/faraday.rb
roar-0.11.5 lib/roar/representer/transport/faraday.rb