esi 0.2.34 → 0.3.6

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: 062220cdbbcb83eb80529009f74272754fcd939b
4
- data.tar.gz: '0957dd64a0549ee45d5e8ec383c7e2e71975bf92'
3
+ metadata.gz: e1c7c9881ffd3be2d8d42fa51cf9e4ba6828cb3c
4
+ data.tar.gz: 0c3cf816d472ef63c6d071a8ee6589cbc4e58e8f
5
5
  SHA512:
6
- metadata.gz: 719ca8eb1fc4ace7c04b7c38a0447e732cf2bee75d0c16a00e73f46a96d97f09d7a26353cfed0de9e3ac4bcefc574a2d113959a9b6b37a426e12ddd1a99c046b
7
- data.tar.gz: f4ccc8bf6046dc2949095a200323e7747502d671d235f7e53f11fecd29dc9ff76cbcc82ddaca98d25ef5e8db8279f909bb189844bb08362971b08d443789eb45
6
+ metadata.gz: d801070c1264b959f51312455eabfb010c3ee37b49edbed942f8d0e2a531946aaa42de24d98d4c5fd228e77df19a244f60800e7e934bb08790c47702741d4892
7
+ data.tar.gz: c5acc9810725635caf1cab02facd1c144be550f6110398fcaef533d53b852b54fee7b3116d1d9957e0d75e3c835c266fe53f39842039cac87f422cc59810fea9
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Esi
2
2
 
