eve_badger 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70091024d0ac71348a011738d03fad11d937efb4
4
+ data.tar.gz: d6f3520205e3c0490f8a3a078bd4bb9617345f28
5
+ SHA512:
6
+ metadata.gz: 13506be23d15db31f10590b2a50e50918893c44c6f8cbed53d1e7c8aff80a13460564eb5ffb78acefa26f66191361a9b1ba058b54030e06748e39ae0821714b7
7
+ data.tar.gz: 26f8fef264d81b8ac4de5e30e5f1be9cee96888c4b860f41db0947d0fa24c8b3114df67fb6d49bb82e0315aaca4569fb00cabbe68e94cff1fc0ad76101812161
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2015 Corey Smedstad <smedstadc@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # EveBadger
2
+
3
+ It badgers the Eve: Online API for [badgerfish](http://badgerfish.ning.com/) responses. Get it?
4
+
5
+ ## About
6
+
7
+ EveBadger is a lightweight interface to the Eve: Online API. Build an EveAPI object to represent your API key and call out to the endpoint you're interested in. It'll return a JSON/Hash representing the response. It also handles caching, throttling and access masks out of the box.
8
+
9
+ I wrote this for 3 reasons:
10
+
11
+ * I prefer working with JSON over XML
12
+ * I wasn't in love with existing EveAPI solutions
13
+ * I wanted to learn how to build a custom Gem (Ruby packaging is awesome, btw)
14
+
15
+ ## What does it do?
16
+
17
+ * Obeys CCP's default request rate limit (can be disabled if you have an exception)
18
+ * Caches responses until their respective cachedUntil timestamps (can be disabled if you prefer your own method)
19
+ * Respects access masks for keys and endpoints (it will raise an exception if you try to access an endpoint that isn't allowed by the keys access mask)
20
+ * Probably annoys OO purists
21
+
22
+ ## What doesn't it do?
23
+
24
+ * EveBadger won't wrap each response inside a nice endpoint specific object, it just gives you the JSON.
25
+ * Doesn't cover the entire EveAPI (just Account, Character and Corporation endpoints this will improve in time)
26
+ * It doesn't install from rubygems yet, because I haven't published it (but you can add a git entry to your Gemfile if you want to use it before I do)
27
+
28
+ ## Planned Improvements
29
+
30
+ * **Full API Coverage** Right now EveBadger covers the stuff I use the most. Eventually I'll go through and add all the remaining endpoints.
31
+ * **Cache Configuration** EveBadger uses the Moneta gem for caching. Currently it's pretty dumb and only tries to link up with an unprotected redis instance on localhost, if this fails it'll fall back to an in-memory Moneta store. I'd like to allow users to configure most aspects of the Moneta store.
32
+ * **Rowset Extraction** *(Maybe)* I'm happy with JSON responses for the most part. I don't want or need a full object for every endpoint, but a single basic response object which does a nice job of extracting rowsets and delegating indexes might be nice.
33
+ * **RubyGems** Once I polish a few things and settle on a handful of decisions I'll publish this to rubygems.
34
+
35
+ ## Usage Examples
36
+
37
+ The basic idea is to make an EveAPI object and call the appropriate category method with the symbol representing the name of the endpoint. It'll spit back JSON and you take it from there.
38
+
39
+ I think you'll find that the category methods and endpoint names map directly to the EveAPI documentation at [this location](https://neweden-dev.com/API).
40
+
41
+ ### Getting a Character List
42
+ ```ruby
43
+ api = EveBadger::EveAPI.new(key_id: my_key_id, vcode: my_vcode)
44
+ response = api.account(:list_of_characters)
45
+ response['rowset']['row'].each do |row|
46
+ puts row['@name']
47
+ end
48
+ ```
49
+
50
+ ### Getting Key Info
51
+ ```ruby
52
+ api = EveBadger::EveAPI.new(key_id: my_key_id, vcode: my_vcode)
53
+ response = api.account(:api_key_info)
54
+ puts response['key']['@accessMask']
55
+ puts response['key']['@type']
56
+ ```
57
+
58
+ ### Getting a Tower List
59
+ ```ruby
60
+ # corporation endpoints expect you to also pass the character_id for the character on the key
61
+ api = EveBadger::EveAPI.new(key_id: my_key_id, vcode: my_vcode, character_id: my_character_id)
62
+ response = api.corporation(:starbase_list)
63
+ response['rowset']['row'].each |starbase|
64
+ puts starbase['@state']
65
+ end
66
+ ```
67
+
68
+ ### Getting the Details of a Specific Object
69
+ ```ruby
70
+ api = EveBadger::EveAPI.new(key_id: my_key_id, vcode: my_vcode, character_id: my_character_id)
71
+ # Detail endpoints are the only exception to the category/endpoint pattern
72
+ # Any endpoint that pulls the details of a particular thing is accessed via the details method
73
+ # Simply pass the extra argument for id_of_interest
74
+ response = api.details(:starbase_detail, my_id_of_interest)
75
+ response['rowset']['row'].each |fuel_row|
76
+ puts "#{fuel_row['@typeID']} - #{fuel_row['@quantity']}"
77
+ end
78
+ ```
79
+
80
+ ### Creating an Object for a Test Server API
81
+ ```ruby
82
+ api = EveBadger::EveAPI.new(server: :sisi, key_id: my_key_id, vcode: my_vcode, character_id: my_character_id)
83
+ # then ontinue as normal
84
+ ```
85
+
86
+ ### Tips for Edge Cases
87
+
88
+ Most of the time you can get away with `response['rowset']['row'].each` but sometimes there is just one row in the rowset and in that case `.each` will iterate over the elements of the object. This is something I'd like to handle automatically inside a generic wrapper for responses in the future. In the meantime it's a good idea to use `.is_a?(Hash)` as a guard clause to handle the single-row case when working with rowsets.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,40 @@
1
+ require 'json'
2
+
3
+ module EveBadger
4
+ module EndpointData
5
+ def self.included(base)
6
+ base.extend(EndpointData)
7
+ end
8
+
9
+ module EndpointData
10
+ open(File.join(File.dirname(__FILE__), 'json', 'account_endpoints.json'), 'r') do |file|
11
+ @@account_endpoint = JSON.parse(file.read.to_s, :symbolize_names => true)
12
+ end
13
+ open(File.join(File.dirname(__FILE__), 'json', 'character_endpoints.json'), 'r') do |file|
14
+ @@character_endpoint = JSON.parse(file.read.to_s, :symbolize_names => true)
15
+ end
16
+ open(File.join(File.dirname(__FILE__), 'json', 'corporation_endpoints.json'), 'r') do |file|
17
+ @@corporation_endpoint = JSON.parse(file.read.to_s, :symbolize_names => true)
18
+ end
19
+ open(File.join(File.dirname(__FILE__), 'json', 'detail_endpoints.json'), 'r') do |file|
20
+ @@detail_endpoint = JSON.parse(file.read.to_s, :symbolize_names => true)
21
+ end
22
+
23
+ def account_endpoint
24
+ @@account_endpoint
25
+ end
26
+
27
+ def character_endpoint
28
+ @@character_endpoint
29
+ end
30
+
31
+ def corporation_endpoint
32
+ @@corporation_endpoint
33
+ end
34
+
35
+ def detail_endpoint
36
+ @@detail_endpoint
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,170 @@
1
+ require 'nokogiri'
2
+ require 'time'
3
+ require 'badgerfish'
4
+ require 'open-uri'
5
+ require 'eve_badger/endpoint_data'
6
+ require 'eve_badger/request_cache'
7
+
8
+ module EveBadger
9
+ class EveAPI
10
+ attr_accessor :user_agent
11
+ attr_reader :key_id, :vcode, :character_id
12
+ include EveBadger::EndpointData
13
+ include EveBadger::RequestCache
14
+
15
+ def initialize(args={})
16
+ @domain = args[:sisi] ? EveBadger.sisi_domain : EveBadger.tq_domain
17
+ @user_agent = EveBadger.user_agent
18
+ @key_id = args[:key_id].to_s if args[:key_id]
19
+ @vcode = args[:vcode].to_s if args[:vcode]
20
+ @character_id = args[:character_id].to_s if args[:character_id]
21
+ @access_mask = args[:access_mask].to_i if args[:access_mask]
22
+ @key_type = args[:key_type].to_sym if args[:key_type]
23
+ end
24
+
25
+ def key_id=(id)
26
+ @key_id = id ? id.to_s : nil
27
+ end
28
+
29
+ def vcode=(code)
30
+ @vcode = code ? code.to_s : nil
31
+ end
32
+
33
+ def character_id=(id)
34
+ @character_id = id ? id.to_s : nil
35
+ end
36
+
37
+ def access_mask=(mask)
38
+ @access_mask = mask ? mask.to_i : nil
39
+ end
40
+
41
+ def key_type=(type)
42
+ @key_type = type ? type.to_sym : nil
43
+ end
44
+
45
+ def access_mask
46
+ @access_mask ||= get_access_mask
47
+ end
48
+
49
+ def key_type
50
+ @key_type ||= get_key_type
51
+ end
52
+
53
+ def account(endpoint_name)
54
+ raise 'missing required key_id or vcode' unless @key_id && @vcode
55
+ endpoint = EveAPI.account_endpoint[endpoint_name.to_sym]
56
+ badgerfish_from api_request(endpoint)
57
+ end
58
+
59
+ def character(endpoint_name)
60
+ raise 'missing required character_id key_id or_vcode' unless @character_id && @key_id && @vcode
61
+ raise 'wrong key type' unless key_type == :Character || :Account
62
+ endpoint = EveAPI.character_endpoint[endpoint_name.to_sym]
63
+ badgerfish_from api_request(endpoint)
64
+ end
65
+
66
+ def corporation(endpoint_name)
67
+ raise 'missing required character_id key_id or_vcode' unless @character_id && @key_id && @vcode
68
+ raise 'wrong key type' unless key_type == :Corporation
69
+ endpoint = EveAPI.corporation_endpoint[endpoint_name.to_sym]
70
+ badgerfish_from api_request(endpoint)
71
+ end
72
+
73
+ def details(endpoint_name, id_of_interest, fromid=nil, rowcount=nil)
74
+ raise 'wrong key type' unless key_type == :Character || :Corporation || :Account
75
+ endpoint = EveAPI.detail_endpoint[endpoint_name.to_sym]
76
+ if endpoint_permitted?(endpoint)
77
+ uri = build_uri(endpoint)
78
+ uri << "&#{endpoint[:detail_id]}=#{id_of_interest}"
79
+ uri << "&fromID=#{fromid}" if fromid
80
+ uri << "&rowCount=#{rowcount}" if rowcount
81
+ badgerfish_from get_response(uri)
82
+ else
83
+ raise "#{endpoint[:path]} not permitted by access mask"
84
+ end
85
+ end
86
+
87
+ private
88
+ def api_request(endpoint)
89
+ if endpoint_permitted?(endpoint)
90
+ get_response(build_uri(endpoint))
91
+ else
92
+ raise "#{endpoint[:path]} not permitted by access mask"
93
+ end
94
+ end
95
+
96
+ def endpoint_permitted?(endpoint)
97
+ endpoint[:access_mask].zero? or (access_mask & endpoint[:access_mask] != 0)
98
+ end
99
+
100
+ def get_access_mask
101
+ fetch_key_info unless @access_mask
102
+ @access_mask
103
+ end
104
+
105
+ def get_key_type
106
+ fetch_key_info unless @key_type
107
+ @key_type
108
+ end
109
+
110
+ def fetch_key_info
111
+ info = account(:api_key_info)
112
+ @access_mask = info['key']['@accessMask'].to_i
113
+ @key_type = info['key']['@type'].to_sym
114
+ end
115
+
116
+ def build_uri(endpoint)
117
+ "#{@domain}#{endpoint[:path]}.xml.aspx#{params}"
118
+ end
119
+
120
+ def params
121
+ "?keyID=#{@key_id}&vCode=#{@vcode}#{"&characterID=#{@character_id}" if @character_id}"
122
+ end
123
+
124
+ def get_response(uri)
125
+ response = cache_get(uri) || http_get(uri)
126
+ raise_for_api_errors! response
127
+ response
128
+ end
129
+
130
+ def cache_get(uri)
131
+ if EveAPI.request_cache
132
+ EveAPI.request_cache[uri]
133
+ end
134
+ end
135
+
136
+ def http_get(uri)
137
+ begin
138
+ response = open(uri) { |res| res.read }
139
+ rescue OpenURI::HTTPError => error
140
+ response = error.io.string
141
+ end
142
+ cache_response(uri, response)
143
+ cache_get(uri) || response
144
+ end
145
+
146
+ def cache_response(uri, response)
147
+ if EveAPI.request_cache
148
+ EveAPI.request_cache.store(uri, response, expires: seconds_until_expire(response))
149
+ end
150
+ end
151
+
152
+ def seconds_until_expire(xml)
153
+ noko = Nokogiri::XML xml
154
+ cached_until = Time.parse(noko.xpath('//cachedUntil').first.content)
155
+ cached_until.to_i - Time.now.to_i
156
+ end
157
+
158
+ def raise_for_api_errors!(response)
159
+ noko = Nokogiri::XML(response)
160
+ if noko.xpath('//error').any?
161
+ raise EveBadger::CCPPleaseError, "#{noko.xpath('//error').first}"
162
+ end
163
+ end
164
+
165
+ def badgerfish_from(xml)
166
+ response = Nokogiri::XML(xml)
167
+ Badgerfish::Parser.new.load(response.xpath('//result/*').to_s)
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,14 @@
1
+ {
2
+ "account_status": {
3
+ "path": "Account/AccountStatus",
4
+ "access_mask": 33554432
5
+ },
6
+ "api_key_info": {
7
+ "path": "Account/APIKeyInfo",
8
+ "access_mask": 0
9
+ },
10
+ "list_of_characters": {
11
+ "path": "Account/Characters",
12
+ "access_mask": 0
13
+ }
14
+ }
@@ -0,0 +1,130 @@
1
+ {
2
+ "account_balance": {
3
+ "path": "Char/AccountBalance",
4
+ "access_mask": 1
5
+ },
6
+ "asset_list": {
7
+ "path": "Char/AssetList",
8
+ "access_mask": 2
9
+ },
10
+ "blueprints": {
11
+ "path": "Char/Blueprints",
12
+ "access_mask": 2
13
+ },
14
+ "calendar_event_attendees": {
15
+ "path": "Char/CalendarEventAttendees",
16
+ "access_mask": 4
17
+ },
18
+ "character_sheet": {
19
+ "path": "Char/CharacterSheet",
20
+ "access_mask": 8
21
+ },
22
+ "contact_list": {
23
+ "path": "Char/ContactList",
24
+ "access_mask": 16
25
+ },
26
+ "contact_notifications": {
27
+ "path": "Char/ContactNotifications",
28
+ "access_mask": 32
29
+ },
30
+ "contracts": {
31
+ "path": "Char/Contracts",
32
+ "access_mask": 67108864
33
+ },
34
+ "contract_bids": {
35
+ "path": "Char/ContractBids",
36
+ "access_mask": 67108864
37
+ },
38
+ "factional_warfare_stats": {
39
+ "path": "Char/FacWarStats",
40
+ "access_mask": 64
41
+ },
42
+ "industry_jobs": {
43
+ "path": "Char/IndustryJobs",
44
+ "access_mask": 128
45
+ },
46
+ "industry_jobs_history": {
47
+ "path": "Char/IndustryJobsHistory",
48
+ "access_mask": 128
49
+ },
50
+ "kill_mails": {
51
+ "path": "Char/KillMails",
52
+ "access_mask": 256
53
+ },
54
+ "locations": {
55
+ "path": "Char/Locations",
56
+ "access_mask": 134217728
57
+ },
58
+ "mail_bodies": {
59
+ "path": "Char/MailBodies",
60
+ "access_mask": 512
61
+ },
62
+ "mailing_lists": {
63
+ "path": "Char/MailingLists",
64
+ "access_mask": 1024
65
+ },
66
+ "mail_messages": {
67
+ "path": "Char/MailMessages",
68
+ "access_mask": 2048
69
+ },
70
+ "market_orders": {
71
+ "path": "Char/MarketOrders",
72
+ "access_mask": 4096
73
+ },
74
+ "medals": {
75
+ "path": "Char/Medals",
76
+ "access_mask": 8192
77
+ },
78
+ "notifications": {
79
+ "path": "Char/Notifications",
80
+ "access_mask": 16384
81
+ },
82
+ "notification_texts": {
83
+ "path": "Char/NotificationsTexts",
84
+ "access_mask": 32768
85
+ },
86
+ "planetary_colonies": {
87
+ "path": "Char/PlanetaryColonies",
88
+ "access_mask": 2
89
+ },
90
+ "planetary_pins": {
91
+ "path": "Char/PlanetaryPins",
92
+ "access_mask": 2
93
+ },
94
+ "planetary_routes": {
95
+ "path": "Char/PlanetaryRoutes",
96
+ "access_mask": 2
97
+ },
98
+ "planetary_links": {
99
+ "path": "Char/PlanetaryLinks",
100
+ "access_mask": 2
101
+ },
102
+ "research": {
103
+ "path": "Char/Research",
104
+ "access_mask": 65536
105
+ },
106
+ "skill_in_training": {
107
+ "path": "Char/SkillInTraining",
108
+ "access_mask": 131072
109
+ },
110
+ "skill_queue": {
111
+ "path": "Char/SkillQueue",
112
+ "access_mask": 262144
113
+ },
114
+ "npc_standings": {
115
+ "path": "Char/Standings",
116
+ "access_mask": 524288
117
+ },
118
+ "upcoming_calendar_events": {
119
+ "path": "Char/UpcomingCalendarEvents",
120
+ "access_mask": 1048576
121
+ },
122
+ "wallet_journal": {
123
+ "path": "Char/WalletJournal",
124
+ "access_mask": 2097152
125
+ },
126
+ "wallet_transactions": {
127
+ "path": "Char/WalletTransactions",
128
+ "access_mask": 4194304
129
+ }
130
+ }
@@ -0,0 +1,110 @@
1
+ {
2
+ "account_balance": {
3
+ "path": "Corp/AccountBalance",
4
+ "access_mask": 1
5
+ },
6
+ "asset_list": {
7
+ "path": "Corp/AssetList",
8
+ "access_mask": 2
9
+ },
10
+ "blueprints": {
11
+ "path": "Corp/Blueprints",
12
+ "access_mask": 2
13
+ },
14
+ "contact_list": {
15
+ "path": "Corp/ContactList",
16
+ "access_mask": 16
17
+ },
18
+ "container_log": {
19
+ "path": "Corp/ContainerLog",
20
+ "access_mask": 32
21
+ },
22
+ "contracts": {
23
+ "path": "Corp/Contracts",
24
+ "access_mask": 8388608
25
+ },
26
+ "contract_bids": {
27
+ "path": "Corp/ContractBids",
28
+ "access_mask": 8388608
29
+ },
30
+ "corporation_sheet": {
31
+ "path": "Corp/CorporationSheet",
32
+ "access_mask": 8
33
+ },
34
+ "customs_offices": {
35
+ "path": "Corp/CustomsOffices",
36
+ "access_mask": 2
37
+ },
38
+ "facilities": {
39
+ "path": "Corp/Facilities",
40
+ "access_mask": 128
41
+ },
42
+ "factional_warfare_stats": {
43
+ "path": "Corp/FacWarStats",
44
+ "access_mask": 64
45
+ },
46
+ "industry_jobs": {
47
+ "path": "Corp/IndustryJobs",
48
+ "access_mask": 128
49
+ },
50
+ "industry_jobs_history": {
51
+ "path": "Corp/IndustryJobsHistory",
52
+ "access_mask": 128
53
+ },
54
+ "kill_mails": {
55
+ "path": "Corp/KillMails",
56
+ "access_mask": 256
57
+ },
58
+ "locations": {
59
+ "path": "Corp/Locations",
60
+ "access_mask": 16777216
61
+ },
62
+ "market_orders": {
63
+ "path": "Corp/MarketOrders",
64
+ "access_mask": 4096
65
+ },
66
+ "medals": {
67
+ "path": "Corp/Medals",
68
+ "access_mask": 8192
69
+ },
70
+ "member_medals": {
71
+ "path": "Corp/MemberMedals",
72
+ "access_mask": 4
73
+ },
74
+ "member_security": {
75
+ "path": "Corp/MemberSecurity",
76
+ "access_mask": 512
77
+ },
78
+ "member_security_log": {
79
+ "path": "Corp/MemberSecurityLog",
80
+ "access_mask": 1024
81
+ },
82
+ "member_tracking": {
83
+ "path": "Corp/MemberTracking",
84
+ "access_mask": 2048
85
+ },
86
+ "outpost_list": {
87
+ "path": "Corp/OutpostList",
88
+ "access_mask": 16384
89
+ },
90
+ "shareholders": {
91
+ "path": "Corp/Shareholders",
92
+ "access_mask": 65536
93
+ },
94
+ "standings": {
95
+ "path": "Corp/Standings",
96
+ "access_mask": 262144
97
+ },
98
+ "starbase_list": {
99
+ "path": "Corp/StarbaseList",
100
+ "access_mask": 524288
101
+ },
102
+ "titles": {
103
+ "path": "Corp/Titles",
104
+ "access_mask": 4194304
105
+ },
106
+ "wallet_transactions": {
107
+ "path": "Corp/WalletTransactions",
108
+ "access_mask": 2097152
109
+ }
110
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "char_contract": {
3
+ "path": "Char/Contracts",
4
+ "access_mask": 67108864,
5
+ "detail_id": "contractID"
6
+ },
7
+ "char_contract_items": {
8
+ "path": "Char/ContractItems",
9
+ "access_mask": 67108864,
10
+ "detail_id": "contractID"
11
+ },
12
+ "corp_contract": {
13
+ "path": "Corp/Contracts",
14
+ "access_mask": 8388608,
15
+ "detail_id": "contractID"
16
+ },
17
+ "corp_contract_items": {
18
+ "path": "Corp/ContractItems",
19
+ "access_mask": 8388608,
20
+ "detail_id": "contractID"
21
+ },
22
+ "wallet_journal": {
23
+ "path": "Corp/WalletJournal",
24
+ "access_mask": 1048576,
25
+ "detail_id": "accountKey"
26
+ },
27
+ "outpost_service": {
28
+ "path": "Corp/OutpostServiceDetail",
29
+ "access_mask": 32768,
30
+ "detail_id": "itemID"
31
+ },
32
+ "starbase": {
33
+ "path": "Corp/StarbaseDetail",
34
+ "access_mask": 131072,
35
+ "detail_id": "itemID"
36
+ }
37
+ }
@@ -0,0 +1,33 @@
1
+ require 'moneta'
2
+
3
+ module EveBadger
4
+ module RequestCache
5
+ def self.included(base)
6
+ base.extend(RequestCache)
7
+ end
8
+
9
+ module RequestCache
10
+ begin
11
+ @@request_cache = Moneta.new(:Redis)
12
+ rescue
13
+ @@request_cache = Moneta.new(:File, dir: File.expand_path(File.join(File.dirname(__FILE__), '..', 'cache')))
14
+ end
15
+
16
+ def request_cache
17
+ @@request_cache
18
+ end
19
+
20
+ def disable_request_cache
21
+ @@request_cache = nil
22
+ end
23
+
24
+ def enable_request_cache
25
+ begin
26
+ @@request_cache = Moneta.new(:Redis)
27
+ rescue
28
+ @@request_cache = Moneta.new(:File, dir: File.expand_path(File.join(File.dirname(__FILE__), '..', 'cache')))
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/eve_badger.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'slowweb'
2
+ require 'eve_badger/eve_api'
3
+
4
+ module EveBadger
5
+ def self.version
6
+ @version ||= File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'VERSION')))
7
+ end
8
+ def self.user_agent
9
+ "EveBadger-#{EveBadger.version}/Ruby-#{RUBY_VERSION}"
10
+ end
11
+ def self.tq_domain
12
+ 'https://api.eveonline.com/'
13
+ end
14
+
15
+ def self.sisi_domain
16
+ 'https://api.testeveonline.com/'
17
+ end
18
+
19
+ # According to CCP the default limit for API access is 30 requests per minute.
20
+ SlowWeb.limit(tq_domain, 30, 60)
21
+ SlowWeb.limit(sisi_domain, 30, 60)
22
+
23
+ def self.disable_throttling
24
+ SlowWeb.reset
25
+ end
26
+
27
+ def self.enable_default_throttling
28
+ SlowWeb.limit(@tq_domain, 30, 60)
29
+ SlowWeb.limit(@sisi_domain, 30, 60)
30
+ end
31
+
32
+ def self.enable_custom_throttling(requests_per_minute)
33
+ SlowWeb.reset
34
+ SlowWeb.limit(@tq_domain, requests_per_minute, 60)
35
+ SlowWeb.limit(@sisi_domain, requests_per_minute, 60)
36
+ end
37
+
38
+ class CCPPleaseError < StandardError
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eve_badger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Corey Smedstad
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: badgerfish
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: slowweb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: moneta
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: redis
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 3.2.0
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '3.2'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.2.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3'
103
+ description: For more information look at the README on the github repository.
104
+ email: smedstadc@gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - LICENSE
110
+ - README.md
111
+ - VERSION
112
+ - lib/eve_badger.rb
113
+ - lib/eve_badger/endpoint_data.rb
114
+ - lib/eve_badger/eve_api.rb
115
+ - lib/eve_badger/json/account_endpoints.json
116
+ - lib/eve_badger/json/character_endpoints.json
117
+ - lib/eve_badger/json/corporation_endpoints.json
118
+ - lib/eve_badger/json/detail_endpoints.json
119
+ - lib/eve_badger/request_cache.rb
120
+ homepage: https://github.com/smedstadc/eve_badger
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 1.9.3
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.6
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: 'A gem for interacting with the Eve: Online API.'
144
+ test_files: []
145
+ has_rdoc: