Class: LL::WK::API::Connection::HTTParty

Inherits:
Base
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ll/wk/api/connection/httparty.rb

Instance Attribute Summary

Attributes inherited from Base

#email, #password, #token, #token_issued, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#auth, #authenticate!, authenticate_payload, #from_api, #page_count, #retrieve_data, #token_expired?, trap_resp_code, #with_cursor, #with_page

Constructor Details

#initialize(url:, email:, password:) ⇒ HTTParty

Returns a new instance of HTTParty.



22
23
24
25
# File 'lib/ll/wk/api/connection/httparty.rb', line 22

def initialize(url:, email:, password:)
  self.class.base_uri url
  super(url: url, email: email, password: password)
end

Class Method Details

.authenticate(email, password, url) {|resp| ... } ⇒ Object

Yields:

  • (resp)


13
14
15
16
17
18
19
20
# File 'lib/ll/wk/api/connection/httparty.rb', line 13

def self.authenticate(email, password, url)
  base_uri url
  resp = post('/session/new',
              body: authenticate_payload(email, password),
              headers: { 'Content-Type' => 'application/json' })
  yield(resp) if block_given?
  resp
end

Instance Method Details

#response_from_api(endpoint, params) {|resp| ... } ⇒ Object

Yields:

  • (resp)


28
29
30
31
32
33
34
# File 'lib/ll/wk/api/connection/httparty.rb', line 28

def response_from_api(endpoint, params)
  self.class.base_uri url
  resp = self.class.get(sanitize_endpoint(endpoint), query: params, headers: { 'Authorization' => auth })
  self.class.trap_resp_code(resp.code)
  yield(resp) if block_given?
  resp
end