3
+ [![TravisCI build status](https://travis-ci.org/dhiemstra/esi.svg?branch=master)](https://travis-ci.org/dhiemstra/esi)
4
+
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/esi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
6
 
5
7
  TODO: Delete this and the text above, and describe your gem
@@ -22,7 +24,7 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- esi = Esi::Client.new(token: 'YOUR_TOKEN', refresh_token: 'REFRESH_TOKEN', token_expires_at: EXPIRE_TIMESTAMP)
27
+ esi = Esi::Client.new(token: 'YOUR_TOKEN', refresh_token: 'REFRESH_TOKEN', expires_at: EXPIRE_TIMESTAMP)
26
28
  esi.character()
27
29
 
28
30
  ### You can optionally specify a callback that will be executed after a new token has been received using the refresh token
@@ -57,3 +59,6 @@ Create a file `config/initializers/esi.rb` with the following options:
57
59
 
58
60
  # Save all responses in this folder
59
61
  Esi.config.response_log_path = Rails.root.join('tmp', 'esi')
62
+
63
+ # Enable Caching
64
+ Esi.config.cache = Rails.cache
data/lib/esi/calls.rb CHANGED
@@ -54,7 +54,7 @@ module Esi
54
54
 
55
55
  class Regions < Base
56
56
  def initialize
57
- @path = "/universe/regions/#{region_id}"
57
+ @path = "/universe/regions/"
58
58
  end
59
59
  end
60
60
 
@@ -66,7 +66,7 @@ module Esi
66
66
 
67
67
  class Constellations < Base
68
68
  def initialize
69
- @path = "/universe/constellations"
69
+ @path = "/universe/constellations/"
70
70
  end
71
71
  end
72
72
 
@@ -82,6 +82,54 @@ module Esi
82
82
  end
83
83
  end
84
84
 
85
+ class SolarSystems < Base
86
+ def initialize
87
+ @path = "/universe/systems/"
88
+ end
89
+ end
90
+
91
+ class Star < Base
92
+ def initialize(star_id)
93
+ @path = "/universe/stars/#{star_id}"
94
+ end
95
+ end
96
+
97
+ class Planet < Base
98
+ def initialize(planet_id)
99
+ @path = "/universe/planets/#{planet_id}"
100
+ end
101
+ end
102
+
103
+ class Moon < Base
104
+ def initialize(moon_id)
105
+ @path = "/universe/moons/#{moon_id}"
106
+ end
107
+ end
108
+
109
+ class Stargate < Base
110
+ def initialize(stargate_id)
111
+ @path = "/universe/stargates/#{stargate_id}"
112
+ end
113
+ end
114
+
115
+ class Station < Base
116
+ def initialize(station_id)
117
+ @path = "/universe/stations/#{station_id}"
118
+ end
119
+ end
120
+
121
+ class Structures < Base
122
+ def initialize
123
+ @path = "/universe/structures/"
124
+ end
125
+ end
126
+
127
+ class Structure < Base
128
+ def initialize(structure_id)
129
+ @path = "universe/structures/#{structure_id}"
130
+ end
131
+ end
132
+
85
133
  class Types < Base
86
134
  def initialize
87
135
  @path = "/universe/types"
@@ -95,6 +143,30 @@ module Esi
95
143
  end
96
144
  end
97
145
 
146
+ class DogmaAttributes < Base
147
+ def initialize
148
+ @path = "/dogma/attributes/"
149
+ end
150
+ end
151
+
152
+ class DogmaAttribute < Base
153
+ def initialize(attribute_id)
154
+ @path = "/dogma/attributes/#{attribute_id}"
155
+ end
156
+ end
157
+
158
+ class DogmaEffects < Base
159
+ def initialize
160
+ @path = "/dogma/effects/"
161
+ end
162
+ end
163
+
164
+ class DogmaEffect < Base
165
+ def initialize(effect_id)
166
+ @path = "/dogma/effects/#{effect_id}"
167
+ end
168
+ end
169
+
98
170
  class IndustryFacilities < Base
99
171
  self.scope = nil
100
172
  self.cache_duration = 3600
data/lib/esi/client.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'active_support/core_ext/string'
2
+ require 'set'
3
+
1
4
  module Esi
2
5
  class Client
3
6
  MAX_ATTEMPTS = 2
@@ -7,7 +10,7 @@ module Esi
7
10
 
8
11
  def initialize(token: nil, refresh_token: nil, expires_at: nil)
9
12
  @logger = Esi.logger
10
- @token = token
13
+ @access_token = token
11
14
  @refresh_token = refresh_token
12
15
  @expires_at = expires_at
13
16
  end
@@ -15,16 +18,28 @@ module Esi
15
18
  def method_missing(name, *args, &block)
16
19
  klass = nil
17
20
  ActiveSupport::Notifications.instrument('esi.client.detect_call') do
18
- class_name = name.to_s.split('_').map(&:capitalize).join
21
+ class_name = method_to_class_name name
19
22
  begin
20
23
  klass = Esi::Calls.const_get(class_name)
21
24
  rescue NameError
22
25
  super(name, *args, &block)
23
26
  end
24
27
  end
28
+ cached_response(klass, *args, &block)
29
+ end
25
30
 
26
- call = klass.new(*args)
27
- call.paginated? ? request_paginated(call, &block) : request(call, &block)
31
+ def method?(name)
32
+ begin
33
+ klass = Esi::Calls.const_get(method_to_class_name(name))
34
+ rescue NameError
35
+ return false
36
+ end
37
+ !klass.nil?
38
+ end
39
+
40
+ def plural_method?(name)
41
+ plural = name.to_s.pluralize.to_sym
42
+ method? plural
28
43
  end
29
44
 
30
45
  def log(message)
@@ -37,13 +52,30 @@ module Esi
37
52
 
38
53
  private
39
54
 
55
+ def make_call(call, &block)
56
+ call.paginated? ? request_paginated(call, &block) : request(call, &block)
57
+ end
58
+
59
+ def cached_response(klass, *args, &block)
60
+ call = klass.new(*args)
61
+ return make_call(call, &block) unless Esi.cache
62
+ cache_key = [klass.name, args].flatten.to_set.hash
63
+ Esi.cache.fetch(cache_key, expires_in: klass.cache_duration) do
64
+ make_call(call, &block)
65
+ end
66
+ end
67
+
68
+ def method_to_class_name(name)
69
+ name.dup.to_s.split('_').map(&:capitalize).join
70
+ end
71
+
40
72
  def oauth
41
73
  @oauth ||= OAuth.new(
42
- access_token: @token,
74
+ access_token: @access_token,
43
75
  refresh_token: @refresh_token,
44
76
  expires_at: @expires_at,
45
77
  callback: -> (token, expires_at) {
46
- @token = token
78
+ @access_token = token
47
79
  @expires_at = expires_at
48
80
  if refresh_callback.respond_to?(:call)
49
81
  refresh_callback.call(token, expires_at)
data/lib/esi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Esi
2
- VERSION = "0.2.34"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/esi.rb CHANGED
@@ -5,7 +5,7 @@ require "addressable/uri"
5
5
  require "active_support/notifications"
6
6
 
7
7
  module Esi
8
- autoload :Version, 'esi/version'
8
+ autoload :VERSION, 'esi/version'
9
9
  autoload :AccessToken, 'esi/access_token'
10
10
  autoload :OAuth, 'esi/o_auth'
11
11
  autoload :Calls, 'esi/calls'
@@ -70,6 +70,7 @@ module Esi
70
70
  timeout: 60,
71
71
  client_id: nil,
72
72
  client_secret: nil,
73
+ cache: nil,
73
74
  scopes: SCOPES
74
75
  }
75
76
 
@@ -86,6 +87,10 @@ module Esi
86
87
  end
87
88
  end
88
89
 
90
+ def cache
91
+ Esi.config.cache
92
+ end
93
+
89
94
  def api_version
90
95
  @api_version || :latest
91
96
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.34
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Hiemstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-31 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2