rshiscores 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: deb75a4dc9c4856ae3a1a6e58ee6b0a6724a8965
4
+ data.tar.gz: 918508c00eee15946a721c5d0fe586789817bc4e
5
+ SHA512:
6
+ metadata.gz: 7509bc568e09299913649725ca853312cd54526882da1d13df52cc7d3ff8384e59ac90271a8865116425272d9300ef6d562702eb77d9012aca601a83380ad9ff
7
+ data.tar.gz: 20bbb5213696e4aa22a25929af9edc38739f2e6e1837eb2d69bf7b18e76bd05d1b8484206b8f225f3a826636e9ba06dc30013fb3f5e28ef4dd34db54ae1b9fdd
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .DS_Store
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in osrshighscores.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sam Broughton
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,49 @@
1
+ # RsHighscores
2
+
3
+ [![Code Climate](https://codeclimate.com/github/sambooo/RsHighscores.png)](https://codeclimate.com/github/sambooo/RsHighscores)
4
+
5
+ Easy to use gem for downloading and parsing Runescape highscores. Inspired to some extent by [Partyhat](https://github.com/clooth/Partyhat)
6
+
7
+ ## Rename and compatibility changes
8
+
9
+ This gem was previously called `osrshighscores` and only worked with Oldschool Runescape. The current version has been renamed to reflect the future version-agnostic highscore parsing that the gem will do. As of version 2.1.0, Oldschool Runescape is supported alongside Runescape 3. There are aliases in place to make code from 1.x work without issue in 2.1.x onwards, so if you were using 1.x you need not change anything.
10
+
11
+ ### Why the change at all?
12
+
13
+ I was asked to port the gem to Runescape 3 by a friend. I figured it would be better to immediately roll-out a working version and then work on merging branches later.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'rshighscores'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install rshighscores
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ require 'rshighscores'
33
+
34
+ foot = RsHighscores::Player.new "Foot", force: true
35
+ highscores = foot.stats
36
+ puts highscores.hunter.level # => 99
37
+
38
+ jebrim = OSRS::Player.new "Jebrim", force: true # RsHighscores::OldSchool::Player would work too
39
+ highscores = jebrim.stats
40
+ puts highscores.agility.level # => 99
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new :test
5
+
6
+ task :default => [:test]
@@ -0,0 +1,10 @@
1
+ %w(stats player oldschool).each do |dep|
2
+ require "rshiscores/#{dep}"
3
+ end
4
+
5
+ module RsHiscores
6
+ VERSION = "3.0.0"
7
+ end
8
+
9
+ module OSRS
10
+ end
@@ -0,0 +1,18 @@
1
+ module RsHiscores
2
+ module OldSchool
3
+ class Stats < RsHiscores::Stats
4
+ StatCount = 24
5
+ Skills = RsHiscores::Stats::Skills.take(StatCount)
6
+ end
7
+
8
+ class Player < RsHiscores::Player
9
+ LookupUrl = "http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player="
10
+ StatClass = RsHiscores::OldSchool::Stats
11
+ end
12
+ end
13
+ end
14
+
15
+ module OSRS
16
+ Player = RsHiscores::OldSchool::Player
17
+ Stats = RsHiscores::OldSchool::Stats
18
+ end
@@ -0,0 +1,34 @@
1
+ require 'open-uri'
2
+
3
+ module RsHiscores
4
+ class Player
5
+ LookupUrl = "http://hiscore.runescape.com/index_lite.ws?player="
6
+ StatClass = RsHiscores::Stats
7
+
8
+ attr_reader :name, :raw_stats, :stats
9
+
10
+ def initialize name, params = {}
11
+ @name = name
12
+ validate_name
13
+
14
+ fetch_highscores if params[:force]
15
+ end
16
+
17
+ def validate_name
18
+ raise "invalid characters in name" if @name =~ /[^A-Za-z0-9_\- ]/
19
+
20
+ raise "name too long" if @name.length > 12
21
+ raise "name too short" if @name.length < 1
22
+
23
+ raise "name starts/ends with a space character" if (name[0] + name[-1]) =~ /[_\- ]/
24
+ end
25
+
26
+ def fetch_highscores
27
+ safe_name = @name.gsub " ", "%20"
28
+ f = open(self.class::LookupUrl + safe_name, "User-Agent" => "Ruby/RsHiscoresGrabber")
29
+
30
+ @raw_stats = f.readlines.map &:chomp # readlines preserves newlines??
31
+ @stats = self.class::StatClass.new @raw_stats
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,87 @@
1
+ module RsHiscores
2
+ class Stats
3
+ Skills = %w(Overall Attack Defence Strength
4
+ Hitpoints Ranged Prayer Magic
5
+ Cooking Woodcutting Fletching Fishing
6
+ Firemaking Crafting Smithing Mining
7
+ Herblore Agility Thieving Slayer
8
+ Farming Runecrafting Hunter Construction
9
+ Summoning Dungeoneering Divination)
10
+
11
+ StatCount = Skills.count
12
+
13
+ attr_accessor :stats, :raw_stats
14
+
15
+ def initialize raw_stats
16
+ @raw_stats = raw_stats
17
+
18
+ parse_stats
19
+ end
20
+
21
+ def stat_count
22
+ self.class::StatCount
23
+ end
24
+
25
+ def skills
26
+ self.class::Skills
27
+ end
28
+
29
+ def validate_raw_stats
30
+ if @raw_stats.length < stat_count
31
+ raise "incorrect input length: expected #{stat_count}, got #{@raw_stats.length}"
32
+ end
33
+ end
34
+
35
+ def parse_stats
36
+ validate_raw_stats
37
+
38
+ @stats = []
39
+ @raw_stats.take(stat_count).each do |line|
40
+ raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/
41
+ stat = Stat.new line.split(",").map(&:to_i)
42
+
43
+ @stats << stat
44
+ end
45
+ end
46
+
47
+ def [] skill
48
+ skill = skill.to_s.capitalize
49
+ raise "non-existant skill lookup" unless skills.index(skill)
50
+
51
+ stats[skills.index(skill)]
52
+ end
53
+
54
+ def method_missing name, *args
55
+ return self[name] if Skills.include? name.to_s.capitalize
56
+ super
57
+ end
58
+ end
59
+
60
+ class Stat
61
+ attr_reader :backing_array
62
+
63
+ def initialize backing_array
64
+ @backing_array = backing_array
65
+ end
66
+
67
+ def length
68
+ backing_array.length
69
+ end
70
+
71
+ def each &block
72
+ backing_array.each &block
73
+ end
74
+
75
+ def rank
76
+ backing_array[0]
77
+ end
78
+
79
+ def level
80
+ backing_array[1]
81
+ end
82
+
83
+ def xp
84
+ backing_array[2]
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rshiscores'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rshiscores"
8
+ spec.version = RsHiscores::VERSION
9
+ spec.authors = ["Sam Broughton", "Joshua Bell"]
10
+ spec.email = ["sam@26th-zerk.co.uk"]
11
+ spec.description = %q{Easy to use gem for downloading and parsing Runescape hiscores}
12
+ spec.summary = %q{RS Hiscore Parser}
13
+ spec.homepage = "https://github.com/sambooo/RsHighscores"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe RsHiscores::Stats do
4
+ before :all do
5
+ @player = RsHiscores::Player.new "jake", force: true
6
+ @stats = RsHiscores::Stats.new @player.raw_stats
7
+ end
8
+
9
+ describe "raw highscore validation" do
10
+ context "valid input" do
11
+ it "correct input length" do
12
+ lambda {
13
+ @stats = RsHiscores::Stats.new @player.raw_stats
14
+ }.should_not raise_error
15
+ end
16
+ end
17
+
18
+ context "invalid input" do
19
+ it "incorrect input length" do
20
+ lambda {
21
+ RsHiscores::Stats.new []
22
+ }.should raise_error(/incorrect input length/)
23
+ end
24
+
25
+ it "malformed input line" do
26
+ lambda {
27
+ RsHiscores::Stats.new Array.new(49) { "" }
28
+ }.should raise_error("malformed raw stats")
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "stat parsing" do
34
+ it "parsed output length" do
35
+ @stats.stats.length.should eq(RsHiscores::Stats::Skills.count)
36
+ end
37
+
38
+ it "stats in groups of three" do
39
+ @stats.stats.each do |skill|
40
+ skill.length.should eq(3)
41
+ end
42
+ end
43
+
44
+ it "stats converted to ints" do
45
+ @stats.stats.each do |skill|
46
+ skill.each do |elem|
47
+ elem.should be_a(Numeric)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "usability" do
54
+ it "stats 'hash' call" do
55
+ lambda {
56
+ @stats[:overall]
57
+ }.should_not raise_error
58
+ end
59
+
60
+ it "stat arrays with convenience methods" do
61
+ @stats.stats.each do |skill|
62
+ skill.rank.should be_a(Numeric)
63
+ skill.level.should be_a(Numeric)
64
+ skill.xp.should be_a(Numeric)
65
+ end
66
+ end
67
+
68
+ it "error on non-existant skill lookup" do
69
+ lambda {
70
+ @stats[:foot]
71
+ }.should raise_error("non-existant skill lookup")
72
+ end
73
+
74
+ it "success on valid skill lookup" do
75
+ RsHiscores::Stats::Skills.each do |name|
76
+ @stats[name].should be_a(RsHiscores::Stat)
77
+ end
78
+ end
79
+
80
+ it "skill_names output" do
81
+ RsHiscores::Stats::Skills.should eq(%w(Overall Attack Defence Strength
82
+ Hitpoints Ranged Prayer Magic
83
+ Cooking Woodcutting Fletching Fishing
84
+ Firemaking Crafting Smithing Mining
85
+ Herblore Agility Thieving Slayer
86
+ Farming Runecrafting Hunter Construction
87
+ Summoning Dungeoneering Divination))
88
+ end
89
+
90
+ it "attempting to call a skill name that doesn't exist" do
91
+ lambda {
92
+ @stats.not_a_skill
93
+ }.should raise_error
94
+ end
95
+
96
+ it "missing method call" do
97
+ RsHiscores::Stats::Skills.each do |name|
98
+ @stats.send(name.downcase).should eq(@stats[name])
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe RsHiscores::OldSchool::Player do
4
+ context "backwards compatibility" do
5
+ it "namespace alias" do
6
+ OSRS::Player.should eq(RsHiscores::OldSchool::Player)
7
+ end
8
+ end
9
+
10
+ context "usability" do
11
+ before :all do
12
+ @player = OSRS::Player.new "jebrim", force: true
13
+ @stats = OSRS::Stats.new @player.raw_stats
14
+ end
15
+
16
+ it "skill_names output" do
17
+ OSRS::Stats::Skills.should eq(%w(Overall Attack Defence Strength
18
+ Hitpoints Ranged Prayer Magic
19
+ Cooking Woodcutting Fletching Fishing
20
+ Firemaking Crafting Smithing Mining
21
+ Herblore Agility Thieving Slayer
22
+ Farming Runecrafting Hunter Construction))
23
+ end
24
+
25
+ it "individual skill lookup" do
26
+ @stats.stats.each do |stat|
27
+ stat.should be_a(RsHiscores::Stat)
28
+ stat.each do |elem|
29
+ elem.should be_a(Numeric)
30
+ end
31
+ end
32
+ end
33
+
34
+ it "named stat lookup" do
35
+ OSRS::Stats::Skills.each do |skill|
36
+ @stats.send(skill.to_sym).should be_a(RsHiscores::Stat)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe RsHiscores::Player do
5
+ describe "name validation" do
6
+ context "valid names" do
7
+ it "ordinary name" do
8
+ lambda {
9
+ RsHiscores::Player.new "foot"
10
+ }.should_not raise_error
11
+ end
12
+
13
+ it "multiple spaces" do
14
+ lambda {
15
+ RsHiscores::Player.new "s u o m i"
16
+ }.should_not raise_error
17
+ end
18
+
19
+ it "spaces being replaced" do
20
+ lambda {
21
+ RsHiscores::Player.new "s u o m i", force: true
22
+ }.should_not raise_error
23
+ end
24
+ end
25
+
26
+ context "errors" do
27
+ it "invalid characters in name" do
28
+ lambda {
29
+ RsHiscores::Player.new "@£$%^&"
30
+ }.should raise_error(Exception, "invalid characters in name")
31
+ end
32
+
33
+ it "name too long" do
34
+ lambda {
35
+ RsHiscores::Player.new "abcdef123456x"
36
+ }.should raise_error(Exception, "name too long")
37
+ end
38
+
39
+ it "name too short" do
40
+ lambda {
41
+ RsHiscores::Player.new ""
42
+ }.should raise_error(Exception, "name too short")
43
+ end
44
+
45
+ it "name starts/ends with space character" do
46
+ lambda {
47
+ RsHiscores::Player.new "_heh_"
48
+ }.should raise_error(Exception, "name starts/ends with a space character")
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "highscore lookup" do
54
+ it "member lookup" do
55
+ player = RsHiscores::Player.new "jake", force: true # Not Foot in case he cancels membership
56
+
57
+ lambda {
58
+ player.fetch_highscores
59
+ }.should_not raise_error
60
+
61
+ player.raw_stats.should_not be_nil
62
+ player.raw_stats.length.should_not eq(0)
63
+ player.raw_stats.each { |e| e.end_with?("\n").should be_false }
64
+
65
+ player.stats.should be_a(RsHiscores::Stats)
66
+ end
67
+
68
+ it "non-member/banned lookup" do
69
+ lambda {
70
+ RsHiscores::Player.new "smithking087", force: true # Known banned player
71
+ }.should raise_error(OpenURI::HTTPError)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rshiscores'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rspec
7
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rshiscores
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Broughton
8
+ - Joshua Bell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Easy to use gem for downloading and parsing Runescape hiscores
57
+ email:
58
+ - sam@26th-zerk.co.uk
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/rshiscores.rb
70
+ - lib/rshiscores/oldschool.rb
71
+ - lib/rshiscores/player.rb
72
+ - lib/rshiscores/stats.rb
73
+ - rshiscores.gemspec
74
+ - spec/lookup_spec.rb
75
+ - spec/oldschool_spec.rb
76
+ - spec/player_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/sambooo/RsHighscores
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: RS Hiscore Parser
102
+ test_files:
103
+ - spec/lookup_spec.rb
104
+ - spec/oldschool_spec.rb
105
+ - spec/player_spec.rb
106
+ - spec/spec_helper.rb