webspicy 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce670706ba555bb3edf4ba23d469bde15dcd33ee
4
- data.tar.gz: 12711a20555b10b0e20503da6a815c95d85bab6c
3
+ metadata.gz: d4beb76e573d7d42f8a85e65608ad59c83038a63
4
+ data.tar.gz: d1c2cb823fa50d41573b3a9116bc5125ef5fc98c
5
5
  SHA512:
6
- metadata.gz: f7685c29ebfb2f25736bc110823550cfa3de86ebb903f107e45bd8a89cbe6687e15b2e88284cd7f857ed3735c072d0faae4515d0625a4b95a5bd5b9dcb150d2c
7
- data.tar.gz: ee5981c3bf710146258d5d457bc108779fa00f86ba65c19f67f95090b9b7988213b5219122e88f26fd4ecb5be3274ee23d75eea742fe2d9620008343f0656a40
6
+ metadata.gz: 73bf0132edf5214d7c0209202987f87e837765f68ff1916fc60e2924e2e4e620825100bf4347b5393d6b348b1bf475905f23e38ccd0fb9a3f79894adf08ed8f2
7
+ data.tar.gz: cd4f8964ccae0a8979a6610dac9aa972f00243f8f421017f536aba75fdba037947d3fca97b8f653a4543554bd8859eae0f2dbef88dbf92ad6ecf6e7d16893f05
@@ -19,19 +19,14 @@ module Webspicy
19
19
  end
20
20
 
21
21
  def url_placeholders
22
- url.scan(/\{([a-zA-Z]+)\}/).map{|x| x.first.to_sym }
22
+ url.scan(/\{([a-zA-Z]+(\.[a-zA-Z]+)*)\}/).map{|x| x.first }
23
23
  end
24
24
 
25
25
  def instantiate_url(params)
26
26
  url, rest = self.url, params.dup
27
27
  url_placeholders.each do |placeholder|
28
- key = [placeholder, placeholder.to_s].find{|x| params.has_key?(x) }
29
- if key
30
- url = url.gsub("{#{placeholder}}", params[key].to_s)
31
- rest.delete(placeholder)
32
- else
33
- raise "Missing URL parameter `#{placeholder}`\n\t(#{params.inspect})"
34
- end
28
+ value, rest = extract_placeholder_value(params, placeholder)
29
+ url = url.gsub("{#{placeholder}}", value.to_s)
35
30
  end
36
31
  [ url, rest ]
37
32
  end
@@ -42,6 +37,20 @@ module Webspicy
42
37
 
43
38
  private
44
39
 
40
+ def extract_placeholder_value(params, placeholder, split = nil)
41
+ return extract_placeholder_value(params, placeholder, placeholder.split(".")) unless split
42
+
43
+ key = [ split.first, split.first.to_sym ].find{|k| params.has_key?(k) }
44
+ raise "Missing URL parameter `#{placeholder}`" unless key
45
+
46
+ if split.size == 1
47
+ [ params[key], params.dup.delete_if{|k| k == key } ]
48
+ else
49
+ value, rest = extract_placeholder_value(params[key], placeholder, split[1..-1])
50
+ [ value, params.merge(key => rest) ]
51
+ end
52
+ end
53
+
45
54
  def bind_services
46
55
  (@raw[:services] ||= []).each do |s|
47
56
  s.resource = self
@@ -2,7 +2,7 @@ module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 8
5
- TINY = 3
5
+ TINY = 4
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -16,5 +16,12 @@ module Webspicy
16
16
  expect(params).to eq(baz: "coz")
17
17
  end
18
18
 
19
+ it 'supports placeholders corresponding to subentities' do
20
+ r = Resource.new(url: "/test/{foo.id}/url")
21
+ url, params = r.instantiate_url(foo: {id: "bar"}, baz: "coz")
22
+ expect(url).to eq("/test/bar/url")
23
+ expect(params).to eq(foo: {}, baz: "coz")
24
+ end
25
+
19
26
  end
20
27
  end
@@ -9,7 +9,12 @@ module Webspicy
9
9
 
10
10
  it 'returns all placeholders' do
11
11
  r = Resource.new(url: "/test/{foo}/url/{bar}")
12
- expect(r.url_placeholders).to eq([:foo, :bar])
12
+ expect(r.url_placeholders).to eq(["foo", "bar"])
13
+ end
14
+
15
+ it 'returns all placeholders expr' do
16
+ r = Resource.new(url: "/test/{foo.id}/url/{bar}")
17
+ expect(r.url_placeholders).to eq(["foo.id", "bar"])
13
18
  end
14
19
 
15
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  requirements: []
197
197
  rubyforge_project:
198
- rubygems_version: 2.6.11
198
+ rubygems_version: 2.5.2
199
199
  signing_key:
200
200
  specification_version: 4
201
201
  summary: Webspicy helps testing web services as software operation black boxes!