Class: Rapidash::Client

Inherits:
Object
  • Object
show all
Includes:
Resourceable
Defined in:
lib/rapidash/client.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resourceable

included, #resource, #resource!

Constructor Details

#initializeClient

Returns a new instance of Client.



7
8
9
# File 'lib/rapidash/client.rb', line 7

def initialize
  raise ConfigurationError.new "Missing Method, define using `method` on your client"
end

Class Attribute Details

.encoderObject

Returns the value of attribute encoder.



12
13
14
# File 'lib/rapidash/client.rb', line 12

def encoder
  @encoder
end

.extension(extension = nil) ⇒ Object

Returns the value of attribute extension.



12
13
14
# File 'lib/rapidash/client.rb', line 12

def extension
  @extension
end

.patchObject

Returns the value of attribute patch.



12
13
14
# File 'lib/rapidash/client.rb', line 12

def patch
  @patch
end

.raise_errorObject

Returns the value of attribute raise_error.



12
13
14
# File 'lib/rapidash/client.rb', line 12

def raise_error
  @raise_error
end

Instance Attribute Details

#extensionObject

Returns the value of attribute extension.



5
6
7
# File 'lib/rapidash/client.rb', line 5

def extension
  @extension
end

Class Method Details

.encode_request_with(format) ⇒ Object

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



53
54
55
56
57
58
59
60
61
62
63
64
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
# 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

.raise_errorsObject



36
37
38
# File 'lib/rapidash/client.rb', line 36

def raise_errors
  @raise_error = true
end

.site(site = nil) ⇒ Object



32
33
34
# File 'lib/rapidash/client.rb', line 32

def site(site = nil)
  @site ||= site
end

.use_patchObject



24
25
26
# File 'lib/rapidash/client.rb', line 24

def use_patch
  @patch = true
end

Instance Method Details

#delete(url, options = {}) ⇒ Object



105
106
107
# File 'lib/rapidash/client.rb', line 105

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

#get(url, options = {}) ⇒ Object



89
90
91
# File 'lib/rapidash/client.rb', line 89

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

#normalize_url(url) ⇒ Object



79
80
81
82
83
84
85
86
87
# 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 = {}) ⇒ Object



101
102
103
# File 'lib/rapidash/client.rb', line 101

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

#post(url, options = {}) ⇒ Object



93
94
95
# File 'lib/rapidash/client.rb', line 93

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

#put(url, options = {}) ⇒ Object



97
98
99
# File 'lib/rapidash/client.rb', line 97

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

#siteObject

Instance methods



69
70
71
72
# File 'lib/rapidash/client.rb', line 69

def site
  return @site if @site
  self.class.respond_to?(:site) && self.class.site
end

#site=(value) ⇒ Object



74
75
76
77
# File 'lib/rapidash/client.rb', line 74

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