Class: BooticClient::Client
- Inherits:
-
Object
- Object
- BooticClient::Client
show all
- Defined in:
- lib/bootic_client/client.rb
Defined Under Namespace
Classes: SafeCacheSerializer
Constant Summary
collapse
- USER_AGENT =
"[BooticClient v#{VERSION}] Ruby-#{RUBY_VERSION} - #{RUBY_PLATFORM}".freeze
- JSON_MIME =
'application/json'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#delete(href, _ = {}, headers = {}) ⇒ Object
-
#get(href, query = {}, headers = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Client
constructor
A new instance of Client.
-
#patch(href, payload = {}, headers = {}) ⇒ Object
-
#post(href, payload = {}, headers = {}) ⇒ Object
-
#put(href, payload = {}, headers = {}) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Client
Returns a new instance of Client.
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/bootic_client/client.rb', line 16
def initialize(options = {}, &block)
@options = {
logging: false,
faraday_adapter: [:net_http_persistent],
user_agent: USER_AGENT
}.merge(options.dup)
@options[:cache_store] = @options[:cache_store] || Faraday::HttpCache::MemoryStore.new
conn &block if block_given?
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
14
15
16
|
# File 'lib/bootic_client/client.rb', line 14
def options
@options
end
|
Instance Method Details
#delete(href, _ = {}, headers = {}) ⇒ Object
56
57
58
59
60
|
# File 'lib/bootic_client/client.rb', line 56
def delete(href, _ = {}, = {})
validated_request!(:delete, href) do |req|
req..update
end
end
|
#get(href, query = {}, headers = {}) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/bootic_client/client.rb', line 28
def get(href, query = {}, = {})
validated_request!(:get, href) do |req|
req..update
req.params.update(query)
end
end
|
#patch(href, payload = {}, headers = {}) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/bootic_client/client.rb', line 49
def patch(href, payload = {}, = {})
validated_request!(:patch, href) do |req|
req..update
req.body = JSON.dump(sanitized(payload))
end
end
|
#post(href, payload = {}, headers = {}) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/bootic_client/client.rb', line 35
def post(href, payload = {}, = {})
validated_request!(:post, href) do |req|
req..update
req.body = JSON.dump(sanitized(payload))
end
end
|
#put(href, payload = {}, headers = {}) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/bootic_client/client.rb', line 42
def put(href, payload = {}, = {})
validated_request!(:put, href) do |req|
req..update
req.body = JSON.dump(sanitized(payload))
end
end
|