Class: SC2Cli::Shared::Api
- Inherits:
-
Object
- Object
- SC2Cli::Shared::Api
- Defined in:
- lib/sc2cli/shared/api.rb
Constant Summary collapse
- @@console =
Console.instance
Instance Attribute Summary collapse
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
- #get(path: "/") ⇒ Object
-
#initialize(configuration:, region: nil) ⇒ Api
constructor
A new instance of Api.
Constructor Details
Instance Attribute Details
#region ⇒ Object (readonly)
Returns the value of attribute region.
28 29 30 |
# File 'lib/sc2cli/shared/api.rb', line 28 def region @region end |
Instance Method Details
#get(path: "/") ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sc2cli/shared/api.rb', line 39 def get(path: "/") @@console.fatal("Path for API request cannot be blank!") if path.empty? @@console.fatal("Path for API request: #{path} does NOT begin with '/'!") unless path.chars.first == "/" server = @region.api_server @token.refresh unless @token.check uri = URI("https://#{server}#{path}") @@console.info("Making API request to: #{uri.to_s}") request = Net::HTTP::Get.new(uri) request["Authorization"] = "Bearer #{@token.token}" http = Net::HTTP.new(uri.hostname, uri.port) http.use_ssl = true response = http.request(request) @@console.fatal("Blizzard API returned: #{response.code}, not 200 for reqest!") if response.code != "200" @@console.fatal("Response body from Blizzard API is not permitted!") if not response.class.body_permitted? @@console.fatal("Response body from Blizzard API is empty!") if response.body.nil? body = JSON.parse(response.body) return body end |