halo-reach-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,208 @@
1
+ require 'helper'
2
+ require 'fakeweb'
3
+ require 'mocha'
4
+
5
+ class TestHaloReachApi < Test::Unit::TestCase
6
+ def setup
7
+ FakeWeb.allow_net_connect = false
8
+ end
9
+
10
+ def teardown
11
+ FakeWeb.allow_net_connect = true
12
+ end
13
+
14
+ def test_api_version
15
+ assert_equal '1.0.0', Halo::Reach::API::VERSION
16
+ end
17
+
18
+ def test_can_set_token
19
+ halo_reach_api = Halo::Reach::API.new('apikeytoken')
20
+
21
+ assert_equal 'apikeytoken', halo_reach_api.token
22
+ end
23
+
24
+ def test_can_set_api_url
25
+ halo_reach_api = Halo::Reach::API.new('apikeytoken', 'http://some.api.url')
26
+
27
+ assert_equal 'http://some.api.url', halo_reach_api.api_url
28
+ end
29
+
30
+ def test_can_set_http_headers
31
+ halo_reach_api = Halo::Reach::API.new('apikeytoken')
32
+ halo_reach_api.expects(:headers).at_least_once
33
+
34
+ halo_reach_api.set_http_headers({'Accept' => 'application/json'})
35
+ end
36
+
37
+ def test_get_game_metadata
38
+ FakeWeb.register_uri(:get,
39
+ 'http://www.bungie.net/api/reach/reachapijson.svc/game/metadata/XXX',
40
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_game_metadata.json'),
41
+ :content_type => "application/json")
42
+
43
+ halo_reach_api = Halo::Reach::API.new('XXX')
44
+ halo_reach_api_response = halo_reach_api.get_game_metadata
45
+
46
+ assert_equal 30, halo_reach_api_response['Data']['AllMapsById'].size
47
+ end
48
+
49
+ def test_get_current_challenges
50
+ FakeWeb.register_uri(:get,
51
+ 'http://www.bungie.net/api/reach/reachapijson.svc/game/challenges/XXX',
52
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_current_challenges.json'),
53
+ :content_type => "application/json")
54
+
55
+ halo_reach_api = Halo::Reach::API.new('XXX')
56
+ halo_reach_api_response = halo_reach_api.get_current_challenges
57
+
58
+ assert_equal 1, halo_reach_api_response['Weekly'].size
59
+ assert_equal 4, halo_reach_api_response['Daily'].size
60
+ end
61
+
62
+ def test_get_game_history
63
+ FakeWeb.register_uri(:get,
64
+ 'http://www.bungie.net/api/reach/reachapijson.svc/player/gamehistory/XXX/MajorNelson/Unknown/0',
65
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_game_history.json'),
66
+ :content_type => "application/json")
67
+
68
+ halo_reach_api = Halo::Reach::API.new('XXX')
69
+ halo_reach_api_response = halo_reach_api.get_game_history('MajorNelson')
70
+
71
+ assert_equal 25, halo_reach_api_response['RecentGames'].size
72
+ end
73
+
74
+ def test_get_game_details
75
+ FakeWeb.register_uri(:get,
76
+ 'http://www.bungie.net/api/reach/reachapijson.svc/game/details/XXX/666',
77
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_game_details.json'),
78
+ :content_type => "application/json")
79
+
80
+ halo_reach_api = Halo::Reach::API.new('XXX')
81
+ halo_reach_api_response = halo_reach_api.get_game_details(666)
82
+
83
+ assert_equal 666, halo_reach_api_response['GameDetails']['GameId']
84
+ end
85
+
86
+ def test_get_player_details_with_stats_by_map
87
+ FakeWeb.register_uri(:get,
88
+ 'http://www.bungie.net/api/reach/reachapijson.svc/player/details/bymap/XXX/foobar',
89
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_player_details_with_stats_by_map.json'),
90
+ :content_type => "application/json")
91
+
92
+ halo_reach_api = Halo::Reach::API.new('XXX')
93
+ halo_reach_api_response = halo_reach_api.get_player_details_with_stats_by_map('foobar')
94
+
95
+ assert_not_nil halo_reach_api_response['StatisticsByMap']
96
+ end
97
+
98
+ def test_get_player_details_with_stats_by_playlist
99
+ FakeWeb.register_uri(:get,
100
+ 'http://www.bungie.net/api/reach/reachapijson.svc/player/details/byplaylist/XXX/foobar',
101
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_player_details_with_stats_by_map.json'),
102
+ :content_type => "application/json")
103
+
104
+ halo_reach_api = Halo::Reach::API.new('XXX')
105
+ halo_reach_api_response = halo_reach_api.get_player_details_with_stats_by_map('foobar')
106
+
107
+ assert_not_nil halo_reach_api_response['StatisticsByPlaylist']
108
+ end
109
+
110
+ def test_get_player_details_with_no_stats
111
+ FakeWeb.register_uri(:get,
112
+ 'http://www.bungie.net/api/reach/reachapijson.svc/player/details/nostats/XXX/foobar',
113
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_player_details_with_no_stats.json'),
114
+ :content_type => "application/json")
115
+
116
+ halo_reach_api = Halo::Reach::API.new('XXX')
117
+ halo_reach_api_response = halo_reach_api.get_player_details_with_no_stats('foobar')
118
+
119
+ assert_equal 'None', halo_reach_api_response['Player']['CampaignProgressCoop']
120
+ end
121
+
122
+ def test_get_player_file_share
123
+ FakeWeb.register_uri(:get,
124
+ 'http://www.bungie.net/api/reach/reachapijson.svc/file/share/XXX/Gamertag',
125
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_player_file_share.json'),
126
+ :content_type => "application/json")
127
+
128
+ halo_reach_api = Halo::Reach::API.new('XXX')
129
+ halo_reach_api_response = halo_reach_api.get_player_file_share('Gamertag')
130
+
131
+ assert_equal 3, halo_reach_api_response['Files'].size
132
+ end
133
+
134
+ def test_get_file_details
135
+ FakeWeb.register_uri(:get,
136
+ 'http://www.bungie.net/api/reach/reachapijson.svc/file/details/XXX/666',
137
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_file_details.json'),
138
+ :content_type => "application/json")
139
+
140
+ halo_reach_api = Halo::Reach::API.new('XXX')
141
+ halo_reach_api_response = halo_reach_api.get_file_details(666)
142
+
143
+ assert_equal 3, halo_reach_api_response['Files'][0]['DownloadCount']
144
+ end
145
+
146
+ def test_get_player_recent_screenshots
147
+ FakeWeb.register_uri(:get,
148
+ 'http://www.bungie.net/api/reach/reachapijson.svc/file/screenshots/XXX/Gamertag',
149
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_player_recent_screenshots.json'),
150
+ :content_type => "application/json")
151
+
152
+ halo_reach_api = Halo::Reach::API.new('XXX')
153
+ halo_reach_api_response = halo_reach_api.get_player_recent_screenshots('Gamertag')
154
+
155
+ assert_equal 5, halo_reach_api_response['Files'].size
156
+ end
157
+
158
+ def test_get_player_file_sets
159
+ FakeWeb.register_uri(:get,
160
+ 'http://www.bungie.net/api/reach/reachapijson.svc/file/sets/XXX/Gamertag',
161
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_player_file_sets.json'),
162
+ :content_type => "application/json")
163
+
164
+ halo_reach_api = Halo::Reach::API.new('XXX')
165
+ halo_reach_api_response = halo_reach_api.get_player_file_sets('Gamertag')
166
+
167
+ # FIXME: Need a gamertag with actual file sets
168
+ assert_equal 0, halo_reach_api_response['FileSets'].size
169
+ end
170
+
171
+ def test_get_player_file_sets
172
+ FakeWeb.register_uri(:get,
173
+ 'http://www.bungie.net/api/reach/reachapijson.svc/file/sets/files/XXX/Gamertag/0',
174
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_player_file_set_files.json'),
175
+ :content_type => "application/json")
176
+
177
+ halo_reach_api = Halo::Reach::API.new('XXX')
178
+ halo_reach_api_response = halo_reach_api.get_player_file_set_files('Gamertag', 0)
179
+
180
+ # FIXME: Need a gamertag with actual file sets and files
181
+ assert_equal 'Player not found.', halo_reach_api_response['reason']
182
+ end
183
+
184
+ def test_get_player_rendered_videos
185
+ FakeWeb.register_uri(:get,
186
+ 'http://www.bungie.net/api/reach/reachapijson.svc/file/videos/XXX/Gamertag/0',
187
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'get_player_rendered_videos.json'),
188
+ :content_type => "application/json")
189
+
190
+ halo_reach_api = Halo::Reach::API.new('XXX')
191
+ halo_reach_api_response = halo_reach_api.get_player_rendered_videos('Gamertag', 0)
192
+
193
+ # FIXME: Need a gamertag with actual rendered videos
194
+ assert_equal 0, halo_reach_api_response['Files'].size
195
+ end
196
+
197
+ def test_reach_file_search
198
+ FakeWeb.register_uri(:get,
199
+ 'http://www.bungie.net/api/reach/reachapijson.svc/file/search/XXX/GameClip/null/null/Week/MostDownloads/0',
200
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'reach_file_search.json'),
201
+ :content_type => "application/json")
202
+
203
+ halo_reach_api = Halo::Reach::API.new('XXX')
204
+ halo_reach_api_response = halo_reach_api.reach_file_search('GameClip', 'null', 'null', 'Week', 'MostDownloads', nil, 0)
205
+
206
+ assert_equal 25, halo_reach_api_response['Files'].size
207
+ end
208
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: halo-reach-api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - David Czarnecki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-22 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: httparty
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ prerelease: false
38
+ name: json
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ type: :development
51
+ prerelease: false
52
+ name: bundler
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 23
59
+ segments:
60
+ - 1
61
+ - 0
62
+ - 0
63
+ version: 1.0.0
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ type: :development
67
+ prerelease: false
68
+ name: jeweler
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 1
75
+ segments:
76
+ - 1
77
+ - 5
78
+ - 1
79
+ version: 1.5.1
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ type: :development
83
+ prerelease: false
84
+ name: rcov
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirement: *id005
95
+ description: Ruby gem for interacting with the Halo:Reach API
96
+ email: dczarnecki@agoragames.com
97
+ executables: []
98
+
99
+ extensions: []
100
+
101
+ extra_rdoc_files:
102
+ - LICENSE.txt
103
+ - README.rdoc
104
+ files:
105
+ - .document
106
+ - .rvmrc
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.rdoc
111
+ - Rakefile
112
+ - VERSION
113
+ - halo-reach-api.gemspec
114
+ - lib/halo-reach-api.rb
115
+ - test/fakeweb/get_current_challenges.json
116
+ - test/fakeweb/get_file_details.json
117
+ - test/fakeweb/get_game_details.json
118
+ - test/fakeweb/get_game_history.json
119
+ - test/fakeweb/get_game_metadata.json
120
+ - test/fakeweb/get_player_details_with_no_stats.json
121
+ - test/fakeweb/get_player_details_with_stats_by_map.json
122
+ - test/fakeweb/get_player_details_with_stats_by_playlist.json
123
+ - test/fakeweb/get_player_file_set_files.json
124
+ - test/fakeweb/get_player_file_sets.json
125
+ - test/fakeweb/get_player_file_share.json
126
+ - test/fakeweb/get_player_recent_screenshots.json
127
+ - test/fakeweb/get_player_rendered_videos.json
128
+ - test/fakeweb/reach_file_search.json
129
+ - test/helper.rb
130
+ - test/test_halo-reach-api.rb
131
+ has_rdoc: true
132
+ homepage: http://github.com/czarneckid/halo-reach-api
133
+ licenses:
134
+ - MIT
135
+ post_install_message:
136
+ rdoc_options: []
137
+
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ requirements: []
159
+
160
+ rubyforge_project:
161
+ rubygems_version: 1.3.7
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Ruby gem for interacting with the Halo:Reach API
165
+ test_files:
166
+ - test/helper.rb
167
+ - test/test_halo-reach-api.rb