pebblebed 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pebblebed/clients/generic_client.rb +9 -1
- data/lib/pebblebed/http.rb +55 -6
- data/lib/pebblebed/version.rb +1 -1
- data/spec/generic_client_spec.rb +23 -0
- data/spec/http_spec.rb +15 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec6e1847afca02058150931728920d66a0488b41
|
4
|
+
data.tar.gz: fe9d7005b7ae347ab80d16473b2787ce46b4188f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a877ec1296f7df0a29b5ae43c2eb99cd99f39f4dbbe8fce3eda0ce397eae5225294bfe53a8df0f6892194febfabb857811bc75f2f0214606c9dab615d8c8e74
|
7
|
+
data.tar.gz: bf10e50a98159afda438c7e6e746dce69e634d5283fbdea2514e7e96434bfde424cd3ee01d3f45aeb1763e3242cda4508702cc6fce72559581cb21a89cded3ce
|
@@ -3,7 +3,7 @@ require 'deepstruct'
|
|
3
3
|
module Pebblebed
|
4
4
|
class GenericClient < AbstractClient
|
5
5
|
def initialize(session_key, root_url)
|
6
|
-
@root_url = root_url
|
6
|
+
@root_url = root_url
|
7
7
|
@root_url = URI(@root_url) unless @root_url.is_a?(URI::HTTP)
|
8
8
|
@session_key = session_key
|
9
9
|
end
|
@@ -22,6 +22,14 @@ module Pebblebed
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def stream(method, url = '', params = {}, options = {})
|
26
|
+
on_data = options[:on_data] or raise "Option :on_data must be specified"
|
27
|
+
method_name = "stream_#{method.to_s.downcase}"
|
28
|
+
raise "Method not supported for streaming" unless Pebblebed::Http.respond_to?(method_name)
|
29
|
+
return Pebblebed::Http.send(method_name, service_url(url), service_params(params),
|
30
|
+
on_data: on_data)
|
31
|
+
end
|
32
|
+
|
25
33
|
def service_url(url, params = nil)
|
26
34
|
result = @root_url.dup
|
27
35
|
result.path = result.path.sub(/\/+$/, "") + url
|
data/lib/pebblebed/http.rb
CHANGED
@@ -50,7 +50,7 @@ module Pebblebed
|
|
50
50
|
|
51
51
|
def self.get(url = nil, params = nil, &block)
|
52
52
|
url, params = url_and_params_from_args(url, params, &block)
|
53
|
-
return
|
53
|
+
return do_easy { |easy|
|
54
54
|
easy.url = url_with_params(url, params)
|
55
55
|
easy.http_get
|
56
56
|
}
|
@@ -59,7 +59,7 @@ module Pebblebed
|
|
59
59
|
def self.post(url, params, &block)
|
60
60
|
url, params = url_and_params_from_args(url, params, &block)
|
61
61
|
content_type, body = serialize_params(params)
|
62
|
-
return
|
62
|
+
return do_easy { |easy|
|
63
63
|
easy.url = url.to_s
|
64
64
|
easy.headers['Accept'] = 'application/json'
|
65
65
|
easy.headers['Content-Type'] = content_type
|
@@ -70,7 +70,7 @@ module Pebblebed
|
|
70
70
|
def self.put(url, params, &block)
|
71
71
|
url, params = url_and_params_from_args(url, params, &block)
|
72
72
|
content_type, body = serialize_params(params)
|
73
|
-
return
|
73
|
+
return do_easy { |easy|
|
74
74
|
easy.url = url.to_s
|
75
75
|
easy.headers['Accept'] = 'application/json'
|
76
76
|
easy.headers['Content-Type'] = content_type
|
@@ -80,12 +80,55 @@ module Pebblebed
|
|
80
80
|
|
81
81
|
def self.delete(url, params, &block)
|
82
82
|
url, params = url_and_params_from_args(url, params, &block)
|
83
|
-
return
|
83
|
+
return do_easy { |easy|
|
84
84
|
easy.url = url_with_params(url, params)
|
85
85
|
easy.http_delete
|
86
86
|
}
|
87
87
|
end
|
88
88
|
|
89
|
+
def self.stream_get(url = nil, params = nil, options = {})
|
90
|
+
return do_easy { |easy|
|
91
|
+
on_data = options[:on_data] or raise "Option :on_data must be specified"
|
92
|
+
|
93
|
+
url, params = url_and_params_from_args(url, params)
|
94
|
+
|
95
|
+
easy.url = url_with_params(url, params)
|
96
|
+
easy.on_body do |data|
|
97
|
+
on_data.call(data)
|
98
|
+
data.length
|
99
|
+
end
|
100
|
+
easy.http_get
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.stream_post(url, params, options = {})
|
105
|
+
return do_easy { |easy|
|
106
|
+
on_data = options[:on_data] or raise "Option :on_data must be specified"
|
107
|
+
|
108
|
+
url, params = url_and_params_from_args(url, params)
|
109
|
+
content_type, body = serialize_params(params)
|
110
|
+
|
111
|
+
easy.url = url.to_s
|
112
|
+
easy.headers['Accept'] = 'application/json'
|
113
|
+
easy.headers['Content-Type'] = content_type
|
114
|
+
easy.http_post(body)
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.stream_put(url, params, options = {})
|
119
|
+
return do_easy { |easy|
|
120
|
+
on_data = options[:on_data] or raise "Option :on_data must be specified"
|
121
|
+
|
122
|
+
url, params = url_and_params_from_args(url, params)
|
123
|
+
content_type, body = serialize_params(params)
|
124
|
+
|
125
|
+
easy.url = url.to_s
|
126
|
+
easy.headers['Accept'] = 'application/json'
|
127
|
+
easy.headers['Content-Type'] = content_type
|
128
|
+
easy.http_put(body)
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
89
132
|
private
|
90
133
|
|
91
134
|
def self.serialize_params(params)
|
@@ -114,11 +157,17 @@ module Pebblebed
|
|
114
157
|
response
|
115
158
|
end
|
116
159
|
|
117
|
-
def self.
|
160
|
+
def self.do_easy(&block)
|
161
|
+
with_easy do |easy|
|
162
|
+
yield easy
|
163
|
+
return handle_http_errors(Response.new(easy))
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.with_easy(&block)
|
118
168
|
easy = Thread.current[:pebblebed_curb_easy] ||= Curl::Easy.new
|
119
169
|
easy.reset
|
120
170
|
yield easy
|
121
|
-
return handle_http_errors(Response.new(easy))
|
122
171
|
end
|
123
172
|
|
124
173
|
def self.url_with_params(url, params)
|
data/lib/pebblebed/version.rb
CHANGED
data/spec/generic_client_spec.rb
CHANGED
@@ -49,4 +49,27 @@ describe Pebblebed::GenericClient do
|
|
49
49
|
expect(result).to eq "Ok"
|
50
50
|
end
|
51
51
|
|
52
|
+
describe 'streaming' do
|
53
|
+
context 'GET' do
|
54
|
+
it "streams response body" do
|
55
|
+
curl_result = DeepStruct.wrap({status: 200, body: nil})
|
56
|
+
allow(Pebblebed::Http).to receive(:stream_get).with(
|
57
|
+
URI.parse("http://example.org/"),
|
58
|
+
{"session" => "session_key"},
|
59
|
+
anything) { |_, _, options|
|
60
|
+
options[:on_data].call("hello")
|
61
|
+
}.and_return(curl_result)
|
62
|
+
|
63
|
+
buf = ""
|
64
|
+
client = Pebblebed::GenericClient.new("session_key", "http://example.org/")
|
65
|
+
result = client.stream(:get, '/', {}, on_data: ->(data) {
|
66
|
+
buf << data
|
67
|
+
})
|
68
|
+
expect(buf).to eq "hello"
|
69
|
+
expect(result.status).to eq 200
|
70
|
+
expect(result.body).to eq nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
52
75
|
end
|
data/spec/http_spec.rb
CHANGED
@@ -87,4 +87,19 @@ describe Pebblebed::Http do
|
|
87
87
|
expect(result["QUERY_STRING"]).to eq "hello=world"
|
88
88
|
end
|
89
89
|
|
90
|
+
describe 'streaming' do
|
91
|
+
context 'GET' do
|
92
|
+
it "streams response body" do
|
93
|
+
buf = ""
|
94
|
+
response = Pebblebed::Http.stream_get(pebble_url, {hello: 'world'},
|
95
|
+
on_data: ->(data) {
|
96
|
+
buf << data
|
97
|
+
})
|
98
|
+
result = JSON.parse(buf)
|
99
|
+
expect(result["QUERY_STRING"]).to eq "hello=world"
|
100
|
+
expect(response.body).to eq nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
90
105
|
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
|
+
version: 0.3.16
|
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: 2017-06
|
12
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -303,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
303
|
version: '0'
|
304
304
|
requirements: []
|
305
305
|
rubyforge_project: pebblebed
|
306
|
-
rubygems_version: 2.5.2
|
306
|
+
rubygems_version: 2.4.5.2
|
307
307
|
signing_key:
|
308
308
|
specification_version: 4
|
309
309
|
summary: Development tools for working with Pebblebed
|
@@ -323,3 +323,4 @@ test_files:
|
|
323
323
|
- spec/sinatra_spec.rb
|
324
324
|
- spec/spec_helper.rb
|
325
325
|
- spec/uid_spec.rb
|
326
|
+
has_rdoc:
|