Class: FortniteApi::Api
- Inherits:
-
Object
- Object
- FortniteApi::Api
- Defined in:
- lib/fortnite_api.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
- #get_json(platform = nil, nickname = nil) ⇒ Object
-
#initialize(api_key = nil) ⇒ Api
constructor
A new instance of Api.
Constructor Details
#initialize(api_key = nil) ⇒ Api
Returns a new instance of Api.
16 17 18 |
# File 'lib/fortnite_api.rb', line 16 def initialize(api_key = nil) @api_key = !api_key.nil? ? api_key : raise(ArgumentError, "API Key not defined: add your API Key'") end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
15 16 17 |
# File 'lib/fortnite_api.rb', line 15 def api_key @api_key end |
Instance Method Details
#get_json(platform = nil, nickname = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fortnite_api.rb', line 20 def get_json(platform = nil, nickname = nil) platform = !platform.nil? && (platform == "pc" || platform == "xbl" || platform == "psn") ? platform : raise(ArgumentError, "Platform not defined: add your plaform") nickname = !nickname.nil? ? nickname : raise(ArgumentError, "Nickame not defined: add your Fortnite nickname") uri = URI.parse("https://api.fortnitetracker.com/v1/profile/#{platform}/#{nickname}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request.add_field("TRN-Api-Key", @api_key) response = http.request(request) json = JSON.parse(response.body) Player.new(json) end |