esi 0.3.6 → 0.4.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 +4 -4
- data/README.md +7 -2
- data/lib/esi.rb +10 -3
- data/lib/esi/calls.rb +8 -12
- data/lib/esi/client.rb +1 -6
- data/lib/esi/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d47a1c60590cea3b27c56f4024cc40def5fe7c00
|
4
|
+
data.tar.gz: eaee95bd3df0a5899d39fffb81c78d805f803bfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c91589ff35b7c1779d97f181967dbd8b5becb0176862674086f134cf647581946b5a6e33c34830c030e3c827c876d7a74e681d0c9721617c9337d8045ff1061c
|
7
|
+
data.tar.gz: fc1779a7ac22b08b19789075f5d6029d60c29cc3468d19b5c01206e6d487d5aafe0a0966351a417dd91f1c23db3f836d0a0fcbce75f25a5fbd876d54e099696e
|
data/README.md
CHANGED
@@ -57,8 +57,13 @@ Create a file `config/initializers/esi.rb` with the following options:
|
|
57
57
|
# Set esi api version to dev
|
58
58
|
Esi.config.api_version = :dev
|
59
59
|
|
60
|
-
# Save all responses in this folder
|
60
|
+
# Save all raw JSON responses in this folder
|
61
61
|
Esi.config.response_log_path = Rails.root.join('tmp', 'esi')
|
62
62
|
|
63
|
-
|
63
|
+
# Caching
|
64
|
+
|
65
|
+
ESI will cache API requests that auto expire based on the `Expires-At` header returned by ESI. By default [`ActiveSupport::Cache::MemoryStore`](http://api.rubyonrails.org/classes/ActiveSupport/Cache/MemoryStore.html) is used. When using Rails you can configure ESI to use the cache configured in your app by setting the `cache` config variable.
|
66
|
+
|
64
67
|
Esi.config.cache = Rails.cache
|
68
|
+
|
69
|
+
To disable caching you can set this value to `nil`.
|
data/lib/esi.rb
CHANGED
@@ -2,7 +2,10 @@ require "oauth2"
|
|
2
2
|
require "forwardable"
|
3
3
|
require "ostruct"
|
4
4
|
require "addressable/uri"
|
5
|
+
require "active_support/cache"
|
5
6
|
require "active_support/notifications"
|
7
|
+
require 'active_support/core_ext/string'
|
8
|
+
require "active_support/core_ext/class/attribute"
|
6
9
|
|
7
10
|
module Esi
|
8
11
|
autoload :VERSION, 'esi/version'
|
@@ -70,12 +73,12 @@ module Esi
|
|
70
73
|
timeout: 60,
|
71
74
|
client_id: nil,
|
72
75
|
client_secret: nil,
|
73
|
-
cache:
|
76
|
+
cache: ActiveSupport::Cache::MemoryStore.new,
|
74
77
|
scopes: SCOPES
|
75
78
|
}
|
76
79
|
|
77
80
|
class << self
|
78
|
-
attr_writer :api_version, :logger
|
81
|
+
attr_writer :api_version, :config, :logger, :cache
|
79
82
|
|
80
83
|
def config
|
81
84
|
@config ||= OpenStruct.new(DEFAULT_CONFIG)
|
@@ -88,7 +91,11 @@ module Esi
|
|
88
91
|
end
|
89
92
|
|
90
93
|
def cache
|
91
|
-
Esi.config.cache
|
94
|
+
if Esi.config.cache.nil?
|
95
|
+
@cache ||= ActiveSupport::Cache::NullStore.new
|
96
|
+
else
|
97
|
+
Esi.config.cache
|
98
|
+
end
|
92
99
|
end
|
93
100
|
|
94
101
|
def api_version
|
data/lib/esi/calls.rb
CHANGED
@@ -34,6 +34,14 @@ module Esi
|
|
34
34
|
|
35
35
|
attr_accessor :path, :params
|
36
36
|
|
37
|
+
def name
|
38
|
+
@name ||= self.class.name.remove('Esi::Calls::').underscore.to_sym
|
39
|
+
end
|
40
|
+
|
41
|
+
def cache_key
|
42
|
+
@cache_key ||= ActiveSupport::Cache.expand_cache_key([name, params].flatten, :esi)
|
43
|
+
end
|
44
|
+
|
37
45
|
def method
|
38
46
|
@method ||= :get
|
39
47
|
end
|
@@ -497,18 +505,6 @@ module Esi
|
|
497
505
|
self.cache_duration = 300
|
498
506
|
end
|
499
507
|
|
500
|
-
class Structures < Base
|
501
|
-
def initialize
|
502
|
-
@path = "/universe/structures"
|
503
|
-
end
|
504
|
-
end
|
505
|
-
|
506
|
-
class Structure < Base
|
507
|
-
def initialize(structure_id)
|
508
|
-
@path = "/universe/structures/#{structure_id}"
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
508
|
class Route < Base
|
513
509
|
def initialize(origin_id, destination_id)
|
514
510
|
@path = "/route/#{origin_id}/#{destination_id}"
|
data/lib/esi/client.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/string'
|
2
|
-
require 'set'
|
3
|
-
|
4
1
|
module Esi
|
5
2
|
class Client
|
6
3
|
MAX_ATTEMPTS = 2
|
@@ -58,9 +55,7 @@ module Esi
|
|
58
55
|
|
59
56
|
def cached_response(klass, *args, &block)
|
60
57
|
call = klass.new(*args)
|
61
|
-
|
62
|
-
cache_key = [klass.name, args].flatten.to_set.hash
|
63
|
-
Esi.cache.fetch(cache_key, expires_in: klass.cache_duration) do
|
58
|
+
Esi.cache.fetch(call.cache_key, expires_in: klass.cache_duration) do
|
64
59
|
make_call(call, &block)
|
65
60
|
end
|
66
61
|
end
|
data/lib/esi/version.rb
CHANGED