Class: Onesky::Rails::Client
- Inherits:
-
Object
- Object
- Onesky::Rails::Client
- Defined in:
- lib/onesky/rails/client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base_locale ⇒ Object
Returns the value of attribute base_locale.
-
#client ⇒ Object
Returns the value of attribute client.
-
#config ⇒ Object
Returns the value of attribute config.
-
#onesky_locales ⇒ Object
Returns the value of attribute onesky_locales.
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
-
#initialize(config_hash) ⇒ Client
constructor
A new instance of Client.
- #to_onesky_locale(locale) ⇒ Object
- #to_rails_locale(locale) ⇒ Object
- #verify_languages! ⇒ Object
Constructor Details
#initialize(config_hash) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/onesky/rails/client.rb', line 9 def initialize(config_hash) unless is_valid_config! config_hash raise ArgumentError, 'Invalid config. Please check if `api_key`, `api_secret` and `project_id` exist.' end @config = config_hash @client = ::Onesky::Client.new(@config['api_key'], @config['api_secret']) @client.plugin_code = 'rails-string' @project = @client.project(@config['project_id'].to_i) @base_locale = config_hash.fetch('base_locale', ::I18n.default_locale) @onesky_locales = [] end |
Instance Attribute Details
#base_locale ⇒ Object
Returns the value of attribute base_locale.
7 8 9 |
# File 'lib/onesky/rails/client.rb', line 7 def base_locale @base_locale end |
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/onesky/rails/client.rb', line 7 def client @client end |
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/onesky/rails/client.rb', line 7 def config @config end |
#onesky_locales ⇒ Object
Returns the value of attribute onesky_locales.
7 8 9 |
# File 'lib/onesky/rails/client.rb', line 7 def onesky_locales @onesky_locales end |
#project ⇒ Object
Returns the value of attribute project.
7 8 9 |
# File 'lib/onesky/rails/client.rb', line 7 def project @project end |
Instance Method Details
#to_onesky_locale(locale) ⇒ Object
34 35 36 |
# File 'lib/onesky/rails/client.rb', line 34 def to_onesky_locale(locale) locale.gsub('_', '-') end |
#to_rails_locale(locale) ⇒ Object
38 39 40 |
# File 'lib/onesky/rails/client.rb', line 38 def to_rails_locale(locale) locale.gsub('-', '_') end |
#verify_languages! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/onesky/rails/client.rb', line 22 def verify_languages! languages = get_languages_from_onesky! languages.each do |language| locale = language['custom_locale'] || to_rails_locale(language['code']) if (language['is_base_language']) verify_base_locale!(locale) else @onesky_locales << locale end end end |