Class: Eagleplatform::Translation
- Inherits:
-
Object
- Object
- Eagleplatform::Translation
- Defined in:
- lib/eagleplatform/translation.rb
Overview
Translations
Class Method Summary collapse
-
.delete(id) ⇒ String
Delete translation from Eagleplatform.
-
.find(id) ⇒ Eagleplaform::Translation
Find Translation by ID.
-
.list(per_page = 50, page = 1) ⇒ Array
Get list of translations.
-
.update(args = {}) ⇒ Hash
Update translation on Eagleplatform.
Instance Method Summary collapse
-
#delete ⇒ String
Switch off translation from Eagleplaform.
-
#statistics(args = {}) ⇒ Array
Get current translation statistics Date format is - ‘dd.mm.yyyy’.
-
#update ⇒ Eagleplatform::Translation
Update translation on Eagleplatform.
Class Method Details
.delete(id) ⇒ String
Delete translation from Eagleplatform
93 94 95 96 97 98 |
# File 'lib/eagleplatform/translation.rb', line 93 def self.delete(id) raise ArgumentError, 'id must be numeric' unless id.is_a? Numeric api_method = {method: Methods::TRANSLATION_DELETE[:method], path: Methods::TRANSLATION_DELETE[:path].gsub(':id',id.to_s)} Eagleplatform.call_api(api_method) == "ok" ? "Translation id: '#{id}' is switched off" : (raise "Can't switch off translation") end |
.find(id) ⇒ Eagleplaform::Translation
Find Translation by ID
55 56 57 58 59 60 61 62 63 |
# File 'lib/eagleplatform/translation.rb', line 55 def self.find(id) raise ArgumentError, "id must be numeric" unless id.is_a? Numeric api_method = {method: Methods::TRANSLATION_GET_INFO[:method], path: Methods::TRANSLATION_GET_INFO[:path].gsub(':id',id.to_s)} result = Eagleplatform.call_api(api_method).first[1]. trans = self.new trans.each_pair { |k,v| trans[k] = result[k] } end |
.list(per_page = 50, page = 1) ⇒ Array
Get list of translations
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/eagleplatform/translation.rb', line 26 def self.list(per_page = 50, page = 1) params = { per_page: per_page.to_s, page: page.to_s } result = Eagleplatform.call_api(Methods::TRANSLATIONS_GET_LIST, params). translations = [] result[:translations].each do |translation| t = self.new t.each_pair { |k,v| t[k] = translation[k.to_s]} translations.push(t) end if result[:total_pages] > 1 puts "Translations per_page: #{per_page}" puts "Current page: #{result[:current_page]}" puts "Total pages: #{result[:total_pages]}" puts "Total entries: #{result[:total_entries]}" end translations end |
.update(args = {}) ⇒ Hash
Update translation on Eagleplatform
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/eagleplatform/translation.rb', line 75 def self.update(args = {}) raise ArgumentError, 'ID is blank' if args[:id].blank? raise ArgumentError, 'id must be numeric' unless args[:id].is_a? Numeric params = { translation: args } api_method = {method: Methods::TRANSLATION_UPDATE[:method], path: Methods::TRANSLATION_UPDATE[:path].gsub(':id',args[:id].to_s)} result = Eagleplatform.call_api(api_method, params).first[1]. end |
Instance Method Details
#delete ⇒ String
Switch off translation from Eagleplaform
131 132 133 134 135 |
# File 'lib/eagleplatform/translation.rb', line 131 def delete api_method = {method: Methods::TRANSLATION_DELETE[:method], path: Methods::TRANSLATION_DELETE[:path].gsub(':id',id.to_s)} Eagleplatform.call_api(api_method) == "ok" ? "Translation id: '#{self.id}', name:#{self.name} is switched off" : (raise "Can't switch off translation") end |
#statistics(args = {}) ⇒ Array
Get current translation statistics
Date format is - 'dd.mm.yyyy'
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/eagleplatform/translation.rb', line 147 def statistics(args = {}) raise "self.id is blank" if self.id.blank? params = { date_from: args[:date_from] || (Time.now - 1.day).strftime('%d.%m.%Y'), date_to: args[:date_to] || Time.now.strftime('%d.%m.%Y') } raise ArgumentError, "Wrong 'date_from' format. Must be 'dd.mm.yyyy'" unless DATE_FORMAT =~ params[:date_from] raise ArgumentError, "Wrong 'date_to' format. Must be 'dd.mm.yyyy'" unless DATE_FORMAT =~ params[:date_from] raise ArgumentError, "date_from: #{params[:date_from]} > date_to: #{params[:date_from]}" if params[:date_from].to_date > params[:date_to].to_date api_method = {method: Methods::TRANSLATION_GET_STATISTICS[:method], path: Methods::TRANSLATION_GET_STATISTICS[:path].gsub(':id',id.to_s)} result = Eagleplatform.call_api(api_method, params).first[1] end |
#update ⇒ Eagleplatform::Translation
Update translation on Eagleplatform
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/eagleplatform/translation.rb', line 108 def update api_method = {method: Methods::TRANSLATION_UPDATE[:method], path: Methods::TRANSLATION_UPDATE[:path].gsub(':id',id.to_s)} params = {} translation = self.to_hash translation.delete(:user_id) translation.delete(:account_id) translation.delete(:status) translation.delete(:created_at) translation.delete(:updated_at) translation.delete(:starts_at) params[:translation] = translation result = Eagleplatform.call_api(api_method, params).first[1]. translation.diff(result).keys.include?(:updated_at) ? self : 'Something wrong' end |