d3api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/d3api.gemspec +24 -0
- data/lib/.DS_Store +0 -0
- data/lib/d3api.rb +13 -0
- data/lib/d3api/.DS_Store +0 -0
- data/lib/d3api/artisan.rb +15 -0
- data/lib/d3api/base_model.rb +24 -0
- data/lib/d3api/career.rb +15 -0
- data/lib/d3api/configuration.rb +21 -0
- data/lib/d3api/connection.rb +18 -0
- data/lib/d3api/endpoint.rb +12 -0
- data/lib/d3api/follower.rb +15 -0
- data/lib/d3api/hero.rb +15 -0
- data/lib/d3api/item.rb +15 -0
- data/lib/d3api/request.rb +19 -0
- data/lib/d3api/version.rb +3 -0
- metadata +129 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 phereford
|
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,29 @@
|
|
1
|
+
# D3api
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'd3api'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install d3api
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/d3api.gemspec
ADDED
@@ -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 'd3api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'd3api'
|
8
|
+
gem.version = D3api::VERSION
|
9
|
+
gem.authors = ['Patrick Hereford']
|
10
|
+
gem.email = ['phereford@gmail.com']
|
11
|
+
gem.description = %q{Diablo 3 API ruby wrapper}
|
12
|
+
gem.summary = %q{Blizzards D3 API}
|
13
|
+
gem.homepage = ''
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_dependency 'faraday', '~> 0.8.4'
|
21
|
+
gem.add_dependency 'faraday_middleware', '~> 0.9.0'
|
22
|
+
gem.add_dependency 'pry'
|
23
|
+
gem.add_development_dependency 'rspec', '2.12.0'
|
24
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/d3api.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module D3api
|
2
|
+
autoload :Configuration, 'd3api/configuration'
|
3
|
+
autoload :Connection, 'd3api/connection'
|
4
|
+
autoload :Endpoint, 'd3api/endpoint'
|
5
|
+
autoload :Request, 'd3api/request'
|
6
|
+
|
7
|
+
autoload :BaseModel, 'd3api/base_model'
|
8
|
+
autoload :Career, 'd3api/career'
|
9
|
+
autoload :Hero, 'd3api/hero'
|
10
|
+
autoload :Item, 'd3api/item'
|
11
|
+
autoload :Follower, 'd3api/follower'
|
12
|
+
autoload :Artisan, 'd3api/artisan'
|
13
|
+
end
|
data/lib/d3api/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module D3api
|
2
|
+
class Artisan < BaseModel
|
3
|
+
include D3api::Request
|
4
|
+
|
5
|
+
def initialize(region, artisan_type)
|
6
|
+
json_response = find(region, artisan_type)
|
7
|
+
|
8
|
+
super json_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(region, artisan_type)
|
12
|
+
get(:us, "data/artisan/#{artisan_type}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'pry'
|
2
|
+
module D3api
|
3
|
+
class BaseModel
|
4
|
+
extend D3api::Request
|
5
|
+
|
6
|
+
attr_accessor :value
|
7
|
+
|
8
|
+
def initialize(value)
|
9
|
+
@value = value
|
10
|
+
parsed_values = JSON.parse(value)
|
11
|
+
fields = parsed_values.keys.inject([]) do |result, element|
|
12
|
+
result << element.to_sym
|
13
|
+
end
|
14
|
+
|
15
|
+
fields.each do |field|
|
16
|
+
field = :heroClass if field == :class
|
17
|
+
|
18
|
+
self.class.send(:define_method, field) do
|
19
|
+
parsed_values[field.to_s]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/d3api/career.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module D3api
|
2
|
+
class Career < BaseModel
|
3
|
+
include D3api::Request
|
4
|
+
|
5
|
+
def initialize(region, battletag_name, battletag_code)
|
6
|
+
json_response = find(region, battletag_name, battletag_code)
|
7
|
+
|
8
|
+
super json_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(region, battletag_name, battletag_code)
|
12
|
+
get(region, "profile/#{battletag_name}-#{battletag_code}/")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module D3api
|
2
|
+
module Configuration
|
3
|
+
REGIONAL_BASE_URL = {
|
4
|
+
:us => 'https://us.battle.net/api/d3/',
|
5
|
+
:eu => 'https://eu.battle.net/api/d3/',
|
6
|
+
:kr => 'https://kr.battle.net/api/d3/',
|
7
|
+
:tw => 'https://tw.battle.net/api/d3/',
|
8
|
+
:ch => 'https://www.battlenet.com.cn/api/d3/'
|
9
|
+
}
|
10
|
+
|
11
|
+
DEFAULT_ENDPOINT = REGIONAL_BASE_URL[:us]
|
12
|
+
|
13
|
+
def self.regional_urls
|
14
|
+
REGIONAL_BASE_URL
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.default_endpoint
|
18
|
+
DEFAULT_ENDPOINT
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module D3api
|
5
|
+
module Connection
|
6
|
+
def connection(region)
|
7
|
+
@connection = begin
|
8
|
+
Faraday.new(url: D3api::Configuration.regional_urls[region]) do |c|
|
9
|
+
c.request :url_encoded
|
10
|
+
c.request :json
|
11
|
+
c.response :json
|
12
|
+
c.response :logger
|
13
|
+
c.adapter Faraday.default_adapter
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module D3api
|
2
|
+
class Follower < BaseModel
|
3
|
+
include D3api::Request
|
4
|
+
|
5
|
+
def initialize(region, follower_type)
|
6
|
+
json_response = find(region, follower_type)
|
7
|
+
|
8
|
+
super json_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(region, follower_type)
|
12
|
+
get(:us, "data/follower/#{follower_type}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/d3api/hero.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module D3api
|
2
|
+
class Hero < BaseModel
|
3
|
+
include D3api::Request
|
4
|
+
|
5
|
+
def initialize(region, battletag_name, battletag_id, hero_id)
|
6
|
+
json_response = find(region, battletag_name, battletag_id, hero_id)
|
7
|
+
|
8
|
+
super json_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(region, battletag_name, battletag_id, hero_id)
|
12
|
+
get(region, "profile/#{battletag_name}-#{battletag_id}/hero/#{hero_id}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/d3api/item.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module D3api
|
2
|
+
class Item < BaseModel
|
3
|
+
include D3api::Request
|
4
|
+
|
5
|
+
def initialize(region, item_hash)
|
6
|
+
json_response = find(region, item_hash)
|
7
|
+
|
8
|
+
super json_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(region, item_hash)
|
12
|
+
get(region, "data/item/#{item_hash}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'pry'
|
2
|
+
module D3api
|
3
|
+
module Request
|
4
|
+
include D3api::Connection
|
5
|
+
|
6
|
+
def get(region, path, options={})
|
7
|
+
request(region, :get, path, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def request(region, action, path, options)
|
12
|
+
response = connection(region).send(action, path) do |request|
|
13
|
+
request.body = options[:body] if options[:body]
|
14
|
+
end
|
15
|
+
|
16
|
+
response.body.to_json
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: d3api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Patrick Hereford
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday_middleware
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.9.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.9.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.12.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - '='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.12.0
|
78
|
+
description: Diablo 3 API ruby wrapper
|
79
|
+
email:
|
80
|
+
- phereford@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- d3api.gemspec
|
91
|
+
- lib/.DS_Store
|
92
|
+
- lib/d3api.rb
|
93
|
+
- lib/d3api/.DS_Store
|
94
|
+
- lib/d3api/artisan.rb
|
95
|
+
- lib/d3api/base_model.rb
|
96
|
+
- lib/d3api/career.rb
|
97
|
+
- lib/d3api/configuration.rb
|
98
|
+
- lib/d3api/connection.rb
|
99
|
+
- lib/d3api/endpoint.rb
|
100
|
+
- lib/d3api/follower.rb
|
101
|
+
- lib/d3api/hero.rb
|
102
|
+
- lib/d3api/item.rb
|
103
|
+
- lib/d3api/request.rb
|
104
|
+
- lib/d3api/version.rb
|
105
|
+
homepage: ''
|
106
|
+
licenses: []
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.24
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Blizzards D3 API
|
129
|
+
test_files: []
|