osrshighscores 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc425cd244d6804fb3948135bae62c6a7f6af509
4
+ data.tar.gz: 3726fa207d7d1d348dbe6299086ca9fb3b7076cf
5
+ SHA512:
6
+ metadata.gz: 6629f2f1db9bc22b03d68e8eb95c7c8fd1acb33ba153cb9331b6a07f0e3fecebdabc19c611f8c7d9c181c01f4826e1c8ecf551fe8e7d1d969f2c68a9a924db63
7
+ data.tar.gz: ec7268254869370639f91c3f435d1e8a69b3a874d0e4fa50d7f8ea5af36a5d033ad3ecff161dfbd09eb4280c9b69520f4e1fe1e001e33f92753eb38bbd49f735
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ 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,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in osrshighscores.gemspec
4
+ gemspec
5
+
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,37 @@
1
+ # Osrshighscores
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 Oldschool Runescape highscores. Inspired to some extent by [Partyhat](https://github.com/clooth/Partyhat)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'osrshighscores'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install osrshighscores
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'osrshighscores'
25
+
26
+ player = Osrs::Player.new "Foot"
27
+ highscores = player.stats
28
+ puts highscores[:hunter].level # => 99
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/examplestats ADDED
@@ -0,0 +1,39 @@
1
+ 18,1943,131798702
2
+ 7972,79,1842946
3
+ 7393,76,1400670
4
+ 29100,79,1984378
5
+ 24218,77,1595313
6
+ 16491,77,1625439
7
+ 93,99,13046064
8
+ 20568,76,1465431
9
+ 818,99,13217265
10
+ 6241,88,4509785
11
+ 19385,78,1691275
12
+ 495,99,13035139
13
+ 6365,57,223442
14
+ 144,99,13035264
15
+ 8385,61,329076
16
+ 1799,80,2112305
17
+ 175,89,5195516
18
+ 91,98,11905458
19
+ 351,99,13039441
20
+ 3375,74,1193183
21
+ 86,90,5818631
22
+ 61,95,9280582
23
+ 1065,99,13034585
24
+ 217,75,1217514
25
+ -1,-1
26
+ -1,-1
27
+ -1,-1
28
+ -1,-1
29
+ -1,-1
30
+ -1,-1
31
+ -1,-1
32
+ -1,-1
33
+ -1,-1
34
+ -1,-1
35
+ -1,-1
36
+ -1,-1
37
+ -1,-1
38
+ -1,-1
39
+ -1,-1
@@ -0,0 +1,7 @@
1
+ %w(version player stats).each do |dep|
2
+ require "osrshighscores/#{dep}"
3
+ end
4
+
5
+ module Osrs
6
+
7
+ end
@@ -0,0 +1,30 @@
1
+ require 'open-uri'
2
+
3
+ module Osrs
4
+ class Player
5
+ @@lookup_url = "http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player="
6
+
7
+ attr_reader :name, :raw_stats, :stats
8
+
9
+ def initialize name
10
+ @name = name
11
+ validate_name
12
+ end
13
+
14
+ def validate_name
15
+ raise "invalid characters in name" if @name =~ /[^A-Za-z0-9_\- ]/
16
+
17
+ raise "name too long" if @name.length > 12
18
+ raise "name too short" if @name.length < 1
19
+
20
+ raise "name starts/ends with a space character" if (name[0] + name[-1]) =~ /[_\- ]/
21
+ end
22
+
23
+ def fetch_highscores
24
+ f = open(@@lookup_url + @name, "User-Agent" => "Ruby/OSRSGrabber")
25
+
26
+ @raw_stats = f.readlines.map &:chomp # Readlines preserves newlines??
27
+ @stats = Osrs::Stats.new @raw_stats
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,57 @@
1
+ module Osrs
2
+ class Stats
3
+ attr_accessor :stats
4
+
5
+ @@skills = %w(Overall Attack Defence Strength
6
+ Hitpoints Ranged Prayer Magic
7
+ Cooking Woodcutting Fletching Fishing
8
+ Firemaking Crafting Smithing Mining
9
+ Herblore Agility Thieving Slayer
10
+ Farming Runecrafting Hunter Construction)
11
+
12
+ def initialize raw_stats
13
+ @raw_stats = raw_stats
14
+ parse_stats
15
+ end
16
+
17
+ def validate_raw_stats
18
+ raise "incorrect input length" unless @raw_stats.length == 39
19
+ end
20
+
21
+ def parse_stats
22
+ validate_raw_stats
23
+
24
+ @stats = []
25
+ @raw_stats.take(24).each do |line|
26
+ raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/
27
+ stat = line.split(",").map(&:to_i)
28
+
29
+ class << stat
30
+ def method_missing name, *args
31
+ case name
32
+ when :rank
33
+ return self[0]
34
+ when :level
35
+ return self[1]
36
+ when :xp
37
+ return self[2]
38
+ end
39
+ end
40
+ end
41
+
42
+ @stats << stat
43
+ end
44
+ end
45
+
46
+ def skill_names
47
+ @@skills
48
+ end
49
+
50
+ def [] skill
51
+ skill = skill.to_s.capitalize
52
+ raise "non-existant skill lookup" unless @@skills.index(skill)
53
+
54
+ stats[@@skills.index(skill)]
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Osrs
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'osrshighscores/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "osrshighscores"
8
+ spec.version = Osrs::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 Oldschool Runescape highscores}
12
+ spec.summary = %q{OSRS 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,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Osrs::Stats do
4
+ player = Osrs::Player.new "jebrim"
5
+ player.fetch_highscores
6
+ stats = Osrs::Stats.new player.raw_stats
7
+
8
+ describe "raw highscore validation" do
9
+ context "valid input" do
10
+ it "correct input length" do
11
+ lambda {
12
+ stats = Osrs::Stats.new player.raw_stats
13
+ }.should_not raise_error
14
+ end
15
+ end
16
+
17
+ context "invalid input" do
18
+ it "incorrect input length" do
19
+ lambda {
20
+ Osrs::Stats.new []
21
+ }.should raise_error("incorrect input length")
22
+ end
23
+
24
+ it "malformed input line" do
25
+ lambda {
26
+ Osrs::Stats.new Array.new(39) { "" }
27
+ }.should raise_error("malformed raw stats")
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "stat parsing" do
33
+ it "parsed output length" do
34
+ stats.stats.length.should eq(24)
35
+ end
36
+
37
+ it "stats in groups of three" do
38
+ stats.stats.each do |skill|
39
+ skill.length.should eq(3)
40
+ end
41
+ end
42
+
43
+ it "stats converted to ints" do
44
+ stats.stats.each do |skill|
45
+ skill.each do |elem|
46
+ elem.should be_a(Numeric)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "usability" do
53
+ it "stats 'hash' call" do
54
+ lambda {
55
+ stats[:overall]
56
+ }.should_not raise_error
57
+ end
58
+
59
+ it "stat arrays with convenience methods" do
60
+ stats.stats.each do |skill|
61
+ skill.rank.should be_a(Numeric)
62
+ skill.level.should be_a(Numeric)
63
+ skill.xp.should be_a(Numeric)
64
+ end
65
+ end
66
+
67
+ it "error on non-existant skill lookup" do
68
+ lambda {
69
+ stats[:foot]
70
+ }.should raise_error("non-existant skill lookup")
71
+ end
72
+
73
+ it "success on valid skill lookup" do
74
+ stats.skill_names.each do |name|
75
+ stats[name].should be_a(Array)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Osrs::Player do
4
+ describe "name validation" do
5
+ context "valid names" do
6
+ it "ordinary name" do
7
+ lambda {
8
+ Osrs::Player.new "foot"
9
+ }.should_not raise_error
10
+ end
11
+
12
+ it "multiple spaces" do
13
+ lambda {
14
+ Osrs::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
+ Osrs::Player.new "@£$%^&"
23
+ }.should raise_error(Exception, "invalid characters in name")
24
+ end
25
+
26
+ it "name too long" do
27
+ lambda {
28
+ Osrs::Player.new "abcdef123456x"
29
+ }.should raise_error(Exception, "name too long")
30
+ end
31
+
32
+ it "name too short" do
33
+ lambda {
34
+ Osrs::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
+ Osrs::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 = Osrs::Player.new "jebrim" # Not Foot in case he cancels membership
49
+ lambda {
50
+ player.fetch_highscores
51
+ }.should_not raise_error
52
+
53
+ player.raw_stats.should_not be_nil
54
+ player.raw_stats.length.should_not eq(0)
55
+ player.raw_stats.each { |e| e.end_with?("\n").should be_false }
56
+
57
+ player.stats.should be_a(Osrs::Stats)
58
+ end
59
+
60
+ it "non-member/banned lookup" do
61
+ player = Osrs::Player.new "smithking087" # Known banned player
62
+ lambda {
63
+ player.fetch_highscores
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 'osrshighscores'
4
+
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osrshighscores
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.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-22 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 Oldschool 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
+ - examplestats
85
+ - lib/osrshighscores.rb
86
+ - lib/osrshighscores/player.rb
87
+ - lib/osrshighscores/stats.rb
88
+ - lib/osrshighscores/version.rb
89
+ - osrshighscores.gemspec
90
+ - spec/lookup_spec.rb
91
+ - spec/player_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: https://github.com/sambooo/OSRSGrabber
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.0.7
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: OSRS Highscore Parser
117
+ test_files:
118
+ - spec/lookup_spec.rb
119
+ - spec/player_spec.rb
120
+ - spec/spec_helper.rb