Class: Gamercard::Client
- Inherits:
-
Object
- Object
- Gamercard::Client
- Defined in:
- lib/gamercard/client.rb
Constant Summary collapse
- GAMERCARD_SERVICE_URL =
"http://gamercard.xbox.com"
Instance Attribute Summary collapse
-
#gamertag ⇒ Object
Returns the value of attribute gamertag.
Instance Method Summary collapse
- #build_url ⇒ Object
- #connection ⇒ Object
- #fetch ⇒ Object
- #fetch_with_redirect ⇒ Object
-
#initialize(gamertag) ⇒ Client
constructor
A new instance of Client.
- #parse(response) ⇒ Object
Constructor Details
#initialize(gamertag) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/gamercard/client.rb', line 9 def initialize gamertag self.gamertag = gamertag end |
Instance Attribute Details
#gamertag ⇒ Object
Returns the value of attribute gamertag.
5 6 7 |
# File 'lib/gamercard/client.rb', line 5 def gamertag @gamertag end |
Instance Method Details
#build_url ⇒ Object
36 37 38 |
# File 'lib/gamercard/client.rb', line 36 def build_url "#{gamertag}.card" end |
#connection ⇒ Object
30 31 32 33 34 |
# File 'lib/gamercard/client.rb', line 30 def connection @connection ||= Faraday.new(:url => GAMERCARD_SERVICE_URL) do |b| b.adapter Gamercard.adapter end end |
#fetch ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/gamercard/client.rb', line 13 def fetch response = fetch_with_redirect if response.success? parse response else response end end |
#fetch_with_redirect ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/gamercard/client.rb', line 22 def fetch_with_redirect resp = connection.get(build_url) if resp.status == 302 && resp['location'] resp = connection.get(resp['location']) end resp end |
#parse(response) ⇒ Object
40 41 42 |
# File 'lib/gamercard/client.rb', line 40 def parse response CardParser.parse response end |