deckard_cain 0.0.3 → 0.0.4
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 +4 -4
- data/.coveralls.yml +3 -0
- data/.gitignore +23 -0
- data/.travis.yml +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +49 -0
- data/README.md +9 -0
- data/Rakefile +4 -0
- data/deckard_cain.gemspec +20 -0
- data/lib/cain/artisan.rb +6 -0
- data/lib/cain/career.rb +26 -0
- data/lib/cain/hero.rb +35 -0
- data/lib/cain/item.rb +6 -0
- data/lib/cain/model.rb +38 -0
- data/lib/cain/version.rb +3 -0
- data/spec/deckard_cain_spec.rb +17 -0
- data/spec/lib/cain/career_spec.rb +22 -0
- data/spec/lib/cain/hero_spec.rb +45 -0
- data/spec/lib/cain/model_spec.rb +24 -0
- data/spec/spec_helper.rb +19 -0
- metadata +34 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e83008d71b011e7f79325749c8f275a7c2e7780
|
4
|
+
data.tar.gz: 47369d7905380ebd7a1d64b987c0bcb5eb46fe52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b05660f27cda2b2a3e6eb26c83872016ca329fc79fe45cf2261c26ccc1fae35e44e89b3e278c0c50df0f054e3589e082ef2138755dd8ac0974ae986a2c6b6b4d
|
7
|
+
data.tar.gz: b02b9292d3688483822ec32372ed9194f49d5224fcd4c91d449a36af578b049a6d76c0eb037451b01ba9b129af4e77f2348b2b59f695cd19f530272e8e56e3ef
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
19
|
+
|
20
|
+
.ignore
|
21
|
+
|
22
|
+
# VCR fragments
|
23
|
+
fixtures
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
coveralls (0.7.0)
|
6
|
+
multi_json (~> 1.3)
|
7
|
+
rest-client
|
8
|
+
simplecov (>= 0.7)
|
9
|
+
term-ansicolor
|
10
|
+
thor
|
11
|
+
crack (0.4.1)
|
12
|
+
safe_yaml (~> 0.9.0)
|
13
|
+
diff-lcs (1.2.4)
|
14
|
+
mime-types (1.25)
|
15
|
+
multi_json (1.8.0)
|
16
|
+
rake (10.1.0)
|
17
|
+
rest-client (1.6.7)
|
18
|
+
mime-types (>= 1.16)
|
19
|
+
rspec (2.14.1)
|
20
|
+
rspec-core (~> 2.14.0)
|
21
|
+
rspec-expectations (~> 2.14.0)
|
22
|
+
rspec-mocks (~> 2.14.0)
|
23
|
+
rspec-core (2.14.6)
|
24
|
+
rspec-expectations (2.14.3)
|
25
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
26
|
+
rspec-mocks (2.14.4)
|
27
|
+
safe_yaml (0.9.7)
|
28
|
+
simplecov (0.7.1)
|
29
|
+
multi_json (~> 1.0)
|
30
|
+
simplecov-html (~> 0.7.1)
|
31
|
+
simplecov-html (0.7.1)
|
32
|
+
term-ansicolor (1.2.2)
|
33
|
+
tins (~> 0.8)
|
34
|
+
thor (0.18.1)
|
35
|
+
tins (0.12.0)
|
36
|
+
vcr (2.7.0)
|
37
|
+
webmock (1.15.2)
|
38
|
+
addressable (>= 2.2.7)
|
39
|
+
crack (>= 0.3.2)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
coveralls (~> 0.7)
|
46
|
+
rake
|
47
|
+
rspec (~> 2.14)
|
48
|
+
vcr (~> 2.7)
|
49
|
+
webmock (~> 1.15)
|
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Deckard Cain
|
2
|
+
============
|
3
|
+
|
4
|
+
[](https://travis-ci.org/1morepx/deckard_cain)
|
5
|
+
[](https://codeclimate.com/github/1morepx/deckard_cain)
|
6
|
+
[](http://badge.fury.io/rb/deckard_cain)
|
7
|
+
[](https://coveralls.io/r/1morepx/deckard_cain)
|
8
|
+
|
9
|
+
Stay a while and listen! Deckard Cain knows all about your Diablo 3 characters! This gem allows you to easily consume the Diablo 3 Community API provided by Blizzard.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "cain/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'deckard_cain'
|
6
|
+
s.version = Cain::VERSION
|
7
|
+
s.date = '2013-04-24'
|
8
|
+
s.summary = 'Stay a while and listen!'
|
9
|
+
s.description = 'Deckard Cain knows everything about the Diablo 3 Community API'
|
10
|
+
s.authors = ["David Mills"]
|
11
|
+
s.email = 'dave@1morepx.com'
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.homepage = 'http://github.com/1morepx/deckard_cain'
|
14
|
+
s.add_development_dependency 'rspec', '~> 2.14'
|
15
|
+
s.add_development_dependency 'coveralls', '~> 0.7'
|
16
|
+
s.add_development_dependency 'webmock', '~> 1.15'
|
17
|
+
s.add_development_dependency 'vcr', '~> 2.7'
|
18
|
+
|
19
|
+
s.add_dependency 'json'
|
20
|
+
end
|
data/lib/cain/artisan.rb
ADDED
data/lib/cain/career.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'cain/model'
|
2
|
+
require 'cain/hero'
|
3
|
+
|
4
|
+
module Cain
|
5
|
+
class Career < Model
|
6
|
+
|
7
|
+
def initialize battle_tag=nil
|
8
|
+
super battle_tag
|
9
|
+
|
10
|
+
uri = URI(path)
|
11
|
+
data = JSON.parse(Net::HTTP.get(uri))
|
12
|
+
data["heroes"].each { |hero| heroes << Hero.build_from_json(hero) }
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_writer :heroes
|
16
|
+
|
17
|
+
def heroes
|
18
|
+
@heroes ||= []
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
def resource_path
|
23
|
+
"profile/#{battle_tag}/"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/cain/hero.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'cain/model'
|
3
|
+
|
4
|
+
module Cain
|
5
|
+
class Hero < Model
|
6
|
+
|
7
|
+
def self.build_from_json params
|
8
|
+
hero = new
|
9
|
+
|
10
|
+
params.keys.each do |key|
|
11
|
+
method = key.gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
|
12
|
+
method = "character_class" if method == "class"
|
13
|
+
hero.send(method + "=", params[key])
|
14
|
+
end
|
15
|
+
|
16
|
+
hero
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :name, :id, :level, :gender, :hardcore, :dead, :paragon_level, :character_class
|
20
|
+
|
21
|
+
def gender= value
|
22
|
+
@gender = value.zero? ? :male : :female
|
23
|
+
end
|
24
|
+
|
25
|
+
def character_class= value
|
26
|
+
value = value.gsub(/-/, '_')
|
27
|
+
@character_class = value.to_sym
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def resource_path
|
32
|
+
"profile/#{battle_tag}/hero/#{id}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/cain/item.rb
ADDED
data/lib/cain/model.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Cain
|
5
|
+
class Model
|
6
|
+
|
7
|
+
attr_accessor :last_updated, :battle_tag
|
8
|
+
def initialize battle_tag=nil
|
9
|
+
@battle_tag = battle_tag
|
10
|
+
end
|
11
|
+
|
12
|
+
def last_updated= timestamp
|
13
|
+
@last_updated = epoch_to_date timestamp
|
14
|
+
end
|
15
|
+
|
16
|
+
def path
|
17
|
+
"http://#{host}/#{api_path}/#{resource_path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def epoch_to_date timestamp
|
23
|
+
DateTime.strptime("#{timestamp}", '%s')
|
24
|
+
end
|
25
|
+
|
26
|
+
def resource_path; end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def host
|
31
|
+
"us.battle.net"
|
32
|
+
end
|
33
|
+
|
34
|
+
def api_path
|
35
|
+
"api/d3"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/cain/version.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DeckardCain, :vcr do
|
4
|
+
it 'returns the correct version string' do
|
5
|
+
DeckardCain.version_string.should == "Deckard Cain version #{Cain::VERSION}"
|
6
|
+
end
|
7
|
+
|
8
|
+
context "career" do
|
9
|
+
let(:battle_tag) { "Daegren-1581" }
|
10
|
+
let(:career) { DeckardCain.fetch_career battle_tag }
|
11
|
+
|
12
|
+
it 'creates a career object with the proper battle tag' do
|
13
|
+
career.battle_tag.should eq battle_tag
|
14
|
+
career.should be_instance_of Cain::Career
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cain/career'
|
3
|
+
require 'cain/hero'
|
4
|
+
|
5
|
+
module Cain
|
6
|
+
describe Career, :vcr do
|
7
|
+
let(:battle_tag){ "Daegren-1581" }
|
8
|
+
subject { described_class.new battle_tag }
|
9
|
+
|
10
|
+
it 'generates the right resource path on battle.net' do
|
11
|
+
subject.path.should eq "http://us.battle.net/api/d3/profile/Daegren-1581/"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has heroes in an array' do
|
15
|
+
subject.heroes.should be_instance_of Array
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has a proper hero object' do
|
19
|
+
subject.heroes.sample.should be_instance_of Cain::Hero
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cain/hero'
|
3
|
+
|
4
|
+
module Cain
|
5
|
+
describe Hero, :vcr do
|
6
|
+
let(:battle_tag) { "Daegren-1581" }
|
7
|
+
subject { described_class.new battle_tag }
|
8
|
+
before do
|
9
|
+
subject.id = 3691256
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#gender' do
|
13
|
+
it 'is male' do
|
14
|
+
subject.gender = 0
|
15
|
+
|
16
|
+
subject.gender.should eq :male
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'is female' do
|
20
|
+
subject.gender = 1
|
21
|
+
|
22
|
+
subject.gender.should eq :female
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#character_class' do
|
27
|
+
it 'represents classes as symbols' do
|
28
|
+
subject.character_class = "demon-hunter"
|
29
|
+
|
30
|
+
subject.character_class.should eq :demon_hunter
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '#path' do
|
35
|
+
before do
|
36
|
+
subject.id = hero_id
|
37
|
+
end
|
38
|
+
let(:hero_id) { 5 }
|
39
|
+
|
40
|
+
it 'path is correct for the resource' do
|
41
|
+
subject.path.should == "http://us.battle.net/api/d3/profile/#{battle_tag}/hero/#{hero_id}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cain/model'
|
3
|
+
|
4
|
+
module Cain
|
5
|
+
class TestModel < Model
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Model do
|
9
|
+
subject { TestModel.new }
|
10
|
+
context '#epoch_to_date' do
|
11
|
+
it 'converts timestamp to sane ruby object' do
|
12
|
+
subject.last_updated = 1365373956
|
13
|
+
|
14
|
+
date = subject.last_updated
|
15
|
+
date.year.should eq 2013
|
16
|
+
date.month.should eq 4
|
17
|
+
date.day.should eq 7
|
18
|
+
date.hour.should eq 22
|
19
|
+
date.minute.should eq 32
|
20
|
+
date.second.should eq 36
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'deckard_cain'
|
7
|
+
require 'vcr'
|
8
|
+
|
9
|
+
VCR.configure do |c|
|
10
|
+
c.cassette_library_dir = 'fixtures/vcr_cassettes'
|
11
|
+
c.hook_into :webmock
|
12
|
+
c.configure_rspec_metadata!
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.color_enabled = true
|
17
|
+
config.formatter = 'documentation'
|
18
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deckard_cain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Mills
|
@@ -66,13 +66,46 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Deckard Cain knows everything about the Diablo 3 Community API
|
70
84
|
email: dave@1morepx.com
|
71
85
|
executables: []
|
72
86
|
extensions: []
|
73
87
|
extra_rdoc_files: []
|
74
88
|
files:
|
89
|
+
- .coveralls.yml
|
90
|
+
- .gitignore
|
91
|
+
- .travis.yml
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- deckard_cain.gemspec
|
97
|
+
- lib/cain/artisan.rb
|
98
|
+
- lib/cain/career.rb
|
99
|
+
- lib/cain/hero.rb
|
100
|
+
- lib/cain/item.rb
|
101
|
+
- lib/cain/model.rb
|
102
|
+
- lib/cain/version.rb
|
75
103
|
- lib/deckard_cain.rb
|
104
|
+
- spec/deckard_cain_spec.rb
|
105
|
+
- spec/lib/cain/career_spec.rb
|
106
|
+
- spec/lib/cain/hero_spec.rb
|
107
|
+
- spec/lib/cain/model_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
76
109
|
homepage: http://github.com/1morepx/deckard_cain
|
77
110
|
licenses: []
|
78
111
|
metadata: {}
|