phrase 0.4.25 → 0.4.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d19161a8b74d93add452fa8141fd6a7c3218736c
4
- data.tar.gz: ccc2ffadca6cac58332e772def7ccb8a00798a91
3
+ metadata.gz: b3c457a53ebdfab70d66596fe2bc8c390049198d
4
+ data.tar.gz: ddba48cccd66f4e762c8df3e0e39aa2f391bbdf8
5
5
  SHA512:
6
- metadata.gz: 7743e6c862f1191d1dbc06b16aa95e982e9d84633bcbb61a1361c9fed8c8d9c9d84d6935b6f0319e702d939397d34c141cba6d526353cdfc5c577ef782d36a0b
7
- data.tar.gz: e0ab46de6616360e7d31aec7a7e5d64d41024307c3638dce43b92c049a473cf9d8cff26340ba44021e41b40bb33a6f19c84c291b8a99f5319defff69cbb67a77
6
+ metadata.gz: a59b70a1f14401ee9b54ce7047c23447db205c3e5e8791ce30f9744b6fc755bcfaf1f2961a2267d3227477cda45c753c8810dc98008d3f2e78f0c91d0bf7d997
7
+ data.tar.gz: a98ce99ff00e6f44ce1a25517a7f49c93b4b5e5c96dd1571844d5959bf4634663a3b4d3820538b197e1996cb61bf2cf495820233ff47ee66a414be1ae4928500
@@ -6,9 +6,13 @@ require 'net/http'
6
6
  require 'net/https'
7
7
  require 'phrase'
8
8
  require 'phrase/api'
9
+ require 'phrase/api/client/http'
9
10
 
10
11
  class Phrase::Api::Client
11
12
 
13
+ # Mixin Factory in order to recognize http_proxy settings in Ruby 1.9.X
14
+ include Phrase::Api::Client::Http
15
+
12
16
  METHOD_GET = :get
13
17
  METHOD_POST = :post
14
18
  METHOD_PUT = :put
@@ -262,14 +266,6 @@ private
262
266
  "#{Phrase::Api::Config.api_path_prefix}#{endpoint}"
263
267
  end
264
268
 
265
- def http_client
266
- client = Net::HTTP.new(Phrase::Api::Config.api_host, Phrase::Api::Config.api_port)
267
- client.use_ssl = true if Phrase::Api::Config.api_use_ssl?
268
- client.verify_mode = OpenSSL::SSL::VERIFY_NONE if Phrase::Api::Config.skip_ssl_validation?
269
- client.ca_file = File.join(File.dirname(__FILE__), "..", "..", "..", "cacert.pem")
270
- client
271
- end
272
-
273
269
  # Support for arrays in POST data
274
270
  # http://blog.assimov.net/blog/2010/06/01/postput-arrays-with-ruby-nethttp-set_form_data/
275
271
  def set_form_data(request, params, separator='&')
@@ -0,0 +1,56 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module Phrase
5
+ module Api
6
+ class Client
7
+ module Http
8
+
9
+ # Mixin Factory
10
+ def self.included(base)
11
+ klass = RUBY_VERSION < "2.0" ? Http1X : Http2X
12
+ base.send :include, klass
13
+ end
14
+
15
+ def handle_ssl_cert(client)
16
+ client.use_ssl = true if Phrase::Api::Config.api_use_ssl?
17
+ client.verify_mode = OpenSSL::SSL::VERIFY_NONE if Phrase::Api::Config.skip_ssl_validation?
18
+ client.ca_file = File.join(File.dirname(__FILE__), "..", "..", "..", "..", "cacert.pem")
19
+ client
20
+ end
21
+
22
+ module Http2X
23
+ def http_client
24
+ client = Net::HTTP.new(Phrase::Api::Config.api_host, Phrase::Api::Config.api_port)
25
+ handle_ssl_cert(client)
26
+ end
27
+ end
28
+
29
+ module Http1X
30
+ class InvalidProxyError < StandardError; end
31
+
32
+ def http_client
33
+ proxy_user, proxy_pass, proxy_host, proxy_port = nil, nil, nil, nil
34
+ if Phrase::Api::Config.proxy.present?
35
+ begin
36
+ uri = URI.parse(Phrase::Api::Config.proxy)
37
+ proxy_user, proxy_pass = uri.userinfo.split(/:/) if uri.userinfo
38
+ proxy_host = uri.host
39
+ proxy_port = uri.port
40
+ rescue URI::InvalidURIError => e
41
+ raise InvalidProxyError.new(e)
42
+ end
43
+ end
44
+
45
+ client = Net::HTTP.new(
46
+ Phrase::Api::Config.api_host, Phrase::Api::Config.api_port,
47
+ proxy_host, proxy_port, proxy_user, proxy_pass
48
+ )
49
+ handle_ssl_cert(client)
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+ end
@@ -27,4 +27,8 @@ class Phrase::Api::Config
27
27
  def self.skip_ssl_validation?
28
28
  ENV.fetch("PHRASE_API_SKIP_SSL_VALIDATION", "0") == "1"
29
29
  end
30
+
31
+ def self.proxy
32
+ ENV.fetch("http_proxy", nil)
33
+ end
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module Phrase
2
- VERSION = "0.4.25"
2
+ VERSION = "0.4.26"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phrase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.25
4
+ version: 0.4.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dynport GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -181,6 +181,7 @@ files:
181
181
  - lib/phrase/adapters/i18n.rb
182
182
  - lib/phrase/api.rb
183
183
  - lib/phrase/api/client.rb
184
+ - lib/phrase/api/client/http.rb
184
185
  - lib/phrase/api/config.rb
185
186
  - lib/phrase/api/exceptions.rb
186
187
  - lib/phrase/api/query_params.rb