phrase 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ require 'phrase/tool_config'
2
2
 
3
3
  require 'optparse'
4
4
  require 'net/http'
5
+ require 'net/https'
5
6
  require 'fileutils'
6
7
 
7
8
  module PhraseGem
@@ -92,7 +93,12 @@ module PhraseGem
92
93
  'filename'=> file,
93
94
  'file_content' => File.read(file)
94
95
  }
95
- res = Net::HTTP.post_form(URI.parse("#{config.api_endpoint}/translation_keys/upload"),params)
96
+
97
+ http = http_client(config)
98
+
99
+ request = Net::HTTP::Post.new("#{config.api_path_prefix}/translation_keys/upload")
100
+ request.set_form_data(params)
101
+ res = http.request(request)
96
102
 
97
103
  dump_summary_to_file(res, file)
98
104
  unless res.code.to_s =~ /^[23]/
@@ -103,10 +109,14 @@ module PhraseGem
103
109
 
104
110
  def pull(config)
105
111
  locale = args[1]
106
- uri = "#{config.api_endpoint}/translations/download?auth_token=#{config.secret}&locale=#{locale}"
107
112
  print "Downloading phrase.#{locale}.yml..."
108
113
  ::FileUtils.mkdir_p("phrase/locales")
109
- res = Net::HTTP.get_response(URI.parse(uri))
114
+
115
+ http = http_client(config)
116
+
117
+ request = Net::HTTP::Get.new("#{config.api_path_prefix}/translations/download?auth_token=#{config.secret}&locale=#{locale}")
118
+ res = http.request(request)
119
+
110
120
  if res.code.to_s =~ /200/
111
121
  puts " OK"
112
122
  File.open("phrase/locales/phrase.#{locale}.yml", "w") do |file|
@@ -162,5 +172,13 @@ USAGE
162
172
  end
163
173
  puts "Summary saved in #{summary_file}"
164
174
  end
175
+
176
+ def http_client(config)
177
+ http = Net::HTTP.new(config.api_host, config.api_port)
178
+ http.use_ssl = true if config.api_use_ssl == "1"
179
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
180
+ http.ca_file = File.join(File.dirname(__FILE__), "..", "..", "cacert.pem")
181
+ http
182
+ end
165
183
  end
166
184
  end
@@ -23,8 +23,20 @@ module PhraseGem
23
23
  save_config!
24
24
  end
25
25
 
26
- def api_endpoint
27
- ENV.fetch("PHRASE_API_ENDPOINT", "https://phraseapp.com/api/v1")
26
+ def api_port
27
+ ENV.fetch("PHRASE_API_PORT", "443")
28
+ end
29
+
30
+ def api_host
31
+ ENV.fetch("PHRASE_API_HOST", "phraseapp.com")
32
+ end
33
+
34
+ def api_path_prefix
35
+ "/api/v1"
36
+ end
37
+
38
+ def api_use_ssl
39
+ ENV.fetch("PHRASE_API_USE_SSL", "1")
28
40
  end
29
41
 
30
42
  private
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "phrase"
7
- s.version = "0.0.1"
7
+ s.version = "0.0.2"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Dynport GmbH"]
10
10
  s.email = ["info@phraseapp.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phrase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-13 00:00:00.000000000Z
12
+ date: 2012-03-14 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: The best way to manage i18n.
15
15
  email:
@@ -24,6 +24,7 @@ files:
24
24
  - Gemfile.lock
25
25
  - README.md
26
26
  - bin/phrase
27
+ - cacert.pem
27
28
  - lib/phrase.rb
28
29
  - lib/phrase/backend.rb
29
30
  - lib/phrase/backend/base.rb