one_sky 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
1
  module OneSky
2
-
2
+
3
3
  # Implements the Translation I/O API for a given :platform_id
4
4
  class Translation
5
-
5
+
6
6
  attr_reader :platform_id, :client
7
-
7
+
8
8
  # Provide the id of the platform, together with an instance of OneSky::Client.
9
9
  def initialize(platform_id, client)
10
10
  @platform_id = platform_id
@@ -13,97 +13,101 @@ module OneSky
13
13
 
14
14
  # Add new strings to be translated.
15
15
  # expects an array of strings, or an array of hashes [{:string_key => k, :string => v}, ...]
16
- def input_strings(strings)
17
- post("string/input", :input => format_input_strings(strings))
16
+ def input_strings(strings, options={})
17
+ params = {:input => format_input_strings(strings)}
18
+ if options[:tag] # include the :tag if there is one
19
+ params[:tag] = options[:tag]
20
+ end
21
+ post("string/input", params)
18
22
  end
19
-
23
+
20
24
  # Add new strings to be translated.
21
25
  # expects a string, or a hash of {:string_key => k, :string => v}
22
- def input_string(string)
23
- input_strings([string])
26
+ def input_string(string, options={})
27
+ input_strings([string], options)
24
28
  end
25
-
29
+
26
30
  # Add new strings to be translated.
27
31
  # expects a hash of {"string_key1" => "String 1", "string_key2" => "String 2"}
28
- def input_phrases(phrases)
32
+ def input_phrases(phrases, options={})
29
33
  strings = phrases.map do |string_key, string|
30
34
  {:string_key => string_key, :string => string}
31
35
  end
32
- input_strings(strings)
36
+ input_strings(strings, options)
33
37
  end
34
-
38
+
35
39
  # Add translation to a string.
36
40
  def translate(string_key, locale, translation)
37
41
  post("string/translate", :"string-key" => string_key, :locale => locale, :translation => translation)
38
42
  end
39
-
43
+
40
44
  # Get the strings with translations.
41
45
  def output
42
46
  get_output
43
47
  end
44
-
48
+
45
49
  # Get the strings for a particular locale.
46
50
  def output_for_locale(locale)
47
51
  get_output(locale)
48
52
  end
49
-
53
+
50
54
  YAML_FORMAT = "RUBY_YAML".freeze
51
55
  PO_FORMAT = "GNU_PO".freeze
52
-
56
+
53
57
  # I don't believe these work right now.
54
-
58
+
55
59
  # Upload a string file to add new strings. In RUBY_YAML format.
56
60
  def upload_yaml(file)
57
61
  upload_file(file, YAML_FORMAT)
58
62
  end
59
-
63
+
60
64
  # Upload a string file to add new strings. In GNU_PO format.
61
65
  def upload_po(file)
62
66
  upload_file(file, PO_FORMAT)
63
67
  end
64
-
68
+
65
69
  # Download strings and translations as string file. In RUBY_YAML format.
66
70
  def download_yaml(locale)
67
71
  download_file(locale, YAML_FORMAT)
68
72
  end
69
-
73
+
70
74
  # Download strings and translations as string file. In GNU_PO format.
71
75
  def download_po(locale)
72
76
  download_file(locale, PO_FORMAT)
73
77
  end
74
-
78
+
75
79
  protected
76
-
80
+
77
81
  # Get the strings with translations.
78
82
  def get_output(locale=nil)
79
83
  options = {}
80
84
  options[:locale] = locale if locale
81
-
85
+
82
86
  get("string/output", options)["translation"]
83
87
  end
84
-
88
+
85
89
  # Upload a string file to add new strings.
86
90
  def upload_file(file, format)
87
91
  post("string/upload", :file => file, :format => format)
88
92
  end
89
-
93
+
90
94
  # Download strings and translations as string file.
91
95
  def download_file(locale, format)
92
96
  get("string/download", :locale => locale, :format => format)
93
97
  end
94
-
98
+
95
99
  def get(path, params={})
96
100
  client.get(path, params.merge(:"platform-id" => platform_id))
97
101
  end
98
-
102
+
99
103
  def post(path, params={})
100
104
  client.post(path, params.merge(:"platform-id" => platform_id))
101
105
  end
