signaling 1.0.0 → 1.1.0
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/signaling/base/http.rb +33 -8
- data/lib/signaling/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: ca19fc3b658bd738c01325701134017ced13e62c
|
4
|
+
data.tar.gz: 8085032158fb6309eb198105fae4d8610b5b9f07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f0242e051f363d0c4547d821b0774fccd073eb1856651881bd136e428d279c326a7aa0568341e8cbaee0ffde3d2761abcbe9192839636f15b268798999775a4
|
7
|
+
data.tar.gz: 76a065116c5c79a40b6468330ec4195b0513eb7beb31f2f9a87a8af9b4d10e5210f43bb973a3ced442127470b31f9aa004682fc75dd9ef70c64f54d4ba251dac
|
data/lib/signaling/base/http.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'addressable/template'
|
2
|
+
|
1
3
|
module Signaling::Base::Http
|
2
4
|
extend ActiveSupport::Concern
|
3
5
|
|
@@ -13,11 +15,14 @@ module Signaling::Base::Http
|
|
13
15
|
|
14
16
|
module ClassMethods
|
15
17
|
def request(action, params = {}, &block)
|
18
|
+
params = params.with_indifferent_access
|
19
|
+
|
16
20
|
http_method = http_method_for(action)
|
17
|
-
|
18
|
-
|
21
|
+
path_params, body_params = split_params(action, params)
|
22
|
+
path = path_for(action, path_params)
|
23
|
+
body = scope_params(body_params)
|
19
24
|
|
20
|
-
response = connection.send(http_method, path,
|
25
|
+
response = connection.send(http_method, path, body)
|
21
26
|
|
22
27
|
block ? block.call(response.body) : response.body
|
23
28
|
end
|
@@ -48,13 +53,33 @@ module Signaling::Base::Http
|
|
48
53
|
|
49
54
|
protected
|
50
55
|
|
51
|
-
def
|
52
|
-
|
56
|
+
def defined_action(action)
|
57
|
+
_defined_actions.try(:[], action) or raise(UndefinedAction, action)
|
58
|
+
end
|
59
|
+
|
60
|
+
def split_params(action, params)
|
61
|
+
path = defined_action(action)[:path]
|
62
|
+
|
63
|
+
path_params = params.slice(*path_parameters(path))
|
64
|
+
body_params = params.except(*path_parameters(path))
|
65
|
+
|
66
|
+
return path_params, body_params
|
67
|
+
end
|
68
|
+
|
69
|
+
def path_parameters(path)
|
70
|
+
path.scan(/:([^\/.]*)/).flatten
|
71
|
+
end
|
53
72
|
|
54
|
-
|
73
|
+
def path_for(action, parameters = {})
|
74
|
+
path = defined_action(action)[:path]
|
75
|
+
|
76
|
+
parameters = parameters.merge(route_key: route_key)
|
77
|
+
|
78
|
+
path_parameters(path).each do |parameter|
|
79
|
+
path = path.gsub(":#{parameter}", parameters[parameter].to_s)
|
80
|
+
end
|
55
81
|
|
56
|
-
path
|
57
|
-
.gsub(":id") { options[:id] || raise('missing :id parameter for route') }
|
82
|
+
path
|
58
83
|
end
|
59
84
|
|
60
85
|
def http_method_for(action)
|
data/lib/signaling/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: signaling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neer Friedman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -236,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
236
|
version: '0'
|
237
237
|
requirements: []
|
238
238
|
rubyforge_project:
|
239
|
-
rubygems_version: 2.
|
239
|
+
rubygems_version: 2.2.1
|
240
240
|
signing_key:
|
241
241
|
specification_version: 4
|
242
242
|
summary: Signaling maps REST-like APIs to ruby objects
|