Class: XboxApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/xbox-api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/xbox-api/client.rb', line 7

def initialize(api_key)
  @api_key = api_key
  @base_url = "https://xboxapi.com/v2"
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



5
6
7
# File 'lib/xbox-api/client.rb', line 5

def api_key
  @api_key
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



5
6
7
# File 'lib/xbox-api/client.rb', line 5

def base_url
  @base_url
end

Instance Method Details

#calls_remainingObject



20
21
22
23
24
25
26
27
# File 'lib/xbox-api/client.rb', line 20

def calls_remaining
  headers = fetch_headers
  {
    limit: headers["x-ratelimit-limit"],
    remaining: headers["x-ratelimit-remaining"],
    resets_in: headers["x-ratelimit-reset"]
  }
end

#fetch_body_and_parse(endpoint) ⇒ Object



16
17
18
# File 'lib/xbox-api/client.rb', line 16

def fetch_body_and_parse(endpoint)
  parse(get_with_token(endpoint).read)
end

#gamer(tag) ⇒ Object



12
13
14
# File 'lib/xbox-api/client.rb', line 12

def gamer(tag)
  XboxApi::Gamer.new(tag, self)
end