102
-
106
+
103
107
  def format_input_strings(strings)
104
108
  JSON.dump(strings.map{|string| format_input_string(string)})
105
109
  end
106
-
110
+
107
111
  def format_input_string(string)
108
112
  case string
109
113
  when String
@@ -114,7 +118,7 @@ module OneSky
114
118
  raise "input string must either be a string, or a hash"
115
119
  end
116
120
  end
117
-
121
+
118
122
  # convert to "string-key" not "string_key"
119
123
  def dashify_string_hash(string_hash)
120
124
  output = Hash.new
@@ -126,4 +130,4 @@ module OneSky
126
130
  end
127
131
 
128
132
  end
129
- end
133
+ end
@@ -1,3 +1,3 @@
1
1
  module OneSky
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
data/one_sky.gemspec CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.name = "one_sky"
7
7
  s.version = OneSky::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Junjun Olympia", "3dd13 Lau", "Matthew Rudy Jacobs"]
9
+ s.authors = ["Junjun Olympia", "Eddie Lau", "Matthew Rudy Jacobs"]
10
10
  s.email = ["romeo.olympia@gmail.com", "tatonlto@gmail.com", "matthewrudyjacobs@gmail.com"]
11
- s.homepage = "http://rubygems.org/gems/one_sky"
11
+ s.homepage = "http://developer.oneskyapp.com/"
12
12
  s.summary = %q{Ruby interface to the OneSky REST API}
13
13
  s.description = %q{OneSky is a community-powered translation service for web and mobile apps. This gem is the core interface to the REST API and is used by other specialty gems such the OneSky extension for I18n, i18n-one_sky.}
14
14
 
@@ -5,70 +5,91 @@ describe OneSky::Translation do
5
5
  let(:secret) { "secret" }
6
6
  let(:project_name) { "some-project" }
7
7
  let(:platform_id) { 123 }
8
-
8
+
9
9
  let(:client) { OneSky::Client.new(api_key, secret) }
10
10
  let(:project) { client.project(project_name) }
11
11
  let(:platform) { project.platform(platform_id) }
12
12
  let(:translation) { platform.translation }
13
-
13
+
14
14
  describe "input_strings" do
15
-
15
+
16
16
  let(:string_array) {
17
17
  ["test1", "test2"]
18
18
  }
19
-
19
+
20
20
  let(:hash_array) {
21
21
  [{:string => "test1"}, {:string => "test2"}]
22
22
  }
23
-
23
+
24
+
24
25
  context "with an array of strings" do
25
26
  it "calls /string/input" do
26
27
  client.should_receive(:post).with("string/input", :input => JSON.dump(hash_array), :"platform-id" => platform_id)
27
-
28
+
28
29
  translation.input_strings(string_array)
29
30
  end
30
31
  end
31
-
32
+
33
+ context "with an array of strings and tag" do
34
+ it "calls /string/input" do
35
+ client.should_receive(:post).with("string/input", :input => JSON.dump(hash_array), :tag => "tagged", :"platform-id" => platform_id)
36
+
37
+ translation.input_strings(string_array, :tag => "tagged")
38
+ end
39
+ end
40
+
32
41
  context "with an array of hashes" do
33
42
  it "calls /string/input" do
34
43
  client.should_receive(:post).with("string/input", :input => JSON.dump(hash_array), :"platform-id" => platform_id)
35
-
44
+
36
45
  translation.input_strings(hash_array)
37
46
  end
38
47
  end
39
-
48
+
40
49
  context "with a complex array of hashes" do
41
50
  it "dasherizes the keys" do
42
51
  original = [{:string => "Test 1", :string_key => "test1"}]
43
52
  dasherized = [{:string => "Test 1", :"string-key" => "test1"}]
44
-
53
+
45
54
  client.should_receive(:post).with("string/input", :input => JSON.dump(dasherized), :"platform-id" => platform_id)
46
-
55
+
47
56
  translation.input_strings(original)
48
57
  end
49
58
  end
50
59
  end
51
-
60
+
52
61
  describe "input_string" do
53
62
  it "defers to input_strings" do
54
- translation.should_receive(:input_strings).with(["test1"])
63
+ translation.should_receive(:input_strings).with(["test1"], {})
55
64
  translation.input_string("test1")
56
65
  end
