Class: ATS::Shiro::API
- Inherits:
-
Object
- Object
- ATS::Shiro::API
- 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
-
#bearer_token ⇒ Object
readonly
Returns the value of attribute bearer_token.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
Instance Method Summary collapse
- #get(url, params: {}, version: 1) ⇒ Object
-
#initialize(configuration:, debug: false) ⇒ API
constructor
A new instance of API.
- #post(url, params: {}, version: 1) ⇒ Object
- #tokens ⇒ Object
- #version ⇒ Object
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_token ⇒ Object (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 |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/ats/shiro/api.rb', line 10 def host @host end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
10 11 12 |
# File 'lib/ats/shiro/api.rb', line 10 def http @http end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/ats/shiro/api.rb', line 10 def port @port end |
#scheme ⇒ Object (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 |
#tokens ⇒ Object
21 22 23 |
# File 'lib/ats/shiro/api.rb', line 21 def tokens ATS::Shiro::Tokens.new(self) end |
#version ⇒ Object
25 26 27 |
# File 'lib/ats/shiro/api.rb', line 25 def version get("version") end |