Class: I28s::Cli::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/i28s/cli/push.rb

Instance Method Summary collapse

Constructor Details

#initialize(locale_identifier, branch: "main") ⇒ Push

Returns a new instance of Push.



9
10
11
12
# File 'lib/i28s/cli/push.rb', line 9

def initialize(locale_identifier, branch: "main")
  @locale_identifier = locale_identifier
  @branch = branch
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/i28s/cli/push.rb', line 14

def call
  translations = Dir.glob("./config/locales/**/*.yml").each_with_object({}) do |filename, translations|
    translations.deep_merge!(YAML.load_file(filename))
  end

  translations = translations[@locale_identifier]

  raise "No translations" unless translations&.any?

  response = Faraday.post(
    "#{I28s::Cli.configuration.base_url}/projects/#{I28s::Cli.configuration.project_token}/#{@branch}/locales/#{@locale_identifier}/import",
    { data: JSON.dump(translations) },
    {
      "Authorization": "Bearer #{I28s::Cli.configuration.api_key}"
    }
  )
  puts response.status
end