poe-watch-api 1.0.0 → 1.0.1
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/README.md +22 -14
- data/lib/api.rb +1 -1
- data/lib/base.rb +5 -3
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf2383b4c1b9982d1f39b96e01f686c6e1ae0322b3337b8923fc290d99f7a764
|
4
|
+
data.tar.gz: dde62b42dc9214c046eb83f954e824e6d399455fdf3b7f610f5e76066c3db254
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e43560a54878190dde861ada8f0adf936ad12ecf1a08e1f51745cd7e84bb951a605ca9d1f7464532d8b8c5efd14902ef2b5f16f2e706928c162f8bdf83842c58
|
7
|
+
data.tar.gz: 0614bdd99b71d9bfbb7c5a99b49f99b30ccd1606928e70e67f9ce92cf79f201ea8f3d439141dbd248e98f1dc3e56226558b02206e0700cc79e87ea41c2c78526
|
data/README.md
CHANGED
@@ -50,10 +50,16 @@ or add it to your `Gemfile`
|
|
50
50
|
gem 'poe-watch-api'
|
51
51
|
```
|
52
52
|
|
53
|
+
Then
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require 'poe_watch'
|
57
|
+
```
|
58
|
+
|
53
59
|
## Dependencies
|
54
60
|
|
55
61
|
This library has a dependency over `redis`. For it to work you need to have redis installed on your machine (and your server, in production, if using Heroku, you can use an addon like `rediscloud`).
|
56
|
-
We use `redis` because we need to cache the data from Poe Watch to avoid refetching all the items data
|
62
|
+
We use `redis` because we need to cache the data from Poe Watch to avoid refetching all the items data too often (there are almost 30k items in PoE which is quite a lot).
|
57
63
|
|
58
64
|
There are two ways of making this gem work with redis:
|
59
65
|
|
@@ -84,19 +90,21 @@ end
|
|
84
90
|
```
|
85
91
|
|
86
92
|
The total footprint of the data from PoeWatch API in redis is a bit less than **2 megabytes**. You can check the exact memory footprint in your redis by calling `PoeWatch::Api.memory_footprint`, the data will be displayed in kilobytes.
|
87
|
-
The default time to live (TTL) of the cache is
|
93
|
+
The default time to live (TTL) of the cache is 1 day.
|
88
94
|
|
89
95
|
## Usage
|
90
96
|
|
91
97
|
Here is a simple usage example:
|
92
|
-
```
|
98
|
+
```ruby
|
99
|
+
require 'poe_watch'
|
100
|
+
|
93
101
|
# See the dependencies section
|
94
102
|
PoeWatch::Api.redis = Redis.new
|
95
103
|
|
96
104
|
# Non mandatory
|
97
105
|
PoeWatch::Api.refresh!(3600) # cache for 1 hour
|
98
106
|
|
99
|
-
PoeWatch::Item.find({ name: "Circle of Nostalgia }).price_for_league('Metamorph')
|
107
|
+
PoeWatch::Item.find({ name: "Circle of Nostalgia" }).price_for_league('Metamorph')
|
100
108
|
```
|
101
109
|
|
102
110
|
### Items
|
@@ -121,14 +129,14 @@ items.first.name # => "Hubris Circlet"
|
|
121
129
|
item = PoeWatch::Item.find(name: "Circle of Nostalgia") # Returns the item "Circle of Nostalgia"
|
122
130
|
item = PoeWatch::Item.find(name: /circle/i) # Returns the first item with a name containing "circle"
|
123
131
|
|
124
|
-
|
125
|
-
|
132
|
+
item.id # => 223
|
133
|
+
item.name # => "Hubris Circlet"
|
126
134
|
```
|
127
135
|
|
128
136
|
#### Item properties
|
129
137
|
|
130
|
-
All properties have an accessor you can use, e.g: `item.id`, `item.name`, `item.
|
131
|
-
All boolean properties have an additionnal question mark accessor, e.g: `item.
|
138
|
+
All properties have an accessor you can use, e.g: `item.id`, `item.name`, `item.category`.
|
139
|
+
All boolean properties have an additionnal question mark accessor, e.g: `item.gem_is_corrupted?`.
|
132
140
|
|
133
141
|
Items only have relevant properties (e.g: map tiers only on maps, stack_size only on currencies, etc...)
|
134
142
|
|
@@ -214,7 +222,7 @@ leagues.first.start? # => "2019-12-13T20:00:00Z"
|
|
214
222
|
#### Find one specific league
|
215
223
|
```ruby
|
216
224
|
league = PoeWatch::League.find(name: "Metamorph") # Return the non hardcore "Metamorph" league
|
217
|
-
league = PoeWatch::League.find(name: /metamorph/i) # Will return the first Metamorph league found
|
225
|
+
league = PoeWatch::League.find(name: /metamorph/i, hardcore: false) # Will return the first non hardcore Metamorph league found
|
218
226
|
|
219
227
|
league.name # => "Metamorph"
|
220
228
|
league.hardcore? # => false
|
@@ -278,11 +286,11 @@ All properties have an accessor you can use, e.g: `category.name`, `category.gro
|
|
278
286
|
### API Cache
|
279
287
|
|
280
288
|
```ruby
|
281
|
-
# Fetch all the data from poe.watch API and cache it for the next
|
289
|
+
# Fetch all the data from poe.watch API and cache it for the next 1 day.
|
282
290
|
# You don't actually need to call this. It is automatically called when using `::find`, `::where`, `::all` or `::count`, and won't do anything if the cache already contains data.
|
283
|
-
# Although beware that if you don't call it first, the first call to find/where/all/count every
|
291
|
+
# Although beware that if you don't call it first, the first call to find/where/all/count every 1 day will take longer (around 2-4 seconds, there are quite a lot of items to fetch).
|
284
292
|
PoeWatch::Api.refresh!
|
285
|
-
# You can also specify a cache TTL different than
|
293
|
+
# You can also specify a cache TTL different than 1 day
|
286
294
|
PoeWatch::Api.refresh!(3600) # 1 hour cache
|
287
295
|
|
288
296
|
# If you need to force clear the cache, you can use
|
@@ -296,12 +304,12 @@ PoeWatch::Api.ready?
|
|
296
304
|
|
297
305
|
## Shortcomings
|
298
306
|
|
299
|
-
-
|
307
|
+
- When you want to fetch the price of an item, we do a request each time using the PoE API `/item` endpoint, which is not ideal. Ideally we'd want to use the `/compact` API for that but I haven't had the time to do that yet.
|
300
308
|
- No rate limiter set for the moment so when fetching a bunch of item prices you could hit the rate limiter of `poe.watch`. I'll add one at some point in the future if is needed or requested.
|
301
309
|
|
302
310
|
## Contribution
|
303
311
|
|
304
|
-
The code is well documented, using [tomdoc](http://tomdoc.org/),
|
312
|
+
The code is well documented, using [tomdoc](http://tomdoc.org/), if you wish to contribute, raise an issue or fork this project and create a pull request :).
|
305
313
|
|
306
314
|
Most of the codebase is in `lib/api`, `lib/base` and `lib/item`.
|
307
315
|
|
data/lib/api.rb
CHANGED
data/lib/base.rb
CHANGED
@@ -29,6 +29,7 @@ module PoeWatch
|
|
29
29
|
|
30
30
|
# Setter for instance variable
|
31
31
|
def __data=(value)
|
32
|
+
puts "SETTING @__data"
|
32
33
|
@__data = value
|
33
34
|
end
|
34
35
|
|
@@ -52,14 +53,15 @@ module PoeWatch
|
|
52
53
|
# Returns an Array of class instances.
|
53
54
|
def all
|
54
55
|
PoeWatch::Api.refresh!
|
55
|
-
|
56
|
+
|
56
57
|
return __data if __data.any?
|
57
|
-
|
58
|
+
puts "PAST DATA"
|
58
59
|
# If data isn't already loaded
|
59
60
|
# puts "Loading #{type} data..."
|
60
61
|
json_data = PoeWatch::Api.send(INFLECTOR[type])
|
61
62
|
if json_data.any?
|
62
|
-
__data = json_data.map { |raw_data| self.new(raw_data) }
|
63
|
+
self.__data = json_data.map { |raw_data| self.new(raw_data) }
|
64
|
+
__data
|
63
65
|
else
|
64
66
|
[]
|
65
67
|
end
|
data/lib/version.rb
CHANGED