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(*_args) ⇒ 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 |
# File 'lib/web_translate_it/translation.rb', line 18 def initialize(params = {}) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity 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 self.string_id = (params['string']['id'] if params['string']) 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/web_translate_it/translation.rb', line 40 def save # rubocop:todo Metrics/MethodLength tries ||= 3 request = Net::HTTP::Post.new("/api/projects/#{Connection.api_key}/strings/#{string_id}/locales/#{locale}/translations") WebTranslateIt::Util.add_fields(request) request.body = 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).positive? sleep(5) retry end end end |
#to_hash ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/web_translate_it/translation.rb', line 56 def to_hash { 'locale' => locale, 'text' => text, 'status' => status } end |
#to_json(*_args) ⇒ Object
64 65 66 |
# File 'lib/web_translate_it/translation.rb', line 64 def to_json(*_args) MultiJson.dump(to_hash) end |