pebblebed 0.3.4 → 0.3.5

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: 06261d549c1cafdbd58b7411d20ea7cc1d36becc
4
- data.tar.gz: 06a49b98c431ce957e898283be7711576f5654ad
3
+ metadata.gz: fb66474bc41c0a30280586d8d8fe9b1482b0afc3
4
+ data.tar.gz: e01c0d2eb6bce7d2664be227cbd0ff498b790969
5
5
  SHA512:
6
- metadata.gz: 8216dfc6d23276310622dd7c984a94a407b244c943957bc6d8c57b64a32b98c8b1be7d362b05f66267b168f93ff3832e53b35cf8eb7136338771edc05e6bacea
7
- data.tar.gz: d6c8b9b1e795455fc23ed9e54f71a605973fd1f030b2261d65a7ef5eac8c9466f32dd66098af1c6ae21fdd43d08832060b89f404edc13012d78f30e9755ae02f
6
+ metadata.gz: c0d1a7b303ef9932e666b6faa5f03555aa428ba82d2f77ea654a41ae4650631ff67519587a3c7193598dab87740160913e9086a0a6bd2d6cd54e9f2ef96c5f17
7
+ data.tar.gz: e40ac5cf384fe6ad9c33713a112c8abb8f930c41a4b810533445bd367277f88bac8619d63c8b20251c4db9d546723f5639f80e41da3cced6c2408260b14f71ad
@@ -36,50 +36,53 @@ module Pebblebed
36
36
  end
37
37
 
38
38
  module Http
39
- class CurlResult
40
- def initialize(curl_result)
41
- @curl_result = curl_result
42
- end
43
-
44
- def status
45
- @curl_result.response_code
46
- end
47
39
 
48
- def url
49
- @curl_result.url
40
+ class Response
41
+ def initialize(easy)
42
+ @body = easy.body_str
43
+ @status = easy.status.to_i
44
+ @url = easy.url
50
45
  end
51
46
 
52
- def body
53
- @curl_result.body_str
54
- end
47
+ attr_reader :body, :status, :url
55
48
  end
56
49
 
57
50
  def self.get(url = nil, params = nil, &block)
58
51
  url, params = url_and_params_from_args(url, params, &block)
59
- handle_curl_response(Curl::Easy.perform(url_with_params(url, params)))
52
+ return with_curl { |easy|
53
+ easy.url = url_with_params(url, params)
54
+ easy.http_get
55
+ }
60
56
  end
61
57
 
62
58
  def self.post(url, params, &block)
63
59
  url, params = url_and_params_from_args(url, params, &block)
64
60
  content_type, body = serialize_params(params)
65
- handle_curl_response(Curl::Easy.http_post(url.to_s, body) do |curl|
66
- curl.headers['Accept'] = 'application/json'
67
- curl.headers['Content-Type'] = content_type
68
- end)
61
+ return with_curl { |easy|
62
+ easy.url = url.to_s
63
+ easy.headers['Accept'] = 'application/json'
64
+ easy.headers['Content-Type'] = content_type
65
+ easy.http_post(body)
66
+ }
69
67
  end
70
68
 
71
69
  def self.put(url, params, &block)
72
70
  url, params = url_and_params_from_args(url, params, &block)
73
71
  content_type, body = serialize_params(params)
74
- handle_curl_response(Curl::Easy.http_put(url.to_s, body) do |curl|
75
- curl.headers['Accept'] = 'application/json'
76
- curl.headers['Content-Type'] = content_type
77
- end)
72
+ return with_curl { |easy|
73
+ easy.url = url.to_s
74
+ easy.headers['Accept'] = 'application/json'
75
+ easy.headers['Content-Type'] = content_type
76
+ easy.http_put(body)
77
+ }
78
78
  end
79
79
 
80
80
  def self.delete(url, params, &block)
81
81
  url, params = url_and_params_from_args(url, params, &block)
82
- handle_curl_response(Curl::Easy.http_delete(url_with_params(url, params)))
82
+ return with_curl { |easy|
83
+ easy.url = url_with_params(url, params)
84
+ easy.http_delete
85
+ }
83
86
  end
84
87
 
85
88
  private
@@ -96,22 +99,25 @@ module Pebblebed
96
99
  return content_type, body
97
100
  end
98
101
 
99
- def self.handle_http_errors(result)
100
- if result.status == 404
101
- errmsg = "Resource not found: '#{result.url}'"
102
- errmsg << extract_error_summary(result.body)
102
+ def self.handle_http_errors(response)
103
+ if response.status == 404
104
+ errmsg = "Resource not found: '#{response.url}'"
105
+ errmsg << extract_error_summary(response.body)
103
106
  # ActiveSupport::SafeBuffer.new is the same as errmsg.html_safe in rails
104
- raise HttpNotFoundError.new(ActiveSupport::SafeBuffer.new(errmsg), result.status)
105
- elsif result.status >= 400
106
- errmsg = "Service request to '#{result.url}' failed (#{result.status}):"
107
- errmsg << extract_error_summary(result.body)
108
- raise HttpError.new(ActiveSupport::SafeBuffer.new(errmsg), result.status, result)
107
+ raise HttpNotFoundError.new(ActiveSupport::SafeBuffer.new(errmsg), response.status)
108
+ elsif response.status >= 400
109
+ errmsg = "Service request to '#{response.url}' failed (#{response.status}):"
110
+ errmsg << extract_error_summary(response.body)
111
+ raise HttpError.new(ActiveSupport::SafeBuffer.new(errmsg), response.status, response)
109
112
  end
110
- result
113
+ response
111
114
  end
112
115
 
113
- def self.handle_curl_response(curl_response)
114
- handle_http_errors(CurlResult.new(curl_response))
116
+ def self.with_curl(&block)
117
+ easy = Thread.current[:pebblebed_curb_easy] ||= Curl::Easy.new
118
+ easy.reset
119
+ yield easy
120
+ return handle_http_errors(Response.new(easy))
115
121
  end
116
122
 
117
123
  def self.url_with_params(url, params)
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebblebed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katrina Owen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-10 00:00:00.000000000 Z
12
+ date: 2016-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  version: '0'
290
290
  requirements: []
291
291
  rubyforge_project: pebblebed
292
- rubygems_version: 2.4.6
292
+ rubygems_version: 2.2.5
293
293
  signing_key:
294
294
  specification_version: 4
295
295
  summary: Development tools for working with Pebblebed