Class: PhraseApp::InContextEditor::ApiWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/phraseapp-in-context-editor-ruby/api_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initializeApiWrapper

Returns a new instance of ApiWrapper.



6
7
8
# File 'lib/phraseapp-in-context-editor-ruby/api_wrapper.rb', line 6

def initialize
  @api_client = PhraseApp::InContextEditor.api_client
end

Instance Method Details

#blacklisted_keysObject



37
38
39
# 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_localeObject



10
11
12
# File 'lib/phraseapp-in-context-editor-ruby/api_wrapper.rb', line 10

def default_locale
  @default_locale ||= select_default_locale
end

#default_translation(key) ⇒ Object



14
15
16
17
18
19
20
# 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) ⇒ Object



27
28
29
30
31
# 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) ⇒ Object



33
34
35
# 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) ⇒ Object



22
23
24
25
# 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