Class: Sherpa::ApiClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sherpa/api_client.rb

Class Method Summary collapse

Class Method Details

.api_uriObject



24
25
26
# File 'lib/sherpa/api_client.rb', line 24

def api_uri
  Sherpa::Config.api_uri
end

.default_headersObject



28
29
30
31
32
# File 'lib/sherpa/api_client.rb', line 28

def default_headers
  {
    "Authorization" => "Token token=#{token}"
  }
end

.get(path) ⇒ Object



8
9
10
# File 'lib/sherpa/api_client.rb', line 8

def get(path)
  handle_response(super(path))
end

.handle_response(response) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/sherpa/api_client.rb', line 16

def handle_response(response)
  if response.success?
    response
  else
    raise FailedRequest, response
  end
end

.post(path, body:) ⇒ Object



12
13
14
# File 'lib/sherpa/api_client.rb', line 12

def post(path, body:)
  handle_response(super(path, body: body))
end

.tokenObject



34
35
36
# File 'lib/sherpa/api_client.rb', line 34

def token
  Sherpa::Config.api_token
end