signaling 1.1.1 → 1.1.2
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/README.md +8 -0
- data/lib/signaling/base/http.rb +1 -12
- data/lib/signaling/base/persistence.rb +14 -3
- data/lib/signaling/version.rb +1 -1
- data/spec/integration/readme_features/query_parameters_spec.rb +21 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aa420bd52662a47fe9b029fde67c52523d8b6f3
|
4
|
+
data.tar.gz: d07a6b76e61582ab251e792dcde5e6c96fef948e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 449ea04532a91de15a945a5fbc280eb4743de3160d304942cbae9872f2f51beeee05585bf24a98fec7a245589b81724923cf2aac929a3580c923c3b96f33a9b2
|
7
|
+
data.tar.gz: a7f512c76f4ac4489b746a8e664096b0df0ae10f1101e3f41538dc5f38c127d0a5d1012ca69e12fc41bf081cfb8202c3eed1addf1c51b3e8983bb877323c1b38
|
data/README.md
CHANGED
@@ -170,6 +170,14 @@ Then you can use:
|
|
170
170
|
# GET /accounts/123/item_lists.json
|
171
171
|
|
172
172
|
|
173
|
+
### Query parameters
|
174
|
+
|
175
|
+
signaling allows sending parameters to remote service:
|
176
|
+
|
177
|
+
> ItemList.all(account_id: '123')
|
178
|
+
# GET /item_lists.json?account_id=123
|
179
|
+
|
180
|
+
|
173
181
|
## Contributing
|
174
182
|
|
175
183
|
1. Fork it
|
data/lib/signaling/base/http.rb
CHANGED
@@ -20,9 +20,8 @@ module Signaling::Base::Http
|
|
20
20
|
http_method = http_method_for(action)
|
21
21
|
path_params, body_params = split_params(action, params)
|
22
22
|
path = path_for(action, path_params)
|
23
|
-
body = scope_params(body_params)
|
24
23
|
|
25
|
-
response = connection.send(http_method, path,
|
24
|
+
response = connection.send(http_method, path, body_params)
|
26
25
|
|
27
26
|
block ? block.call(response.body) : response.body
|
28
27
|
end
|
@@ -89,20 +88,10 @@ module Signaling::Base::Http
|
|
89
88
|
method || raise(UndefinedAction, action)
|
90
89
|
end
|
91
90
|
|
92
|
-
def scope_params(params)
|
93
|
-
key = params.is_a?(Array) ? param_key.pluralize : param_key
|
94
|
-
|
95
|
-
{ key => to_params(params, true) }
|
96
|
-
end
|
97
|
-
|
98
91
|
def route_key
|
99
92
|
ActiveModel::Naming.route_key(self).pluralize
|
100
93
|
end
|
101
94
|
|
102
|
-
def param_key
|
103
|
-
ActiveModel::Naming.param_key(self)
|
104
|
-
end
|
105
|
-
|
106
95
|
# changes attribtue names to param names (defined by ":param_name")
|
107
96
|
def set_param_names(params)
|
108
97
|
HashWithIndifferentAccess.new.tap do |result|
|
@@ -3,7 +3,7 @@ module Signaling::Base::Persistence
|
|
3
3
|
|
4
4
|
module ClassMethods
|
5
5
|
def create(params)
|
6
|
-
from_response(request(:create, params))
|
6
|
+
from_response(request(:create, scope_params(params)))
|
7
7
|
rescue Signaling::Error::UnprocessableEntity => e
|
8
8
|
from_response(e.response[:body])
|
9
9
|
end
|
@@ -12,6 +12,15 @@ module Signaling::Base::Persistence
|
|
12
12
|
from_response(request(:destroy, id: id))
|
13
13
|
end
|
14
14
|
|
15
|
+
def scope_params(params)
|
16
|
+
key = params.is_a?(Array) ? param_key.pluralize : param_key
|
17
|
+
|
18
|
+
{ key => to_params(params, true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def param_key
|
22
|
+
ActiveModel::Naming.param_key(self)
|
23
|
+
end
|
15
24
|
end
|
16
25
|
|
17
26
|
def new?
|
@@ -45,13 +54,15 @@ module Signaling::Base::Persistence
|
|
45
54
|
private
|
46
55
|
|
47
56
|
def update(params = attributes)
|
48
|
-
self.class.
|
57
|
+
params = self.class.scope_params(params).merge(id: self.id)
|
58
|
+
self.class.request(:update, params) do |response|
|
49
59
|
self.attributes = response
|
50
60
|
end
|
51
61
|
end
|
52
62
|
|
53
63
|
def create
|
54
|
-
self.class.
|
64
|
+
params = self.class.scope_params(attributes.except(:id))
|
65
|
+
self.class.request(:create, params) do |response|
|
55
66
|
self.attributes = response
|
56
67
|
end
|
57
68
|
end
|
data/lib/signaling/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "README features" do
|
4
|
+
describe "Query parameters" do
|
5
|
+
before do
|
6
|
+
stub_request(:get, expected_item_lists_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
specify "are sent to remote service" do
|
10
|
+
ExampleCom::ItemList.all(account_id: '123')
|
11
|
+
expect_request(:get, path: expected_item_lists_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def expected_item_lists_path
|
15
|
+
example_com_build_url('item_lists.json?account_id=123')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: signaling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neer Friedman
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- spec/integration/readme_features/custom_action_path_spec.rb
|
211
211
|
- spec/integration/readme_features/errors_spec.rb
|
212
212
|
- spec/integration/readme_features/nested_models_spec.rb
|
213
|
+
- spec/integration/readme_features/query_parameters_spec.rb
|
213
214
|
- spec/spec_helper.rb
|
214
215
|
- spec/support/example_com.rb
|
215
216
|
- spec/support/example_com/item.rb
|
@@ -248,6 +249,7 @@ test_files:
|
|
248
249
|
- spec/integration/readme_features/custom_action_path_spec.rb
|
249
250
|
- spec/integration/readme_features/errors_spec.rb
|
250
251
|
- spec/integration/readme_features/nested_models_spec.rb
|
252
|
+
- spec/integration/readme_features/query_parameters_spec.rb
|
251
253
|
- spec/spec_helper.rb
|
252
254
|
- spec/support/example_com.rb
|
253
255
|
- spec/support/example_com/item.rb
|