Class: SourcedConfig::Locale::GSheetsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/sourced_config/locale/g_sheets_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ GSheetsClient

Returns a new instance of GSheetsClient.



8
9
10
# File 'lib/sourced_config/locale/g_sheets_client.rb', line 8

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/sourced_config/locale/g_sheets_client.rb', line 12

def url
  @url
end

Instance Method Details

#load(locale) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/sourced_config/locale/g_sheets_client.rb', line 14

def load(locale)
  Rails.logger.debug { "[locale - #{locale}] Strings read (as UTF-8) from remote URL #{url}" }
  content = get_content
  parse_body(content.body.force_encoding("UTF-8")).reduce({}) do |memo, row|
    parse_item(row, memo)
  end
rescue => e
  Rails.logger.error "[locale - #{locale}] Could not fetch TSV doc directly from Google Spreadsheets: #{e.message}"
  {}
end