eve_badger 0.1.3 → 0.1.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 +4 -4
- data/VERSION +1 -1
- data/lib/eve_badger.rb +3 -0
- data/lib/eve_badger/cache.rb +5 -0
- data/lib/eve_badger/endpoints.rb +11 -0
- data/lib/eve_badger/eve_api.rb +22 -0
- data/lib/eve_badger/response.rb +5 -4
- data/lib/eve_badger/throttle.rb +10 -9
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7106375fe68a66fd53f03bff72a195bd64d98e7b
|
4
|
+
data.tar.gz: 3c1a5413f29c173d50dd79d2ec8393e129014e0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e45cc78bef49f7b6afaca5bbc2ca6cf1a3a902f840bef7caf9a76cce47ccbbf734e074357dceb0c7a06d0be4d7b267674a78a6bce3a1c761959fe41a50666f3
|
7
|
+
data.tar.gz: b62c670fd8059cbf02ada0e30b93e7917ee64430970d47e2c12ac98477731300f81214f1042e08c4ed891fbc40d26757e0b740cd241fc06bde49a1a2aa8ba73e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/eve_badger.rb
CHANGED
@@ -9,14 +9,17 @@ module EveBadger
|
|
9
9
|
@version ||= File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'VERSION'))).chomp
|
10
10
|
end
|
11
11
|
|
12
|
+
# provides the default user agent for EveAPI objects, it's a good idea to customize your user agent string to identify your application
|
12
13
|
def self.default_user_agent
|
13
14
|
"EveBadger-#{EveBadger.version}/Ruby-#{RUBY_VERSION}"
|
14
15
|
end
|
15
16
|
|
17
|
+
# provides the default domain for the tranquility (live game server) api
|
16
18
|
def self.default_tq_domain
|
17
19
|
'https://api.eveonline.com/'
|
18
20
|
end
|
19
21
|
|
22
|
+
# provides the detault domain for the singularity (public test server, nicknamed "sisi") api
|
20
23
|
def self.default_sisi_domain
|
21
24
|
'https://api.testeveonline.com/'
|
22
25
|
end
|
data/lib/eve_badger/cache.rb
CHANGED
@@ -18,18 +18,22 @@ module EveBadger
|
|
18
18
|
@cache = Moneta.new(*args, **kwargs)
|
19
19
|
end
|
20
20
|
|
21
|
+
# disable request caching
|
21
22
|
def self.disable
|
22
23
|
@cache = nil
|
23
24
|
end
|
24
25
|
|
26
|
+
# test whether request caching is enabled
|
25
27
|
def self.enabled?
|
26
28
|
@cache ? true : false
|
27
29
|
end
|
28
30
|
|
31
|
+
# return the class type of the enabled cache, caches adapters which don't natively support expiration will all appear as Moneta::Expires
|
29
32
|
def self.type
|
30
33
|
@cache.class
|
31
34
|
end
|
32
35
|
|
36
|
+
# store a value in the cache if it is enabled
|
33
37
|
def self.store(key, value, options={})
|
34
38
|
if @cache
|
35
39
|
@cache.store(key, value, options)
|
@@ -38,6 +42,7 @@ module EveBadger
|
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
45
|
+
# retrieve a value from the cache it if is enabled
|
41
46
|
def self.get(key)
|
42
47
|
if @cache
|
43
48
|
@cache[key]
|
data/lib/eve_badger/endpoints.rb
CHANGED
@@ -4,52 +4,63 @@ module EveBadger
|
|
4
4
|
class Endpoint
|
5
5
|
attr_reader :path, :access_mask, :detail_id
|
6
6
|
|
7
|
+
# initialize with :path, :access_mask and optionally :detail_id
|
7
8
|
def initialize(data)
|
8
9
|
@path = data[:path]
|
9
10
|
@access_mask = data[:access_mask]
|
10
11
|
@detail_id = data[:detail_id] if data[:detail_id]
|
11
12
|
end
|
12
13
|
|
14
|
+
# test whether a given api key bitmask is sufficient to make a request against this endpoint
|
13
15
|
def permitted?(other_mask)
|
14
16
|
@access_mask.zero? or (other_mask & @access_mask != 0)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
20
|
+
# loads endpoint data from JSON files packaged with the gem, these JSON files are easily edited if API endpoints are added or changed in the future
|
18
21
|
module Endpoints
|
22
|
+
# load account endpoint data
|
19
23
|
open(File.join(File.dirname(__FILE__), 'json', 'account_endpoints.json'), 'r') do |file|
|
20
24
|
@account_endpoints = JSON.parse(file.read.to_s, :symbolize_names => true)
|
21
25
|
end
|
22
26
|
|
27
|
+
# load character endpoint data
|
23
28
|
open(File.join(File.dirname(__FILE__), 'json', 'character_endpoints.json'), 'r') do |file|
|
24
29
|
@character_endpoints = JSON.parse(file.read.to_s, :symbolize_names => true)
|
25
30
|
end
|
26
31
|
|
32
|
+
# load corporation endpoint data
|
27
33
|
open(File.join(File.dirname(__FILE__), 'json', 'corporation_endpoints.json'), 'r') do |file|
|
28
34
|
@corporation_endpoints = JSON.parse(file.read.to_s, :symbolize_names => true)
|
29
35
|
end
|
30
36
|
|
37
|
+
# load detail endpoint data
|
31
38
|
open(File.join(File.dirname(__FILE__), 'json', 'detail_endpoints.json'), 'r') do |file|
|
32
39
|
@detail_endpoints = JSON.parse(file.read.to_s, :symbolize_names => true)
|
33
40
|
end
|
34
41
|
|
42
|
+
# takes an account endpoint name and returns an endpoint data object
|
35
43
|
def self.account(endpoint)
|
36
44
|
data = @account_endpoints[endpoint]
|
37
45
|
raise ArgumentError, "unsupported endpoint: #{endpoint}" unless data
|
38
46
|
Endpoint.new(data)
|
39
47
|
end
|
40
48
|
|
49
|
+
# takes a character endpoint name and returns an endpoint data object
|
41
50
|
def self.character(endpoint)
|
42
51
|
data = @character_endpoints[endpoint]
|
43
52
|
raise ArgumentError, "unsupported endpoint: #{endpoint}" unless data
|
44
53
|
Endpoint.new(data)
|
45
54
|
end
|
46
55
|
|
56
|
+
# takes a corporation endpoint name and returns an endpoint data object
|
47
57
|
def self.corporation(endpoint)
|
48
58
|
data = @corporation_endpoints[endpoint]
|
49
59
|
raise ArgumentError, "unsupported endpoint: #{endpoint}" unless data
|
50
60
|
Endpoint.new(data)
|
51
61
|
end
|
52
62
|
|
63
|
+
# takes a detail endpoint name and returns an endpoint data object
|
53
64
|
def self.detail(endpoint)
|
54
65
|
data = @detail_endpoints[endpoint]
|
55
66
|
raise ArgumentError, "unsupported endpoint: #{endpoint}" unless data
|
data/lib/eve_badger/eve_api.rb
CHANGED
@@ -18,40 +18,49 @@ module EveBadger
|
|
18
18
|
@key_type = args[:key_type].to_sym if args[:key_type]
|
19
19
|
end
|
20
20
|
|
21
|
+
# sets key_it, coerces to string
|
21
22
|
def key_id=(id)
|
22
23
|
@key_id = id ? id.to_s : nil
|
23
24
|
end
|
24
25
|
|
26
|
+
# sets vcode, coerces to string
|
25
27
|
def vcode=(code)
|
26
28
|
@vcode = code ? code.to_s : nil
|
27
29
|
end
|
28
30
|
|
31
|
+
# sets character_id, coerces to string
|
29
32
|
def character_id=(id)
|
30
33
|
@character_id = id ? id.to_s : nil
|
31
34
|
end
|
32
35
|
|
36
|
+
# sets access_mask, coerces to integer
|
33
37
|
def access_mask=(mask)
|
34
38
|
@access_mask = mask ? mask.to_i : nil
|
35
39
|
end
|
36
40
|
|
41
|
+
# sets key_type, coerces to symbol
|
37
42
|
def key_type=(type)
|
38
43
|
@key_type = type ? type.to_sym : nil
|
39
44
|
end
|
40
45
|
|
46
|
+
# access or retrieve access_mask, will also set key_type if an automatic fetch is triggered
|
41
47
|
def access_mask
|
42
48
|
@access_mask ||= get_access_mask
|
43
49
|
end
|
44
50
|
|
51
|
+
# access or retrieve key_type, will also set access_mask if an automatic fetch is triggered
|
45
52
|
def key_type
|
46
53
|
@key_type ||= get_key_type
|
47
54
|
end
|
48
55
|
|
56
|
+
# takes an account endpoint name and returns a response object, raises an APIKeyError if the request would fail
|
49
57
|
def account(endpoint_name)
|
50
58
|
raise EveBadger::APIKeyError, 'missing required key_id or vcode' unless @key_id && @vcode
|
51
59
|
endpoint = EveBadger::Endpoints.account(endpoint_name.to_sym)
|
52
60
|
api_request(endpoint)
|
53
61
|
end
|
54
62
|
|
63
|
+
# takes a character endpoint name and returns a response object, raises an APIKeyError if the request would fail
|
55
64
|
def character(endpoint_name)
|
56
65
|
raise EveBadger::APIKeyError, 'missing required character_id key_id or_vcode' unless @character_id && @key_id && @vcode
|
57
66
|
raise EveBadger::APIKeyError, 'wrong key type' unless [:Character, :Account].include?(key_type)
|
@@ -59,6 +68,7 @@ module EveBadger
|
|
59
68
|
api_request(endpoint)
|
60
69
|
end
|
61
70
|
|
71
|
+
# takes a corporation endpoint name and returns a response object, raises an APIKeyError if the request would fail
|
62
72
|
def corporation(endpoint_name)
|
63
73
|
raise EveBadger::APIKeyError, 'missing required character_id key_id or_vcode' unless @character_id && @key_id && @vcode
|
64
74
|
raise EveBadger::APIKeyError, 'wrong key type' unless key_type == :Corporation
|
@@ -66,6 +76,7 @@ module EveBadger
|
|
66
76
|
api_request(endpoint)
|
67
77
|
end
|
68
78
|
|
79
|
+
# takes a detail endpoint name and id of interest then returns a response from the given endpoint name, raises an APIKeyError if the request would fail
|
69
80
|
def details(endpoint_name, id_of_interest, fromid=nil, rowcount=nil)
|
70
81
|
raise EveBadger::APIKeyError, 'wrong key type' unless [:Character, :Corporation, :Account].include?(key_type)
|
71
82
|
endpoint = EveBadger::Endpoints.detail(endpoint_name.to_sym)
|
@@ -81,6 +92,7 @@ module EveBadger
|
|
81
92
|
end
|
82
93
|
|
83
94
|
private
|
95
|
+
# takes an endpoint hash and makes an api request to it, raises an APIKeyError if the request would fail
|
84
96
|
def api_request(endpoint)
|
85
97
|
if endpoint.access_mask.zero? or endpoint.permitted?(access_mask)
|
86
98
|
get_response(build_uri(endpoint))
|
@@ -89,41 +101,49 @@ module EveBadger
|
|
89
101
|
end
|
90
102
|
end
|
91
103
|
|
104
|
+
# returns the access mask for a key and will retrieve it if not present
|
92
105
|
def get_access_mask
|
93
106
|
fetch_key_info unless @access_mask
|
94
107
|
@access_mask
|
95
108
|
end
|
96
109
|
|
110
|
+
# returns api key type as a symbol example: :Account, :Character, :Corporation
|
97
111
|
def get_key_type
|
98
112
|
fetch_key_info unless @key_type
|
99
113
|
@key_type
|
100
114
|
end
|
101
115
|
|
116
|
+
# sets @access_mask and @key_type from the public :api_key_info endpoint
|
102
117
|
def fetch_key_info
|
103
118
|
info = account(:api_key_info).result_as_json
|
104
119
|
@access_mask = info['key']['@accessMask'].to_i
|
105
120
|
@key_type = info['key']['@type'].to_sym
|
106
121
|
end
|
107
122
|
|
123
|
+
# builds a uri string for a given endpoint
|
108
124
|
def build_uri(endpoint)
|
109
125
|
"#{@domain}#{endpoint.path}.xml.aspx#{params}"
|
110
126
|
end
|
111
127
|
|
128
|
+
# builds the default params string for most requests
|
112
129
|
def params
|
113
130
|
"?keyID=#{@key_id}&vCode=#{@vcode}#{"&characterID=#{@character_id}" if @character_id}"
|
114
131
|
end
|
115
132
|
|
133
|
+
# attempts to get a http response from the request cache first, then makes an http request if not found
|
116
134
|
def get_response(uri)
|
117
135
|
response = cache_get(uri) || http_get(uri)
|
118
136
|
EveBadger::Response.new(response)
|
119
137
|
end
|
120
138
|
|
139
|
+
# get an http response from the cache if is enabled, returns nil if expired or not found
|
121
140
|
def cache_get(uri)
|
122
141
|
if EveBadger::Cache.enabled?
|
123
142
|
EveBadger::Cache.get(hash_of(uri))
|
124
143
|
end
|
125
144
|
end
|
126
145
|
|
146
|
+
# get a uri via http
|
127
147
|
def http_get(uri)
|
128
148
|
begin
|
129
149
|
response = open(uri) { |res| res.read }
|
@@ -134,6 +154,7 @@ module EveBadger
|
|
134
154
|
response || cache_get(uri)
|
135
155
|
end
|
136
156
|
|
157
|
+
# store an http response in the cache if it is enabled
|
137
158
|
def store_response(uri, response)
|
138
159
|
if EveBadger::Cache.enabled?
|
139
160
|
EveBadger::Cache.store(hash_of(uri), response, expires: cached_until(response))
|
@@ -145,6 +166,7 @@ module EveBadger
|
|
145
166
|
Digest::SHA1.hexdigest(uri)
|
146
167
|
end
|
147
168
|
|
169
|
+
# returns the number of seconds until the cachedUntil value in the xml response from the the API
|
148
170
|
def cached_until(xml)
|
149
171
|
noko = Nokogiri::XML xml
|
150
172
|
seconds_until_expire = Time.parse(noko.xpath('//cachedUntil').text)
|
data/lib/eve_badger/response.rb
CHANGED
@@ -8,26 +8,27 @@ module EveBadger
|
|
8
8
|
@content = content
|
9
9
|
end
|
10
10
|
|
11
|
-
# returns
|
11
|
+
# returns the response content as ruby hash representing badgerfish notation JSON
|
12
12
|
def as_json
|
13
13
|
Badgerfish::Parser.new.load(@content)
|
14
14
|
end
|
15
15
|
|
16
|
-
# returns the response content as
|
16
|
+
# returns the response content as raw XML which you can feed into your favorite parser
|
17
17
|
def as_xml
|
18
18
|
@content
|
19
19
|
end
|
20
20
|
|
21
|
-
# same as #as_xml but
|
21
|
+
# same as #as_xml, but only returns the content of the <result> tag
|
22
22
|
def result_as_xml
|
23
23
|
Nokogiri::XML(@content).xpath("//result/*").to_s
|
24
24
|
end
|
25
25
|
|
26
|
-
# same as #as_json but
|
26
|
+
# same as #as_json, but only returns the content of the <result> tag
|
27
27
|
def result_as_json
|
28
28
|
Badgerfish::Parser.new.load(@content)['eveapi']['result']
|
29
29
|
end
|
30
30
|
|
31
|
+
# fetch any <error> tag in the document, helpful for api error checking
|
31
32
|
def api_errors
|
32
33
|
document = Nokogiri::XML(@content)
|
33
34
|
document.xpath('//error')
|
data/lib/eve_badger/throttle.rb
CHANGED
@@ -2,24 +2,25 @@ require 'slowweb'
|
|
2
2
|
|
3
3
|
module EveBadger
|
4
4
|
module Throttle
|
5
|
+
# disable request throttling
|
5
6
|
def self.disable
|
6
7
|
SlowWeb.reset
|
7
8
|
end
|
8
9
|
|
9
|
-
# enables the default rate limit of 30 requests per
|
10
|
+
# enables the default rate limit of 30 requests per second
|
10
11
|
def self.enable_default
|
11
|
-
SlowWeb.limit(EveBadger.default_tq_domain, 30,
|
12
|
-
SlowWeb.limit(EveBadger.default_sisi_domain, 30,
|
12
|
+
SlowWeb.limit(EveBadger.default_tq_domain, 30, 1)
|
13
|
+
SlowWeb.limit(EveBadger.default_sisi_domain, 30, 1)
|
13
14
|
end
|
14
15
|
|
15
|
-
#
|
16
|
-
def self.enable_custom(
|
16
|
+
# set a custom rate limit if ccp has granted your application an exception
|
17
|
+
def self.enable_custom(requests_per_second)
|
17
18
|
SlowWeb.reset
|
18
|
-
SlowWeb.limit(EveBadger.default_tq_domain,
|
19
|
-
SlowWeb.limit(EveBadger.default_sisi_domain,
|
19
|
+
SlowWeb.limit(EveBadger.default_tq_domain, requests_per_second, 1)
|
20
|
+
SlowWeb.limit(EveBadger.default_sisi_domain, requests_per_second, 1)
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
+
# test if request throttling is currently enabled
|
23
24
|
def self.enabled?
|
24
25
|
if SlowWeb.get_limit(EveBadger.default_tq_domain) || SlowWeb.get_limit(EveBadger.default_sisi_domain)
|
25
26
|
true
|
@@ -28,4 +29,4 @@ module EveBadger
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
31
|
-
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eve_badger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Smedstad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 5.7
|
75
|
+
version: '5.7'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 5.7
|
82
|
+
version: '5.7'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: load_path
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|