Class: BooticClient::Client

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

Constructor Details

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

Returns a new instance of Client.


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bootic_client/client.rb', line 18

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

#optionsObject (readonly)

Returns the value of attribute options.


16
17
18
# File 'lib/bootic_client/client.rb', line 16

def options
  @options
end

Instance Method Details

#delete(href, _ = {}, headers = {}) ⇒ Object


58
59
60
61
62
# File 'lib/bootic_client/client.rb', line 58

def delete(href, _ = {}, headers = {})
  validated_request!(:delete, href) do |req|
    req.headers.update headers
  end
end

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


30
31
32
33
34
35
# File 'lib/bootic_client/client.rb', line 30

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


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

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


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

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


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

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