Class: MotionPhrase::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-phrase/api_client.rb

Constant Summary collapse

API_CLIENT_IDENTIFIER =
"motion_phrase"
API_BASE_URI =
"https://phraseapp.com/api/v1/"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sharedClientObject



6
7
8
9
# File 'lib/motion-phrase/api_client.rb', line 6

def self.sharedClient
  Dispatch.once { @instance ||= new }
  @instance
end

Instance Method Details

#storeTranslation(keyName, content, fallbackContent, currentLocale) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/motion-phrase/api_client.rb', line 11

def storeTranslation(keyName, content, fallbackContent, currentLocale)
  return unless development?
  
  content ||= fallbackContent
  data = {
    locale: currentLocale,
    key: keyName,
    content: content,
    allow_update: false,
    skip_verification: true,
    api_client: API_CLIENT_IDENTIFIER,
  }
  client.post("translations/store", authenticated(data)) do |result|
    if result.success?
      log "Translation stored [#{data.inspect}]"
    elsif result.failure?
      log "Error while storing translation [#{data.inspect}]"
    end
  end
end