class Rapidash::Client

Attributes

encoder[RW]
extension[RW]
patch[RW]
raise_error[RW]
extension[RW]

Public Class Methods

encode_request_with(format) click to toggle source

How should the request body for POST and PUT requests be formatted.

Examples:

class Client < Rapidash::Client
  encode_request_with :json
end

Arguments:

format - Symbol. One of :url_encoded, :multipart, :json

Returns String of set format

# File lib/rapidash/client.rb, line 53
def encode_request_with(format)
  format = format.to_s.to_sym

  unless [:url_encoded, :multipart, :json].include?(format)
    raise ArgumentError, 'you must pass one of :url_encoded, :multipart or :json to encode_request_with'
  end

  # Map json to multi_json to make it consistent with MutiJson parsing of responses
  format = :multi_json if format == :json

  @encoder ||= format
end
method(method) click to toggle source
# File lib/rapidash/client.rb, line 14
def method(method)
  case method
  when :http then include HTTPClient
  when :oauth then include OAuthClient
  when :test then include TestClient
  else
    raise ConfigurationError.new "Invalid API Authentication Method"
  end
end
new() click to toggle source
# File lib/rapidash/client.rb, line 7
def initialize
  raise ConfigurationError.new "Missing Method, define using `method` on your client"
end
raise_errors() click to toggle source
# File lib/rapidash/client.rb, line 36
def raise_errors
  @raise_error = true
end
site(site = nil) click to toggle source
# File lib/rapidash/client.rb, line 32
def site(site = nil)
  @site ||= site
end
use_patch() click to toggle source
# File lib/rapidash/client.rb, line 24
def use_patch
  @patch = true
end

Public Instance Methods

delete(url, options = {}) click to toggle source
# File lib/rapidash/client.rb, line 105
def delete(url, options = {})
  request(:delete, url, options)
end
get(url, options = {}) click to toggle source
# File lib/rapidash/client.rb, line 89
def get(url, options = {})
  request(:get, url, options)
end
normalize_url(url) click to toggle source
# File lib/rapidash/client.rb, line 79
def normalize_url(url)
  if extension
    "#{url}.#{extension}"
  elsif self.class.respond_to?(:extension) && self.class.extension
    "#{url}.#{self.class.extension}"
  else
    url
  end
end
patch(url, options = {}) click to toggle source
# File lib/rapidash/client.rb, line 101
def patch(url, options = {})
  request(:patch, url, options)
end
post(url, options = {}) click to toggle source
# File lib/rapidash/client.rb, line 93
def post(url, options = {})
  request(:post, url, options)
end
put(url, options = {}) click to toggle source
# File lib/rapidash/client.rb, line 97
def put(url, options = {})
  request(:put, url, options)
end
site() click to toggle source

Instance methods

# File lib/rapidash/client.rb, line 69
def site
  return @site if @site
  self.class.respond_to?(:site) && self.class.site
end
site=(value) click to toggle source
# File lib/rapidash/client.rb, line 74
def site=(value)
  @site = value
  @connection = nil
end

Private Instance Methods

connection_builder() click to toggle source
# File lib/rapidash/client.rb, line 111
def connection_builder
  lambda do |builder|
    builder.request self.class.encoder || :url_encoded

    if self.class.respond_to?(:raise_error) && self.class.raise_error
      builder.use Faraday::Response::RaiseRapidashError
    end

    builder.use FaradayMiddleware::FollowRedirects
    builder.use FaradayMiddleware::Mashify

    builder.use FaradayMiddleware::MultiJson::ParseJson, :content_type => /\bjson$/
    builder.use FaradayMiddleware::ParseXml, :content_type => /\bxml$/

    builder.adapter :net_http
  end
end