Class: BooticClient::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
24
25
# File 'lib/bootic_client/client.rb', line 16

def initialize(options = {}, &block)
  @options = {
    access_token: nil,
    logging: false
  }.merge(options.dup)

  @options[:cache_store] = @options[:cache_store] || Faraday::HttpCache::MemoryStore.new

  conn &block if block_given?
end

Instance Attribute Details

#options ⇒ Object (readonly)

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, query = {}) ⇒ Object



51
52
53
# File 'lib/bootic_client/client.rb', line 51

def delete(href, query = {})
  validated_request!(:delete, href)
end

#get(href, query = {}) ⇒ Object



27
28
29
30
31
# File 'lib/bootic_client/client.rb', line 27

def get(href, query = {})
  validated_request!(:get, href) do |req|
    req.params.update(query)
  end
end

#patch(href, payload = {}) ⇒ Object



45
46
47
48
49
# File 'lib/bootic_client/client.rb', line 45

def patch(href, payload = {})
  validated_request!(:patch, href) do |req|
    req.body = JSON.dump(payload)
  end
end

#post(href, payload = {}) ⇒ Object



33
34
35
36
37
# File 'lib/bootic_client/client.rb', line 33

def post(href, payload = {})
  validated_request!(:post, href) do |req|
    req.body = JSON.dump(payload)
  end
end

#put(href, payload = {}) ⇒ Object



39
40
41
42
43
# File 'lib/bootic_client/client.rb', line 39

def put(href, payload = {})
  validated_request!(:put, href) do |req|
    req.body = JSON.dump(payload)
  end
end