Class: MissingTranslationApi

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/missing_translation_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token) ⇒ MissingTranslationApi



12
13
14
15
16
17
18
19
20
# File 'lib/missing_translation_api.rb', line 12

def initialize(api_token)
  @api_token = api_token
  @options = {
    headers: {
      token: @api_token,
      'Content-Type': "application/json"
    }
  }
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



7
8
9
# File 'lib/missing_translation_api.rb', line 7

def api_token
  @api_token
end

Instance Method Details

#download(content_type = "yaml") ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/missing_translation_api.rb', line 34

def download(content_type = "yaml")
  response = self.class.get('/translations/export', @options.merge({
    body: {
      content_type: content_type
    }.to_json
  }))
  response.parsed_response["data"] || []
end

#upload(language, group, keys, content_type = "yaml") ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/missing_translation_api.rb', line 22

def upload(language, group, keys, content_type = "yaml")
  p "Pushing #{keys.count} keys on #{group} for #{language}"
  self.class.post("/translations/import", @options.merge({
    body: {
      content_type: content_type,
      group: group,
      language: language,
      keys: keys
    }.to_json
  }))
end