sc2ranks 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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@sc2ranks
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'httparty'
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.5.2"
9
+ gem "rcov", ">= 0"
10
+ end
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.8)
5
+ git (1.2.5)
6
+ httparty (0.6.1)
7
+ crack (= 0.1.8)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rake (0.8.7)
13
+ rcov (0.9.9)
14
+ shoulda (2.11.3)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.0.0)
21
+ httparty
22
+ jeweler (~> 1.5.2)
23
+ rcov
24
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Christopher Giroir
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.
@@ -0,0 +1,21 @@
1
+ = sc2ranks
2
+
3
+ A gem used to access the api of http://sc2ranks.com
4
+
5
+ Documentation about the api can be found at http://sc2ranks.com/api
6
+
7
+ == Contributing to sc2ranks
8
+
9
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
10
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
11
+ * Fork the project
12
+ * Start a feature/bugfix branch
13
+ * Commit and push until you are happy with your contribution
14
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ * 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.
16
+
17
+ == Copyright
18
+
19
+ Copyright (c) 2011 Christopher Giroir. See LICENSE.txt for
20
+ further details.
21
+
@@ -0,0 +1,54 @@
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 = "sc2ranks"
16
+ gem.homepage = "http://github.com/Kelsin/sc2ranks"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A gem to access the api of sc2ranks.com}
19
+ gem.description = %Q{This gem allows you to access data from http://sc2ranks.com}
20
+ gem.email = "kelsin@valefor.com"
21
+ gem.authors = ["Christopher Giroir"]
22
+ gem.add_runtime_dependency 'httparty', '> 0.6.1'
23
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
24
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "sc2ranks #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,29 @@
1
+ require 'httparty'
2
+ require 'sc2ranks/character'
3
+
4
+ class Sc2ranks
5
+ include HTTParty
6
+ format :xml
7
+ base_uri 'sc2ranks.com'
8
+
9
+ # Constant used to parse bnet profile urls
10
+ RE = %r{http://([a-zA-Z]+)\.battle\.net/sc2/[a-zA-Z0-9]+/profile/([0-9]+)/[01]/([a-zA-Z0-9]+)/}
11
+
12
+ def initialize(key)
13
+ self.class.default_params :appKey => key
14
+ end
15
+
16
+ def character(url)
17
+ parse_bnet_url url
18
+
19
+ data = self.class.get("/api/base/teams/#{@region}/#{@character}.xml")
20
+ Character.new data['hash']
21
+ end
22
+
23
+ def parse_bnet_url(url)
24
+ Sc2ranks::RE =~ url
25
+
26
+ @region = $1
27
+ @character = "#{$3}!#{$2}"
28
+ end
29
+ end
@@ -0,0 +1,90 @@
1
+ class Sc2ranks
2
+ class Character
3
+ attr_reader :region
4
+ attr_reader :name
5
+ attr_reader :bnet_id
6
+ attr_reader :id
7
+ attr_reader :updated_at
8
+ attr_reader :achievement_points
9
+ attr_reader :character_code
10
+ attr_reader :portrait
11
+ attr_reader :teams
12
+
13
+ def initialize(http)
14
+ @region = http['region']
15
+ @name = http['name']
16
+ @bnet_id = http['bnet_id']
17
+ @id = http['id']
18
+ @updated_at = http['updated_at']
19
+ @achievement_points = http['achievement_points']
20
+ @character_code = http['character_code']
21
+
22
+ @portrait = Portrait.new(http['portrait'])
23
+
24
+ @teams = []
25
+ http['teams'].each do |data|
26
+ @teams << Team.new(data)
27
+ end
28
+ end
29
+
30
+ def team(bracket, is_random = false)
31
+ if bracket == 1
32
+ @teams.detect do |team|
33
+ team.bracket == 1
34
+ end
35
+ else
36
+ @teams.select do |team|
37
+ team.bracket == bracket and team.is_random == is_random
38
+ end
39
+ end
40
+ end
41
+
42
+ class Team
43
+ attr_reader :bracket
44
+ attr_reader :is_random
45
+ attr_reader :fav_race
46
+ attr_reader :updated_at
47
+ attr_reader :league
48
+ attr_reader :division
49
+ attr_reader :division_rank
50
+ attr_reader :world_rank
51
+ attr_reader :region_rank
52
+ attr_reader :wins
53
+ attr_reader :losses
54
+ attr_reader :points
55
+ attr_reader :ratio
56
+
57
+ def initialize(http)
58
+ @bracket = http['bracket']
59
+ @is_random = http['is_random']
60
+ @fav_race = http['fav_race']
61
+ @updated_at = http['updated_at']
62
+ @league = http['league']
63
+ @division = http['division']
64
+ @division_rank = http['division_rank']
65
+ @world_rank = http['world_rank']
66
+ @region_rank = http['region_rank']
67
+ @wins = http['wins']
68
+ @losses = http['losses']
69
+ @points = http['points']
70
+ @ratio = http['ratio']
71
+ end
72
+
73
+ def is_random?
74
+ @is_random
75
+ end
76
+ end
77
+
78
+ class Portrait
79
+ attr_reader :icon_id
80
+ attr_reader :column
81
+ attr_reader :row
82
+
83
+ def initialize(http)
84
+ @icon_id = http['icon_id']
85
+ @column = http['column']
86
+ @row = http['row']
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,72 @@
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{sc2ranks}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Christopher Giroir"]
12
+ s.date = %q{2011-01-09}
13
+ s.description = %q{This gem allows you to access data from http://sc2ranks.com}
14
+ s.email = %q{kelsin@valefor.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
+ "lib/sc2ranks.rb",
29
+ "lib/sc2ranks/character.rb",
30
+ "sc2ranks.gemspec",
31
+ "test/helper.rb",
32
+ "test/test_sc2ranks.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/Kelsin/sc2ranks}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{A gem to access the api of sc2ranks.com}
39
+ s.test_files = [
40
+ "test/helper.rb",
41
+ "test/test_sc2ranks.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
50
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ s.add_runtime_dependency(%q<httparty>, ["> 0.6.1"])
55
+ else
56
+ s.add_dependency(%q<httparty>, [">= 0"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ s.add_dependency(%q<httparty>, ["> 0.6.1"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<httparty>, [">= 0"])
65
+ s.add_dependency(%q<shoulda>, [">= 0"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
68
+ s.add_dependency(%q<rcov>, [">= 0"])
69
+ s.add_dependency(%q<httparty>, ["> 0.6.1"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,18 @@
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 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'sc2ranks'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestSc2ranks < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sc2ranks
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Christopher Giroir
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-09 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: :development
37
+ prerelease: false
38
+ name: shoulda
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: 7
75
+ segments:
76
+ - 1
77
+ - 5
78
+ - 2
79
+ version: 1.5.2
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
+ - !ruby/object:Gem::Dependency
96
+ type: :runtime
97
+ prerelease: false
98
+ name: httparty
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">"
103
+ - !ruby/object:Gem::Version
104
+ hash: 5
105
+ segments:
106
+ - 0
107
+ - 6
108
+ - 1
109
+ version: 0.6.1
110
+ requirement: *id006
111
+ description: This gem allows you to access data from http://sc2ranks.com
112
+ email: kelsin@valefor.com
113
+ executables: []
114
+
115
+ extensions: []
116
+
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.rdoc
120
+ files:
121
+ - .document
122
+ - .rvmrc
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE.txt
126
+ - README.rdoc
127
+ - Rakefile
128
+ - VERSION
129
+ - lib/sc2ranks.rb
130
+ - lib/sc2ranks/character.rb
131
+ - sc2ranks.gemspec
132
+ - test/helper.rb
133
+ - test/test_sc2ranks.rb
134
+ has_rdoc: true
135
+ homepage: http://github.com/Kelsin/sc2ranks
136
+ licenses:
137
+ - MIT
138
+ post_install_message:
139
+ rdoc_options: []
140
+
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project:
164
+ rubygems_version: 1.3.7
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: A gem to access the api of sc2ranks.com
168
+ test_files:
169
+ - test/helper.rb
170
+ - test/test_sc2ranks.rb