almodovar 1.4.0 → 1.5.0

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: a03ef84c9f0f43fc48e8592f8a0279d2569cf252
4
- data.tar.gz: 3f5312eedc88662b3a5ea0175b23bd2038131521
3
+ metadata.gz: a6a4155b3c2891ccd7f193593f9c5a612e1bb16a
4
+ data.tar.gz: 353891dd01565285a46782fd3a31c5d504efb906
5
5
  SHA512:
6
- metadata.gz: cad22336edc9785ee8eab726c90941a09be9e16b553926591ad89cf79b9d97fc146997d01ace6143c466718cb9467f318721247add17a39b9263cf0b6207745c
7
- data.tar.gz: 7b67c6c048372157493b495a259f078ff3421d075ef9f57be6a6e251d93d725e46c0b33b7fb05b83162fce2e18a3e040761d06fe50a788c9832f35087a43beb7
6
+ metadata.gz: c74c6def4417b942ff3c345c56523984f80d9331ae4551c68dc4c86a3f0d9cbb390cfe3958f57eb7ac909f6e119ee205f7190bbd261a5399f23bec80381246bb
7
+ data.tar.gz: b9ff041e5187657d7c90800c36f8a298e32f98f426dc2045fbf25e64f0928c910f5226b452f58ba3c1dd5bfd27bfdee4e1c17376d47fcae868c362a48837420e
@@ -16,14 +16,27 @@ require 'almodovar/errors'
16
16
  require 'almodovar/to_xml'
17
17
 
18
18
  module Almodovar
19
-
20
19
  class << self
20
+ DEFAULT_SEND_TIMEOUT = 120
21
+ DEFAULT_CONNECT_TIMEOUT = 30
22
+ DEFAULT_RECEIVE_TIMEOUT = 120
23
+
21
24
  def default_options
22
- @default_options ||= {
23
- :timeout => 120,
24
- :connect_timeout => 30,
25
- :user_agent => "Almodovar/#{Almodovar::VERSION}"
25
+ default = {
26
+ send_timeout: DEFAULT_SEND_TIMEOUT,
27
+ connect_timeout: DEFAULT_CONNECT_TIMEOUT,
28
+ receive_timeout: DEFAULT_RECEIVE_TIMEOUT,
29
+ user_agent: "Almodovar/#{Almodovar::VERSION}"
30
+ }
31
+ default.merge(@default_options || {})
32
+ end
33
+
34
+ def default_options=(options = {})
35
+ @default_options = {
36
+ send_timeout: options[:send_timeout],
37
+ connect_timeout: options[:connect_timeout],
38
+ receive_timeout: options[:receive_timeout]
26
39
  }
27
40
  end
28
41
  end
29
- end
42
+ end
@@ -8,4 +8,16 @@ module Almodovar
8
8
  super("Status code #{response.status} on resource #{url}")
9
9
  end
10
10
  end
11
+
12
+ class TimeoutError < StandardError
13
+ end
14
+
15
+ class SendTimeoutError < TimeoutError
16
+ end
17
+
18
+ class ReceiveTimeoutError < TimeoutError
19
+ end
20
+
21
+ class ConnectTimeoutError < TimeoutError
22
+ end
11
23
  end
@@ -7,18 +7,19 @@ module Almodovar
7
7
  Nokogiri::XML.parse(response.body).root
8
8
  end
9
9
  end
10
-
10
+
11
11
  def url_with_params
12
12
  @options[:expand] = @options[:expand].join(",") if @options[:expand].is_a?(Array)
13
13
  params = @options.map { |k, v| "#{k}=#{v}" }.join("&")
14
14
  params = "?#{params}" unless params.empty?
15
15
  @url + params
16
16
  end
17
-
17
+
18
18
  def http
19
19
  @http ||= Almodovar::HttpClient.new.tap do |session|
20
- session.timeout = Almodovar::default_options[:timeout]
20
+ session.send_timeout = Almodovar::default_options[:send_timeout]
21
21
  session.connect_timeout = Almodovar::default_options[:connect_timeout]
22
+ session.receive_timeout = Almodovar::default_options[:receive_timeout]
22
23
  session.agent_name = Almodovar::default_options[:user_agent]
23
24
 
24
25
  if @auth
@@ -28,10 +29,9 @@ module Almodovar
28
29
  end
29
30
  end
30
31
  end
31
-
32
+
32
33
  def check_errors(response, url)
33
34
  raise(Almodovar::HttpError.new(response, url)) if response.status >= 400
34
35
  end
35
36
  end
36
-
37
- end
37
+ end
@@ -2,7 +2,6 @@ require 'httpclient'
2
2
 
3
3
  module Almodovar
4
4
  class HttpClient
5
-
6
5
  attr_accessor :client,
7
6
  :headers,
8
7
  :username,
@@ -11,13 +10,10 @@ module Almodovar
11
10
 
12
11
  delegate :agent_name=,
13
12
  :connect_timeout=,
13
+ :send_timeout=,
14
+ :receive_timeout=,
14
15
  :to => :client
15
16
 
16
-
17
- def timeout=(value)
18
- client.send_timeout = value
19
- end
20
-
21
17
  def initialize
22
18
  @client = HTTPClient.new
23
19
  end
@@ -71,7 +67,7 @@ module Almodovar
71
67
  end
72
68
 
73
69
  def request(method, uri, options = {})
74
- uri = URI.parse(uri)
70
+ uri = URI.parse(URI.escape(URI.unescape(uri)))
75
71
  if (requires_auth?)
76
72
  domain = domain_for(uri)
77
73
  uri.user = username
@@ -79,6 +75,12 @@ module Almodovar
79
75
  set_client_auth(domain)
80
76
  end
81
77
  client.request(method, uri, :body => options[:body], :header => options[:headers].stringify_keys || {}, :follow_redirect => true)
78
+ rescue HTTPClient::SendTimeoutError => e
79
+ raise SendTimeoutError.new(e)
80
+ rescue HTTPClient::ReceiveTimeoutError => e
81
+ raise ReceiveTimeoutError.new(e)
82
+ rescue HTTPClient::ConnectTimeoutError => e
83
+ raise ConnectTimeoutError.new(e)
82
84
  end
83
85
  end
84
86
 
@@ -100,5 +102,4 @@ module Almodovar
100
102
  class HttpResponse
101
103
  attr_accessor :status, :body
102
104
  end
103
-
104
- end
105
+ end
@@ -1,3 +1,3 @@
1
1
  module Almodovar
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: almodovar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BeBanjo S.L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-08 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -134,9 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.4.7
137
+ rubygems_version: 2.5.1
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: BeBanjo API client
141
141
  test_files: []
142
- has_rdoc: