restiny 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 525f30b84be418f2709f43396452fe3fb5f1b7fc307f5096a6698da8a1a61d3b
4
- data.tar.gz: 3e008a19f1766d4d0a89a840e7439acae17d714bd5ec22cfd637af8aa9790f46
3
+ metadata.gz: 9ad23e571d4f6b91fc296e0578074983f8d6883518ffe94743a6003bbf20dfd0
4
+ data.tar.gz: 6aba22d2cfb3a8bc2f8c93d0a11ccfef63a55eaa8aaec008a3b769710d4b3ff5
5
5
  SHA512:
6
- metadata.gz: 4a741c23f022a5a9faa659aa26a8de4b39233caceaf1b11713209b605012d0cf721b2c2f06c4bbb865fe5f28f166d0b88a1446a06052aad88b35810ebc293a33
7
- data.tar.gz: 530fd77d6b734bf749e9ce55b950dae7da4acc8f4719c95d57bf8f3dbb6403f0b804b7960b09cc434814b6f77e1c649ca651b86e649dd3b69081cea56d3e0359
6
+ metadata.gz: e600c2e4a0552420404dd6aa11692613e65cd6ee7efddc7a5200f8750569e39f259d5156b25fb8baca7175f7575b870794827213548e74877c7faeea23c18e75
7
+ data.tar.gz: 2e319308c54b1e793862400bc5ff362d0570924edf372d1f07a1f06766210e031dda2c79b7db8d171588d8dc8b849c482f6bb4d0ca86902e7d739bd6c831a410
@@ -1,5 +1,4 @@
1
1
  # frozen_string/literal: true
2
-
3
2
  require 'down'
4
3
  require 'json'
5
4
  require 'sqlite3'
@@ -8,73 +7,91 @@ require 'zip'
8
7
  module Restiny
9
8
  class Manifest
