Class: Resterl::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/resterl/client.rb
Defined Under Namespace
Classes: TooManyRedirects
Constant Summary
collapse
- DEFAULTS =
{
max_redirect_depth: 10,
cache: Resterl::Caches::SimpleCache.new,
ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE,
expiry_multiplier: 10,
open_timeout: 15,
read_timeout: 60,
minimum_cache_lifetime: 5 * 60 }
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#delete(url, params, data, headers) ⇒ Object
-
#get(url, params, headers) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#invalidate(url, params, headers) ⇒ Object
-
#post(url, params, data, headers) ⇒ Object
-
#put(url, params, data, headers) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
18
19
20
21
|
# File 'lib/resterl/client.rb', line 18
def initialize(options = {})
@options = DEFAULTS.merge(options).freeze
@cache = @options[:cache]
end
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
5
6
7
|
# File 'lib/resterl/client.rb', line 5
def cache
@cache
end
|
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/resterl/client.rb', line 5
def options
@options
end
|
Instance Method Details
#delete(url, params, data, headers) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/resterl/client.rb', line 57
def delete url, params, data,
url = setup_url url
request = Resterl::DeleteRequest.new(self, url, params, data, )
request.perform.response
end
|
#get(url, params, headers) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/resterl/client.rb', line 23
def get url, params,
url = setup_url(url)
cache_key = data_to_cache_key url, params,
old_response = @cache.read(cache_key)
if old_response && !old_response.expired?
old_response
else
new_get_request url, cache_key, params, , old_response
end
end
|
#invalidate(url, params, headers) ⇒ Object
64
65
66
|
# File 'lib/resterl/client.rb', line 64
def invalidate url, params,
@cache.delete data_to_cache_key(url, params, )
end
|
#post(url, params, data, headers) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/resterl/client.rb', line 41
def post url, params, data,
url = setup_url url
request = Resterl::PostRequest.new(self, url, params, data, )
response = request.perform.response
response
end
|
#put(url, params, data, headers) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/resterl/client.rb', line 50
def put url, params, data,
url = setup_url url
request = Resterl::PutRequest.new(self, url, params, data, )
request.perform.response
end
|