sc2ranksapi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .idea/
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'httparty', '~> 0.11.0'
5
+ gem 'rspec', '~>2.12.0'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Wong
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Sc2ranksapi
2
+
3
+ This gem is used to access the sc2ranks api as described here. http://www.sc2ranks.com/api.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sc2ranksapi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sc2ranksapi
18
+
19
+ ## Usage
20
+
21
+ Just instantiate a new instance of the api, and make a character with the url from battle.net and you're good to go
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ require 'httparty'
2
+ require 'sc2ranksapi/character'
3
+
4
+ class Sc2RanksApi
5
+ include HTTParty
6
+ format :json
7
+ base_uri "sc2ranks.com"
8
+
9
+ BNET_REGEX = %r{http://([a-zA-Z]+)\.battle\.net/sc2/[a-zA-Z0-9]+/profile/([0-9]+)/[01]/([a-zA-Z0-9]+)/}
10
+
11
+ def initialize(appKey)
12
+ self.class.default_params :appKey => appKey
13
+ end
14
+
15
+ def character(url)
16
+ region, char = parse_bnet_url url
17
+
18
+ json_response = self.class.get("/api/base/teams/#{region}/#{char}.json")
19
+
20
+ Character.new json_response.parsed_response
21
+ end
22
+
23
+ def parse_bnet_url(url)
24
+ Sc2RanksApi::BNET_REGEX =~ url
25
+ return $1, "#{$3}!#{$2}"
26
+ end
27
+
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'sc2ranksapi/team'
2
+
3
+ class Sc2RanksApi
4
+ class Character
5
+ attr_reader :teams, :portrait, :region, :name, :achievement_points, :updated_at
6
+
7
+ def initialize(data)
8
+ @achievement_points = data["achievement_points"]
9
+ @name = data["name"]
10
+ @region = data["region"]
11
+ @updated_at = data["updated_at"]
12
+
13
+ add_teams data["teams"]
14
+ end
15
+
16
+ def add_teams(teams_data)
17
+ @teams = Hash.new if @teams.nil?
18
+
19
+ teams_data.each do |team_data|
20
+ team = Team.new(team_data)
21
+ bracket = team_data["bracket"]
22
+ @teams[bracket] = Array.new if @teams[bracket].nil?
23
+ @teams[bracket] << team
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ class Sc2RanksApi
2
+ class Team
3
+ attr_reader :world_rank, :region_rank, :division, :division_rank, :league, :points, :wins, :losses, :favorite_race
4
+
5
+ def initialize(data)
6
+ @world_rank = data["world_rank"]
7
+ @region_rank = data["region_rank"]
8
+ @division_rank = data["division_rank"]
9
+ @division = data["division"]
10
+ @league = data["league"]
11
+ @points = data["points"]
12
+ @wins = data["wins"]
13
+ @losses = data["losses"]
14
+ @favorite_race = data["favorite_race"]
15
+ end
16
+
17
+ def ratio
18
+ @wins/(@wins + @losses)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ class Sc2RanksApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sc2ranksapi/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Andrew Wong"]
6
+ gem.email = ["iamawong@outlook.com"]
7
+ gem.homepage = "https://github.com/iamawong/sc2ranksapi"
8
+ gem.description = "This gem allows you to access data from http://sc2ranks.com."
9
+ gem.summary = "Gem to get Starcraft2 information about players."
10
+ gem.version = Sc2RanksApi::VERSION
11
+
12
+ gem.add_dependency "httparty", "~> 0.11.0"
13
+
14
+ gem.files = `git ls-files`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.name = "sc2ranksapi"
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,37 @@
1
+ require '../spec_helper'
2
+
3
+ describe Sc2RanksApi::Character do
4
+ before :each do
5
+ data = {
6
+ "achievement_points" => 1,
7
+ "name" => "iamawong",
8
+ "region" => "eu",
9
+ "updated_at" => 123456,
10
+ "teams" => []
11
+ }
12
+
13
+ @character = Sc2RanksApi::Character.new(data)
14
+ end
15
+
16
+ it 'should have one achievement point' do
17
+ @character.achievement_points.should eq 1
18
+ end
19
+
20
+ it 'should have correct name' do
21
+ @character.name.should eq 'iamawong'
22
+ end
23
+
24
+ it 'should have european region' do
25
+ @character.region.should eq 'eu'
26
+ end
27
+
28
+ it 'should be updated time correct' do
29
+ @character.updated_at.should eq 123456
30
+ end
31
+
32
+ it 'should have empty teams' do
33
+ @character.teams.should be_an_instance_of Hash
34
+
35
+ @character.teams.should be_empty
36
+ end
37
+ end
@@ -0,0 +1,34 @@
1
+ require '../spec_helper'
2
+
3
+ describe Sc2RanksApi::Team do
4
+ before(:each) do
5
+ data = {
6
+ "world_rank" => 1,
7
+ "region_rank" => 2,
8
+ "division" => "alpha",
9
+ "division_rank" => 3,
10
+ "league" => 'centauri',
11
+ "points" => 4,
12
+ "wins" => 5,
13
+ "losses" => 6,
14
+ "favorite_race" => 'zerg'
15
+ }
16
+ @team = Sc2RanksApi::Team.new(data)
17
+ end
18
+
19
+ it 'should parse data' do
20
+ @team.world_rank.should eq 1
21
+ @team.region_rank.should eq 2
22
+ @team.division.should eq "alpha"
23
+ @team.division_rank.should eq 3
24
+ @team.league.should eq 'centauri'
25
+ @team.points.should eq 4
26
+ @team.wins.should eq 5
27
+ @team.losses.should eq 6
28
+ @team.favorite_race.should eq 'zerg'
29
+ end
30
+
31
+ it 'should have correct ratio' do
32
+ @team.ratio.should eq 5/(5+6)
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sc2RanksApi do
4
+ before(:each) do
5
+ @api = Sc2RanksApi.new "sc2ranksapitest.com"
6
+ end
7
+
8
+ it 'should have default params of hash' do
9
+ @api.class.default_params.should be_an_instance_of Hash
10
+ end
11
+
12
+ it 'should have app key as a default param' do
13
+ @api.class.default_params.should have_key :appKey
14
+ end
15
+
16
+ it 'should return a character' do
17
+ character = @api.character "http://us.battle.net/sc2/en/profile/844448/1/wong/"
18
+ character.should be_an_instance_of Sc2RanksApi::Character
19
+ end
20
+
21
+ describe 'parsing battle.net url' do
22
+ before(:each) do
23
+ @region, @user = @api.parse_bnet_url "http://us.battle.net/sc2/en/profile/844448/1/wong/"
24
+ end
25
+
26
+ it 'should parse the region' do
27
+ @region.should eq 'us'
28
+ end
29
+
30
+ it 'should parse the user correctly' do
31
+ @user.should eq 'wong!844448'
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+
3
+ require File.dirname(__FILE__) + '/../lib/sc2ranksapi'
4
+ require File.dirname(__FILE__) + '/../lib/sc2ranksapi/team'
5
+ require File.dirname(__FILE__) + '/../lib/sc2ranksapi/character'
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sc2ranksapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Wong
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.11.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.11.0
30
+ description: This gem allows you to access data from http://sc2ranks.com.
31
+ email:
32
+ - iamawong@outlook.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - lib/sc2ranksapi.rb
43
+ - lib/sc2ranksapi/character.rb
44
+ - lib/sc2ranksapi/team.rb
45
+ - lib/sc2ranksapi/version.rb
46
+ - sc2ranksapi.gemspec
47
+ - spec/sc2ranksapi/character_spec.rb
48
+ - spec/sc2ranksapi/team_spec.rb
49
+ - spec/sc2ranksapi_spec.rb
50
+ - spec/spec_helper.rb
51
+ homepage: https://github.com/iamawong/sc2ranksapi
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Gem to get Starcraft2 information about players.
75
+ test_files:
76
+ - spec/sc2ranksapi/character_spec.rb
77
+ - spec/sc2ranksapi/team_spec.rb
78
+ - spec/sc2ranksapi_spec.rb
79
+ - spec/spec_helper.rb