10
9
  TABLES = {
11
- 'DestinyAchievementDefinition': { item: 'achievement', items: 'achievements' },
12
- 'DestinyActivityDefinition': { item: 'activity', items: 'activities' },
13
- 'DestinyActivityGraphDefinition': { item: 'activity_graph', items: 'activity_graphs' },
14
- 'DestinyActivityModeDefinition': { item: 'activity_modes', items: 'activity_modes' },
15
- 'DestinyActivityModifierDefinition': { item: 'activity_modifier', items: 'activity_modifiers' },
16
- 'DestinyActivityTypeDefinition': { item: 'activity_type', items: 'activity_types' },
17
- 'DestinyArtifactDefinition': { item: 'artifact', items: 'artifacts' },
18
- 'DestinyBondDefinition': { item: 'bond', items: 'bonds' },
19
- 'DestinyBreakerTypeDefinition': { item: 'breaker_type', items: 'breaker_types' },
20
- 'DestinyChecklistDefinition': { item: 'checklist', items: 'checklists' },
21
- 'DestinyClassDefinition': { item: 'class', items: 'classes' },
22
- 'DestinyCollectibleDefinition': { item: 'collectible', items: 'collectibles' },
23
- 'DestinyDamageTypeDefinition': { item: 'damage_type', items: 'damage_types' },
24
- 'DestinyDestinationDefinition': { item: 'destination', items: 'destinations' },
25
- 'DestinyEnergyTypeDefinition': { item: 'energy_type', items: 'energy_types' },
26
- 'DestinyEquipmentSlotDefinition': { item: 'equipment_slot', items: 'equipment_slots' },
27
- 'DestinyEventCardDefinition': { item: 'event_card', items: 'event_cards' },
28
- 'DestinyFactionDefinition': { item: 'faction', items: 'factions' },
29
- 'DestinyGenderDefinition': { item: 'gender', items: 'genders' },
30
- 'DestinyHistoricalStatsDefinition': { item: 'historical_stat', items: 'historical_stats' },
31
- 'DestinyInventoryBucketDefinition': { item: 'inventory_bucket', items: 'inventory_buckets' },
32
- 'DestinyInventoryItemDefinition': { item: 'inventory_item', items: 'inventory_items' },
33
- 'DestinyItemCategoryDefinition': { item: 'item_category', items: 'item_categories' },
34
- 'DestinyItemTierTypeDefinition': { item: 'item_tier_type', items: 'item_tier_types' },
35
- 'DestinyLocationDefinition': { item: 'location', items: 'locations' },
36
- 'DestinyLoreDefinition': { item: 'lore', items: 'lore_entries' },
37
- 'DestinyMaterialRequirementSetDefinition': { item: 'material_requirement_set', items: 'material_requirement_sets' },
38
- 'DestinyMedalTierDefinition': { item: 'medal_tier', items: 'medal_tiers' },
39
- 'DestinyMetricDefinition': { item: 'metric', items: 'metrics' },
40
- 'DestinyMilestoneDefinition': { item: 'milestone', items: 'milestones' },
41
- 'DestinyObjectiveDefinition': { item: 'objective', items: 'objectives' },
42
- 'DestinyPlaceDefinition': { item: 'place', items: 'places' },
43
- 'DestinyPlugSetDefinition': { item: 'plug_set', items: 'plug_sets' },
44
- 'DestinyPowerCapDefinition': { item: 'power_cap', items: 'power_caps' },
45
- 'DestinyPresentationNodeDefinition': { item: 'presentation_node', items: 'presentation_nodes' },
46
- 'DestinyProgressionDefinition': { item: 'progression', items: 'progression_data' },
47
- 'DestinyProgressionLevelRequirementDefinition': { item: 'progression_level_requirement', items: 'progression_level_requirements' },
48
- 'DestinyRaceDefinition': { item: 'race', items: 'races' },
49
- 'DestinyRecordDefinition': { item: 'record', items: 'records' },
50
- 'DestinyReportReasonCategoryDefinition': { item: 'report_reason_category', items: 'report_reason_categories' },
51
- 'DestinyRewardSourceDefinition': { item: 'reward_source', items: 'reward_sources' },
52
- 'DestinySackRewardItemListDefinition': { item: 'sack_reward_item_list', items: 'sack_reward_item_lists' },
53
- 'DestinySandboxPatternDefinition': { item: 'sandbox_pattern', items: 'sandbox_patterns' },
54
- 'DestinySandboxPerkDefinition': { item: 'sandbox_perk', items: 'sandbox_perks' },
55
- 'DestinySeasonDefinition': { item: 'season', items: 'seasons' },
56
- 'DestinySeasonPassDefinition': { item: 'season_pass', items: 'season_passes' },
57
- 'DestinySocketCategoryDefinition': { item: 'socket_category', items: 'socket_categories' },
58
- 'DestinySocketTypeDefinition': { item: 'socket_type', items: 'socket_types' },
59
- 'DestinyStatDefinition': { item: 'stat', items: 'stats' },
60
- 'DestinyStatGroupDefinition': { item: 'stat_group', items: 'stat_groups' },
61
- 'DestinyTalentGridDefinition': { item: 'talent_grid', items: 'talent_grids' },
62
- 'DestinyTraitCategoryDefinition': { item: 'trait_category', items: 'trait_categories' },
63
- 'DestinyTraitDefinition': { item: 'trait', items: 'traits' },
64
- 'DestinyUnlockDefinition': { item: 'unlock', items: 'unlocks' },
65
- 'DestinyVendorDefinition': { item: 'vendor', items: 'vendors' },
66
- 'DestinyVendorGroupDefinition': { item: 'vendor_group', items: 'vendor_groups' }
10
+ 'Achievement': { item: 'achievement', items: 'achievements' },
11
+ 'Activity': { item: 'activity', items: 'activities' },
12
+ 'ActivityGraph': { item: 'activity_graph', items: 'activity_graphs' },
13
+ 'ActivityMode': { item: 'activity_modes', items: 'activity_modes' },
14
+ 'ActivityModifier': { item: 'activity_modifier', items: 'activity_modifiers' },
15
+ 'ActivityType': { item: 'activity_type', items: 'activity_types' },
16
+ 'Artifact': { item: 'artifact', items: 'artifacts' },
17
+ 'Bond': { item: 'bond', items: 'bonds' },
18
+ 'BreakerType': { item: 'breaker_type', items: 'breaker_types' },
19
+ 'Checklist': { item: 'checklist', items: 'checklists' },
20
+ 'Class': { item: 'class', items: 'classes' },
21
+ 'Collectible': { item: 'collectible', items: 'collectibles' },
22
+ 'DamageType': { item: 'damage_type', items: 'damage_types' },
23
+ 'Destination': { item: 'destination', items: 'destinations' },
24
+ 'EnergyType': { item: 'energy_type', items: 'energy_types' },
25
+ 'EquipmentSlot': { item: 'equipment_slot', items: 'equipment_slots' },
26
+ 'EventCard': { item: 'event_card', items: 'event_cards' },
27
+ 'Faction': { item: 'faction', items: 'factions' },
28
+ 'Gender': { item: 'gender', items: 'genders' },
29
+ 'HistoricalStats': { item: 'historical_stat', items: 'historical_stats' },
30
+ 'InventoryBucket': { item: 'inventory_bucket', items: 'inventory_buckets' },
31
+ 'InventoryItem': { item: 'inventory_item', items: 'inventory_items' },
32
+ 'ItemCategory': { item: 'item_category', items: 'item_categories' },
33
+ 'ItemTierType': { item: 'item_tier_type', items: 'item_tier_types' },
34
+ 'Location': { item: 'location', items: 'locations' },
35
+ 'Lore': { item: 'lore', items: 'lore_entries' },
36
+ 'MaterialRequirementSet': { item: 'material_requirement_set', items: 'material_requirement_sets' },
37
+ 'MedalTier': { item: 'medal_tier', items: 'medal_tiers' },
38
+ 'Metric': { item: 'metric', items: 'metrics' },
39
+ 'Milestone': { item: 'milestone', items: 'milestones' },
40
+ 'Objective': { item: 'objective', items: 'objectives' },
41
+ 'Place': { item: 'place', items: 'places' },
42
+ 'PlugSet': { item: 'plug_set', items: 'plug_sets' },
43
+ 'PowerCap': { item: 'power_cap', items: 'power_caps' },
44
+ 'PresentationNode': { item: 'presentation_node', items: 'presentation_nodes' },
45
+ 'Progression': { item: 'progression', items: 'progression_data' },
46
+ 'ProgressionLevelRequirement': { item: 'progression_level_requirement', items: 'progression_level_requirements' },
47
+ 'Race': { item: 'race', items: 'races' },
48
+ 'Record': { item: 'record', items: 'records' },
49
+ 'ReportReasonCategory': { item: 'report_reason_category', items: 'report_reason_categories' },
50
+ 'RewardSource': { item: 'reward_source', items: 'reward_sources' },
51
+ 'SackRewardItemList': { item: 'sack_reward_item_list', items: 'sack_reward_item_lists' },
52
+ 'SandboxPattern': { item: 'sandbox_pattern', items: 'sandbox_patterns' },
53
+ 'SandboxPerk': { item: 'sandbox_perk', items: 'sandbox_perks' },
54
+ 'Season': { item: 'season', items: 'seasons' },
55
+ 'SeasonPass': { item: 'season_pass', items: 'season_passes' },
56
+ 'SocketCategory': { item: 'socket_category', items: 'socket_categories' },
57
+ 'SocketType': { item: 'socket_type', items: 'socket_types' },
58
+ 'Stat': { item: 'stat', items: 'stats' },
59
+ 'StatGroup': { item: 'stat_group', items: 'stat_groups' },
60
+ 'TalentGrid': { item: 'talent_grid', items: 'talent_grids' },
61
+ 'TraitCategory': { item: 'trait_category', items: 'trait_categories' },
62
+ 'Trait': { item: 'trait', items: 'traits' },
63
+ 'Unlock': { item: 'unlock', items: 'unlocks' },
64
+ 'Vendor': { item: 'vendor', items: 'vendors' },
65
+ 'VendorGroup': { item: 'vendor_group', items: 'vendor_groups' }
67
66
  }
