Sha256: 8d62428d4ab7dfa99696de5a81431b5b6a48d71889f10368761c8c82e2abc1c5

Contents?: true

Size: 805 Bytes

Versions: 1

Compression:

Stored size: 805 Bytes

Contents

require 'faraday'

module Rapidash
  module HTTPClient

    attr_accessor :site
    attr_writer :connection

    def site=(value)
      @connection = nil
      @site = value
    end

    def connection
      @connection ||= Faraday.new(site)
    end

    def get(url, options = {})
      request(:get, url, options)
    end

    def post(url, options = {})
      request(:post, url, options)
    end

    def request(verb, url, options = {})
      url = connection.build_url(url, options[:params]).to_s
      response = connection.run_request(verb, url, options[:body], options[:header])

      case response.status.to_s[0]
      #Handle redirects
      when "3"
        request(verb, response.headers["location"], options)
      when "2"
        return Response.new(response)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rapidash-0.0.1 lib/rapidash/http_client.rb