hearthstone_card_api 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d79457c921527c72de8580ffd57d65f1986c6a6
4
- data.tar.gz: 97499ca213a04cddd5872bbd3b2d90df5b6c07d6
3
+ metadata.gz: 6c1803c850cca3741dd9e94b421d71943eb11216
4
+ data.tar.gz: 90592bb9d6989151f02fd141bc04042f6e612a8b
5
5
  SHA512:
6
- metadata.gz: bff57d7eff33868cb9c7a0537b73a0f4af09b2868ee64eb461c7895dad9523b0dcbfe3fab3a567f0d573639e58c26c8aecebdd6943288eafa95cc96b5f0ff387
7
- data.tar.gz: 19ca1b33ade1e2da85813d642e01e9009806d42bba5a592614a64e76cf907aba7ccf24f4ed0b5f3778287c8929d02fa985112807bbd44a3a0c7970b057720c17
6
+ metadata.gz: 49c31241399e22c40e28091da7cb99a221f5e21bf9e9b2642a3a330a532377f3538f5ccf9a44893847502cd8fce9d5b6606efd548491f5a39c1fb258f7805fec
7
+ data.tar.gz: 5e51ef07fe902960b241cd0bfd04530720d627a7f6f4f9ddfe3ed18aeba3622565f6cfd32af6d9ef2254d39d637bbb6253ee94b1f31c7caeb665de754efe377b
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
 
3
3
  *swo
4
4
  *swp
5
+ *.gem
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:**
@@ -1,6 +1,4 @@
1
1
  require File.expand_path('../lib/hearthstone_card_api/version', __FILE__)
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.name = 'hearthstone_card_api'
@@ -1,3 +1,3 @@
1
1
  module HearthstoneCardApi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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.3
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