Class: ATS::Shiro::API

Inherits:
Object
  • Object
show all
Defined in:
lib/ats/shiro/api.rb

Constant Summary collapse

HEADERS =
{
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'User-Agent' => "RubyGems/ATS #{ATS::VERSION}",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration:, debug: false) ⇒ API

Returns a new instance of API.



12
13
14
15
16
17
18
19
# File 'lib/ats/shiro/api.rb', line 12

def initialize(configuration:, debug: false)
  @http = HttpAPI.new(headers: HEADERS, debug: debug)
  @configuration = configuration
  @port = configuration[:port]
  @scheme = configuration[:scheme]
  @host = configuration[:host]
  @bearer_token = configuration[:bearer_token]
end

Instance Attribute Details

#bearer_tokenObject (readonly)

Returns the value of attribute bearer_token.



10
11
12
# File 'lib/ats/shiro/api.rb', line 10

def bearer_token
  @bearer_token
end

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/ats/shiro/api.rb', line 10

def host
  @host
end

#httpObject (readonly)

Returns the value of attribute http.



10
11
12
# File 'lib/ats/shiro/api.rb', line 10

def http
  @http
end

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/ats/shiro/api.rb', line 10

def port
  @port
end

#schemeObject (readonly)

Returns the value of attribute scheme.



10
11
12
# File 'lib/ats/shiro/api.rb', line 10

def scheme
  @scheme
end

Instance Method Details

#get(url, params: {}, version: 1) ⇒ Object



29
30
31
32
33
# File 'lib/ats/shiro/api.rb', line 29

def get(url, params: {}, version: 1)
  http.get(build_uri(url, version: version), headers: headers, body: params) do |request, response|
    JSON.parse(response.body, symbolize_names: true)
  end
end

#post(url, params: {}, version: 1) ⇒ Object



35
36
37
38
39
# File 'lib/ats/shiro/api.rb', line 35

def post(url, params: {}, version: 1)
  http.post(build_uri(url, version: version), headers: headers, body: params) do |request, response|
    JSON.parse(response.body, symbolize_names: true)
  end
end

#tokensObject



21
22
23
# File 'lib/ats/shiro/api.rb', line 21

def tokens
  ATS::Shiro::Tokens.new(self)
end

#versionObject



25
26
27
# File 'lib/ats/shiro/api.rb', line 25

def version
  get("version")
end