rshighscores 2.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 344d5fdf838f325840ce3656527d712edd3fb9c6
4
+ data.tar.gz: b9fd1fe8d2f9a7b4cfc4eb6f8fd3025c672faf77
5
+ SHA512:
6
+ metadata.gz: c7464194e33cf7d901c109431d5d512f75dd20d989000a0b2939132d53647ffd5745416d3f47bd4980fdc492ff53efa0776be92ddf300a06c873370fb8e7d409
7
+ data.tar.gz: ef9171b1468052ea74465737d1246f22f472d9fd35053bc4ccdbcec10de6b1c6c24a92621cd617dff9e793960884a53c9b8d89e5580790cb87d3843214cf7040
data/.gitignore ADDED
@@ -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 documentation
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in osrshighscores.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # RsHighscores
2
+
3
+ [![Code Climate](https://codeclimate.com/github/sambooo/OSRSGrabber.png)](https://codeclimate.com/github/sambooo/OSRSGrabber)
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. Currently, there is no support for Oldschool Runescape at all.
10
+
11
+ ### But what if I want the Oldschool Runescape version?
12
+
13
+ Don't worry, it's still around. It currently resides in its own branch, `version-1` and will still function as before. I intend to merge the two versions later on for ease of development and use so keep an eye out for version 3.x.
14
+
15
+ ### Why the change at all?
16
+
17
+ 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.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'rshighscores'
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install highscores
32
+
33
+ ## Usage
34
+
35
+ ```ruby
36
+ require 'rshighscores'
37
+
38
+ player = RsHighscores::Player.new "Foot"
39
+ highscores = player.stats
40
+ puts highscores.hunter.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
data/Rakefile ADDED
@@ -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,32 @@
1
+ require 'open-uri'
2
+
3
+ module RsHighscores
4
+ class Player
5
+ @@lookup_url = "http://hiscore.runescape.com/index_lite.ws?player="
6
+
7
+ attr_reader :name, :raw_stats, :stats
8
+
9
+ def initialize name, force = :no_force
10
+ @name = name
11
+ validate_name
12
+
13
+ fetch_highscores if force == :force
14
+ end
15
+
16
+ def validate_name
17
+ raise "invalid characters in name" if @name =~ /[^A-Za-z0-9_\- ]/
18
+
19
+ raise "name too long" if @name.length > 12
20
+ raise "name too short" if @name.length < 1
21
+
22
+ raise "name starts/ends with a space character" if (name[0] + name[-1]) =~ /[_\- ]/
23
+ end
24
+
25
+ def fetch_highscores
26
+ f = open(@@lookup_url + @name, "User-Agent" => "Ruby/RsHighscoresGrabber")
27
+
28
+ @raw_stats = f.readlines.map &:chomp # readlines preserves newlines??
29
+ @stats = RsHighscores::Stats.new @raw_stats
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,64 @@
1
+ module RsHighscores
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
+ attr_accessor :stats, :raw_stats
12
+
13
+ def initialize raw_stats
14
+ @expected_stat_count = 44
15
+ @raw_stats = raw_stats
16
+
17
+ parse_stats
18
+ end
19
+
20
+ def validate_raw_stats
21
+ raise "incorrect input length" unless @raw_stats.length == @expected_stat_count
22
+ end
23
+
24
+ def parse_stats
25
+ validate_raw_stats
26
+
27
+ @stats = []
28
+ @raw_stats.take(@@skills.count).each do |line|
29
+ raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/
30
+ stat = line.split(",").map(&:to_i)
31
+
32
+ class << stat
33
+ def method_missing name, *args
34
+ case name
35
+ when :rank
36
+ return self[0]
37
+ when :level
38
+ return self[1]
39
+ when :xp
40
+ return self[2]
41
+ end
42
+ end
43
+ end
44
+
45
+ @stats << stat
46
+ end
47
+ end
48
+
49
+ def skill_names
50
+ @@skills
51
+ end
52
+
53
+ def [] skill
54
+ skill = skill.to_s.capitalize
55
+ raise "non-existant skill lookup" unless @@skills.index(skill)
56
+
57
+ stats[@@skills.index(skill)]
58
+ end
59
+
60
+ def method_missing name, *args
61
+ return self[name] if @@skills.include? name.to_s
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,7 @@
1
+ %w(player stats).each do |dep|
2
+ require "rshighscores/#{dep}"
3
+ end
4
+
5
+ module RsHighscores
6
+ VERSION = "2.0.0"
7
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rshighscores'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rshighscores"
8
+ spec.version = RsHighscores::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 highscores}
12
+ spec.summary = %q{RS Highscore Parser}
13
+ spec.homepage = "https://github.com/sambooo/OSRSGrabber"
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
+ spec.add_development_dependency "shoulda"
25
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe RsHighscores::Stats do
4
+ before :all do
5
+ @player = RsHighscores::Player.new "jake", :force
6
+ @stats = RsHighscores::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 = RsHighscores::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
+ RsHighscores::Stats.new []
22
+ }.should raise_error("incorrect input length")
23
+ end
24
+
25
+ it "malformed input line" do
26
+ lambda {
27
+ RsHighscores::Stats.new Array.new(44) { "" }
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(@stats.skill_names.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
+ @stats.skill_names.each do |name|
76
+ @stats[name].should be_a(Array)
77
+ end
78
+ end
79
+
80
+ it "missing method call" do
81
+ @stats.skill_names.each do |name|
82
+ @stats.send(name.to_sym).should eq(@stats[name])
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe RsHighscores::Player do
4
+ describe "name validation" do
5
+ context "valid names" do
6
+ it "ordinary name" do
7
+ lambda {
8
+ RsHighscores::Player.new "foot"
9
+ }.should_not raise_error
10
+ end
11
+
12
+ it "multiple spaces" do
13
+ lambda {
14
+ RsHighscores::Player.new "s u o m i"
15
+ }.should_not raise_error
16
+ end
17
+ end
18
+
19
+ context "errors" do
20
+ it "invalid characters in name" do
21
+ lambda {
22
+ RsHighscores::Player.new "@£$%^&"
23
+ }.should raise_error(Exception, "invalid characters in name")
24
+ end
25
+
26
+ it "name too long" do
27
+ lambda {
28
+ RsHighscores::Player.new "abcdef123456x"
29
+ }.should raise_error(Exception, "name too long")
30
+ end
31
+
32
+ it "name too short" do
33
+ lambda {
34
+ RsHighscores::Player.new ""
35
+ }.should raise_error(Exception, "name too short")
36
+ end
37
+
38
+ it "name starts/ends with space character" do
39
+ lambda {
40
+ RsHighscores::Player.new "_heh_"
41
+ }.should raise_error(Exception, "name starts/ends with a space character")
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "highscore lookup" do
47
+ it "member lookup" do
48
+ player = RsHighscores::Player.new "jake", :force # Not Foot in case he cancels membership
49
+
50
+ lambda {
51
+ player.fetch_highscores
52
+ }.should_not raise_error
53
+
54
+ player.raw_stats.should_not be_nil
55
+ player.raw_stats.length.should_not eq(0)
56
+ player.raw_stats.each { |e| e.end_with?("\n").should be_false }
57
+
58
+ player.stats.should be_a(RsHighscores::Stats)
59
+ end
60
+
61
+ it "non-member/banned lookup" do
62
+ lambda {
63
+ RsHighscores::Player.new "smithking087", :force # Known banned player
64
+ }.should raise_error(OpenURI::HTTPError)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rshighscores'
4
+
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rshighscores
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Broughton
8
+ - Joshua Bell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-29 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
+ - !ruby/object:Gem::Dependency
57
+ name: shoulda
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: Easy to use gem for downloading and parsing Runescape highscores
71
+ email:
72
+ - sam@26th-zerk.co.uk
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - .travis.yml
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/rshighscores.rb
85
+ - lib/rshighscores/player.rb
86
+ - lib/rshighscores/stats.rb
87
+ - rshighscores.gemspec
88
+ - spec/lookup_spec.rb
89
+ - spec/player_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/sambooo/OSRSGrabber
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.7
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: RS Highscore Parser
115
+ test_files:
116
+ - spec/lookup_spec.rb
117
+ - spec/player_spec.rb
118
+ - spec/spec_helper.rb