hearthstone-api 1.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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +54 -0
- data/.travis.yml +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +99 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hearthstone-api.gemspec +39 -0
- data/lib/hearthstone.rb +5 -0
- data/lib/hearthstone/api.rb +132 -0
- data/lib/hearthstone/version.rb +3 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fd5da3cca95acf4109c023d3127b61262538e0e82fdb8f1c7a63415bd75b72a3
|
4
|
+
data.tar.gz: b565592d723593ef4a67cd7197462d7b4694315a817a50205be7ae23a2b42542
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49ef43eb7d72bae13f54ebb6045da2dd3be8c50b59b6f1005a4812b9dd3ff35aacf9af61bfc1482064e2ec409e1e56b5e7f23f985175e01a9ddc54f3243f24a0
|
7
|
+
data.tar.gz: 2060f13054ae4eaa6c31e058379658cf3804eae70dd930a3ccf687596c25c39f94e9661857b8831daeb5cf6e4bb45dc1d41fadeaa94d0b1d04ff5ad3c86badea
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
Exclude:
|
6
|
+
- bin/*
|
7
|
+
- vendor/**/*
|
8
|
+
|
9
|
+
Bundler/OrderedGems:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
CyclomaticComplexity:
|
13
|
+
Max: 7
|
14
|
+
|
15
|
+
Gemspec/OrderedDependencies:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Rails:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
AsciiComments:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
LineLength:
|
28
|
+
Max: 180
|
29
|
+
|
30
|
+
ClassLength:
|
31
|
+
Max: 200
|
32
|
+
|
33
|
+
ModuleLength:
|
34
|
+
Max: 200
|
35
|
+
|
36
|
+
MethodLength:
|
37
|
+
Max: 50
|
38
|
+
|
39
|
+
BlockLength:
|
40
|
+
Max: 50
|
41
|
+
Exclude:
|
42
|
+
- Rakefile
|
43
|
+
- '**/*.rake'
|
44
|
+
- 'spec/**/*.rb'
|
45
|
+
|
46
|
+
Documentation:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
FileName:
|
50
|
+
Exclude:
|
51
|
+
- Capfile
|
52
|
+
|
53
|
+
Metrics/AbcSize:
|
54
|
+
Max: 40
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at a.dai.0814ap@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hearthstone-api (1.0.0)
|
5
|
+
faraday (~> 0.9.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
byebug (11.0.1)
|
12
|
+
coderay (1.1.2)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
dotenv (2.7.5)
|
15
|
+
faraday (0.9.2)
|
16
|
+
multipart-post (>= 1.2, < 3)
|
17
|
+
jaro_winkler (1.5.3)
|
18
|
+
method_source (0.9.2)
|
19
|
+
multipart-post (2.1.1)
|
20
|
+
parallel (1.17.0)
|
21
|
+
parser (2.6.4.0)
|
22
|
+
ast (~> 2.4.0)
|
23
|
+
powerpack (0.1.2)
|
24
|
+
pry (0.12.2)
|
25
|
+
coderay (~> 1.1.0)
|
26
|
+
method_source (~> 0.9.0)
|
27
|
+
pry-byebug (3.7.0)
|
28
|
+
byebug (~> 11.0)
|
29
|
+
pry (~> 0.10)
|
30
|
+
rainbow (3.0.0)
|
31
|
+
rake (10.5.0)
|
32
|
+
rspec (3.8.0)
|
33
|
+
rspec-core (~> 3.8.0)
|
34
|
+
rspec-expectations (~> 3.8.0)
|
35
|
+
rspec-mocks (~> 3.8.0)
|
36
|
+
rspec-core (3.8.2)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-expectations (3.8.4)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.8.0)
|
41
|
+
rspec-mocks (3.8.1)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.8.0)
|
44
|
+
rspec-support (3.8.2)
|
45
|
+
rubocop (0.58.2)
|
46
|
+
jaro_winkler (~> 1.5.1)
|
47
|
+
parallel (~> 1.10)
|
48
|
+
parser (>= 2.5, != 2.5.1.1)
|
49
|
+
powerpack (~> 0.1)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
ruby-progressbar (~> 1.7)
|
52
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
53
|
+
ruby-progressbar (1.10.1)
|
54
|
+
unicode-display_width (1.6.0)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
bundler (~> 2.0)
|
61
|
+
dotenv (~> 2.1, >= 2.1.1)
|
62
|
+
hearthstone-api!
|
63
|
+
pry-byebug
|
64
|
+
rake (~> 10.0)
|
65
|
+
rspec (~> 3.0)
|
66
|
+
rubocop (~> 0.58.1)
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 DaiAoki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
[](https://travis-ci.org/DaiAoki/hearthstone-api)
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
# Hearthstone::Api
|
6
|
+
This is My favorite social card game 'Hearthstone' API client by pure Ruby with simple interface.
|
7
|
+
It covers all official endpoints. (Detail: [API Official Reference Page](https://develop.battle.net/documentation/api-reference/hearthstone-game-data-api))
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'hearthstone-api'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install hearthstone-api
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
Before coding, you have to get client_id(= `YOUR_CLIENT_ID` ) and client_secret(= `YOUR_CLIENT_SECRET` ) in [Official Page](https://develop.battle.net).
|
27
|
+
|
28
|
+
```
|
29
|
+
# initialize client
|
30
|
+
client = Hearthstone::Api.new(
|
31
|
+
{
|
32
|
+
client_id: <YOUR_CLIENT_ID>, # Required
|
33
|
+
client_secret: <YOUR_CLIENT_SECRET>, # Required
|
34
|
+
locale: "ja_JP", # Optionally, default: "en_US"
|
35
|
+
}
|
36
|
+
)
|
37
|
+
|
38
|
+
# Card search
|
39
|
+
cards = client.search
|
40
|
+
|
41
|
+
# Fetch one card
|
42
|
+
card = client.fetch('52119-arch-villain-rafaam')
|
43
|
+
|
44
|
+
# Fetch deck
|
45
|
+
deck = client.deck("AAECAQcG+wyd8AKS+AKggAOblAPanQMMS6IE/web8wLR9QKD+wKe+wKz/AL1gAOXlAOalAOSnwMA")
|
46
|
+
|
47
|
+
# All metadata
|
48
|
+
metadata = client.metadata
|
49
|
+
|
50
|
+
# Specific metadata
|
51
|
+
sets = client.fetch_metadata("sets")
|
52
|
+
setGroups = client.fetch_metadata("setGroups")
|
53
|
+
types = client.fetch_metadata("types")
|
54
|
+
rarities = client.fetch_metadata("rarities")
|
55
|
+
classes = client.fetch_metadata("classes")
|
56
|
+
minionTypes = client.fetch_metadata("minionTypes")
|
57
|
+
keywords = client.fetch_metadata("keywords")
|
58
|
+
filterableFields = client.fetch_metadata("filterableFields")
|
59
|
+
numericFields = client.fetch_metadata("numericFields")
|
60
|
+
```
|
61
|
+
|
62
|
+
## Search Options
|
63
|
+
You can search by specifying conditions.
|
64
|
+
|
65
|
+
| option | type | description |
|
66
|
+
|:-----------:|:-------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
67
|
+
| set | string | The slug of the set the card belongs to. If you do not supply a value, cards from all sets will be returned. |
|
68
|
+
| class | string | The slug of the card's class. |
|
69
|
+
| manaCost | numbers | The mana cost required to play the card. You can include multiple values in a comma-separated list of numeric values. |
|
70
|
+
| attack | numbers | The attack power of the minion or weapon. You can include multiple values in a comma-separated list of numeric values. |
|
71
|
+
| health | numbers | The health of a minion. You can include multiple values in a comma-separated list of numeric values. |
|
72
|
+
| collectible | numbers | Whether a card is collectible. A value of 1 indicates that collectible cards should be returned; 0 indicates uncollectible cards. To return all cards, use a value of '0,1'. |
|
73
|
+
| rarity | string | The rarity of a card. This value must match the rarity slugs found in metadata. |
|
74
|
+
| type | string | The type of card (for example, minion, spell, and so on). This value must match the type slugs found in metadata. |
|
75
|
+
| minionType | string | The type of minion card (for example, beast, murloc, dragon, and so on). This value must match the minion type slugs found in metadata. |
|
76
|
+
| keyword | string | A required keyword on the card (for example, battlecry, deathrattle, and so on). This value must match the keyword slugs found in metadata. |
|
77
|
+
| textFilter | string | A text string used to filter cards. You must include a locale along with the textFilter parameter. |
|
78
|
+
| page | number | A page number. |
|
79
|
+
| pageSize | number | The number of results to choose per page. A value will be selected automatically if you do not supply a pageSize or if the pageSize is higher than the maximum allowed. |
|
80
|
+
| sort | string | The field used to sort the results. Valid values include manaCost, attack, health, and name. Results are sorted by manaCost by default. Cards will also be sorted by class automatically in most cases. |
|
81
|
+
| order | string | The order in which to sort the results. Valid values are asc or desc. The default value is asc. |
|
82
|
+
|
83
|
+
## Development
|
84
|
+
|
85
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
86
|
+
|
87
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/DaiAoki/hearthstone-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
92
|
+
|
93
|
+
## License
|
94
|
+
|
95
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
96
|
+
|
97
|
+
## Code of Conduct
|
98
|
+
|
99
|
+
Everyone interacting in the Hearthstone::Api project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/DaiAoki/hearthstone-api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hearthstone/api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "hearthstone/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "hearthstone-api"
|
7
|
+
spec.version = Hearthstone::VERSION
|
8
|
+
spec.authors = ["DaiAoki"]
|
9
|
+
spec.email = ["a.dai.0814ap@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Hearthstone API"
|
12
|
+
spec.description = "Hearthstone API Wrapper by Ruby which presents API client for getting card, deck, metadata and so on. "
|
13
|
+
spec.homepage = "https://github.com/DaiAoki/hearthstone-api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "https://github.com/DaiAoki/hearthstone-api"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = "https://hearthstone-app.com"
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/DaiAoki/hearthstone-api"
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "pry-byebug"
|
35
|
+
spec.add_development_dependency "rubocop", "~> 0.58.1"
|
36
|
+
spec.add_development_dependency "dotenv", '~> 2.1', '>= 2.1.1'
|
37
|
+
|
38
|
+
spec.add_dependency "faraday", "~> 0.9.2"
|
39
|
+
end
|
data/lib/hearthstone.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Hearthstone
|
5
|
+
class Error < StandardError; end
|
6
|
+
class InvalidClientError < Error; end
|
7
|
+
|
8
|
+
class Api
|
9
|
+
attr_reader :client_id, :client_secret, :region, :locale, :access_token, :is_valid
|
10
|
+
|
11
|
+
OAUTH_URL = "https://us.battle.net/oauth/token"
|
12
|
+
|
13
|
+
def initialize(options={})
|
14
|
+
@client_id = options[:client_id]
|
15
|
+
@client_secret = options[:client_secret]
|
16
|
+
@region = options[:region] || "us"
|
17
|
+
@locale = options[:locale] || "en_US"
|
18
|
+
@access_token = get_token
|
19
|
+
@is_valid = true
|
20
|
+
rescue Hearthstone::InvalidClientError => e
|
21
|
+
@is_valid = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def endpoint
|
25
|
+
@endpoint ||= Faraday::Connection.new(url: "https://#{region}.api.blizzard.com") do |builder|
|
26
|
+
builder.use Faraday::Request::UrlEncoded
|
27
|
+
builder.use Faraday::Adapter::NetHttp
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid?
|
32
|
+
is_valid
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns an up-to-date list of all cards matching the search criteria.
|
36
|
+
# Allow Options
|
37
|
+
# - set[string] : The slug of the set the card belongs to. If you do not supply a value, cards from all sets will be returned.
|
38
|
+
# - class[string] : The slug of the card's class.
|
39
|
+
# - manaCost[numbers] : The mana cost required to play the card. You can include multiple values in a comma-separated list of numeric values.
|
40
|
+
# - attack[numbers] : The attack power of the minion or weapon. You can include multiple values in a comma-separated list of numeric values.
|
41
|
+
# - health[numbers] : The health of a minion. You can include multiple values in a comma-separated list of numeric values.
|
42
|
+
# - collectible[numbers] : Whether a card is collectible. A value of 1 indicates that collectible cards should be returned; 0 indicates uncollectible cards.
|
43
|
+
# To return all cards, use a value of '0,1'.
|
44
|
+
# - rarity[string] : The rarity of a card. This value must match the rarity slugs found in metadata.
|
45
|
+
# - type[string] : The type of card (for example, minion, spell, and so on). This value must match the type slugs found in metadata.
|
46
|
+
# - minionType[string] : The type of minion card (for example, beast, murloc, dragon, and so on).
|
47
|
+
# This value must match the minion type slugs found in metadata.
|
48
|
+
# - keyword[string] : A required keyword on the card (for example, battlecry, deathrattle, and so on).
|
49
|
+
# This value must match the keyword slugs found in metadata.
|
50
|
+
# - textFilter[string] : A text string used to filter cards. You must include a locale along with the textFilter parameter.
|
51
|
+
# - page[number] : A page number.
|
52
|
+
# - pageSize[number] : The number of results to choose per page.
|
53
|
+
# A value will be selected automatically if you do not supply a pageSize or if the pageSize is higher than the maximum allowed.
|
54
|
+
# - sort[string] : The field used to sort the results. Valid values include manaCost, attack, health, and name.
|
55
|
+
# Results are sorted by manaCost by default. Cards will also be sorted by class automatically in most cases.
|
56
|
+
# - order[string] : The order in which to sort the results. Valid values are asc or desc. The default value is asc.
|
57
|
+
def search(options={})
|
58
|
+
request(:get, "/hearthstone/cards", localized_options(options))
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the card with an ID or slug that matches the one you specify.
|
62
|
+
# Allow Options
|
63
|
+
# - none
|
64
|
+
def fetch(slug, options={})
|
65
|
+
request(:get, "/hearthstone/cards/#{slug}", localized_options(options))
|
66
|
+
end
|
67
|
+
|
68
|
+
# Finds a deck by its deck code.
|
69
|
+
# Allow Options
|
70
|
+
# - none
|
71
|
+
def deck(deckcode, options={})
|
72
|
+
request(:get, "/hearthstone/deck/#{deckcode}", localized_options(options))
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns information about the categorization of cards.
|
76
|
+
# Metadata includes the card set, set group (for example, Standard or Year of the Dragon), rarity, class, card type, minion type, and keywords.
|
77
|
+
def metadata(options={})
|
78
|
+
request(:get, "/hearthstone/metadata", localized_options(options))
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns information about just one type of metadata.
|
82
|
+
def fetch_metadata(type, options={})
|
83
|
+
request(:get, "/hearthstone/metadata/#{type}", localized_options(options))
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def get_token
|
90
|
+
con = Faraday::Connection.new(url: OAUTH_URL) do |builder|
|
91
|
+
builder.use Faraday::Request::UrlEncoded
|
92
|
+
builder.use Faraday::Adapter::NetHttp
|
93
|
+
end
|
94
|
+
res = con.get do |req|
|
95
|
+
req.params[:grant_type] = 'client_credentials'
|
96
|
+
req.params[:client_id] = client_id
|
97
|
+
req.params[:client_secret] = client_secret
|
98
|
+
end
|
99
|
+
json = JSON.parse(res.body)
|
100
|
+
if token = json["access_token"]
|
101
|
+
token
|
102
|
+
else
|
103
|
+
raise Hearthstone::InvalidClientError
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def localized_options(options)
|
108
|
+
options.merge(region: region, locale: locale)
|
109
|
+
end
|
110
|
+
|
111
|
+
def request(method, url, options={})
|
112
|
+
case method
|
113
|
+
when :get then get(url, options)
|
114
|
+
when :post then post(url, options)
|
115
|
+
when :put then put(url, options)
|
116
|
+
when :delete then delete(url, options)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def get(url, options={})
|
121
|
+
res = endpoint.get do |req|
|
122
|
+
req.url url
|
123
|
+
req.params[:access_token] = access_token
|
124
|
+
options.each{|k,v| req.params[k] = v} if options
|
125
|
+
req.headers = {
|
126
|
+
'Accept' => 'application/json',
|
127
|
+
}
|
128
|
+
end
|
129
|
+
res.body.empty? ? {} : JSON.parse(res.body)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hearthstone-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DaiAoki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.58.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.58.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.1'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 2.1.1
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '2.1'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.1.1
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: faraday
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.9.2
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.9.2
|
117
|
+
description: 'Hearthstone API Wrapper by Ruby which presents API client for getting
|
118
|
+
card, deck, metadata and so on. '
|
119
|
+
email:
|
120
|
+
- a.dai.0814ap@gmail.com
|
121
|
+
executables: []
|
122
|
+
extensions: []
|
123
|
+
extra_rdoc_files: []
|
124
|
+
files:
|
125
|
+
- ".gitignore"
|
126
|
+
- ".rspec"
|
127
|
+
- ".rubocop.yml"
|
128
|
+
- ".travis.yml"
|
129
|
+
- CODE_OF_CONDUCT.md
|
130
|
+
- Gemfile
|
131
|
+
- Gemfile.lock
|
132
|
+
- LICENSE.txt
|
133
|
+
- README.md
|
134
|
+
- Rakefile
|
135
|
+
- bin/console
|
136
|
+
- bin/setup
|
137
|
+
- hearthstone-api.gemspec
|
138
|
+
- lib/hearthstone.rb
|
139
|
+
- lib/hearthstone/api.rb
|
140
|
+
- lib/hearthstone/version.rb
|
141
|
+
homepage: https://github.com/DaiAoki/hearthstone-api
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata:
|
145
|
+
homepage_uri: https://hearthstone-app.com
|
146
|
+
source_code_uri: https://github.com/DaiAoki/hearthstone-api
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubygems_version: 3.0.6
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Hearthstone API
|
166
|
+
test_files: []
|