compose_url 0.1.0 → 0.1.1
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/compose_url.rb +12 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6729d272071f8a515e6077829668636e2617c41f
|
4
|
+
data.tar.gz: c8e776fd305bd085e922de1c09a503c035e73f80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd1bbc682fd5373258f0e7edae303594577bbe7a06797474defba7ee9238709508c4de1d3afe6e9115c27cc0000801bd9ddaf3a95a9d76e700416d1916df1eb1
|
7
|
+
data.tar.gz: 4e0cf2696d342c325c570dd411dcb095eb1cc24b1950534b8e539c7352f91dae80184002f82e1baa76fa267227664e3c798ffb524901d832361c1bbb0a0170b4
|
data/lib/compose_url.rb
CHANGED
@@ -4,9 +4,9 @@ require 'uri'
|
|
4
4
|
class ComposeURL
|
5
5
|
attr_accessor :params
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@url =
|
9
|
-
@params = params
|
7
|
+
def initialize(base_url, params={})
|
8
|
+
@url = init_url(base_url)
|
9
|
+
@params = init_params(base_url).merge(params)
|
10
10
|
end
|
11
11
|
|
12
12
|
def add_param(k, v)
|
@@ -27,15 +27,16 @@ class ComposeURL
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
raise ComposeURLError.new('Invalid key') unless k == escape(k) # key shouldn't require escaping, or should it?
|
33
|
-
escape(k)
|
30
|
+
def init_url(base_url)
|
31
|
+
base_url[/[^?]+/]
|
34
32
|
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def init_params(base_url)
|
35
|
+
base_url.gsub(init_url(base_url), '').gsub('?', '').split('&').inject({}) {|h, pair|
|
36
|
+
pair = pair.split('=')
|
37
|
+
h[pair[0]] = pair[1]
|
38
|
+
; h
|
39
|
+
}
|
39
40
|
end
|
40
41
|
|
41
42
|
def validate_url(url)
|
@@ -45,7 +46,7 @@ class ComposeURL
|
|
45
46
|
|
46
47
|
def params_string
|
47
48
|
@params.map { |k,v|
|
48
|
-
"#{
|
49
|
+
"#{escape(k)}=#{escape(v)}"
|
49
50
|
}.join('&')
|
50
51
|
end
|
51
52
|
|