gamertag 1.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +11 -1
  3. data/LICENSE.md +11 -0
  4. data/README.md +84 -0
  5. data/gamertag.gemspec +25 -25
  6. data/lib/faraday/response/cleanup_xbox_leaders_naming.rb +30 -0
  7. data/lib/faraday/response/raise_xbox_leaders_error.rb +22 -0
  8. data/lib/gamertag.rb +21 -10
  9. data/lib/gamertag/client.rb +25 -0
  10. data/lib/gamertag/client/achievements.rb +15 -0
  11. data/lib/gamertag/client/friends.rb +14 -0
  12. data/lib/gamertag/client/games.rb +41 -0
  13. data/lib/gamertag/client/profile.rb +14 -0
  14. data/lib/gamertag/configuration.rb +48 -0
  15. data/lib/gamertag/connection.rb +22 -0
  16. data/lib/gamertag/error.rb +22 -0
  17. data/lib/gamertag/version.rb +2 -2
  18. data/spec/client/achievements_spec.rb +21 -0
  19. data/spec/client/friends_spec.rb +23 -0
  20. data/spec/client/games_spec.rb +49 -0
  21. data/spec/client/profile_spec.rb +22 -0
  22. data/spec/client_spec.rb +7 -0
  23. data/spec/faraday/xboxleader_cleanup_spec.rb +59 -0
  24. data/spec/faraday/xboxleader_error_spec.rb +63 -0
  25. data/spec/fixtures/achievements.json +654 -0
  26. data/spec/fixtures/errors/friends_not_found.json +9 -0
  27. data/spec/fixtures/errors/game_not_found.json +9 -0
  28. data/spec/fixtures/errors/gamertag_not_found.json +9 -0
  29. data/spec/fixtures/errors/invalid_game_id.json +9 -0
  30. data/spec/fixtures/errors/invalid_gamertag.json +9 -0
  31. data/spec/fixtures/friends.json +772 -0
  32. data/spec/fixtures/gamertag_not_found.json +9 -0
  33. data/spec/fixtures/games.json +2244 -0
  34. data/spec/fixtures/profile.json +125 -0
  35. data/spec/gamertag_spec.rb +13 -0
  36. data/spec/helper.rb +38 -0
  37. metadata +92 -124
  38. data/.gitignore +0 -9
  39. data/.rspec +0 -3
  40. data/.rvmrc +0 -1
  41. data/Gemfile +0 -4
  42. data/LICENSE +0 -20
  43. data/README.mdown +0 -106
  44. data/Rakefile +0 -12
  45. data/lib/gamertag/friends.rb +0 -25
  46. data/lib/gamertag/played_games.rb +0 -73
  47. data/lib/gamertag/profile.rb +0 -13
  48. data/lib/gamertag/simple_profile.rb +0 -68
  49. data/spec/fixtures/vcr_cassettes/Friends_Belial1984.yml +0 -520
  50. data/spec/fixtures/vcr_cassettes/PlayedGames_Belial1984.yml +0 -1309
  51. data/spec/fixtures/vcr_cassettes/PlayedGames_some_user.yml +0 -100
  52. data/spec/fixtures/vcr_cassettes/SimpleProfile_Belial1984.yml +0 -45
  53. data/spec/friends_spec.rb +0 -19
  54. data/spec/played_games_spec.rb +0 -25
  55. data/spec/profile_spec.rb +0 -15
  56. data/spec/simple_profile_spec.rb +0 -69
  57. data/spec/spec_helper.rb +0 -15
  58. data/spec/version_spec.rb +0 -7
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d867e724bcb5d37345fd299a61c6b29f5147f32b
4
+ data.tar.gz: 661506f822872344343fec30c6dc5d93da682861
5
+ SHA512:
6
+ metadata.gz: 677d6061086874b060f7617dd170faf42768892d7f65e9bf642ca9394dd453674773895668ebc90dad66cc86d8b8a25f18dedf42b826bfe306f5b8db48f85dd9
7
+ data.tar.gz: 02016cec46d80a5609260ddd49e1db239a2b511b784bad299e5fb82c0e378826dcbe51d5a344021a3cfb8b1bd79ec361542527ddfb22a1bd29ae57bc86fdb690
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.1
4
+
5
+ * Forgot to enable the passing of options to the client, currently only the version/adapter really, but possibly others in future.
6
+
7
+
8
+ ## 2.0.0
9
+
10
+ * Completely re-written (inspired by [Octokit.rb](https://github.com/octokit/octokit.rb)), replacing a lot of old crappy code, updating to the Xbox Leaders 2.0 API throughout, dropping the XboxGamertag API and finally employing Faraday so the adapter can be configured/swapped out as the user sees fit.
11
+ * New licence.
12
+
3
13
  ## 1.1.0
4
14
 
5
15
  * Added support for a gamertag's friends via `Gamertag::Friends`. 2 methods on this class, `friends` and
@@ -20,4 +30,4 @@
20
30
 
21
31
  ## 1.0.0
22
32
 
23
- * Initial release
33
+ * Initial release
@@ -0,0 +1,11 @@
1
+ *DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE*
2
+ *Version 2, December 2004*
3
+
4
+ Copyright (C) 2013 Baris Balic <leafybasil@gmail.com>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
7
+
8
+ *DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
9
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION*
10
+
11
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
@@ -0,0 +1,84 @@
1
+ # Gamertag Raq [![Build Status](https://travis-ci.org/barisbalic/gamertag.png?branch=master)](https://travis-ci.org/barisbalic/gamertag) [![Dependency Status]
2
+
3
+ A simple wrapper for the [Xbox Leaders](https://www.xboxleaders.com/) 2.0 API, which allows you to pull back public information about an Xbox Live user with just their Gamertag. This includes their profile, friends, games played and achievements.
4
+
5
+ ## Divergence from API
6
+
7
+ The Xbox Leaders API has evolved recently and will probably continue to do so now that it has more focus from it's developer. As a result I've made some choices that may not marry up completely with the API documentation, however I feel they are sensible/idiomatic, and where reasonable I've suggested to the Xbox Leaders team that they could make changes directly to the API.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'gamertag'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install gamertag
23
+
24
+
25
+ ## Documentation
26
+
27
+ LINK TO RDOC
28
+
29
+ ### Examples
30
+
31
+ #### Override the adapter
32
+
33
+ ```ruby
34
+ client = Gamertag::Client.new(:adapter => :em_http)
35
+ client.profile('Major Nelson')
36
+ ```
37
+
38
+ #### Retrieve a user
39
+
40
+ ```ruby
41
+ Gamertag.profile('Major Nelson')
42
+ => #<Hashie::Mash avatar=#<Hashie::Mash full="http://avatar.xboxlive.com/avatar/Major Nelson/avatar-body.png" large="http://avatar.xboxlive.com/avatar/Major Nelson/avatarpic-l.png" small="http://avatar.xboxlive.com/avatar/Major Nelson/avatarpic-s.png"> badges=#<Hashie::Mash kinect_launch_team=true nxe_launch_team=true xbox_launch_team=true> biography="" freshness="new" gamerscore=63937 gamertag="Major Nelson" location="" motto="" name="" online=false presence="Last seen 1 minute ago playing Xbox.com" recent_activity=[#<Hashie::Mash achievements=#<Hashie::Mash current=36 total=69> artwork=#<Hashie::Mash large="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d8025454087c/1033/boxartlg.jpg" small="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d8025454087c/1033/boxartsm.jpg"> gamerscore=#<Hashie::Mash current=770 total=1625> id=1414793340 is_app=false last_played="1372305965" progress=52.2 title="Borderlands 2">, #<Hashie::Mash achievements=#<Hashie::Mash current=43 total=76> artwork=#<Hashie::Mash large="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d8024d530919/1033/boxartlg.jpg" small="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d8024d530919/1033/boxartsm.jpg"> gamerscore=#<Hashie::Mash current=825 total=1750> id=1297287449 is_app=false last_played="1372216446" progress=56.6 title="Halo 4">, #<Hashie::Mash achievements=#<Hashie::Mash current=28 total=63> artwork=#<Hashie::Mash large="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d80245410950/1033/boxartlg.jpg" small="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d80245410950/1033/boxartsm.jpg"> gamerscore=#<Hashie::Mash current=680 total=1600> id=1161890128 is_app=false last_played="1372131482" progress=44.4 title="Battlefield 3">, #<Hashie::Mash achievements=#<Hashie::Mash current=0 total=0> artwork=#<Hashie::Mash large="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d8025848085b/1033/boxartlg.jpg" small="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d8025848085b/1033/boxartsm.jpg"> gamerscore=#<Hashie::Mash current=0 total=0> id=1481115739 is_app=true last_played="1371965964" progress=0 title="Xbox Music and Video">, #<Hashie::Mash achievements=#<Hashie::Mash current=0 total=0> artwork=#<Hashie::Mash large="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d8024d530a1b/1033/boxartlg.jpg" small="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d8024d530a1b/1033/boxartsm.jpg"> gamerscore=#<Hashie::Mash current=0 total=0> id=1297287707 is_app=true last_played="1371335033" progress=0 title="Live Event Player">] reputation=20 tier="gold">
43
+ ```
44
+
45
+ #### Retrieve games played by a user
46
+
47
+ ```ruby
48
+ Gamertag.games('Major Nelson')
49
+ => [#<Hashie::Mash achievements=#<Hashie::Mash current=1 total=31> artwork=#<Hashie::Mash large="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802415607d3/1033/boxartlg.jpg" small="http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802415607d3/1033/boxartsm.jpg"> gamerscore=#<Hashie::Mash current=5 total=1000> id=1096157139 is_app=false last_played="1132028299" progress=3.2 title="Gun">, …]
50
+ ```
51
+
52
+ #### Retrieve friends of a user
53
+
54
+ ```ruby
55
+ Gamertag.friends('Major Nelson')
56
+ => [#<Hashie::Mash gamerpic=#<Hashie::Mash large="https://avatar-ssl.xboxlive.com/avatar/allad1nsane/avatarpic-s.png" small="https://avatar-ssl.xboxlive.com/avatar/allad1nsane/avatarpic-l.png"> gamerscore=21080 gamertag="allad1nsane" last_seen="1371973384" online=false status="Last seen 6/23/2013 playing Max Payne 3">, …]
57
+ ```
58
+
59
+ #### Retrieve user's achievements
60
+
61
+ ```ruby
62
+ Gamertag.achievements('Major Nelson', 1414793309)
63
+ => [#<Hashie::Mash artwork=#<Hashie::Mash locked="https://live.xbox.com/tiles/4g/ym/0zc8P2NhbC9GWxoEGlxTWTVkL2FjaC8wL2EyAAAAAVBQUPyJDP4=.jpg" unlocked=""> description="Kill 20 enemies by knocking them off Columbia." gamerscore=25 id=36 secret=false title="Bon Voyage" unlock_date="1368255380" unlocked=true>, …]
64
+ ```
65
+
66
+
67
+ ## Contributors
68
+
69
+ As of 2.0, the codebase is completely re-written, however I'd like to thank [David Czarnecki](https://github.com/czarneckid) for his contributions, especially for putting up with the original crappy code.
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create new Pull Request
78
+
79
+ ## Copyright
80
+
81
+ Copyright (c) 2011-2013 Baris Balic, David Czarnecki.
82
+ See [LICENSE][] for details.
83
+
84
+ [license]: LICENSE.md
@@ -1,30 +1,30 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("lib", __FILE__)
3
- require "./lib/gamertag/version"
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gamertag/version'
4
5
 
5
- Gem::Specification.new do |s|
6
- s.name = "gamertag"
7
- s.version = Gamertag::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Baris Balic", "David Czarnecki"]
10
- s.email = ["baris@webloch.co.uk", "dczarnecki@agoragames.com"]
11
- s.homepage = "https://github.com/barisbalic/gamertag"
12
- s.summary = %q{A gem for retrieving your XBOX Live gamertag information}
13
- s.description = %q{A gem for retrieving your XBOX Live gamertag information}
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gamertag'
8
+ spec.version = Gamertag::VERSION
9
+ spec.authors = ['Baris Balic']
10
+ spec.email = ['leafybasil@gmail.com']
11
+ spec.description = %q{A wrapper for the XboxLeaders API}
12
+ spec.summary = %q{A wrapper for the XboxLeaders API}
13
+ spec.homepage = 'https://github.com/barisbalic/gamertag'
14
+ spec.licenses = ['DWHTFYWTPL']
14
15
 
15
- s.rubyforge_project = "gamertag"
16
+ spec.files = %w(CHANGELOG.md LICENSE.md README.md gamertag.gemspec)
17
+ spec.files += Dir.glob("lib/**/*.rb")
18
+ spec.files += Dir.glob("spec/**/*")
19
+ spec.test_files = Dir.glob("spec/**/*")
16
20
 
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
21
-
22
- s.add_dependency('json')
23
- s.add_dependency('hashie')
24
- s.add_dependency('nokogiri')
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
25
24
 
26
- s.add_development_dependency('rake')
27
- s.add_development_dependency('rspec')
28
- s.add_development_dependency('vcr')
29
- s.add_development_dependency('fakeweb')
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_dependency 'faraday', '~> 0.8'
27
+ spec.add_dependency 'faraday_middleware', '~> 0.9'
28
+ spec.add_dependency 'hashie', '~> 2.0'
29
+ spec.add_dependency 'multi_json', '~> 1.3'
30
30
  end
@@ -0,0 +1,30 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ # @api private
5
+ module Faraday
6
+ class Response::CleanupXboxLeadersNaming < Response::Middleware
7
+ MAPPINGS = {
8
+ 'xboxlaunchteam' => 'xbox_launch_team',
9
+ 'kinectlaunchteam' => 'kinect_launch_team',
10
+ 'nxelaunchteam' => 'nxe_launch_team',
11
+ 'recentactivity' => 'recent_activity',
12
+ 'isapp' => 'is_app',
13
+ 'lastplayed' => 'last_played',
14
+ '"friend":' => '"gamertag":',
15
+ 'lastseen' => 'last_seen',
16
+ 'unlockdate' => 'unlock_date'
17
+ }
18
+
19
+ def initialize(app = nil, options = {})
20
+ super(app)
21
+ end
22
+
23
+ def parse(body)
24
+ MAPPINGS.each do |k,v|
25
+ body.gsub!(k, v)
26
+ end
27
+ body
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ # @api private
5
+ module Faraday
6
+ class Response::RaiseXboxLeadersError < Response::Middleware
7
+ # Bit crappy but at the moment there's little to be done about it, I have
8
+ # suggested to vendor that the API use HTTP response codes
9
+ ERROR_MAP = {
10
+ 'The gameid supplied was not valid.' => Gamertag::InvalidGameId,
11
+ 'The gamertag supplied was not valid.' => Gamertag::InvalidGamertag,
12
+ 'The gamertag supplied does not exist on Xbox Live.' => Gamertag::GamertagNotFound,
13
+ 'The gamertag supplied has never played this game or does not exist on Xbox Live.' => Gamertag::AchievementNotFound,
14
+ "No friends found, or friend's list is set to private." => Gamertag::FriendsNotFound
15
+ }
16
+
17
+ def on_complete(response)
18
+ key = response[:body]['data']['message']
19
+ raise ERROR_MAP[key].new(response) if ERROR_MAP.has_key? key
20
+ end
21
+ end
22
+ end
@@ -1,11 +1,22 @@
1
- require 'net/http'
2
- require 'date'
3
- require 'json'
4
- require 'hashie'
5
- require 'nokogiri'
1
+ require 'gamertag/configuration'
2
+ require 'gamertag/error'
3
+ require 'gamertag/client'
6
4
 
7
- require 'gamertag/simple_profile'
8
- require 'gamertag/friends'
9
- require 'gamertag/played_games'
10
- require 'gamertag/profile'
11
- require 'gamertag/version'
5
+ module Gamertag
6
+ extend Configuration
7
+
8
+ class << self
9
+ # Alias for Gamertag::Client.new
10
+ #
11
+ # @return [Gamertag::Client]
12
+ def new(opts={})
13
+ Gamertag::Client.new(opts)
14
+ end
15
+
16
+ # Delegate calls to Gamertag::Client instance
17
+ def method_missing(method, *args, &block)
18
+ return super unless new.respond_to?(method)
19
+ new.send(method, *args, &block)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'gamertag/connection'
2
+
3
+ require 'gamertag/client/profile'
4
+ require 'gamertag/client/games'
5
+ require 'gamertag/client/friends'
6
+ require 'gamertag/client/achievements'
7
+
8
+ module Gamertag
9
+ class Client
10
+ attr_accessor(*Configuration::OPTION_KEYS)
11
+
12
+ def initialize(opts={})
13
+ options = Gamertag.options.merge(opts)
14
+ Configuration::OPTION_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ include Gamertag::Connection
20
+ include Gamertag::Client::Profile
21
+ include Gamertag::Client::Friends
22
+ include Gamertag::Client::Games
23
+ include Gamertag::Client::Achievements
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module Gamertag
2
+ class Client
3
+ module Achievements
4
+ # Retrieve the achievements for the user
5
+ #
6
+ # @see https://www.xboxleaders.com/examples/#achievements
7
+ # @param gamertag [string] User's gamertag
8
+ # @param game_id [Fixnum] The Game ID
9
+ # @return [Array<Hashie::Mash>] A list of achievements for the specified game
10
+ def achievements(gamertag, game_id)
11
+ get('/achievements.json', :gamertag => gamertag, :gameid => game_id).data.achievements
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Gamertag
2
+ class Client
3
+ module Friends
4
+ # Retrieve the friends of the user
5
+ #
6
+ # @see https://www.xboxleaders.com/examples/#friends
7
+ # @param gamertag [String] User's gamertag
8
+ # @return [Array<Hashie::Mash>] A list of friends
9
+ def friends(gamertag)
10
+ get('/friends.json', :gamertag => gamertag).data.friends
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ module Gamertag
2
+ class Client
3
+ module Games
4
+ # Retrieve the games played by the user
5
+ #
6
+ # @see https://www.xboxleaders.com/examples/#games
7
+ # @param gamertag [String] User's gamertag
8
+ # @return [Array<Hashie::Mash>] List of the games played
9
+ def games(gamertag)
10
+ get('/games.json', :gamertag => gamertag).data.games
11
+ end
12
+
13
+ # Retrieve the potential gamerscore for the user
14
+ #
15
+ # @see https://www.xboxleaders.com/examples/#games
16
+ # @param gamertag [String] User's gamertag
17
+ # @return [Fixnum] The score the user has achieved
18
+ def potential_gamerscore(gamertag)
19
+ get('/games.json', :gamertag => gamertag).data.gamerscore.total
20
+ end
21
+
22
+ # Retrieve the number of achievements the user could achieve from the collection of games that they have played at some point
23
+ #
24
+ # @see https://www.xboxleaders.com/examples/#games
25
+ # @param gamertag [String] User's gamertag
26
+ # @return [Fixnum] The potential achievement count for the user
27
+ def potential_achievement_count(gamertag)
28
+ get('/games.json', :gamertag => gamertag).data.achievements.total
29
+ end
30
+
31
+ # Retrieve the number of achievements the user has actually achieved from the collection of games that they have played
32
+ #
33
+ # @see https://www.xboxleaders.com/examples/#games
34
+ # @param gamertag [String] User's gamertag
35
+ # @return [Fixnum] The actual achievement count for the user
36
+ def achievement_count(gamertag)
37
+ get('/games.json', :gamertag => gamertag).data.achievements.current
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ module Gamertag
2
+ class Client
3
+ module Profile
4
+ # Retrieve the profile for the user
5
+ #
6
+ # @see https://www.xboxleaders.com/examples/#profile
7
+ # @param gamertag [string] User's gamertag
8
+ # @return <Hashie::Mash> The user's profile
9
+ def profile(gamertag)
10
+ get('/profile.json', :gamertag => gamertag).data
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,48 @@
1
+ require 'faraday'
2
+ require 'gamertag/version'
3
+
4
+ module Gamertag
5
+ module Configuration
6
+ OPTION_KEYS = [
7
+ :endpoint_url,
8
+ :api_version,
9
+ :adapter
10
+ ]
11
+
12
+ DEFAULT_ENDPOINT_URL = 'https://www.xboxleaders.com'
13
+ DEFAULT_API_VERSION = '2.0'
14
+ DEFAULT_ADAPTER = Faraday.default_adapter
15
+
16
+ attr_accessor(*OPTION_KEYS)
17
+
18
+ def self.extended(base)
19
+ base.defaults
20
+ end
21
+
22
+ def configure
23
+ yield self
24
+ end
25
+
26
+ def options
27
+ OPTION_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
28
+ end
29
+
30
+ def defaults
31
+ self.endpoint_url = DEFAULT_ENDPOINT_URL
32
+ self.api_version = DEFAULT_API_VERSION
33
+ self.adapter = DEFAULT_ADAPTER
34
+ end
35
+
36
+ def adapter=(adapter)
37
+ @adapter = adapter
38
+ end
39
+
40
+ def endpoint_url=(endpoint_url)
41
+ @endpoint_url = endpoint_url
42
+ end
43
+
44
+ def api_version=(api_version)
45
+ @api_version = api_version
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/response/raise_xbox_leaders_error'
3
+ require 'faraday/response/cleanup_xbox_leaders_naming'
4
+
5
+ module Gamertag
6
+ # @private
7
+ module Connection
8
+ def get(path, params={})
9
+ conn = Faraday.new(:url => endpoint_url) do |faraday|
10
+ faraday.use Faraday::Response::RaiseXboxLeadersError
11
+ faraday.use Faraday::Response::Mashify
12
+ faraday.use Faraday::Response::ParseJson
13
+ faraday.use Faraday::Response::CleanupXboxLeadersNaming
14
+
15
+ faraday.adapter adapter
16
+ end
17
+
18
+ response = conn.get "/api/#{api_version}#{path}", params
19
+ response.body
20
+ end
21
+ end
22
+ end