Class: GdsApi::JsonClient
Constant Summary
collapse
{
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'User-Agent' => "GDS Api Client v. #{GdsApi::VERSION}"
}
- DEFAULT_TIMEOUT_IN_SECONDS =
4
- DEFAULT_CACHE_SIZE =
100
- DEFAULT_CACHE_TTL =
15 * 60
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#delete_json!(url, params = nil, additional_headers = {}) ⇒ Object
-
#get_json!(url, additional_headers = {}, &create_response) ⇒ Object
-
#get_raw(url) ⇒ Object
-
#get_raw!(url) ⇒ Object
-
#initialize(options = {}) ⇒ JsonClient
constructor
A new instance of JsonClient.
-
#post_json!(url, params, additional_headers = {}) ⇒ Object
-
#post_multipart(url, params) ⇒ Object
-
#put_json!(url, params, additional_headers = {}) ⇒ Object
-
#put_multipart(url, params) ⇒ Object
#ignoring, #ignoring_missing
Constructor Details
#initialize(options = {}) ⇒ JsonClient
Returns a new instance of JsonClient.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/gds_api/json_client.rb', line 29
def initialize(options = {})
if options[:disable_timeout] or options[:timeout].to_i < 0
raise "It is no longer possible to disable the timeout."
end
@logger = options[:logger] || GdsApi::Base.logger
if options[:disable_cache] || (options[:cache_size] == 0)
@cache = NullCache.new
else
cache_size = options[:cache_size] || DEFAULT_CACHE_SIZE
cache_ttl = options[:cache_ttl] || DEFAULT_CACHE_TTL
@cache = JsonClient.cache(cache_size, cache_ttl)
end
@options = options
end
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
27
28
29
|
# File 'lib/gds_api/json_client.rb', line 27
def cache
@cache
end
|
#logger ⇒ Object
Returns the value of attribute logger.
27
28
29
|
# File 'lib/gds_api/json_client.rb', line 27
def logger
@logger
end
|
#options ⇒ Object
Returns the value of attribute options.
27
28
29
|
# File 'lib/gds_api/json_client.rb', line 27
def options
@options
end
|
Class Method Details
.cache(size = DEFAULT_CACHE_SIZE, ttl = DEFAULT_CACHE_TTL) ⇒ Object
Cache TTL will be overridden for a given request/response by the Expires header if it is included in the response.
LRUCache doesn’t respect a cache size of 0, and instead effectively creates a cache with a size of 1.
19
20
21
|
# File 'lib/gds_api/json_client.rb', line 19
def self.cache(size=DEFAULT_CACHE_SIZE, ttl=DEFAULT_CACHE_TTL)
@cache ||= LRUCache.new(max_size: size, ttl: ttl)
end
|
.cache=(c) ⇒ Object
23
24
25
|
# File 'lib/gds_api/json_client.rb', line 23
def self.cache=(c)
@cache = c
end
|
Instance Method Details
#delete_json!(url, params = nil, additional_headers = {}) ⇒ Object
91
92
93
|
# File 'lib/gds_api/json_client.rb', line 91
def delete_json!(url, params = nil, = {})
do_json_request(:delete, url, params, )
end
|
#get_json!(url, additional_headers = {}, &create_response) ⇒ Object
79
80
81
|
# File 'lib/gds_api/json_client.rb', line 79
def get_json!(url, = {}, &create_response)
do_json_request(:get, url, nil, , &create_response)
end
|
#get_raw(url) ⇒ Object
59
60
61
62
63
|
# File 'lib/gds_api/json_client.rb', line 59
def get_raw(url)
ignoring_missing do
get_raw!(url)
end
end
|
#get_raw!(url) ⇒ Object
55
56
57
|
# File 'lib/gds_api/json_client.rb', line 55
def get_raw!(url)
do_raw_request(:get, url)
end
|
#post_json!(url, params, additional_headers = {}) ⇒ Object
83
84
85
|
# File 'lib/gds_api/json_client.rb', line 83
def post_json!(url, params, = {})
do_json_request(:post, url, params, )
end
|
#post_multipart(url, params) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/gds_api/json_client.rb', line 95
def post_multipart(url, params)
r = do_raw_request(:post, url, params.merge({
:multipart => true
}))
Response.new(r)
end
|
#put_json!(url, params, additional_headers = {}) ⇒ Object
87
88
89
|
# File 'lib/gds_api/json_client.rb', line 87
def put_json!(url, params, = {})
do_json_request(:put, url, params, )
end
|
#put_multipart(url, params) ⇒ Object
102
103
104
105
106
107
|
# File 'lib/gds_api/json_client.rb', line 102
def put_multipart(url, params)
r = do_raw_request(:put, url, params.merge({
:multipart => true
}))
Response.new(r)
end
|