nestful 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nestful/helpers.rb +8 -0
- data/lib/nestful/resource.rb +13 -5
- data/lib/nestful/version.rb +1 -1
- data/test/nestful/test_resource.rb +13 -0
- metadata +4 -4
data/lib/nestful/helpers.rb
CHANGED
@@ -10,6 +10,14 @@ module Nestful
|
|
10
10
|
value.to_s.split('_').map {|w| w.capitalize }.join
|
11
11
|
end
|
12
12
|
|
13
|
+
def deep_merge(hash, other_hash)
|
14
|
+
hash.merge(other_hash) do |key, oldval, newval|
|
15
|
+
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
|
16
|
+
newval = newval.to_hash if newval.respond_to?(:to_hash)
|
17
|
+
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? deep_merge(oldval, newval) : newval
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
# Stolen from Rack:
|
14
22
|
|
15
23
|
DEFAULT_SEP = /[&;] */n
|
data/lib/nestful/resource.rb
CHANGED
@@ -14,10 +14,18 @@ module Nestful
|
|
14
14
|
superclass.respond_to?(:path) ? superclass.path : nil
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.
|
18
|
-
@
|
19
|
-
return @
|
20
|
-
superclass.respond_to?(:
|
17
|
+
def self.defaults(value = nil)
|
18
|
+
@defaults = value if value
|
19
|
+
return @defaults if @defaults
|
20
|
+
superclass.respond_to?(:defaults) ? superclass.defaults : {}
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
alias_method :endpoint=, :endpoint
|
25
|
+
alias_method :path=, :path
|
26
|
+
alias_method :defaults=, :defaults
|
27
|
+
alias_method :options, :defaults
|
28
|
+
alias_method :options=, :defaults
|
21
29
|
end
|
22
30
|
|
23
31
|
def self.url
|
@@ -45,7 +53,7 @@ module Nestful
|
|
45
53
|
end
|
46
54
|
|
47
55
|
def self.request(url, options = {})
|
48
|
-
Request.new(url, self.options
|
56
|
+
Request.new(url, Helpers.deep_merge(self.options, options)).execute
|
49
57
|
end
|
50
58
|
|
51
59
|
def self.all(*args)
|
data/lib/nestful/version.rb
CHANGED
@@ -10,6 +10,12 @@ class TestResource < MiniTest::Unit::TestCase
|
|
10
10
|
path '/v1/charges'
|
11
11
|
end
|
12
12
|
|
13
|
+
class Token < Nestful::Resource
|
14
|
+
endpoint 'http://example.com'
|
15
|
+
path '/v1/tokens'
|
16
|
+
defaults :params => {:one => 1}
|
17
|
+
end
|
18
|
+
|
13
19
|
def setup
|
14
20
|
end
|
15
21
|
|
@@ -42,4 +48,11 @@ class TestResource < MiniTest::Unit::TestCase
|
|
42
48
|
charge.put(:capture)
|
43
49
|
assert_requested(:put, 'http://example.com/v1/charges/1/capture')
|
44
50
|
end
|
51
|
+
|
52
|
+
def test_defaults
|
53
|
+
stub_request(:any, 'http://example.com/v1/tokens/1/capture?one=1')
|
54
|
+
charge = Token.new({:id => 1})
|
55
|
+
charge.get(:capture)
|
56
|
+
assert_requested(:get, 'http://example.com/v1/tokens/1/capture?one=1')
|
57
|
+
end
|
45
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nestful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -58,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
segments:
|
60
60
|
- 0
|
61
|
-
hash: -
|
61
|
+
hash: -3312569918476156670
|
62
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
version: '0'
|
68
68
|
segments:
|
69
69
|
- 0
|
70
|
-
hash: -
|
70
|
+
hash: -3312569918476156670
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
73
|
rubygems_version: 1.8.24
|