Class: Babelyoda::Tanker
- Inherits:
-
Object
- Object
- Babelyoda::Tanker
- Includes:
- SpecificationLoader
- Defined in:
- lib/babelyoda/tanker.rb
Defined Under Namespace
Classes: FileNameInvalidError
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #create(keyset_name) ⇒ Object
- #drop_keyset!(keyset_name) ⇒ Object
- #export(keyset_name = nil, languages = nil, status = nil, safe = false) ⇒ Object
- #list ⇒ Object
- #load_keyset(keyset_name, languages = nil, status = nil, safe = false) ⇒ Object
- #replace(keyset, language = nil) ⇒ Object
Methods included from SpecificationLoader
#dump, included, #initialize, #method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Babelyoda::SpecificationLoader
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
60 61 62 |
# File 'lib/babelyoda/tanker.rb', line 60 def endpoint @endpoint end |
#project_id ⇒ Object
Returns the value of attribute project_id.
62 63 64 |
# File 'lib/babelyoda/tanker.rb', line 62 def project_id @project_id end |
#token ⇒ Object
Returns the value of attribute token.
61 62 63 |
# File 'lib/babelyoda/tanker.rb', line 61 def token @token end |
Instance Method Details
#create(keyset_name) ⇒ Object
82 83 84 |
# File 'lib/babelyoda/tanker.rb', line 82 def create(keyset_name) post('/keysets/create/', { 'project-id' => project_id, 'keyset-id' => keyset_name }) end |
#drop_keyset!(keyset_name) ⇒ Object
108 109 110 |
# File 'lib/babelyoda/tanker.rb', line 108 def drop_keyset!(keyset_name) delete("/admin/project/#{project_id}/keyset/", { :keyset => keyset_name }) end |
#export(keyset_name = nil, languages = nil, status = nil, safe = false) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/babelyoda/tanker.rb', line 86 def export(keyset_name = nil, languages = nil, status = nil, safe = false) payload = { 'project-id' => project_id } payload.merge!({ 'keyset-id' => keyset_name }) if keyset_name if languages value = languages value = languages.join(',') if languages.respond_to?(:join) payload.merge!({ 'language' => value }) end payload.merge!({ 'status' => status.to_s }) if status payload.merge!({ 'safe' => safe }) if safe get('/projects/export/xml/', payload) end |
#list ⇒ Object
78 79 80 |
# File 'lib/babelyoda/tanker.rb', line 78 def list get('/keysets/', { 'project-id' => project_id }).css('keyset').map { |keyset| keyset['id'] } end |
#load_keyset(keyset_name, languages = nil, status = nil, safe = false) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/babelyoda/tanker.rb', line 99 def load_keyset(keyset_name, languages = nil, status = nil, safe = false) doc = export(keyset_name, languages, status, safe) doc.css("keyset[@id='#{keyset_name}']").each do |keyset_node| keyset = Babelyoda::Keyset.parse_xml(keyset_node) return keyset if keyset.name == keyset_name end Babelyoda::Keyset.new(keyset_name) end |
#replace(keyset, language = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/babelyoda/tanker.rb', line 64 def replace(keyset, language = nil) doc = project_xml do |xml| keyset.to_xml(xml, language) end payload = { :file => StringIO.new(doc), 'project-id' => project_id, 'keyset-id' => keyset.name, :format => 'xml' } payload.merge!({:language => language}) if language post('/keysets/replace/', payload) end |