onesky-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/lib/generators/onesky/init_generator.rb +40 -0
- data/lib/generators/templates/onesky.yml.tt +15 -0
- data/lib/onesky/rails.rb +3 -0
- data/lib/onesky/rails/client.rb +61 -0
- data/lib/onesky/rails/file_client.rb +95 -0
- data/lib/onesky/rails/railtie.rb +13 -0
- data/lib/onesky/rails/version.rb +5 -0
- data/lib/tasks/onesky.rake +23 -0
- data/onesky-rails.gemspec +28 -0
- data/spec/fixtures/locales/en.json +13 -0
- data/spec/fixtures/locales/en.yml +9 -0
- data/spec/fixtures/locales/ja.yml +9 -0
- data/spec/onesky/rails/client_spec.rb +54 -0
- data/spec/onesky/rails/file_client_spec.rb +68 -0
- data/spec/spec_helper.rb +58 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 050bfda813855a702a0b5be38709edac3548e85f
|
4
|
+
data.tar.gz: 2a05ef6ed61f81f12abe4c1aa260a4c8fd4d4fb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c5304cdbd9d8dd27b80aaf274d5e76b06f334ac3c7b4ed5f5e659848284204e81f6e3995f33770d7e2b4552df44b37971663cb753f27c4d16a97aa4ef2ad47a
|
7
|
+
data.tar.gz: 15487c1b04badf988663ffc8e90706fced1571be5fb510ae561ee98ee43efbd661c07d7378c827742a88fd98246d66b0e5abf6591243a6b3f29899c46c161cb8
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Victor Lam
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Onesky::Rails
|
2
|
+
|
3
|
+
Integrate Rails app with [OneSky](http://www.oneskyapp.com) that provide `upload` and `download` rake command to sync string files
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'onesky-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install onesky-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
**Basic setup**
|
22
|
+
```
|
23
|
+
rails generate onesky:init <api_key> <api_secret> <project_id>
|
24
|
+
```
|
25
|
+
Generate config file at `config/onesky.yml`
|
26
|
+
|
27
|
+
**Upload string files**
|
28
|
+
```
|
29
|
+
rake onesky:upload
|
30
|
+
```
|
31
|
+
Upload all string files of `I18n.default_locale` to [OneSky](http://www.oneskyapp.com). Note that default locale must match with base language of project.
|
32
|
+
|
33
|
+
**Download translations**
|
34
|
+
```
|
35
|
+
rake onesky:download
|
36
|
+
```
|
37
|
+
Download translations of files uploaded in all languages activated in project.
|
38
|
+
|
39
|
+
## TODO
|
40
|
+
- Specify file to upload
|
41
|
+
- Specify file and language to download
|
42
|
+
- Support framework other than RoR
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( http://github.com/onesky/onesky-rails/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Onesky
|
2
|
+
module Generators
|
3
|
+
class InitGenerator < ::Rails::Generators::Base
|
4
|
+
|
5
|
+
desc "Generate config file for onesky-rails gem."
|
6
|
+
|
7
|
+
argument :api_key, :type => :string, :desc => "API Key"
|
8
|
+
argument :api_secret, :type => :string, :desc => "API Secret"
|
9
|
+
argument :project_id, :type => :string, :desc => "Project ID"
|
10
|
+
|
11
|
+
class_option :force, :type => :boolean, :default => false, :desc => "Overwrite if config file already exists"
|
12
|
+
|
13
|
+
CONFIG_PATH = File.join(::Rails.root.to_s, 'config', 'onesky.yml')
|
14
|
+
|
15
|
+
def remove_config_file
|
16
|
+
if File.exists? CONFIG_PATH
|
17
|
+
if options.force?
|
18
|
+
say_status("warning", "Overwrite existing config file.", :yellow)
|
19
|
+
remove_file CONFIG_PATH
|
20
|
+
else
|
21
|
+
say_status("error", "Please use --force to overwrite existing config file.", :red)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
source_root File.expand_path("../../templates", __FILE__)
|
27
|
+
|
28
|
+
def create_config_file
|
29
|
+
# create_file(CONFIG_PATH, YAML_COMMENT + config_hash.to_yaml)
|
30
|
+
template "onesky.yml.tt", "config/onesky.yml"
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def config_hash
|
36
|
+
{api_key: api_key, api_secret: api_secret, project_id: project_id.to_i}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#
|
2
|
+
# To load your OneSky details from the environment
|
3
|
+
# just add some erb tags like this.
|
4
|
+
#
|
5
|
+
# api_key: <%%= ENV["ONESKY_API_KEY"] %>
|
6
|
+
# api_secret: <%%= ENV["ONESKY_API_SECRET"] %>
|
7
|
+
# project_id: <%%= ENV["ONESKY_PROJECT_ID"] %>
|
8
|
+
#
|
9
|
+
---
|
10
|
+
api_key: <%= config_hash[:api_key] %>
|
11
|
+
api_secret: <%= config_hash[:api_secret] %>
|
12
|
+
project_id: <%= config_hash[:project_id] %>
|
13
|
+
|
14
|
+
upload:
|
15
|
+
is_keeping_all_strings: true
|
data/lib/onesky/rails.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'onesky'
|
2
|
+
|
3
|
+
module Onesky
|
4
|
+
module Rails
|
5
|
+
|
6
|
+
class Client
|
7
|
+
attr_accessor :client, :project, :base_locale, :onesky_locales, :config
|
8
|
+
|
9
|
+
def initialize(config_hash)
|
10
|
+
unless is_valid_config! config_hash
|
11
|
+
raise ArgumentError, 'Invalid config. Please check if `api_key`, `api_secret` and `project_id` exist.'
|
12
|
+
end
|
13
|
+
|
14
|
+
@config = config_hash
|
15
|
+
@client = ::Onesky::Client.new(@config['api_key'], @config['api_secret'])
|
16
|
+
@project = @client.project(@config['project_id'].to_i)
|
17
|
+
@base_locale = ::I18n.default_locale
|
18
|
+
@onesky_locales = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def verify_languages!
|
22
|
+
languages = get_languages_from_onesky!
|
23
|
+
languages.each do |language|
|
24
|
+
locale = to_rails_locale(language['code'])
|
25
|
+
if (language['is_base_language'])
|
26
|
+
verify_base_locale!(locale)
|
27
|
+
else
|
28
|
+
@onesky_locales << locale
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_onesky_locale(locale)
|
34
|
+
locale.gsub('_', '-')
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_rails_locale(locale)
|
38
|
+
locale.gsub('-', '_')
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def is_valid_config!(config)
|
44
|
+
config.has_key?('api_key') && config.has_key?('api_secret') && config.has_key?('project_id')
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_languages_from_onesky!
|
48
|
+
JSON.parse(@project.list_language)['data']
|
49
|
+
end
|
50
|
+
|
51
|
+
def verify_base_locale!(locale)
|
52
|
+
if (locale != @base_locale.to_s)
|
53
|
+
raise BaseLanguageNotMatchError, "The default locale (#{@base_locale.to_s}) of your Rails app doesn't match the base language (#{locale}) of the OneSky project"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class BaseLanguageNotMatchError < StandardError; end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'onesky/rails/client'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Onesky
|
5
|
+
module Rails
|
6
|
+
|
7
|
+
class FileClient < Onesky::Rails::Client
|
8
|
+
|
9
|
+
FILE_FORMAT = 'RUBY_YAML'
|
10
|
+
ENCODING = 'UTF-8'
|
11
|
+
DIR_PREFIX = 'onesky_'
|
12
|
+
TRANSLATION_NOTICE = <<-NOTICE
|
13
|
+
# This file is generated by onesky-rails gem and will be overwritten at the next download
|
14
|
+
# Therefore, you should not modify this file
|
15
|
+
# If you want to modify the translation, please do it at OneSky platform
|
16
|
+
# If you still want to modify this file directly, please upload this file to OneSky platform after modification in order to update the translation at OneSky
|
17
|
+
|
18
|
+
NOTICE
|
19
|
+
|
20
|
+
def upload(string_path)
|
21
|
+
verify_languages!
|
22
|
+
|
23
|
+
get_default_locale_files(string_path).map do |path|
|
24
|
+
filename = File.basename(path)
|
25
|
+
puts "Uploading #{filename}"
|
26
|
+
@project.upload_file(file: path, file_format: FILE_FORMAT, is_keeping_all_strings: is_keep_strings?)
|
27
|
+
path
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def download(string_path)
|
32
|
+
verify_languages!
|
33
|
+
|
34
|
+
files = get_default_locale_files(string_path).map {|path| File.basename(path)}
|
35
|
+
|
36
|
+
@onesky_locales.each do |locale|
|
37
|
+
puts "#{locale_dir(locale)}/"
|
38
|
+
onesky_locale = locale.gsub('_', '-')
|
39
|
+
files.each do |file|
|
40
|
+
response = @project.export_translation(source_file_name: file, locale: onesky_locale)
|
41
|
+
if response.code == 200
|
42
|
+
saved_file = save_translation(response, string_path, locale, file)
|
43
|
+
puts " #{saved_file}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def locale_dir(locale)
|
52
|
+
DIR_PREFIX + locale
|
53
|
+
end
|
54
|
+
|
55
|
+
def extract_file_name(header_hash)
|
56
|
+
search_text = 'filename='
|
57
|
+
if disposition = header_hash[:content_disposition]
|
58
|
+
if idx = disposition.index(search_text)
|
59
|
+
disposition[(idx + search_text.length)..-1]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def make_translation_dir(dir_path, locale)
|
65
|
+
target_path = File.join(dir_path, locale_dir(locale))
|
66
|
+
Dir.mkdir(target_path) unless File.directory?(target_path)
|
67
|
+
target_path
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_default_locale_files(string_path)
|
71
|
+
Dir.glob("#{string_path}/**/*.yml").map do |path|
|
72
|
+
content_hash = YAML.load_file(path)
|
73
|
+
path if content_hash && content_hash.has_key?(@base_locale.to_s)
|
74
|
+
end.compact
|
75
|
+
end
|
76
|
+
|
77
|
+
def save_translation(response, string_path, locale, file)
|
78
|
+
locale_path = make_translation_dir(string_path, locale)
|
79
|
+
target_file = extract_file_name(response.headers) || file
|
80
|
+
File.open(File.join(locale_path, target_file), 'w') do |f|
|
81
|
+
f.write(TRANSLATION_NOTICE + response.body.force_encoding(ENCODING))
|
82
|
+
end
|
83
|
+
target_file
|
84
|
+
end
|
85
|
+
|
86
|
+
def is_keep_strings?
|
87
|
+
return true unless (@config.has_key?('upload') && @config['upload'].has_key?('is_keeping_all_strings'))
|
88
|
+
|
89
|
+
!!@config['upload']['is_keeping_all_strings']
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
namespace :onesky do
|
2
|
+
|
3
|
+
desc "Upload string files of base locale to OneSky platform."
|
4
|
+
task :upload => :environment do
|
5
|
+
file_client.upload(locale_path)
|
6
|
+
puts 'Done!'
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Download translations from OneSky platform."
|
10
|
+
task :download => :environment do
|
11
|
+
file_client.download(locale_path)
|
12
|
+
puts 'Done!'
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_client
|
16
|
+
Onesky::Rails::FileClient.new YAML.load_file(Rails.root.join('config', 'onesky.yml'))
|
17
|
+
end
|
18
|
+
|
19
|
+
def locale_path
|
20
|
+
Rails.root.join("config/locales")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'onesky/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "onesky-rails"
|
8
|
+
spec.version = Onesky::Rails::VERSION
|
9
|
+
spec.authors = ["Victor Lam"]
|
10
|
+
spec.email = ["victorebox@yahoo.com.hk"]
|
11
|
+
spec.summary = "Rails plugin to sync string files with OneSky"
|
12
|
+
spec.description = "Integrate Rails app with OneSky that provide `upload` and `download` rake command to sync string files"
|
13
|
+
spec.homepage = "https://github.com/onesky/onesky-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "i18n", ">= 0.5.0"
|
22
|
+
spec.add_dependency "onesky-ruby", "~> 0.0.1"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
27
|
+
spec.add_development_dependency "webmock", "~> 1.19"
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Onesky::Rails::Client do
|
4
|
+
|
5
|
+
describe '#new' do
|
6
|
+
|
7
|
+
it 'with correct config' do
|
8
|
+
stub_request(:get, full_path_with_auth_hash("/projects/#{config_hash['project_id']}/languages", config_hash['api_key'], config_hash['api_secret']))
|
9
|
+
.to_return(status: 200, body: languages_response.to_json)
|
10
|
+
|
11
|
+
client = Onesky::Rails::Client.new(config_hash)
|
12
|
+
expect(client.base_locale).to eq(I18n.default_locale)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'with invalid config' do
|
16
|
+
expect{Onesky::Rails::Client.new({})}.to raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#verify_languages!' do
|
21
|
+
let(:client) {Onesky::Rails::Client.new(config_hash)}
|
22
|
+
|
23
|
+
context 'success' do
|
24
|
+
before(:each) do
|
25
|
+
stub_request(:get, full_path_with_auth_hash("/projects/#{config_hash['project_id']}/languages", config_hash['api_key'], config_hash['api_secret']))
|
26
|
+
.to_return(status: 200, body: languages_response.to_json)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'to retrieve languages activated at OneSky' do
|
30
|
+
expect{client.verify_languages!}.to_not raise_error
|
31
|
+
expect(client.onesky_locales).to eq(['ja'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'fail' do
|
36
|
+
it 'with incorrect credentials' do
|
37
|
+
stub_request(:get, full_path_with_auth_hash("/projects/#{config_hash['project_id']}/languages", config_hash['api_key'], config_hash['api_secret']))
|
38
|
+
.to_return(status: 401, body: {meta: {code: 401, message: 'Fail to authorize'}}.to_json)
|
39
|
+
|
40
|
+
expect{client.verify_languages!}.to raise_error(Onesky::Errors::UnauthorizedError, '401 Unauthorized - Fail to authorize')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'with mis-match base locale' do
|
44
|
+
I18n.default_locale = :ja
|
45
|
+
|
46
|
+
stub_request(:get, full_path_with_auth_hash("/projects/#{config_hash['project_id']}/languages", config_hash['api_key'], config_hash['api_secret']))
|
47
|
+
.to_return(status: 200, body: languages_response.to_json)
|
48
|
+
|
49
|
+
expect{client.verify_languages!}.to raise_error(Onesky::Rails::BaseLanguageNotMatchError, 'The default locale (ja) of your Rails app doesn\'t match the base language (en) of the OneSky project')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Onesky::Rails::FileClient do
|
4
|
+
|
5
|
+
let(:client) {Onesky::Rails::FileClient.new(config_hash)}
|
6
|
+
let(:file_path) { File.expand_path("../../../fixtures/locales", __FILE__) }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
stub_language_request(config_hash['api_key'], config_hash['api_secret'], config_hash['project_id'])
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#upload' do
|
13
|
+
it 'strings to onesky' do
|
14
|
+
stub_request(:post, full_path_with_auth_hash("/projects/#{config_hash['project_id']}/files", config_hash['api_key'], config_hash['api_secret']))
|
15
|
+
.to_return(status: 201)
|
16
|
+
|
17
|
+
expect(client.upload(file_path)).to eq(["#{file_path}/en.yml"])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'download' do
|
22
|
+
|
23
|
+
let(:file_name) {'ja.yml'}
|
24
|
+
let(:response_headers) do
|
25
|
+
{
|
26
|
+
'Content-Type' => 'text/plain',
|
27
|
+
'Content-Disposition' => "attachment; filename=#{file_name}",
|
28
|
+
}
|
29
|
+
end
|
30
|
+
let(:query_string) {'&source_file_name=en.yml&locale=ja'}
|
31
|
+
|
32
|
+
def locale_dir
|
33
|
+
File.join(file_path, 'onesky_ja')
|
34
|
+
end
|
35
|
+
|
36
|
+
def locale_files
|
37
|
+
Dir.glob("#{locale_dir}/*.yml")
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_test_dir
|
41
|
+
if File.directory?(locale_dir)
|
42
|
+
File.delete(*Dir.glob("#{locale_dir}/**/*"))
|
43
|
+
Dir.delete(locale_dir)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
before(:each) do
|
48
|
+
delete_test_dir
|
49
|
+
end
|
50
|
+
|
51
|
+
after(:each) do
|
52
|
+
delete_test_dir
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'download translations from OneSky and save as YAML files' do
|
56
|
+
stub_request(:get, full_path_with_auth_hash("/projects/#{config_hash['project_id']}/translations", config_hash['api_key'], config_hash['api_secret']) + query_string)
|
57
|
+
.to_return(
|
58
|
+
status: 200,
|
59
|
+
body: File.read(File.join(file_path, file_name)),
|
60
|
+
headers: response_headers)
|
61
|
+
|
62
|
+
expect(locale_files).to be_empty
|
63
|
+
client.download(file_path)
|
64
|
+
expect(locale_files).to eq(["#{locale_dir}/#{file_name}"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'i18n'
|
4
|
+
require 'onesky/rails'
|
5
|
+
require 'onesky'
|
6
|
+
|
7
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
original_locale = I18n.default_locale
|
11
|
+
config.before(:each) do
|
12
|
+
I18n.enforce_available_locales = false
|
13
|
+
I18n.default_locale = original_locale # reset to default locale
|
14
|
+
end
|
15
|
+
|
16
|
+
config.after(:each) do
|
17
|
+
I18n.default_locale = original_locale # reset to default locale
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def auth_query_string(api_key, api_secret)
|
22
|
+
now = Time.now.to_i
|
23
|
+
output = '?'
|
24
|
+
output += "api_key=#{api_key}"
|
25
|
+
output += "×tamp=#{now.to_s}"
|
26
|
+
output += "&dev_hash=#{Digest::MD5.hexdigest(now.to_s + api_secret)}"
|
27
|
+
|
28
|
+
output
|
29
|
+
end
|
30
|
+
|
31
|
+
def full_path_with_auth_hash(path, api_key, api_secret)
|
32
|
+
"#{Helpers::Request::ENDPOINT}/#{Helpers::Request::VERSION}#{path}#{auth_query_string(api_key, api_secret)}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def stub_language_request(api_key, api_secret, project_id)
|
36
|
+
stub_request(:get, full_path_with_auth_hash("/projects/#{project_id}/languages", api_key, api_secret))
|
37
|
+
.to_return(status: 200, body: languages_response.to_json)
|
38
|
+
end
|
39
|
+
|
40
|
+
def languages_response
|
41
|
+
{data:
|
42
|
+
[
|
43
|
+
{code: 'en', is_base_language: true},
|
44
|
+
{code: 'ja', is_base_language: false},
|
45
|
+
]
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def config_hash
|
50
|
+
{
|
51
|
+
"api_key" => 'fakeapi',
|
52
|
+
"api_secret" => 'fakesecret',
|
53
|
+
"project_id" => 99,
|
54
|
+
"upload" => {
|
55
|
+
"is_keeping_all_strings" => true
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onesky-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Lam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: onesky-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.19'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.19'
|
97
|
+
description: Integrate Rails app with OneSky that provide `upload` and `download`
|
98
|
+
rake command to sync string files
|
99
|
+
email:
|
100
|
+
- victorebox@yahoo.com.hk
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/generators/onesky/init_generator.rb
|
112
|
+
- lib/generators/templates/onesky.yml.tt
|
113
|
+
- lib/onesky/rails.rb
|
114
|
+
- lib/onesky/rails/client.rb
|
115
|
+
- lib/onesky/rails/file_client.rb
|
116
|
+
- lib/onesky/rails/railtie.rb
|
117
|
+
- lib/onesky/rails/version.rb
|
118
|
+
- lib/tasks/onesky.rake
|
119
|
+
- onesky-rails.gemspec
|
120
|
+
- spec/fixtures/locales/en.json
|
121
|
+
- spec/fixtures/locales/en.yml
|
122
|
+
- spec/fixtures/locales/ja.yml
|
123
|
+
- spec/onesky/rails/client_spec.rb
|
124
|
+
- spec/onesky/rails/file_client_spec.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
homepage: https://github.com/onesky/onesky-rails
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.2.2
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Rails plugin to sync string files with OneSky
|
150
|
+
test_files:
|
151
|
+
- spec/fixtures/locales/en.json
|
152
|
+
- spec/fixtures/locales/en.yml
|
153
|
+
- spec/fixtures/locales/ja.yml
|
154
|
+
- spec/onesky/rails/client_spec.rb
|
155
|
+
- spec/onesky/rails/file_client_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
has_rdoc:
|