Class: DmLiveResources::ResourceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/dm_live_resources/resource_manager.rb

Constant Summary collapse

@@db =
Resource.db

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ResourceManager

Returns a new instance of ResourceManager.



11
12
13
14
15
16
17
18
19
# File 'lib/dm_live_resources/resource_manager.rb', line 11

def initialize(args = {})
  @gsheet_identifier = args[:gs_identifier]
  @gsheet_title = args[:gs_title]
  @gsheet_content = args[:gs_content]
  @gsheet_sheets = args[:gs_sheets]
  @gsheet_api_key = args[:gs_api_key]
  @dmagic_api_key = args[:dm_api_key]
  @dmagic_id = args[:dm_id]
end

Instance Attribute Details

#dmagic_api_keyObject (readonly)

Returns the value of attribute dmagic_api_key.



7
8
9
# File 'lib/dm_live_resources/resource_manager.rb', line 7

def dmagic_api_key
  @dmagic_api_key
end

#dmagic_idObject (readonly)

Returns the value of attribute dmagic_id.



7
8
9
# File 'lib/dm_live_resources/resource_manager.rb', line 7

def dmagic_id
  @dmagic_id
end

#gsheet_api_keyObject (readonly)

Returns the value of attribute gsheet_api_key.



7
8
9
# File 'lib/dm_live_resources/resource_manager.rb', line 7

def gsheet_api_key
  @gsheet_api_key
end

#gsheet_contentObject (readonly)

Returns the value of attribute gsheet_content.



7
8
9
# File 'lib/dm_live_resources/resource_manager.rb', line 7

def gsheet_content
  @gsheet_content
end

#gsheet_identifierObject (readonly)

Returns the value of attribute gsheet_identifier.



7
8
9
# File 'lib/dm_live_resources/resource_manager.rb', line 7

def gsheet_identifier
  @gsheet_identifier
end

#gsheet_sheetsObject (readonly)

Returns the value of attribute gsheet_sheets.



7
8
9
# File 'lib/dm_live_resources/resource_manager.rb', line 7

def gsheet_sheets
  @gsheet_sheets
end

#gsheet_titleObject (readonly)

Returns the value of attribute gsheet_title.



7
8
9
# File 'lib/dm_live_resources/resource_manager.rb', line 7

def gsheet_title
  @gsheet_title
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



7
8
9
# File 'lib/dm_live_resources/resource_manager.rb', line 7

def table_name
  @table_name
end

Class Method Details

.check_tables(tables) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dm_live_resources/resource_manager.rb', line 41

def self.check_tables(tables)
  @@db.results_as_hash = true
  tables.each do |table|
    # Retrieve the last row added to the table
    row = @@db.get_first_row("SELECT * FROM '#{table}' ORDER BY DateAdded DESC LIMIT 1")
    resource_data = Resource.data_as_hash(row['GSheetApiKey'], row['GSheetIdentifier'], row['GSheetSheets'], row['GSheetTitle'], row['DMagicApiKey'], row['DMagicId'])
    sheet = GSheet.new(resource_data)
    if Resource.update_required?(row, sheet)
      resource_data = Resource.add_gsheet_data(resource_data, sheet.exported_file, sheet.title)
      dm = DMSheet.new(resource_data)
      dm.update_resource
      @@db.execute(Resource.insert_query(table), sheet.api_key, sheet.identifier, sheet.title, sheet.content, sheet.sheets, dm.api_key, dm.id)
    end
  end
end

.update_db_tablesObject



57
58
59
60
# File 'lib/dm_live_resources/resource_manager.rb', line 57

def self.update_db_tables
  tables = Resource.return_tables
  self.check_tables(tables)
end

Instance Method Details

#create_new_tableObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dm_live_resources/resource_manager.rb', line 25

def create_new_table
  @@db.execute %Q{
   CREATE TABLE IF NOT EXISTS #{table_name} (
   Id INTEGER PRIMARY KEY,
   GSheetApiKey,
   GSheetIdentifier,
   GSheetTitle,
   GSheetContent,
   GSheetSheets,
   DMagicApiKey,
   DMagicId,
   DateAdded datetime default current_timestamp)
   }
 @@db.execute(Resource.insert_query(table_name), gsheet_api_key, gsheet_identifier, gsheet_title, gsheet_content, gsheet_sheets, dmagic_api_key, dmagic_id)
end