Class: WebTranslateIt::Translation
- Inherits:
-
Object
- Object
- WebTranslateIt::Translation
- Defined in:
- lib/web_translate_it/translation.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#status ⇒ Object
Returns the value of attribute status.
-
#string_id ⇒ Object
Returns the value of attribute string_id.
-
#text ⇒ Object
Returns the value of attribute text.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Translation
constructor
Initialize a new WebTranslateIt::Translation.
-
#save ⇒ Object
Save a WebTranslateIt::Translation.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Translation
Initialize a new WebTranslateIt::Translation
Implementation Example:
WebTranslateIt::Translation.new({ :string_id => "1234", :text => "Super!" })
to instantiate a new Translation without any text.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/web_translate_it/translation.rb', line 18 def initialize(params = {}) params.stringify_keys! self.id = params["id"] || nil self.locale = params["locale"] || nil self.text = params["text"] || nil self.status = params["status"] || "status_unproofread" self.created_at = params["created_at"] || nil self.updated_at = params["updated_at"] || nil self.version = params["version"] || nil if params["string"] self.string_id = params["string"]["id"] else self.string_id = nil end end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/web_translate_it/translation.rb', line 7 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/web_translate_it/translation.rb', line 7 def id @id end |
#locale ⇒ Object
Returns the value of attribute locale.
7 8 9 |
# File 'lib/web_translate_it/translation.rb', line 7 def locale @locale end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/web_translate_it/translation.rb', line 7 def status @status end |
#string_id ⇒ Object
Returns the value of attribute string_id.
7 8 9 |
# File 'lib/web_translate_it/translation.rb', line 7 def string_id @string_id end |
#text ⇒ Object
Returns the value of attribute text.
7 8 9 |
# File 'lib/web_translate_it/translation.rb', line 7 def text @text end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
7 8 9 |
# File 'lib/web_translate_it/translation.rb', line 7 def updated_at @updated_at end |
#version ⇒ Object
Returns the value of attribute version.
7 8 9 |
# File 'lib/web_translate_it/translation.rb', line 7 def version @version end |
Instance Method Details
#save ⇒ Object
Save a WebTranslateIt::Translation
Implementation Example:
translation = WebTranslateIt::Translation.new({ :string_id => "1234", :text => "Super!" })
WebTranslateIt::Connection.new('secret_api_token') do
translation.save
end
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/web_translate_it/translation.rb', line 44 def save tries ||= 3 request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/strings/#{self.string_id}/locales/#{self.locale}/translations") WebTranslateIt::Util.add_fields(request) request.body = self.to_json begin Util.handle_response(Connection.http_connection.request(request), true, true) rescue Timeout::Error puts "Request timeout. Will retry in 5 seconds." if (tries -= 1) > 0 sleep(5) retry else success = false end end end |
#to_hash ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/web_translate_it/translation.rb', line 62 def to_hash { "locale" => locale, "text" => text, "status" => status } end |
#to_json ⇒ Object
70 71 72 |
# File 'lib/web_translate_it/translation.rb', line 70 def to_json MultiJson.dump(self.to_hash) end |