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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -14
  3. data/lib/api.rb +1 -1
  4. data/lib/base.rb +5 -3
  5. data/lib/version.rb +1 -1
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bcf552167fc4cc9a0b3945ebd661e7830f3d39da65ba739a34b9dcc62f953d3
4
- data.tar.gz: 0fb40c82867df71538b03e187bc09fa4b62f43007edf39d022b601c25279f434
3
+ metadata.gz: cf2383b4c1b9982d1f39b96e01f686c6e1ae0322b3337b8923fc290d99f7a764
4
+ data.tar.gz: dde62b42dc9214c046eb83f954e824e6d399455fdf3b7f610f5e76066c3db254
5
5
  SHA512:
6
- metadata.gz: 4c6624a5ffc9c2ea4a5ab717121e4fdc20d48bcb40d4ba5eb42996f70c314b3b331a71ac1df9b9f88d34c5a67e0dceda0d543cc36c0148003b0f2f3bc2a6e03c
7
- data.tar.gz: fae8e08f03d03d1f0e2859e9d1963144df65fe5108b1ba3e0c6715328717974669dece5baa8882862d04be74a132abc6e6e1c62064d62a97eae411b1e0587cc7
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 to often (there are almost 30k items in PoE which is quite a lot).
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 45 minutes.
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
- items.id # => 223
125
- items.name # => "Hubris Circlet"
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.hardcore`.
131
- All boolean properties have an additionnal question mark accessor, e.g: `item.hardcore?`.
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 45 minutes.
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 45 minutes will take longer (around 2-4 seconds, there are quite a lot of items to fetch).
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 45 minutes
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
- - Doing a find or where on an item will always take some time (1-2 seconds) because it has to traverse all ~30k objects from PoE to find your matches. This could probably be optimised but I haven't had the time to get around to do it.
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/), is you wish to contribute, raise an issue or fork this project and create a pull request :).
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
@@ -34,7 +34,7 @@ module PoeWatch
34
34
 
35
35
  ITEM_API = "https://api.poe.watch/item"
36
36
 
37
- DEFAULT_EXPIRY = 45 * 60 # 45 minutes
37
+ DEFAULT_EXPIRY = 86400 # 1 day
38
38
 
39
39
  @updating = false
40
40
  @redis = $redis
@@ -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
@@ -1,3 +1,3 @@
1
1
  module PoeWatch
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poe-watch-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GabrielDehan