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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8784fb8e4727801f77797c4e4ebabf9fe826f079
4
- data.tar.gz: dc9aa50680a5bc469f12c00bc03a86faddfef1b6
3
+ metadata.gz: ca19fc3b658bd738c01325701134017ced13e62c
4
+ data.tar.gz: 8085032158fb6309eb198105fae4d8610b5b9f07
5
5
  SHA512:
6
- metadata.gz: 5eedfa6faf94e6514bdf7f2111d8c232f0b7ca75c4afc58fb70246bd77191fb6ce025d3e585ba73ec9f350a42da132ad753b72631b7fc9c3ddf6520a7c59131f
7
- data.tar.gz: 00adad312a2ad7716ee5fe8da03c3ef17c6f355e1898235f98121019d6524e45503af5e6e0724f267ca1ec6433cd49283dd6050815daa1802a670d9656a2ab8c
6
+ metadata.gz: 4f0242e051f363d0c4547d821b0774fccd073eb1856651881bd136e428d279c326a7aa0568341e8cbaee0ffde3d2761abcbe9192839636f15b268798999775a4
7
+ data.tar.gz: 76a065116c5c79a40b6468330ec4195b0513eb7beb31f2f9a87a8af9b4d10e5210f43bb973a3ced442127470b31f9aa004682fc75dd9ef70c64f54d4ba251dac
@@ -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
- path = path_for(action, id: params[:id])
18
- scoped_params = scope_params(params.except(:id))
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, scoped_params)
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 path_for(action, options = nil)
52
- path = _defined_actions.try(:[], action).try(:[], :path)
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
- raise(UndefinedAction, action) unless path
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.gsub(":route_key", route_key)
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)
@@ -1,3 +1,3 @@
1
1
  module Signaling
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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.0.0
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-01-18 00:00:00.000000000 Z
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.0.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