esi 0.4.6 → 0.4.7.pre.alpha.pre.60

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esi
4
+ class Calls
5
+ class Alliances < Base
6
+ self.cache_duration = 3600
7
+
8
+ def initialize
9
+ @path = '/alliances'
10
+ end
11
+ end
12
+
13
+ class AllianceNames < Base
14
+ self.cache_duration = 3600
15
+
16
+ def initialize(alliance_ids)
17
+ @path = '/alliances/names'
18
+ @params = { alliance_ids: alliance_ids.join(',') }
19
+ end
20
+ end
21
+
22
+ class Alliance < Base
23
+ self.cache_duration = 3600
24
+
25
+ def initialize(alliance_id)
26
+ @path = "/alliances/#{alliance_id}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module Esi
6
+ class Calls
7
+ # Base parent class used for all API calls. Provides basic functionality and state for caching
8
+ # and request initialization
9
+ class Base
10
+ CACHE_NAMESPACE = 'esi'
11
+
12
+ class_attribute :scope
13
+ class_attribute :cache_duration
14
+
15
+ attr_accessor :path, :params
16
+
17
+ # Returns an unique key based on the endpoint and params which is used for caching
18
+ # @return [String] cache key
19
+ def cache_key
20
+ @cache_key ||= begin
21
+ checksum = Digest::MD5.hexdigest("#{path.gsub(%r{^\/}, '')}:#{sorted_params}")
22
+ "#{CACHE_NAMESPACE}:#{checksum}"
23
+ end
24
+ end
25
+
26
+ # Returns the request HTTP method to use
27
+ # @return [Symbol] request method
28
+ def method
29
+ @method ||= :get
30
+ end
31
+
32
+ # Returns the generated endpoint URL including any parameters
33
+ # @return [String] request URI
34
+ def url
35
+ Esi.generate_url(path, params)
36
+ end
37
+
38
+ # @param page [Integer] page number
39
+ def page=(page)
40
+ self.params ||= {}
41
+ self.params[:page] = page
42
+ end
43
+
44
+ # Returns whether the endpoint supports pagination
45
+ # @return [Boolean]
46
+ def paginated?
47
+ !@paginated
48
+ end
49
+
50
+ private
51
+
52
+ # Transforms the params hash into a sorted array
53
+ # @return [Array] sorted array of params
54
+ def sorted_params
55
+ sorted = {}
56
+ params.each do |k, v|
57
+ sorted[k] = v.respond_to?(:sort) ? v.sort : v
58
+ end
59
+ sorted.sort
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esi
4
+ class Calls
5
+ class CharacterNames < Base
6
+ self.cache_duration = 3600
7
+
8
+ def initialize(character_ids)
9
+ @path = '/characters/names'
10
+ @params = { character_ids: character_ids.join(',') }
11
+ end
12
+ end
13
+
14
+ class Character < Base
15
+ self.cache_duration = 3600
16
+
17
+ def initialize(character_id)
18
+ @path = "/characters/#{character_id}"
19
+ end
20
+ end
21
+
22
+ # Cache: 2 minutes
23
+ class CharacterWallet < Base
24
+ self.scope = 'esi-wallet.read_character_wallet.v1'
25
+ self.cache_duration = 120
26
+
27
+ def initialize(character_id)
28
+ @path = "/characters/#{character_id}/wallet"
29
+ end
30
+ end
31
+
32
+ class CharacterSkills < Base
33
+ self.scope = 'esi-skills.read_skills.v1'
34
+ self.cache_duration = 120
35
+
36
+ def initialize(character_id)
37
+ @path = "/characters/#{character_id}/skills"
38
+ end
39
+ end
40
+
41
+ class CharacterWalletJournal < Base
42
+ self.scope = 'esi-wallet.read_character_wallet.v1'
43
+ self.cache_duration = 3600
44
+
45
+ def initialize(character_id)
46
+ @path = "/characters/#{character_id}/wallet/journal"
47
+ end
48
+ end
49
+
50
+ class CharacterWalletTransactions < Base
51
+ self.scope = 'esi-wallet.read_character_wallet.v1'
52
+ self.cache_duration = 3600
53
+
54
+ def initialize(character_id)
55
+ @path = "/characters/#{character_id}/wallet/transactions"
56
+ end
57
+ end
58
+
59
+ class CharacterOrders < Base
60
+ self.scope = 'esi-markets.read_character_orders.v1'
61
+ self.cache_duration = 3600
62
+
63
+ def initialize(character_id)
64
+ @path = "/characters/#{character_id}/orders"
65
+ end
66
+ end
67
+
68
+ class CharacterIndustryJobs < Base
69
+ self.scope = 'esi-industry.read_character_jobs.v1'
70
+ self.cache_duration = 300
71
+
72
+ def initialize(character_id, with_completed: true)
73
+ @path = "/characters/#{character_id}/industry/jobs"
74
+ @params = { include_completed: with_completed }
75
+ end
76
+ end
77
+
78
+ class CharacterBlueprints < Base
79
+ self.scope = 'esi-characters.read_blueprints.v1'
80
+ self.cache_duration = 3600
81
+
82
+ def initialize(character_id)
83
+ @path = "/characters/#{character_id}/blueprints"
84
+ end
85
+ end
86
+
87
+ # Character asset list
88
+ class CharacterAssets < Base
89
+ self.scope = 'esi-assets.read_assets.v1'
90
+ self.cache_duration = 3600
91
+
92
+ def initialize(character_id)
93
+ @path = "/characters/#{character_id}/assets"
94
+ @paginated = true
95
+ end
96
+ end
97
+
98
+ # @deprecated Use {CharacterAssets} instead
99
+ class Assets < Base
100
+ self.scope = 'esi-assets.read_assets.v1'
101
+ self.cache_duration = 3600
102
+
103
+ def initialize(character_id)
104
+ @path = "/characters/#{character_id}/assets"
105
+ end
106
+ end
107
+
108
+ class CharacterContracts < Base
109
+ self.scope = 'esi-contracts.read_character_contracts.v1'
110
+ self.cache_duration = 3600
111
+
112
+ def initialize(character_id)
113
+ @path = "/characters/#{character_id}/contracts"
114
+ end
115
+ end
116
+
117
+ class ContractItems < Base
118
+ self.scope = 'esi-contracts.read_character_contracts.v1'
119
+ self.cache_duration = 3600
120
+
121
+ def initialize(character_id, contract_id)
122
+ @path = "/characters/#{character_id}/contracts/#{contract_id}/items"
123
+ end
124
+ end
125
+
126
+ class CharacterLocation < Base
127
+ self.scope = 'esi-location.read_location.v1'
128
+ self.cache_duration = 5
129
+
130
+ def initialize(character_id)
131
+ @path = "/characters/#{character_id}/location"
132
+ end
133
+ end
134
+
135
+ class CharacterMail < Base
136
+ self.scope = 'esi-mail.read_mail.v1'
137
+ self.cache_duration = 30
138
+
139
+ def initialize(character_id)
140
+ @path = "/characters/#{character_id}/mail"
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esi
4
+ class Calls
5
+ class CorporationNames < Base
6
+ self.cache_duration = 3600
7
+
8
+ def initialize(corporation_ids)
9
+ @path = '/corporations/names'
10
+ @params = { corporation_ids: corporation_ids.join(',') }
11
+ end
12
+ end
13
+
14
+ class Corporation < Base
15
+ self.cache_duration = 3600
16
+
17
+ def initialize(corporation_id)
18
+ @path = "/corporations/#{corporation_id}"
19
+ end
20
+ end
21
+
22
+ class CorporationAssets < Base
23
+ self.scope = 'esi-assets.read_corporation_assets.v1'
24
+ self.cache_duration = 3600
25
+
26
+ def initialize(corporation_id)
27
+ @path = "/corporations/#{corporation_id}/assets"
28
+ @paginated = true
29
+ end
30
+ end
31
+
32
+ class CorporationIndustryJobs < Base
33
+ self.scope = 'esi-industry.read_corporation_jobs.v1'
34
+ self.cache_duration = 300
35
+
36
+ def initialize(corporation_id, with_completed: true)
37
+ @path = "/corporations/#{corporation_id}/industry/jobs"
38
+ @params = { include_completed: with_completed }
39
+ end
40
+ end
41
+
42
+ class CorporationBlueprints < Base
43
+ self.scope = 'esi-corporations.read_blueprints.v1'
44
+ self.cache_duration = 3600
45
+
46
+ def initialize(corporation_id)
47
+ @path = "/corporations/#{corporation_id}/blueprints"
48
+ end
49
+ end
50
+
51
+ class CorporationStructures < Base
52
+ self.scope = 'esi-corporations.read_structures.v1'
53
+ self.cache_duration = 3600
54
+
55
+ def initialize(corporation_id)
56
+ @path = "/corporations/#{corporation_id}/structures"
57
+ end
58
+ end
59
+
60
+ class CorporationMembers < Base
61
+ self.scope = 'esi-corporations.read_corporation_membership.v1'
62
+ self.cache_duration = 3600
63
+
64
+ def initialize(corporation_id)
65
+ @path = "/corporations/#{corporation_id}/members"
66
+ end
67
+ end
68
+
69
+ class CorporationMemberTracking < Base
70
+ self.scope = 'esi-corporations.track_members.v1'
71
+ self.cache_duration = 3600
72
+
73
+ def initialize(corporation_id)
74
+ @path = "/corporations/#{corporation_id}/membertracking"
75
+ end
76
+ end
77
+
78
+ # Link: https://esi.tech.ccp.is/dev/#!/Corporation/get_corporations_corporation_id_roles
79
+ class CorporationRoles < Base
80
+ self.scope = 'esi-corporations.read_corporation_membership.v1'
81
+ self.cache_duration = 3600
82
+
83
+ def initialize(corporation_id)
84
+ @path = "/corporations/#{corporation_id}/roles"
85
+ end
86
+ end
87
+
88
+ class CorporationWallet < Base
89
+ self.scope = 'esi-wallet.read_corporation_wallet.v1'
90
+ self.cache_duration = 120
91
+
92
+ def initialize(corporation_id)
93
+ @path = "/corporations/#{corporation_id}/wallets"
94
+ end
95
+ end
96
+
97
+ class CorporationWallets < Base
98
+ self.scope = 'esi-wallet.read_corporation_wallets.v1'
99
+ self.cache_duration = 300
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esi
4
+ class Calls
5
+ class DogmaAttributes < Base
6
+ def initialize
7
+ @path = '/dogma/attributes/'
8
+ end
9
+ end
10
+
11
+ class DogmaAttribute < Base
12
+ def initialize(attribute_id)
13
+ @path = "/dogma/attributes/#{attribute_id}"
14
+ end
15
+ end
16
+
17
+ class DogmaEffects < Base
18
+ def initialize
19
+ @path = '/dogma/effects/'
20
+ end
21
+ end
22
+
23
+ class DogmaEffect < Base
24
+ def initialize(effect_id)
25
+ @path = "/dogma/effects/#{effect_id}"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esi
4
+ class Calls
5
+ class Fittings < Base
6
+ self.scope = 'esi-fittings.read_fittings.v1'
7
+
8
+ def initialize(character_id)
9
+ @path = "/characters/#{character_id}/fittings"
10
+ end
11
+ end
12
+
13
+ class DeleteFitting < Base
14
+ def initialize(character_id, fitting_id)
15
+ @path = "characters/#{character_id}/fittings/#{fitting_id}"
16
+ @method = :delete
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esi
4
+ class Calls
5
+ class Fleet < Base
6
+ def initialize(fleet_id)
7
+ @path = "/fleets/#{fleet_id}"
8
+ end
9
+ end
10
+
11
+ class FleetMembers < Base
12
+ def initialize(fleet_id)
13
+ @path = "/fleets/#{fleet_id}/members"
14
+ end
15
+ end
16
+
17
+ class FleetWings < Base
18
+ def initialize(fleet_id)
19
+ @path = "/fleets/#{fleet_id}/wings"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esi
4
+ class Calls
5
+ class IndustryFacilities < Base
6
+ self.scope = nil
7
+ self.cache_duration = 3600
8
+
9
+ def initialize
10
+ @path = '/industry/facilities'
11
+ end
12
+ end
13
+
14
+ class IndustrySystems < Base
15
+ self.scope = nil
16
+ self.cache_duration = 3600
17
+
18
+ def initialize
19
+ @path = '/industry/systems'
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Esi
4
+ class Calls
5
+ class Info
6
+ attr_reader :name, :call
7
+ delegate :scope, :cache_duration, to: :call
8
+
9
+ def initialize(name)
10
+ @name = name.to_sym
11
+ @call = Calls.const_get(name.to_s.camelize)
12
+ end
13
+
14
+ def to_s
15
+ @name.to_s
16
+ end
17
+
18
+ def character?
19
+ name.to_s.starts_with?('character')
20
+ end
21
+
22
+ def corporation?
23
+ name.to_s.starts_with?('corporat')
24
+ end
25
+ end
26
+ end
27
+ end