class ATS::Shiro::API
Constants
- HEADERS
Attributes
bearer_token[R]
host[R]
http[R]
port[R]
scheme[R]
Public Class Methods
new(configuration:, debug: false)
click to toggle source
# File lib/ats/shiro/api.rb, line 12 def initialize(configuration:, debug: false) @http = Net::Hippie::Client.new(headers: HEADERS, verify_mode: debug ? OpenSSL::SSL::VERIFY_NONE : nil) @configuration = configuration @port = configuration[:port] @scheme = configuration[:scheme] @host = configuration[:host] @bearer_token = configuration[:bearer_token] end
Public Instance Methods
get(url, params: {}, version: 1)
click to toggle source
# 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)
click to toggle source
# 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
tokens()
click to toggle source
# File lib/ats/shiro/api.rb, line 21 def tokens ATS::Shiro::Tokens.new(self) end
version()
click to toggle source
# File lib/ats/shiro/api.rb, line 25 def version get("version") end
Private Instance Methods
build_uri(relative_url, version:)
click to toggle source
# File lib/ats/shiro/api.rb, line 43 def build_uri(relative_url, version:) URI::Generic.build(host: host, port: port, scheme: scheme, path: "/api/v#{version}/#{relative_url}") end
headers()
click to toggle source
# File lib/ats/shiro/api.rb, line 47 def headers { AUTHORIZATION: "Bearer #{bearer_token}" } end