eve_app 0.1.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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +21 -0
  5. data/app/controllers/eve_app/application_controller.rb +5 -0
  6. data/app/controllers/eve_app/regions_controller.rb +3 -0
  7. data/app/controllers/eve_app/simple_resource_controller.rb +38 -0
  8. data/app/controllers/eve_app/solar_systems_controller.rb +2 -0
  9. data/app/controllers/eve_app/types_controller.rb +3 -0
  10. data/app/helpers/eve_app/entity_helper.rb +15 -0
  11. data/app/helpers/eve_app/output_helper.rb +25 -0
  12. data/app/models/eve_app/activity.rb +26 -0
  13. data/app/models/eve_app/activity_material.rb +11 -0
  14. data/app/models/eve_app/activity_product.rb +8 -0
  15. data/app/models/eve_app/activity_skill.rb +5 -0
  16. data/app/models/eve_app/application_record.rb +5 -0
  17. data/app/models/eve_app/category.rb +27 -0
  18. data/app/models/eve_app/concerns/activity_relation.rb +26 -0
  19. data/app/models/eve_app/group.rb +3 -0
  20. data/app/models/eve_app/market_group.rb +25 -0
  21. data/app/models/eve_app/region.rb +3 -0
  22. data/app/models/eve_app/solar_system.rb +14 -0
  23. data/app/models/eve_app/station.rb +9 -0
  24. data/app/models/eve_app/type.rb +57 -0
  25. data/app/serializers/eve_app/application_serializer.rb +2 -0
  26. data/app/serializers/eve_app/region_serializer.rb +5 -0
  27. data/app/serializers/eve_app/solar_system_serializer.rb +8 -0
  28. data/app/serializers/eve_app/type_serializer.rb +11 -0
  29. data/config/routes.rb +5 -0
  30. data/lib/eve_app/engine.rb +6 -0
  31. data/lib/eve_app/eve_central.rb +78 -0
  32. data/lib/eve_app/item_parser.rb +112 -0
  33. data/lib/eve_app/sde/data_importer.rb +43 -0
  34. data/lib/eve_app/sde/downloader.rb +53 -0
  35. data/lib/eve_app/sde/normalizer.rb +106 -0
  36. data/lib/eve_app/sde.rb +27 -0
  37. data/lib/eve_app/version.rb +3 -0
  38. data/lib/eve_app/xml_api/calls.rb +197 -0
  39. data/lib/eve_app/xml_api/classes.rb +260 -0
  40. data/lib/eve_app/xml_api/client.rb +86 -0
  41. data/lib/eve_app/xml_api.rb +10 -0
  42. data/lib/eve_app.rb +35 -0
  43. data/lib/table-list.yml +88 -0
  44. data/lib/table-map.yml +177 -0
  45. data/lib/tasks/eve_app.rake +30 -0
  46. metadata +186 -0