66
+
67
+ it "passes on a :tag" do
68
+ translation.should_receive(:input_strings).with(["test1"], {:tag => "tagged"})
69
+ translation.input_string("test1", :tag => "tagged")
70
+ end
71
+
57
72
  end
58
-
73
+
59
74
  describe "input_phrases" do
60
75
  it "defers to input_strings" do
61
- translation.should_receive(:input_strings).with([{:string_key => "test1", :string => "Test 1"}])
76
+ translation.should_receive(:input_strings).with([{:string_key => "test1", :string => "Test 1"}], {})
62
77
  translation.input_phrases("test1" => "Test 1")
63
78
  end
79
+
80
+ it "passes on a :tag" do
81
+ translation.should_receive(:input_strings).with([{:string_key => "test1", :string => "Test 1"}], {:tag => "tagged"})
82
+ translation.input_phrases({"test1" => "Test 1"}, :tag => "tagged")
83
+ end
84
+
64
85
  end
65
-
86
+
66
87
  describe "translate" do
67
-
88
+
68
89
  let(:string_key) { "test1" }
69
90
  let(:locale) { "en_US" }
70
91
  let(:string) { "Test 1" }
71
-
92
+
72
93
  it "calls /string/translate" do
73
94
  client.should_receive(:post).with(
74
95
  "string/translate",
@@ -77,13 +98,13 @@ describe OneSky::Translation do
77
98
  :translation => string,
78
99
  :"platform-id" => platform_id
79
100
  )
80
-
101
+
81
102
  translation.translate(string_key, locale, string)
82
103
  end
83
104
  end
84
-
105
+
85
106
  describe "output" do
86
-
107
+
87
108
  let(:example) do
88
109
  {
89
110
  "translation" => {
@@ -108,12 +129,12 @@ describe OneSky::Translation do
108
129
  "md5" => "95e6198f16ea363291dfa9bc18282545"
109
130
  }
110
131
  end
111
-
132
+
112
133
  it "calls /string/output" do
113
134
  client.should_receive(:get).with("string/output", :"platform-id" => platform_id).and_return(example)
114
135
  translation.output.should == example["translation"]
115
136
  end
116
-
137
+
117
138
  context "for_locale" do
118
139
  it "calls /string/output with the locale" do
119
140
  client.should_receive(:get).with("string/output", :"platform-id" => platform_id, :locale => "en_US").and_return(example)
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_sky
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Junjun Olympia
9
- - 3dd13 Lau
9
+ - Eddie Lau
10
10
  - Matthew Rudy Jacobs
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-12-07 00:00:00.000000000 Z
14
+ date: 2012-02-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
18
- requirement: &70215713483240 !ruby/object:Gem::Requirement
18
+ requirement: &70150153158340 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 1.4.0
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70215713483240
26
+ version_requirements: *70150153158340
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rest-client
29
- requirement: &70215713396900 !ruby/object:Gem::Requirement
29
+ requirement: &70150153157440 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 1.4.0
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70215713396900
37
+ version_requirements: *70150153157440
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &70215713808380 !ruby/object:Gem::Requirement
40
+ requirement: &70150153156480 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 2.2.0
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70215713808380
48
+ version_requirements: *70150153156480
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: bundler
51
- requirement: &70215713741580 !ruby/object:Gem::Requirement
51
+ requirement: &70150153156020 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 1.0.0
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70215713741580
59
+ version_requirements: *70150153156020
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: time_freeze
62
- requirement: &70215713707880 !ruby/object:Gem::Requirement
62
+ requirement: &70150153155640 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,7 +67,7 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70215713707880
70
+ version_requirements: *70150153155640
71
71
  description: OneSky is a community-powered translation service for web and mobile
72
72
  apps. This gem is the core interface to the REST API and is used by other specialty
73
73
  gems such the OneSky extension for I18n, i18n-one_sky.
@@ -105,7 +105,7 @@ files:
105
105
  - spec/spec_helper.rb
106
106
  - spec/translation_spec.rb
107
107
  - spec/utility_spec.rb
108
- homepage: http://rubygems.org/gems/one_sky
108
+ homepage: http://developer.oneskyapp.com/
109
109
  licenses: []
110
110
  post_install_message:
111
111
  rdoc_options: []