Class: PhraseApp::Android::Upload
- Inherits:
-
PhraseAppClient
- Object
- PhraseAppClient
- PhraseApp::Android::Upload
- Defined in:
- lib/phraseapp_android/upload.rb
Instance Attribute Summary
Attributes inherited from PhraseAppClient
#client, #locale_files, #locales, #project_id, #sub_path
Instance Method Summary collapse
Methods inherited from PhraseAppClient
#initialize, #locale_file_name, #read_locale_file, #read_xml_file
Constructor Details
This class inherits a constructor from PhraseApp::Android::PhraseAppClient
Instance Method Details
#build_upload_file ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/phraseapp_android/upload.rb', line 18 def build_upload_file tmp = Tempfile.new %w(translations .xml) doc = Nokogiri::XML::Document.new doc.encoding = 'utf-8' res = doc.create_element 'resources', 'xmlns:tools' => 'http://schemas.android.com/tools' doc.add_child res %w(strings arrays).each do |file| read_locale_file(file, nil).at('//resources').element_children.each do |el| res.add_child(el) if el.attr('tools:ignore').nil? end end tmp.write doc.to_xml(indent: 4) tmp.close tmp end |
#perform(locale = 'en') ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/phraseapp_android/upload.rb', line 6 def perform(locale = 'en') file = build_upload_file params = PhraseApp::RequestParams::UploadParams.new file: file.path, file_format: 'xml', locale_id: locale upload = client.upload_create project_id, params puts 'Successfully uploaded.'.green file.unlink upload end |