class PhraseApp::InContextEditor::ApiWrapper

Public Class Methods

new() click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 6
def initialize
  @api_client = PhraseApp::InContextEditor.api_client
end

Public Instance Methods

blacklisted_keys() click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 37
def blacklisted_keys
  PhraseApp::InContextEditor::ApiCollection.new(@api_client, "blacklisted_keys_list", project_id).collection.map{ |rule| rule.name }
end
default_locale() click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 10
def default_locale
  @default_locale ||= select_default_locale
end
default_translation(key) click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 14
def default_translation(key)
  params = PhraseApp::RequestParams::TranslationsByKeyParams.new
  translations = PhraseApp::InContextEditor::ApiCollection.new(@api_client, "translations_by_key", project_and_key_id(key), params).collection
  return unless translations.present?

  translations.select{ |translation| translation.locale["id"] == default_locale.id }
end
keys_by_names(names) click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 27
def keys_by_names(names)
  names = names.join(',')
  params = PhraseApp::RequestParams::KeysSearchParams.new(:q => "name:#{names}")
  keys_list(params)
end
keys_list(params) click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 33
def keys_list(params)
  PhraseApp::InContextEditor::ApiCollection.new(@api_client, "keys_search", project_id, params).collection
end
keys_with_prefix(prefix) click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 22
def keys_with_prefix(prefix)
  params = PhraseApp::RequestParams::KeysSearchParams.new(q:"#{prefix}*")
  keys_list(params)
end

Private Instance Methods

project_and_key_id(key) click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 54
def project_and_key_id(key)
  project_id << key.id
end
project_id() click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 50
def project_id
  [PhraseApp::InContextEditor.project_id]
end
select_default_locale() click to toggle source
# File lib/phraseapp-in-context-editor-ruby/api_wrapper.rb, line 43
def select_default_locale
  locales = PhraseApp::InContextEditor::ApiCollection.new(@api_client, "locales_list", project_id).collection
  return unless locales.present?

  locales.select{ |loc| loc.default }.first
end