hearthstone_card_api 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +108 -0
- data/hearthstone_card_api.gemspec +0 -2
- data/lib/hearthstone_card_api/version.rb +1 -1
- data/lib/hearthstone_card_api.rb +6 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c1803c850cca3741dd9e94b421d71943eb11216
|
4
|
+
data.tar.gz: 90592bb9d6989151f02fd141bc04042f6e612a8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c31241399e22c40e28091da7cb99a221f5e21bf9e9b2642a3a330a532377f3538f5ccf9a44893847502cd8fce9d5b6606efd548491f5a39c1fb258f7805fec
|
7
|
+
data.tar.gz: 5e51ef07fe902960b241cd0bfd04530720d627a7f6f4f9ddfe3ed18aeba3622565f6cfd32af6d9ef2254d39d637bbb6253ee94b1f31c7caeb665de754efe377b
|
data/.gitignore
CHANGED
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# HearthstoneCardApi
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/hearthstone_card_api.svg)](https://badge.fury.io/rb/hearthstone_card_api)
|
4
|
+
|
5
|
+
An easy to use ruby wrapper for the Hearthstone game api located at HearthstoneApi.com
|
6
|
+
|
7
|
+
Get cards back in your favorite format (JSON, hash, even ruby objects!)
|
8
|
+
|
9
|
+
This gem is currently in *beta* and may be changing frequently until I post otherwise. Use with caution in production applications.
|
10
|
+
## How To Install
|
11
|
+
If using a Gemfile, add the following line :
|
12
|
+
```ruby
|
13
|
+
gem 'hearthstone_card_api'
|
14
|
+
```
|
15
|
+
Then run bundler :
|
16
|
+
```ruby
|
17
|
+
bundle install
|
18
|
+
```
|
19
|
+
If not using a Gemfile run :
|
20
|
+
```ruby
|
21
|
+
gem install hearthstone_card_api
|
22
|
+
```
|
23
|
+
## Configuration
|
24
|
+
Get your api key at https://market.mashape.com/omgvamp/hearthstone
|
25
|
+
|
26
|
+
Place this config block in your application, if you are using Rails that place may be in a file you create at **config/initializers/hearthstone_card_api.rb**
|
27
|
+
```ruby
|
28
|
+
HearthstoneCardApi.configuration do |config|
|
29
|
+
config.api_key = "YOUR_API_KEY_123123"
|
30
|
+
config.data_format = "objects" #THIS LINE IS OPTIONAL!
|
31
|
+
end
|
32
|
+
```
|
33
|
+
Optionally you can also pick your preferred format for the data you receive, currently supported values are "objects", "json", and "hash".
|
34
|
+
|
35
|
+
If you do not indicate a **data_format**, "objects" will be the default value.
|
36
|
+
## Basic Usage
|
37
|
+
```ruby
|
38
|
+
foo = HearthstoneCardApi::Public.new
|
39
|
+
```
|
40
|
+
When you add the above to your code you can access Hearthstone card data very easily :
|
41
|
+
```ruby
|
42
|
+
cards = foo.get_cards()
|
43
|
+
|
44
|
+
cards.count
|
45
|
+
=> 1070
|
46
|
+
```
|
47
|
+
All card methods will return an array of Ruby objects (Assuming your set data format is the default "objects").
|
48
|
+
|
49
|
+
When returning objects the only exception to receiving an array is in the **get_card_by_id** method which returns a single object.
|
50
|
+
|
51
|
+
By default only player collectible cards are returned, this is equivalent to passing in **collectible: 1**
|
52
|
+
|
53
|
+
Passing in **collectible: 0** will return both collectible and non-collectible cards.
|
54
|
+
```ruby
|
55
|
+
cards = foo.get_cards(collectible:0)
|
56
|
+
|
57
|
+
cards.count
|
58
|
+
=> 2844
|
59
|
+
```
|
60
|
+
See below for many more ways to filter your returned cards.
|
61
|
+
|
62
|
+
## Endpoints
|
63
|
+
**Return all cards.**
|
64
|
+
```ruby
|
65
|
+
foo.get_cards
|
66
|
+
```
|
67
|
+
**Search cards by partial name.**
|
68
|
+
```ruby
|
69
|
+
cards = foo.search_cards(name:"Boar")
|
70
|
+
|
71
|
+
cards[0].name
|
72
|
+
=> "Stonetusk Boar"
|
73
|
+
|
74
|
+
cards[0].flavor
|
75
|
+
=> "This card is boaring."
|
76
|
+
```
|
77
|
+
**Return a card by its card id.**
|
78
|
+
```ruby
|
79
|
+
card = foo.get_card_by_id(id:"AT_005")
|
80
|
+
|
81
|
+
card.name
|
82
|
+
=> "Polymorph: Boar"
|
83
|
+
```
|
84
|
+
**Return cards by name. (For partial names use the search method instead.)**
|
85
|
+
|
86
|
+
This may return more than one card if there are multiple cards with that same name (especially if you are choosing to return both collectible and non-collectible cards), for example "Loatheb" is a collectible card, as well as a boss card.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
foo.get_card_by_name(name:"Elven Archer")
|
90
|
+
```
|
91
|
+
**Returns cards by Type/Race/Quality/Faction/Class.**
|
92
|
+
```ruby
|
93
|
+
foo.get_cards_by(trait:"qualities", value:"Common")
|
94
|
+
```
|
95
|
+
Available trait strings => **"types"**,**"races"**,**"qualities"**,**"factions"**,**"classes"**
|
96
|
+
|
97
|
+
For a thorough look at the optional values for the above you can call the **get_info** method or check out HearthstoneApi.com
|
98
|
+
|
99
|
+
## Additional Filters
|
100
|
+
Pass in a hash with the key "filters" to narrow your card results even further:
|
101
|
+
```ruby
|
102
|
+
foo.get_cards(filters:{attack:2, cost:3})
|
103
|
+
|
104
|
+
foo.search_cards(name:"Archer", filters:{health:1})
|
105
|
+
|
106
|
+
foo.get_cards_by(trait:"qualities", value:"Common", filters:{attack:4})
|
107
|
+
```
|
108
|
+
Available keys for filters => **attack:** , **cost:** , **durability:** , **health:** , **collectible:**
|
data/lib/hearthstone_card_api.rb
CHANGED
@@ -41,7 +41,12 @@ module HearthstoneCardApi
|
|
41
41
|
def get_card_by_id(args={}) #expects {:id}
|
42
42
|
url = "cards/#{args[:id]}"
|
43
43
|
args[:url] = url
|
44
|
-
call.return_cards(args)
|
44
|
+
data = call.return_cards(args)
|
45
|
+
if data.is_a? Hash or data.is_a? String #if 404 error, hash, or string
|
46
|
+
return data
|
47
|
+
else
|
48
|
+
return data[0] #else return single obj
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
def get_card_by_name(args={}) #expects {:name}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hearthstone_card_api
|
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
|
- Jeane Ramos
|
@@ -33,6 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
35
|
- LICENSE.txt
|
36
|
+
- README.md
|
36
37
|
- hearthstone_card_api.gemspec
|
37
38
|
- lib/hearthstone_card_api.rb
|
38
39
|
- lib/hearthstone_card_api/caller.rb
|