Class: Rapidash::Client
- Inherits:
-
Object
- Object
- Rapidash::Client
- Includes:
- Resourceable
- Defined in:
- lib/rapidash/client.rb
Class Attribute Summary collapse
-
.encoder ⇒ Object
Returns the value of attribute encoder.
-
.extension(extension = nil) ⇒ Object
Returns the value of attribute extension.
-
.patch ⇒ Object
Returns the value of attribute patch.
-
.raise_error ⇒ Object
Returns the value of attribute raise_error.
Instance Attribute Summary collapse
-
#extension ⇒ Object
Returns the value of attribute extension.
Class Method Summary collapse
-
.encode_request_with(format) ⇒ Object
How should the request body for POST and PUT requests be formatted.
- .method(method) ⇒ Object
- .raise_errors ⇒ Object
- .site(site = nil) ⇒ Object
- .use_patch ⇒ Object
Instance Method Summary collapse
- #delete(url, options = {}) ⇒ Object
- #get(url, options = {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #normalize_url(url) ⇒ Object
- #patch(url, options = {}) ⇒ Object
- #post(url, options = {}) ⇒ Object
- #put(url, options = {}) ⇒ Object
-
#site ⇒ Object
Instance methods.
- #site=(value) ⇒ Object
Methods included from Resourceable
included, #resource, #resource!
Constructor Details
#initialize ⇒ Client
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
.encoder ⇒ Object
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 |
.patch ⇒ Object
Returns the value of attribute patch.
12 13 14 |
# File 'lib/rapidash/client.rb', line 12 def patch @patch end |
.raise_error ⇒ Object
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
#extension ⇒ Object
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_errors ⇒ Object
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_patch ⇒ Object
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, = {}) request(:delete, url, ) end |
#get(url, options = {}) ⇒ Object
89 90 91 |
# File 'lib/rapidash/client.rb', line 89 def get(url, = {}) request(:get, url, ) 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, = {}) request(:patch, url, ) end |
#post(url, options = {}) ⇒ Object
93 94 95 |
# File 'lib/rapidash/client.rb', line 93 def post(url, = {}) request(:post, url, ) end |
#put(url, options = {}) ⇒ Object
97 98 99 |
# File 'lib/rapidash/client.rb', line 97 def put(url, = {}) request(:put, url, ) end |
#site ⇒ Object
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 |