Class: Babelyoda::Tanker
- Inherits:
-
Object
- Object
- Babelyoda::Tanker
- Includes:
- SpecificationLoader
- Defined in:
- lib/babelyoda/tanker.rb
Defined Under Namespace
Classes: FileNameInvalidError, KeysetNameInvalidError
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 = :en) ⇒ 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.
110 111 112 |
# File 'lib/babelyoda/tanker.rb', line 110 def endpoint @endpoint end |
#project_id ⇒ Object
Returns the value of attribute project_id.
112 113 114 |
# File 'lib/babelyoda/tanker.rb', line 112 def project_id @project_id end |
#token ⇒ Object
Returns the value of attribute token.
111 112 113 |
# File 'lib/babelyoda/tanker.rb', line 111 def token @token end |
Instance Method Details
#create(keyset_name) ⇒ Object
133 134 135 136 |
# File 'lib/babelyoda/tanker.rb', line 133 def create(keyset_name) validate_keyset_name!(keyset_name) post('/keysets/create/', { 'project-id' => project_id, 'keyset-id' => keyset_name }) end |
#drop_keyset!(keyset_name) ⇒ Object
162 163 164 165 |
# File 'lib/babelyoda/tanker.rb', line 162 def drop_keyset!(keyset_name) validate_keyset_name!(keyset_name) delete("/admin/project/#{project_id}/keyset/", { :keyset => keyset_name }) end |
#export(keyset_name = nil, languages = nil, status = nil, safe = false) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/babelyoda/tanker.rb', line 138 def export(keyset_name = nil, languages = nil, status = nil, safe = false) payload = { 'project-id' => project_id } validate_keyset_name!(keyset_name) if keyset_name 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
129 130 131 |
# File 'lib/babelyoda/tanker.rb', line 129 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
152 153 154 155 156 157 158 159 160 |
# File 'lib/babelyoda/tanker.rb', line 152 def load_keyset(keyset_name, languages = nil, status = nil, safe = false) validate_keyset_name!(keyset_name) 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 = :en) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/babelyoda/tanker.rb', line 114 def replace(keyset, language = :en) validate_keyset_name!(keyset.name) doc = project_xml do |xml| keyset.to_xml(xml, language) end payload = { :file => StringIO.new(doc), 'project-id' => project_id, 'keyset-id' => keyset.name, 'language' => language, :format => 'xml' } post('/keysets/replace/', payload) end |