Class: PhraseApp::Android::PhraseAppClient

Inherits:
Object
  • Object
show all
Defined in:
lib/phraseapp_android/phrase_app_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PhraseAppClient

Returns a new instance of PhraseAppClient.



13
14
15
16
17
18
19
# File 'lib/phraseapp_android/phrase_app_client.rb', line 13

def initialize(options = {})
  credentials = PhraseApp::Auth::Credentials.new token: (options[:token] || ENV['PHRASE_ACCESS_TOKEN'])
  self.client = PhraseApp::Client.new credentials
  self.project_id = options[:project_id] || ENV['PHRASE_PROJECT_ID']
  self.sub_path = options[:path]
  find_locales
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



11
12
13
# File 'lib/phraseapp_android/phrase_app_client.rb', line 11

def client
  @client
end

#locale_filesObject

Returns the value of attribute locale_files.



11
12
13
# File 'lib/phraseapp_android/phrase_app_client.rb', line 11

def locale_files
  @locale_files
end

#localesObject

Returns the value of attribute locales.



11
12
13
# File 'lib/phraseapp_android/phrase_app_client.rb', line 11

def locales
  @locales
end

#project_idObject

Returns the value of attribute project_id.



11
12
13
# File 'lib/phraseapp_android/phrase_app_client.rb', line 11

def project_id
  @project_id
end

#sub_pathObject

Returns the value of attribute sub_path.



11
12
13
# File 'lib/phraseapp_android/phrase_app_client.rb', line 11

def sub_path
  @sub_path
end

Instance Method Details

#locale_file_name(file_name, locale) ⇒ Object



34
35
36
37
# File 'lib/phraseapp_android/phrase_app_client.rb', line 34

def locale_file_name(file_name, locale)
  locale = '-' + locale unless locale.nil?
  locale_files.find { |f| f.end_with?("values#{locale}/#{file_name}.xml") }
end

#read_locale_file(file_name, locale) ⇒ Object



30
31
32
# File 'lib/phraseapp_android/phrase_app_client.rb', line 30

def read_locale_file(file_name, locale)
  read_xml_file locale_file_name(file_name, locale)
end

#read_xml_file(file_name) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/phraseapp_android/phrase_app_client.rb', line 21

def read_xml_file(file_name)
  if file_name
    f = File.open file_name
    doc = Nokogiri::XML f
    f.close
    doc
  end
end