pebblebed 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a72b667ab7760684fba215b9c8b1efcae9c1294
4
- data.tar.gz: 2a0663c6a8a01c4996c5e4726d39efbeca6cb97e
3
+ metadata.gz: 6499b7c6db946a08a8965eb636dd2664c77766d4
4
+ data.tar.gz: a2bef073f3582e8abeb730c9f51fdd043f537c3a
5
5
  SHA512:
6
- metadata.gz: 22492117f67d35017f0458d5d6b829378f8ae9583b4fcd1d7d6a36d88ddce51e8ea2f886c3b3060072c4834629ca8ef7a722c462dcd82aff232d77e0bcb0f495
7
- data.tar.gz: ac85b869fe8d67e0f364ddf3054bb72bf107740c9fa45daf9a3c0174b0ed247a64af2835f8dad39a40c73e60511bd667f1ba00e6c920a371ff8c541b697bfe4d
6
+ metadata.gz: cf8b594a75a82357e9875d982853653bdaee5781efee3dba623d08b28cb068c9411c38068bf8eda8cd7420fd2a106f0103c04e2875432ad1ac0c91580896ccb2
7
+ data.tar.gz: d83e1d1ef0ab9b42bbde60dc0a49843c759d853a35dbca27c906273f114b1843aa1af893d0ad5f9610df69918a4cc105b23c7dc421cf4015f77bb3e4f3e7a5e2
@@ -9,6 +9,7 @@ require 'pathbuilder'
9
9
  require 'active_support'
10
10
  require 'timeout'
11
11
  require 'resolv'
12
+ require 'addressable/uri'
12
13
 
13
14
  module Pebblebed
14
15
 
@@ -78,19 +79,19 @@ module Pebblebed
78
79
  end
79
80
 
80
81
  def self.get(url = nil, params = nil, &block)
81
- url, params = url_and_params_from_args(url, params, &block)
82
+ url, params, query = url_and_params_from_args(url, params, &block)
82
83
  return do_request(url) { |connection|
83
84
  connection.get(
84
85
  :host => url.host,
85
86
  :path => url.path,
86
- :query => params,
87
+ :query => QueryParams.encode((params || {}).merge(query)),
87
88
  :persistent => true
88
89
  )
89
90
  }
90
91
  end
91
92
 
92
93
  def self.post(url, params, &block)
93
- url, params = url_and_params_from_args(url, params, &block)
94
+ url, params, query = url_and_params_from_args(url, params, &block)
94
95
  content_type, body = serialize_params(params)
95
96
  return do_request(url, idempotent: false) { |connection|
96
97
  connection.post(
@@ -101,13 +102,14 @@ module Pebblebed
101
102
  'Content-Type' => content_type
102
103
  },
103
104
  :body => body,
105
+ :query => query,
104
106
  :persistent => true
105
107
  )
106
108
  }
107
109
  end
108
110
 
109
111
  def self.put(url, params, &block)
110
- url, params = url_and_params_from_args(url, params, &block)
112
+ url, params, query = url_and_params_from_args(url, params, &block)
111
113
  content_type, body = serialize_params(params)
112
114
  return do_request(url) { |connection|
113
115
  connection.put(
@@ -118,18 +120,19 @@ module Pebblebed
118
120
  'Content-Type' => content_type
119
121
  },
120
122
  :body => body,
123
+ :query => query,
121
124
  :persistent => true
122
125
  )
123
126
  }
124
127
  end
125
128
 
126
129
  def self.delete(url, params, &block)
127
- url, params = url_and_params_from_args(url, params, &block)
130
+ url, params, query = url_and_params_from_args(url, params, &block)
128
131
  return do_request(url) { |connection|
129
132
  connection.delete(
130
133
  :host => url.host,
131
134
  :path => url.path,
132
- :query => params,
135
+ :query => query,
133
136
  :persistent => true
134
137
  )
135
138
  }
@@ -145,12 +148,12 @@ module Pebblebed
145
148
  def self.stream_get(url = nil, params = nil, options = {})
146
149
  on_data = options[:on_data] or raise "Option :on_data must be specified"
147
150
 