@@ -0,0 +1,86 @@
1
+ require 'fileutils'
2
+ require 'net/http'
3
+ require 'rest-client'
4
+
5
+ module EveApp
6
+ module XmlApi
7
+ class Client
8
+ API_HOST = 'https://api.eveonline.com'
9
+ MAX_TRIES = 4
10
+ REQUEST_TIMEOUT = 60
11
+
12
+ attr_reader :key_id, :vcode
13
+ attr_accessor :save_responses, :character_id
14
+
15
+ def initialize(key_id, vcode)
16
+ @key_id = key_id
17
+ @vcode = vcode
18
+ @save_responses = false
19
+ @character_id = nil
20
+ end
21
+
22
+ def method_missing(name, params={})
23
+ call = Calls.const_get(name.to_s.camelize)
24
+ params[:last_id] ? walk(call, params) : request(call, params)
25
+ # rescue NameError
26
+ # super
27
+ end
28
+
29
+ private
30
+
31
+ def walk(call, params={})
32
+ last_id = params.delete(:last_id)
33
+ from_id = nil
34
+ collection = call.new
35
+
36
+ 50.times do
37
+ page = request(call, params.merge(rowCount: 1000, fromID: from_id))
38
+ page.results.reject! { |r| r.id <= last_id }
39
+
40
+ if collection.cached_until.nil? || collection.cached_until > page.cached_until
41
+ collection.cached_until = page.cached_until
42
+ end
43
+ break if page.blank?
44
+
45
+ collection.merge(page)
46
+ from_id = page.ids.min
47
+ break if from_id <= last_id
48
+ end
49
+
50
+ collection
51
+ end
52
+
53
+ def request(call, params={})
54
+ params = params.merge({ rowCount: 500, keyID: key_id, vCode: vcode })
55
+ params[:characterID] = character_id if character_id
56
+ response = nil
57
+
58
+ 1.upto(MAX_TRIES) do |try|
59
+ begin
60
+ response = RestClient::Request.execute(
61
+ method: :get,
62
+ url: "#{API_HOST}#{call.endpoint}",
63
+ timeout: REQUEST_TIMEOUT,
64
+ headers: { params: params }
65
+ )
66
+ # rescue RestClient::Exception => ex
67
+ # error = Calls::ErrorResponse.new(ex, call, params)
68
+ # raise error
69
+ end
70
+ break if response
71
+ end
72
+
73
+ if save_responses
74
+ folder = Rails.root.join('tmp', call.to_s.underscore)
75
+ FileUtils.mkdir_p(folder)
76
+ File.write(folder.join("#{Time.now.to_i.to_s}.xml"), response.body)
77
+ end
78
+
79
+ xml = Nokogiri::XML(response.body)
80
+ call.new(xml)
81
+ rescue Errno::ECONNRESET, Net::ReadTimeout, RestClient::Exceptions::ReadTimeout
82
+ raise ConnectionError, $!.message
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,10 @@
1
+ module EveApp
2
+ module XmlApi
3
+ autoload :Calls, 'eve_app/xml_api/calls'
4
+ autoload :Classes, 'eve_app/xml_api/classes'
5
+ autoload :Client, 'eve_app/xml_api/client'
6
+
7
+ class ApiError < StandardError; end
8
+ class ConnectionError < ApiError; end
9
+ end
10
+ end
data/lib/eve_app.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "pathname"
2
+ require "active_model_serializers"
3
+ require "eve_app/engine"
4
+
5
+ module EveApp
6
+ autoload :EveCentral, 'eve_app/eve_central'
7
+ autoload :ItemParser, 'eve_app/item_parser'
8
+ autoload :SDE, 'eve_app/sde'
9
+ autoload :XmlApi, 'eve_app/xml_api'
10
+
11
+ class << self
12
+ def root
13
+ @root ||= Pathname.new(File.expand_path("../../", __FILE__))
14
+ end
15
+
16
+ def table_name_prefix
17
+ @_table_name_prefix ||= begin
18
+ prefix = EveApp::SDE.config.table_prefix.presence
19
+ prefix ? "#{prefix}_" : super
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ if defined?(::Rails)
26
+ module ::Rails
27
+ class Application
28
+ rake_tasks do
29
+ Dir[File.join(EveApp.root, "/lib/tasks/", "**/*.rake")].each do |file|
30
+ load file
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,88 @@
1
+ - agtAgentTypes
2
+ - agtAgents
3
+ - agtResearchAgents
4
+ - certCerts
5
+ - certMasteries
6
+ - certSkills
7
+ - chrAncestries
8
+ - chrAttributes
9
+ - chrBloodlines
10
+ - chrFactions
11
+ - chrRaces
12
+ - crpActivities
13
+ - crpNPCCorporationDivisions
14
+ - crpNPCCorporationResearchFields
15
+ - crpNPCCorporationTrades
16
+ - crpNPCCorporations
17
+ - crpNPCDivisions
18
+ - dgmAttributeCategories
19
+ - dgmAttributeTypes
20
+ - dgmEffects
21
+ - dgmExpressions
22
+ - dgmTypeAttributes
23
+ - dgmTypeEffects
24
+ - eveGraphics
25
+ - eveIcons
26
+ - eveUnits
27
+ - industryActivity
28
+ - industryActivityMaterials
29
+ - industryActivityProbabilities
30
+ - industryActivityProducts
31
+ - industryActivityRaces
32
+ - industryActivitySkills
33
+ - industryBlueprints
34
+ - invCategories
35
+ - invContrabandTypes
36
+ - invControlTowerResourcePurposes
37
+ - invControlTowerResources
38
+ - invFlags
39
+ - invGroups
40
+ - invItems
41
+ - invMarketGroups
42
+ - invMetaGroups
43
+ - invMetaTypes
44
+ - invNames
45
+ - invPositions
46
+ - invTraits
47
+ - invTypeMaterials
48
+ - invTypeReactions
49
+ - invTypes
50
+ - invUniqueNames
51
+ - invVolumes
52
+ - mapCelestialStatistics
53
+ - mapConstellationJumps
54
+ - mapConstellations
55
+ - mapDenormalize
56
+ - mapJumps
57
+ - mapLandmarks
58
+ - mapLocationScenes
59
+ - mapLocationWormholeClasses
60
+ - mapRegionJumps
61
+ - mapRegions
62
+ - mapSolarSystemJumps
63
+ - mapSolarSystems
64
+ - mapUniverse
65
+ - planetSchematics
66
+ - planetSchematicsPinMap
67
+ - planetSchematicsTypeMap
68
+ - ramActivities
69
+ - ramAssemblyLineStations
70
+ - ramAssemblyLineTypeDetailPerCategory
71
+ - ramAssemblyLineTypeDetailPerGroup
72
+ - ramAssemblyLineTypes
73
+ - ramInstallationTypeContents
74
+ - skinLicense
75
+ - skinMaterials
76
+ - skinShip
77
+ - skins
78
+ - staOperationServices
79
+ - staOperations
80
+ - staServices
81
+ - staStationTypes
82
+ - staStations
83
+ - translationTables
84
+ - trnTranslationColumns
85
+ - trnTranslationLanguages
86
+ - trnTranslations
87
+ - warCombatZoneSystems
88
+ - warCombatZones
data/lib/table-map.yml ADDED
@@ -0,0 +1,177 @@
1
+ ---
2
+ agtAgentTypes:
3
+ destination: agt_agent_types
4
+ agtAgents:
5
+ destination: agt_agents
6
+ agtResearchAgents:
7
+ destination: agt_research_agents
8
+ certCerts:
9
+ destination: cert_certs
10
+ certMasteries:
11
+ destination: cert_masteries
12
+ certSkills:
13
+ destination: cert_skills
14
+ chrAncestries:
15
+ destination: chr_ancestries
16
+ chrAttributes:
17
+ destination: chr_attributes
18
+ chrBloodlines:
19
+ destination: chr_bloodlines
20
+ chrFactions:
21
+ destination: chr_factions
22
+ chrRaces:
23
+ destination: chr_races
24
+ crpActivities:
25
+ destination: crp_activities
26
+ crpNPCCorporationDivisions:
27
+ destination: crp_npccorporation_divisions
28
+ crpNPCCorporationResearchFields:
29
+ destination: crp_npccorporation_research_fields
30
+ crpNPCCorporationTrades:
31
+ destination: crp_npccorporation_trades
32
+ crpNPCCorporations:
33
+ destination: crp_npccorporations
34
+ crpNPCDivisions:
35
+ destination: crp_npcdivisions
36
+ dgmAttributeCategories:
37
+ destination: dgm_attribute_categories
38
+ dgmAttributeTypes:
39
+ destination: dgm_attribute_types
40
+ dgmEffects:
41
+ destination: dgm_effects
42
+ dgmExpressions:
43
+ destination: dgm_expressions
44
+ dgmTypeAttributes:
45
+ destination: dgm_type_attributes
46
+ dgmTypeEffects:
47
+ destination: dgm_type_effects
48
+ eveGraphics:
49
+ destination: eve_graphics
50
+ eveIcons:
51
+ destination: eve_icons
52
+ eveUnits:
53
+ destination: eve_units
54
+ industryActivity:
55
+ destination: industry_activity
56
+ industryActivityMaterials:
57
+ destination: industry_activity_materials
58
+ industryActivityProbabilities:
59
+ destination: industry_activity_probabilities
60
+ industryActivityProducts:
61
+ destination: industry_activity_products
62
+ industryActivityRaces:
63
+ destination: industry_activity_races
64
+ industryActivitySkills:
65
+ destination: industry_activity_skills
66
+ industryBlueprints:
67
+ destination: industry_blueprints
68
+ invCategories:
69
+ destination: inv_categories
70
+ invContrabandTypes:
71
+ destination: inv_contraband_types
72
+ invControlTowerResourcePurposes:
73
+ destination: inv_control_tower_resource_purposes
74
+ invControlTowerResources:
75
+ destination: inv_control_tower_resources
76
+ invFlags:
77
+ destination: inv_flags
78
+ invGroups:
79
+ destination: inv_groups
80
+ invItems:
81
+ destination: inv_items
82
+ invMarketGroups:
83
+ destination: inv_market_groups
84
+ invMetaGroups:
85
+ destination: inv_meta_groups
86
+ invMetaTypes:
87
+ destination: inv_meta_types
88
+ invNames:
89
+ destination: inv_names
90
+ invPositions:
91
+ destination: inv_positions
92
+ invTraits:
93
+ destination: inv_traits
94
+ invTypeMaterials:
95
+ destination: inv_type_materials
96
+ invTypeReactions:
97
+ destination: inv_type_reactions
98
+ invTypes:
99
+ destination: inv_types
100
+ invUniqueNames:
101
+ destination: inv_unique_names
102
+ invVolumes:
103
+ destination: inv_volumes
104
+ mapCelestialStatistics:
105
+ destination: map_celestial_statistics
106
+ mapConstellationJumps:
107
+ destination: map_constellation_jumps
108
+ mapConstellations:
109
+ destination: map_constellations
110
+ mapDenormalize:
111
+ destination: map_denormalize
112
+ mapJumps:
113
+ destination: map_jumps
114
+ mapLandmarks:
115
+ destination: map_landmarks
116
+ mapLocationScenes:
117
+ destination: map_location_scenes
118
+ mapLocationWormholeClasses:
119
+ destination: map_location_wormhole_classes
120
+ mapRegionJumps:
121
+ destination: map_region_jumps
122
+ mapRegions:
123
+ destination: map_regions
124
+ mapSolarSystemJumps:
125
+ destination: map_solar_system_jumps
126
+ mapSolarSystems:
127
+ destination: map_solar_systems
128
+ mapUniverse:
129
+ destination: map_universe
130
+ planetSchematics:
131
+ destination: planet_schematics
132
+ planetSchematicsPinMap:
133
+ destination: planet_schematics_pin_map
134
+ planetSchematicsTypeMap:
135
+ destination: planet_schematics_type_map
136
+ ramActivities:
137
+ destination: ram_activities
138
+ ramAssemblyLineStations:
139
+ destination: ram_assembly_line_stations
140
+ ramAssemblyLineTypeDetailPerCategory:
141
+ destination: ram_assembly_line_type_detail_per_category
142
+ ramAssemblyLineTypeDetailPerGroup:
143
+ destination: ram_assembly_line_type_detail_per_group
144
+ ramAssemblyLineTypes:
145
+ destination: ram_assembly_line_types
146
+ ramInstallationTypeContents:
147
+ destination: ram_installation_type_contents
148
+ skinLicense:
149
+ destination: skin_license
150
+ skinMaterials:
151
+ destination: skin_materials
152
+ skinShip:
153
+ destination: skin_ship
154
+ skins:
155
+ destination: skins
156
+ staOperationServices:
157
+ destination: sta_operation_services
158
+ staOperations:
159
+ destination: sta_operations
160
+ staServices:
161
+ destination: sta_services
162
+ staStationTypes:
163
+ destination: sta_station_types
164
+ staStations:
165
+ destination: sta_stations
166
+ translationTables:
167
+ destination: translation_tables
168
+ trnTranslationColumns:
169
+ destination: trn_translation_columns
170
+ trnTranslationLanguages:
171
+ destination: trn_translation_languages
172
+ trnTranslations:
173
+ destination: trn_translations
174
+ warCombatZoneSystems:
175
+ destination: war_combat_zone_systems
176
+ warCombatZones:
177
+ destination: war_combat_zones
@@ -0,0 +1,30 @@
1
+ require 'eve_app'
2
+
3
+ namespace :eve_app do
4
+ namespace :sde do
5
+ def importer
6
+ @importer ||= EveApp::SDE::DataImporter.new
7
+ end
8
+
9
+ desc "Download latest postgresql datadump"
10
+ task :download do
11
+ importer.download
12
+ end
13
+
14
+ desc "Import and normalize EVE database"
15
+ task import: :environment do
16
+ importer.restore
17
+ importer.normalize
18
+ end
19
+
20
+ desc "Import raw data into the database"
21
+ task restore: :environment do
22
+ importer.restore
23
+ end
24
+
25
+ desc "Import raw data into the database"
26
+ task normalize: :environment do
27
+ importer.normalize
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eve_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Danny Hiemstra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sshkit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: kaminari
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: active_model_serializers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Basic models for the EveSDE data
112
+ email:
113
+ - dannyhiemstra@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - MIT-LICENSE
119
+ - README.md
120
+ - Rakefile
121
+ - app/controllers/eve_app/application_controller.rb
122
+ - app/controllers/eve_app/regions_controller.rb
123
+ - app/controllers/eve_app/simple_resource_controller.rb
124
+ - app/controllers/eve_app/solar_systems_controller.rb
125
+ - app/controllers/eve_app/types_controller.rb
126
+ - app/helpers/eve_app/entity_helper.rb
127
+ - app/helpers/eve_app/output_helper.rb
128
+ - app/models/eve_app/activity.rb
129
+ - app/models/eve_app/activity_material.rb
130
+ - app/models/eve_app/activity_product.rb
131
+ - app/models/eve_app/activity_skill.rb
132
+ - app/models/eve_app/application_record.rb
133
+ - app/models/eve_app/category.rb
134
+ - app/models/eve_app/concerns/activity_relation.rb
135
+ - app/models/eve_app/group.rb
136
+ - app/models/eve_app/market_group.rb
137
+ - app/models/eve_app/region.rb
138
+ - app/models/eve_app/solar_system.rb
139
+ - app/models/eve_app/station.rb
140
+ - app/models/eve_app/type.rb
141
+ - app/serializers/eve_app/application_serializer.rb
142
+ - app/serializers/eve_app/region_serializer.rb
143
+ - app/serializers/eve_app/solar_system_serializer.rb
144
+ - app/serializers/eve_app/type_serializer.rb
145
+ - config/routes.rb
146
+ - lib/eve_app.rb
147
+ - lib/eve_app/engine.rb
148
+ - lib/eve_app/eve_central.rb
149
+ - lib/eve_app/item_parser.rb
150
+ - lib/eve_app/sde.rb
151
+ - lib/eve_app/sde/data_importer.rb
152
+ - lib/eve_app/sde/downloader.rb
153
+ - lib/eve_app/sde/normalizer.rb
154
+ - lib/eve_app/version.rb
155
+ - lib/eve_app/xml_api.rb
156
+ - lib/eve_app/xml_api/calls.rb
157
+ - lib/eve_app/xml_api/classes.rb
158
+ - lib/eve_app/xml_api/client.rb
159
+ - lib/table-list.yml
160
+ - lib/table-map.yml
161
+ - lib/tasks/eve_app.rake
162
+ homepage: http://www.evebuddy.net
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.6.11
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: EveApp API
186
+ test_files: []