68
67
 
69
68
  attr_reader :file_path
70
69
 
71
70
  TABLES.each do |table_name, method_names|
72
- define_method method_names[:item] do |id|
73
- query_table(table_name, id: id)[0]
71
+ full_table_name = "Destiny#{table_name}Definition"
72
+
73
+ define_method method_names[:item] do |hash|
74
+ query = "SELECT json FROM #{full_table_name} WHERE json_extract(json, '$.hash')=?"
75
+
76
+ result = perform_query(query, [hash])
77
+ result = JSON.parse(result[0]['json']) unless result.nil?
74
78
  end
75
79
 
76
- define_method method_names[:items] do |limit: nil|
77
- query_table(table_name, limit: limit)
80
+ define_method method_names[:items] do |limit: nil, filter_empty: false, &block|
81
+ query = "SELECT json_extract(json, '$.hash') AS hash, json_extract(json, '$.displayProperties.name') AS name
82
+ FROM #{full_table_name} "
83
+
84
+ query << "WHERE json_extract(json, '$.displayProperties.name') IS NOT NULL " if filter_empty
85
+ query << "ORDER BY json_extract(json, '$.index')"
86
+
87
+ bindings = []
88
+
89
+ if limit
90
+ query << " LIMIT ?"
91
+ bindings << limit
92
+ end
93
+
94
+ perform_query(query, bindings)
78
95
  end
79
96
  end
80
97
 
@@ -102,42 +119,10 @@ module Restiny
102
119
 
103
120
  private
104
121
 
105
- def self.clean_row_keys(row_hash)
106
- OpenStruct.new.tap do |output|
107
- row_hash.each_pair do |key, value|
108
- key = key.gsub(/(\B[A-Z])/, '_\1') if key =~ /\B[A-Z]/
109
- output[key.downcase] = if value.is_a?(Hash)
110
- clean_row_keys(value)
111
- elsif value.is_a?(Array)
112
- value.map { |item| item.is_a?(Hash) ? clean_row_keys(item) : value }
113
- else
114
- value
115
- end
116
- end
117
- end
118
- end
119
-
120
- def query_table(table_name, id: nil, limit: nil)
121
- query = "SELECT json FROM #{table_name}"
122
- bindings = []
123
-
124
- if id
125
- query << " WHERE id=?"
126
- bindings << id
127
- end
128
-
129
- query << " ORDER BY json_extract(json, '$.index')" unless id
130
-
131
- if limit
132
- query << " LIMIT ?"
133
- bindings << limit
134
- end
135
-
136
- @database.execute(query, bindings).map do |row|
137
- Manifest::clean_row_keys(JSON.parse(row['json'])) unless row['json'].nil?
138
- end
122
+ def perform_query(query, bindings, &block)
123
+ @database.execute(query, bindings)
139
124
  rescue SQLite3::Exception => e
140
- raise Restiny::Error.new("Error while querying the manifest (#{e})")
125
+ raise Restiny::RequestError.new("Error while querying the manifest (#{e})")
141
126
  end
142
127
  end
143
128
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Restiny
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restiny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-10 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday