pebblebed 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pebblebed/http.rb +41 -35
- data/lib/pebblebed/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb66474bc41c0a30280586d8d8fe9b1482b0afc3
|
4
|
+
data.tar.gz: e01c0d2eb6bce7d2664be227cbd0ff498b790969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0d1a7b303ef9932e666b6faa5f03555aa428ba82d2f77ea654a41ae4650631ff67519587a3c7193598dab87740160913e9086a0a6bd2d6cd54e9f2ef96c5f17
|
7
|
+
data.tar.gz: e40ac5cf384fe6ad9c33713a112c8abb8f930c41a4b810533445bd367277f88bac8619d63c8b20251c4db9d546723f5639f80e41da3cced6c2408260b14f71ad
|
data/lib/pebblebed/http.rb
CHANGED
@@ -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
|
-
|
49
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
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(
|
100
|
-
if
|
101
|
-
errmsg = "Resource not found: '#{
|
102
|
-
errmsg << extract_error_summary(
|
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),
|
105
|
-
elsif
|
106
|
-
errmsg = "Service request to '#{
|
107
|
-
errmsg << extract_error_summary(
|
108
|
-
raise HttpError.new(ActiveSupport::SafeBuffer.new(errmsg),
|
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
|
-
|
113
|
+
response
|
111
114
|
end
|
112
115
|
|
113
|
-
def self.
|
114
|
-
|
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)
|
data/lib/pebblebed/version.rb
CHANGED
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
|
+
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:
|
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.
|
292
|
+
rubygems_version: 2.2.5
|
293
293
|
signing_key:
|
294
294
|
specification_version: 4
|
295
295
|
summary: Development tools for working with Pebblebed
|