bf3 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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/README.md +18 -0
- data/Rakefile +10 -0
- data/bf3.gemspec +19 -0
- data/lib/bf3.rb +37 -0
- data/lib/bf3/version.rb +3 -0
- data/test/bf3_test.rb +29 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Simple Battlefield 3 Stats
|
2
|
+
powered by bf3stats.com
|
3
|
+
|
4
|
+
## Example:
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
require 'bf3'
|
8
|
+
|
9
|
+
player = Bf3::Player.new('Raengr', '360')
|
10
|
+
stats = player.callUp() # get global stats
|
11
|
+
|
12
|
+
kdratio = stats['global']['kills'].to_f / stats['global']['deaths'].to_f
|
13
|
+
# OR, conveniently
|
14
|
+
kdratio = player.kdr()
|
15
|
+
|
16
|
+
# to get ALL THE STATS!
|
17
|
+
all_stats = player.callUp('all')
|
18
|
+
```
|
data/Rakefile
ADDED
data/bf3.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bf3/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Taylor Beseda"]
|
6
|
+
gem.email = ["tbeseda@gmail.com"]
|
7
|
+
gem.description = "Stats for Battlefield 3 from bf3stats.copm"
|
8
|
+
gem.summary = ""
|
9
|
+
gem.homepage = "http://github.com/tbeseda/bf3"
|
10
|
+
|
11
|
+
gem.add_dependency "httparty"
|
12
|
+
|
13
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
gem.name = "bf3"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = Bf3::VERSION
|
19
|
+
end
|
data/lib/bf3.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bf3/version'
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Bf3
|
6
|
+
|
7
|
+
class Player
|
8
|
+
|
9
|
+
def initialize(name, platform)
|
10
|
+
@name = name
|
11
|
+
@platform = platform
|
12
|
+
end
|
13
|
+
|
14
|
+
def callUp(opt='clear,global')
|
15
|
+
body = {
|
16
|
+
player: @name,
|
17
|
+
output: 'json',
|
18
|
+
opt: opt
|
19
|
+
}
|
20
|
+
response = HTTParty.post("http://api.bf3stats.com/#{@platform}/player/", :body => body)
|
21
|
+
if response.code == 200
|
22
|
+
stats = JSON(response.body)['stats']
|
23
|
+
@stats = stats
|
24
|
+
return stats
|
25
|
+
else
|
26
|
+
return response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def kdr
|
31
|
+
self.callUp() unless @stats and @stats['global']['kills']
|
32
|
+
return @stats['global']['kills'].to_f / @stats['global']['deaths']
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/bf3/version.rb
ADDED
data/test/bf3_test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'bf3'
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
|
5
|
+
describe Bf3::Player do
|
6
|
+
before do
|
7
|
+
@player = Bf3::Player.new('Raengr', '360')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'getting a player' do
|
11
|
+
it 'should return the player requested' do
|
12
|
+
soldier = @player.callUp()
|
13
|
+
soldier['global'].wont_be_nil
|
14
|
+
end
|
15
|
+
it 'should have some global stats' do
|
16
|
+
soldier = @player.callUp('clear,rank')
|
17
|
+
soldier['global'].must_be_nil
|
18
|
+
soldier['rank'].wont_be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'some vanity stats' do
|
23
|
+
it 'should return a floating point kill to death ratio' do
|
24
|
+
kdr = @player.kdr()
|
25
|
+
kdr.wont_be_nil
|
26
|
+
kdr.must_be_instance_of(Float)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bf3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Taylor Beseda
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &70189798739800 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70189798739800
|
25
|
+
description: Stats for Battlefield 3 from bf3stats.copm
|
26
|
+
email:
|
27
|
+
- tbeseda@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- bf3.gemspec
|
37
|
+
- lib/bf3.rb
|
38
|
+
- lib/bf3/version.rb
|
39
|
+
- test/bf3_test.rb
|
40
|
+
homepage: http://github.com/tbeseda/bf3
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.11
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: ''
|
64
|
+
test_files:
|
65
|
+
- test/bf3_test.rb
|