halo-reach-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Add dependencies to develop your gem here.
4
+ # Include everything needed to run rake, tests, features, etc.
5
+ group :development do
6
+ gem "bundler", "~> 1.0.0"
7
+ gem "jeweler", "~> 1.5.1"
8
+ gem "rcov", ">= 0"
9
+ end
10
+
11
+ gem 'httparty'
12
+ gem 'json'
13
+
14
+ group :test do
15
+ gem 'fakeweb'
16
+ gem 'mocha'
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.6)
5
+ fakeweb (1.2.8)
6
+ git (1.2.5)
7
+ httparty (0.5.2)
8
+ crack (= 0.1.6)
9
+ jeweler (1.5.1)
10
+ bundler (~> 1.0.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ json (1.4.6)
14
+ mocha (0.9.8)
15
+ rake
16
+ rake (0.8.7)
17
+ rcov (0.8.1.2.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.0.0)
24
+ fakeweb
25
+ httparty
26
+ jeweler (~> 1.5.1)
27
+ json
28
+ mocha
29
+ rcov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 David Czarnecki
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = Halo::Reach::API
2
+
3
+ Ruby gem for interacting with the Halo:Reach API
4
+
5
+ * Official: http://www.bungie.net/fanclub/statsapi/Group/Resources/Article.aspx?cid=545064
6
+ * Unofficial wiki: http://www.haloreachapi.net/wiki/Available_methods
7
+
8
+ == Requirements
9
+
10
+ * HTTParty
11
+ * JSON
12
+ * FakeWeb (testing)
13
+ * Mocha (testing)
14
+
15
+ == Install
16
+
17
+ * sudo gem install halo-reach-api
18
+
19
+ == Example
20
+
21
+ >> require 'halo-reach-api'
22
+ => true
23
+ >> halo_reach_api = Halo::Reach::API.new('xxx') # An API key will cost you 750 MS points/year for your application
24
+ => #<Halo::Reach::API:0x1015ec2c8 @token="xxx", @api_url="http://www.bungie.net/api/reach/reachapijson.svc/">
25
+
26
+ Look at the unofficial wiki for complete descriptions of the API calls.
27
+
28
+ == FAQ
29
+
30
+ Q: How do I get an API key?
31
+
32
+ A: You must be a Bungie Pro subscriber. http://www.haloreachapi.net/wiki/API_key
33
+
34
+ Q: Can I have your API key?
35
+
36
+ A: No. You can subscribe to Bungie Pro and generate an API key for your application.
37
+
38
+ Q: Dates are funky and not parsed as dates. For example:
39
+
40
+ >> { "Credits" : 1000,
41
+ "Description" : "Earn 20 assists today in multiplayer Matchmaking.",
42
+ "ExpirationDate" : "/Date(1290510000000-0800)/",
43
+ "IsWeeklyChallenge" : false,
44
+ "Name" : "Pass the Rock"
45
+ },
46
+
47
+ A: Yes they are funky. Yes. They. Are. I'm considering how I would actually parse that out. I may write a helper method on the API class to take a date like that
48
+ and parse it into something useable. Or you can submit a patch for that?!
49
+
50
+ == Contributing to halo-reach-api
51
+
52
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
53
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
54
+ * Fork the project
55
+ * Start a feature/bugfix branch
56
+ * Commit and push until you are happy with your contribution
57
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
58
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
59
+
60
+ == Copyright
61
+
62
+ Copyright (c) 2010 David Czarnecki. See LICENSE.txt for further details.
63
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "halo-reach-api"
16
+ gem.homepage = "http://github.com/czarneckid/halo-reach-api"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby gem for interacting with the Halo:Reach API}
19
+ gem.description = %Q{Ruby gem for interacting with the Halo:Reach API}
20
+ gem.email = "dczarnecki@agoragames.com"
21
+ gem.authors = ["David Czarnecki"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "halo-reach-api #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,82 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{halo-reach-api}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Czarnecki"]
12
+ s.date = %q{2010-11-22}
13
+ s.description = %q{Ruby gem for interacting with the Halo:Reach API}
14
+ s.email = %q{dczarnecki@agoragames.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "halo-reach-api.gemspec",
29
+ "lib/halo-reach-api.rb",
30
+ "test/fakeweb/get_current_challenges.json",
31
+ "test/fakeweb/get_file_details.json",
32
+ "test/fakeweb/get_game_details.json",
33
+ "test/fakeweb/get_game_history.json",
34
+ "test/fakeweb/get_game_metadata.json",
35
+ "test/fakeweb/get_player_details_with_no_stats.json",
36
+ "test/fakeweb/get_player_details_with_stats_by_map.json",
37
+ "test/fakeweb/get_player_details_with_stats_by_playlist.json",
38
+ "test/fakeweb/get_player_file_set_files.json",
39
+ "test/fakeweb/get_player_file_sets.json",
40
+ "test/fakeweb/get_player_file_share.json",
41
+ "test/fakeweb/get_player_recent_screenshots.json",
42
+ "test/fakeweb/get_player_rendered_videos.json",
43
+ "test/fakeweb/reach_file_search.json",
44
+ "test/helper.rb",
45
+ "test/test_halo-reach-api.rb"
46
+ ]
47
+ s.homepage = %q{http://github.com/czarneckid/halo-reach-api}
48
+ s.licenses = ["MIT"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.7}
51
+ s.summary = %q{Ruby gem for interacting with the Halo:Reach API}
52
+ s.test_files = [
53
+ "test/helper.rb",
54
+ "test/test_halo-reach-api.rb"
55
+ ]
56
+
57
+ if s.respond_to? :specification_version then
58
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
63
+ s.add_runtime_dependency(%q<json>, [">= 0"])
64
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
66
+ s.add_development_dependency(%q<rcov>, [">= 0"])
67
+ else
68
+ s.add_dependency(%q<httparty>, [">= 0"])
69
+ s.add_dependency(%q<json>, [">= 0"])
70
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
72
+ s.add_dependency(%q<rcov>, [">= 0"])
73
+ end
74
+ else
75
+ s.add_dependency(%q<httparty>, [">= 0"])
76
+ s.add_dependency(%q<json>, [">= 0"])
77
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
78
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
79
+ s.add_dependency(%q<rcov>, [">= 0"])
80
+ end
81
+ end
82
+
@@ -0,0 +1,113 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module Halo
6
+ module Reach
7
+ class API
8
+ include HTTParty
9
+
10
+ VERSION = '1.0.0'.freeze
11
+ API_URL = 'http://www.bungie.net/api/reach/reachapijson.svc/'
12
+
13
+ DEFAULT_HEADERS = {
14
+ 'User-Agent' => "Halo:Reach API gem #{VERSION}"
15
+ }
16
+
17
+ headers(DEFAULT_HEADERS)
18
+
19
+ format(:json)
20
+
21
+ attr_accessor :api_url
22
+ attr_accessor :token
23
+
24
+ def initialize(token, api_url = API_URL)
25
+ @token = token
26
+ @api_url = api_url
27
+ end
28
+
29
+ def debug(location = $stderr)
30
+ self.class.debug_output(location)
31
+ end
32
+
33
+ def set_http_headers(http_headers = {})
34
+ http_headers.merge!(DEFAULT_HEADERS)
35
+ headers(http_headers)
36
+ end
37
+
38
+ def get_game_metadata
39
+ game_metadata_uri = "game/metadata/#{@token}"
40
+ self.class.get(@api_url + game_metadata_uri)
41
+ end
42
+
43
+ def get_current_challenges
44
+ current_challenges_uri = "game/challenges/#{@token}"
45
+ self.class.get(@api_url + current_challenges_uri)
46
+ end
47
+
48
+ def get_game_details(game_id)
49
+ get_game_details_uri = "game/details/#{@token}/#{game_id}"
50
+ self.class.get(@api_url + get_game_details_uri)
51
+ end
52
+
53
+ def get_game_history(gamertag, variant_class = 'Unknown', page = 0)
54
+ get_game_history_uri = "player/gamehistory/#{@token}/#{URI.escape(gamertag)}/#{variant_class}/#{page}"
55
+ self.class.get(@api_url + get_game_history_uri)
56
+ end
57
+
58
+ def get_player_details_with_stats_by_map(gamertag)
59
+ get_player_details_with_stats_by_map_uri = "player/details/bymap/#{@token}/#{URI.escape(gamertag)}"
60
+ self.class.get(@api_url + get_player_details_with_stats_by_map_uri)
61
+ end
62
+
63
+ def get_player_details_with_stats_by_playlist(gamertag)
64
+ get_player_details_with_stats_by_playlist_uri = "player/details/byplaylist/#{@token}/#{URI.escape(gamertag)}"
65
+ self.class.get(@api_url + get_player_details_with_stats_by_playlist_uri)
66
+ end
67
+
68
+ def get_player_details_with_no_stats(gamertag)
69
+ get_player_details_with_no_stats_uri = "player/details/nostats/#{@token}/#{URI.escape(gamertag)}"
70
+ self.class.get(@api_url + get_player_details_with_no_stats_uri)
71
+ end
72
+
73
+ def get_player_file_share(gamertag)
74
+ get_player_file_share_uri = "file/share/#{@token}/#{URI.escape(gamertag)}"
75
+ self.class.get(@api_url + get_player_file_share_uri)
76
+ end
77
+
78
+ def get_file_details(file_id)
79
+ get_file_details_uri = "file/details/#{@token}/#{file_id}"
80
+ self.class.get(@api_url + get_file_details_uri)
81
+ end
82
+
83
+ def get_player_recent_screenshots(gamertag)
84
+ get_player_recent_screenshots_uri = "file/screenshots/#{@token}/#{URI.escape(gamertag)}"
85
+ self.class.get(@api_url + get_player_recent_screenshots_uri)
86
+ end
87
+
88
+ def get_player_file_sets(gamertag)
89
+ get_player_file_sets_uri = "file/sets/#{@token}/#{URI.escape(gamertag)}"
90
+ self.class.get(@api_url + get_player_file_sets_uri)
91
+ end
92
+
93
+ def get_player_file_set_files(gamertag, file_set_id)
94
+ get_player_file_set_files_uri = "file/sets/files/#{@token}/#{URI.escape(gamertag)}/#{file_set_id}"
95
+ self.class.get(@api_url + get_player_file_set_files_uri)
96
+ end
97
+
98
+ def get_player_rendered_videos(gamertag, page = 0)
99
+ get_player_rendered_videos_uri = "file/videos/#{@token}/#{URI.escape(gamertag)}/#{page}"
100
+ self.class.get(@api_url + get_player_rendered_videos_uri)
101
+ end
102
+
103
+ def reach_file_search(file_category, map_filter, engine_filter, date_filter, sort_filter, tags, page = 0)
104
+ reach_file_search_uri = "file/search/#{@token}/#{file_category}/#{map_filter}/#{engine_filter}/#{date_filter}/#{sort_filter}/#{page}"
105
+ unless tags.nil?
106
+ reach_file_search_uri += "?tags=#{URI.escape(tags)}"
107
+ end
108
+
109
+ self.class.get(@api_url + reach_file_search_uri)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,34 @@
1
+ { "Daily" : [ { "Credits" : 1000,
2
+ "Description" : "Kill 100 enemies in multiplayer Matchmaking.",
3
+ "ExpirationDate" : "/Date(1290510000000-0800)/",
4
+ "IsWeeklyChallenge" : false,
5
+ "Name" : "Gunslinger"
6
+ },
7
+ { "Credits" : 1000,
8
+ "Description" : "Earn 20 assists today in multiplayer Matchmaking.",
9
+ "ExpirationDate" : "/Date(1290510000000-0800)/",
10
+ "IsWeeklyChallenge" : false,
11
+ "Name" : "Pass the Rock"
12
+ },
13
+ { "Credits" : 1400,
14
+ "Description" : "Complete a Campaign mission on Heroic with Cloud and Famine on.",
15
+ "ExpirationDate" : "/Date(1290510000000-0800)/",
16
+ "IsWeeklyChallenge" : false,
17
+ "Name" : "Foggy Notion"
18
+ },
19
+ { "Credits" : 1800,
20
+ "Description" : "Kill 250 Grunts in Firefight Matchmaking.",
21
+ "ExpirationDate" : "/Date(1290510000000-0800)/",
22
+ "IsWeeklyChallenge" : false,
23
+ "Name" : "A Satisfied Thirst"
24
+ }
25
+ ],
26
+ "Weekly" : [ { "Credits" : 16000,
27
+ "Description" : "Complete 16 Daily Challenges this week.",
28
+ "ExpirationDate" : "/Date(1291028400000-0800)/",
29
+ "IsWeeklyChallenge" : true,
30
+ "Name" : "Dedication/Time"
31
+ } ],
32
+ "reason" : "Okay",
33
+ "status" : 0
34
+ }
@@ -0,0 +1 @@
1
+ {"Files":[{"ScreenshotMediumUrl":"/Stats/Reach/Screenshot.ashx?fid=546727&size=medium", "FileDetailsUrl":"/stats/reach/filedetails.aspx?fid=546727", "CreateDate":"/Date(1284664679000-0700)/", "ScreenshotThumbnailUrl":"/Stats/Reach/Screenshot.ashx?fid=546727", "RenderedWMVPathHD":nil, "RenderedWMVPath":nil, "RenderJobStatus":nil, "MapId":5070, "FileId":546727, "Title":"Seen The Light?", "Author":"Gamertag", "ScreenshotFullSizeUrl":"/Stats/Reach/Screenshot.ashx?fid=85D1D1186B5621EAD709D287EA30EDA1&size=full", "ModifiedDate":"/Date(1284664679000-0700)/", "FileCategory":"Image", "OriginalAuthor":"Gamertag", "LikesCount":0, "Description":"The Pillar of Autumn on Normal, Thursday September 16, 2010 20:17:17", "DownloadCount":3, "RenderJobResolution":nil}], "FileSets":nil, "reason":"Okay", "status":0}