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