148
- url, params = url_and_params_from_args(url, params)
151
+ url, params, query = url_and_params_from_args(url, params)
149
152
  return do_request(url) { |connection|
150
153
  connection.get(
151
154
  :host => url.host,
152
155
  :path => url.path,
153
- :query => params,
156
+ :query => QueryParams.encode((params || {}).merge(query)),
154
157
  :persistent => false,
155
158
  :response_block => streamer(on_data)
156
159
  )
@@ -160,7 +163,7 @@ module Pebblebed
160
163
  def self.stream_post(url, params, options = {})
161
164
  on_data = options[:on_data] or raise "Option :on_data must be specified"
162
165
 
163
- url, params = url_and_params_from_args(url, params)
166
+ url, params, query = url_and_params_from_args(url, params)
164
167
  content_type, body = serialize_params(params)
165
168
 
166
169
  return do_request(url) { |connection|
@@ -173,6 +176,7 @@ module Pebblebed
173
176
  },
174
177
  :body => body,
175
178
  :persistent => false,
179
+ :query => query,
176
180
  :response_block => streamer(on_data)
177
181
  )
178
182
  }
@@ -181,7 +185,7 @@ module Pebblebed
181
185
  def self.stream_put(url, params, options = {})
182
186
  on_data = options[:on_data] or raise "Option :on_data must be specified"
183
187
 
184
- url, params = url_and_params_from_args(url, params)
188
+ url, params, query = url_and_params_from_args(url, params)
185
189
  content_type, body = serialize_params(params)
186
190
 
187
191
  return do_request(url) { |connection|
@@ -193,6 +197,7 @@ module Pebblebed
193
197
  'Content-Type' => content_type
194
198
  },
195
199
  :body => body,
200
+ :query => query,
196
201
  :persistent => false,
197
202
  :response_block => streamer(on_data)
198
203
  )
@@ -315,7 +320,8 @@ module Pebblebed
315
320
  url.path = url.path.chomp("/")+pathbuilder.path
316
321
  (params ||= {}).merge!(pathbuilder.params)
317
322
  end
318
- [url, params]
323
+ query = Addressable::URI.parse(url.to_s).query_values
324
+ [url, params, query]
319
325
  end
320
326
 
321
327
  def self.extract_error_summary(body)
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/spec/http_spec.rb CHANGED
@@ -17,7 +17,7 @@ describe Pebblebed::Http do
17
17
  end
18
18
 
19
19
  let :pebble_url do
20
- "http://localhost:8666/api/mock/v1/echo"
20
+ "http://localhost:8666/api/mock/v1/echo?foo=bar"
21
21
  end
22
22
 
23
23
  before :all do
@@ -86,9 +86,17 @@ describe Pebblebed::Http do
86
86
  end
87
87
 
88
88
  it "encodes gets as url params" do
89
- response = Pebblebed::Http.get(pebble_url, {hello: 'world'})
89
+ params = {
90
+ 'min' => {
91
+ 'hits' => '1'
92
+ },
93
+ 'limit' => '2'
94
+ }
95
+ params['fields'] = {'document.category' => 'test'}
96
+ params['max'] = {'hits' => '3'}
97
+ response = Pebblebed::Http.get(pebble_url, params)
90
98
  result = JSON.parse(response.body)
91
- expect(result["QUERY_STRING"]).to eq "hello=world"
99
+ expect(result["QUERY_STRING"]).to eq "min[hits]=1&limit=2&fields[document.category]=test&max[hits]=3&foo=bar"
92
100
  end
93
101
 
94
102
  describe 'streaming' do
@@ -100,7 +108,7 @@ describe Pebblebed::Http do
100
108
  buf << data
101
109
  })
102
110
  result = JSON.parse(buf)
103
- expect(result["QUERY_STRING"]).to eq "hello=world"
111
+ expect(result["QUERY_STRING"]).to eq "hello=world&foo=bar"
104
112
  expect(response.body).to eq ''
105
113
  end
106
114
 
@@ -112,7 +120,7 @@ describe Pebblebed::Http do
112
120
  buf << data
113
121
  })
114
122
  result = JSON.parse(buf)
115
- expect(result["QUERY_STRING"]).to eq "hello=world"
123
+ expect(result["QUERY_STRING"]).to eq "hello=world&foo=bar"
116
124
  expect(response.body).to eq ''
117
125
  end
118
126
  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.4.0
4
+ version: 0.4.1
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: 2018-03-22 00:00:00.000000000 Z
12
+ date: 2018-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec