uri-query_params 0.6.2 → 0.7.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.
- data/ChangeLog.md +8 -1
- data/README.md +7 -1
- data/Rakefile +0 -10
- data/gemspec.yml +0 -1
- data/lib/uri/query_params/extensions.rb +2 -2
- data/lib/uri/query_params/extensions/addressable/uri.rb +11 -0
- data/lib/uri/query_params/extensions/uri.rb +1 -0
- data/lib/uri/query_params/extensions/uri/generic.rb +39 -0
- data/lib/uri/query_params/mixin.rb +53 -58
- data/lib/uri/query_params/version.rb +1 -1
- data/spec/extensions/addressable/uri_spec.rb +9 -0
- data/spec/extensions/uri/generic_spec.rb +9 -0
- data/spec/extensions/{http_spec.rb → uri/http_spec.rb} +1 -1
- metadata +15 -23
- data/lib/uri/query_params/extensions/http.rb +0 -11
- data/lib/uri/query_params/extensions/https.rb +0 -3
- data/spec/extensions/https_spec.rb +0 -9
data/ChangeLog.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
### 0.7.0 / 2012-03-27
|
2
|
+
|
3
|
+
* Inject {URI::QueryParams::Mixin} into {URI::Generic}, so all URIs have
|
4
|
+
`query_params`.
|
5
|
+
* Inject {URI::QueryParams::Mixin} into `Addressable::URI`, if `addressable/uri`
|
6
|
+
is loaded.
|
7
|
+
|
1
8
|
### 0.6.2 / 2012-03-15
|
2
9
|
|
3
10
|
* Fixed a query parameter ordering issue in {URI::QueryParams.dump},
|
@@ -26,7 +33,7 @@
|
|
26
33
|
* Contains RFC 3986 unsafe URI characters.
|
27
34
|
* Use {URI::QueryParams::UNSAFE} in {URI::QueryParams.dump} for safer
|
28
35
|
query strings.
|
29
|
-
* Added
|
36
|
+
* Added `URI::QueryParams::Mixin#query`:
|
30
37
|
* If any query-params are set, dump them out using
|
31
38
|
{URI::QueryParams.dump}.
|
32
39
|
* Renamed `parse_query_params` to
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
## Description
|
9
9
|
|
10
10
|
Allows access to the query component of the URI as a Hash. This is similar
|
11
|
-
to `$_GET` from PHP, except available on any
|
11
|
+
to `$_GET` from PHP, except available on any Ruby URI object.
|
12
12
|
|
13
13
|
## Examples
|
14
14
|
|
@@ -29,6 +29,12 @@ Setting the URI query_params:
|
|
29
29
|
url.to_s
|
30
30
|
# => "http://www.google.com/search?btnG=Search&hs=1HY&rls=org.mozilla:en-US:official&client=firefox-a&hl=en&q=Upright%20Citizens%20Brigade"
|
31
31
|
|
32
|
+
Parsing URI query_params embedded within the Fragment Identifier:
|
33
|
+
|
34
|
+
url = URI('https://twitter.com/#!/download?lang=en&logged_out=1')
|
35
|
+
URI(url.fragment).query_params
|
36
|
+
# => {"logged_out"=>"1", "lang"=>"en"}
|
37
|
+
|
32
38
|
## Install
|
33
39
|
|
34
40
|
$ gem install uri-query_params
|
data/Rakefile
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
|
4
|
-
begin
|
5
|
-
gem 'ore-tasks', '~> 0.4'
|
6
|
-
require 'ore/tasks'
|
7
|
-
|
8
|
-
Ore::Tasks.new
|
9
|
-
rescue LoadError => e
|
10
|
-
warn e.message
|
11
|
-
warn "Run `gem install ore-tasks` to install 'ore/tasks'."
|
12
|
-
end
|
13
|
-
|
14
4
|
begin
|
15
5
|
gem 'rspec', '~> 2.4'
|
16
6
|
require 'rspec/core/rake_task'
|
data/gemspec.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'uri/query_params/extensions/
|
2
|
-
require 'uri/query_params/extensions/
|
1
|
+
require 'uri/query_params/extensions/uri'
|
2
|
+
require 'uri/query_params/extensions/addressable/uri' if defined?(Addressable)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'uri/query_params/extensions/uri/generic'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'uri/query_params/mixin'
|
2
|
+
|
3
|
+
require 'uri/generic'
|
4
|
+
|
5
|
+
module URI
|
6
|
+
class Generic
|
7
|
+
|
8
|
+
include URI::QueryParams::Mixin
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
alias raw_path_query path_query
|
13
|
+
|
14
|
+
#
|
15
|
+
# Parses the query parameters from the query data, populating
|
16
|
+
# query_params with the parsed parameters.
|
17
|
+
#
|
18
|
+
# @see QueryParams.parse
|
19
|
+
#
|
20
|
+
# @since 0.5.2
|
21
|
+
#
|
22
|
+
def path_query
|
23
|
+
if @query_params
|
24
|
+
str = @path
|
25
|
+
|
26
|
+
unless @query_params.empty?
|
27
|
+
str += '?' + URI::QueryParams.dump(@query_params)
|
28
|
+
end
|
29
|
+
|
30
|
+
str
|
31
|
+
else
|
32
|
+
# do not rebuild the path-query, if the query_params have not
|
33
|
+
# been parsed yet
|
34
|
+
raw_path_query
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -10,6 +10,58 @@ module URI
|
|
10
10
|
# Allows setting the query_params.
|
11
11
|
attr_writer :query_params
|
12
12
|
|
13
|
+
#
|
14
|
+
# Called when {Mixin} is included into a URI Class. Overrides the `query`
|
15
|
+
# and `query=` methods to transparently update the {#query_params}.
|
16
|
+
#
|
17
|
+
def self.included(base)
|
18
|
+
base.module_eval do
|
19
|
+
alias raw_query query
|
20
|
+
|
21
|
+
#
|
22
|
+
# The raw query-string.
|
23
|
+
#
|
24
|
+
# @return [String, nil]
|
25
|
+
# The raw query-string.
|
26
|
+
#
|
27
|
+
# @see QueryParams.dump
|
28
|
+
#
|
29
|
+
# @since 0.5.2
|
30
|
+
#
|
31
|
+
def query
|
32
|
+
if @query_params
|
33
|
+
URI::QueryParams.dump(@query_params)
|
34
|
+
else
|
35
|
+
raw_query
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
alias raw_query= query=
|
40
|
+
|
41
|
+
#
|
42
|
+
# Sets the query string and updates query_params.
|
43
|
+
#
|
44
|
+
# @param [String] query_str
|
45
|
+
# The new URI query string to use.
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
# The new URI query string.
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# url.query = 'a=1&b=2'
|
52
|
+
# # => "a=1&b=2"
|
53
|
+
#
|
54
|
+
# @see QueryParams.parse
|
55
|
+
#
|
56
|
+
def query=(new_query)
|
57
|
+
new_query = (self.raw_query = new_query)
|
58
|
+
|
59
|
+
parse_query_params! if @query_params
|
60
|
+
return new_query
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
13
65
|
#
|
14
66
|
# Deep-copies the {#query_params} from another URL.
|
15
67
|
#
|
@@ -26,46 +78,6 @@ module URI
|
|
26
78
|
super(url)
|
27
79
|
end
|
28
80
|
|
29
|
-
#
|
30
|
-
# The raw query-string.
|
31
|
-
#
|
32
|
-
# @return [String, nil]
|
33
|
-
# The raw query-string.
|
34
|
-
#
|
35
|
-
# @see QueryParams.dump
|
36
|
-
#
|
37
|
-
# @since 0.5.2
|
38
|
-
#
|
39
|
-
def query
|
40
|
-
if @query_params
|
41
|
-
QueryParams.dump(@query_params)
|
42
|
-
else
|
43
|
-
super
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Sets the query string and updates query_params.
|
49
|
-
#
|
50
|
-
# @param [String] query_str
|
51
|
-
# The new URI query string to use.
|
52
|
-
#
|
53
|
-
# @return [String]
|
54
|
-
# The new URI query string.
|
55
|
-
#
|
56
|
-
# @example
|
57
|
-
# url.query = 'a=1&b=2'
|
58
|
-
# # => "a=1&b=2"
|
59
|
-
#
|
60
|
-
# @see QueryParams.parse
|
61
|
-
#
|
62
|
-
def query=(raw_query)
|
63
|
-
new_query = super(raw_query)
|
64
|
-
|
65
|
-
parse_query_params! if @query_params
|
66
|
-
return new_query
|
67
|
-
end
|
68
|
-
|
69
81
|
#
|
70
82
|
# The query params of the URI.
|
71
83
|
#
|
@@ -111,26 +123,9 @@ module URI
|
|
111
123
|
# @since 0.5.2
|
112
124
|
#
|
113
125
|
def parse_query_params!
|
114
|
-
@query_params = QueryParams.parse(@query)
|
126
|
+
@query_params = URI::QueryParams.parse(@query)
|
115
127
|
end
|
116
128
|
|
117
|
-
private
|
118
|
-
|
119
|
-
def path_query
|
120
|
-
if @query_params
|
121
|
-
str = @path
|
122
|
-
|
123
|
-
unless @query_params.empty?
|
124
|
-
str += '?' + QueryParams.dump(@query_params)
|
125
|
-
end
|
126
|
-
|
127
|
-
str
|
128
|
-
else
|
129
|
-
# do not rebuild the path-query, if the query_params have not
|
130
|
-
# been parsed yet
|
131
|
-
super
|
132
|
-
end
|
133
|
-
end
|
134
129
|
end
|
135
130
|
end
|
136
131
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'query_params_mixin_examples'
|
3
|
+
require 'uri/query_params/extensions/addressable/uri'
|
4
|
+
|
5
|
+
describe Addressable::URI do
|
6
|
+
let(:uri) { described_class.parse('http://www.example.com/page.php') }
|
7
|
+
|
8
|
+
it_should_behave_like "URI::QueryParams::Mixin"
|
9
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uri-query_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: ore-tasks
|
16
|
-
requirement: &19935200 !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0.4'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: *19935200
|
25
14
|
- !ruby/object:Gem::Dependency
|
26
15
|
name: rspec
|
27
|
-
requirement: &
|
16
|
+
requirement: &13944620 !ruby/object:Gem::Requirement
|
28
17
|
none: false
|
29
18
|
requirements:
|
30
19
|
- - ~>
|
@@ -32,10 +21,10 @@ dependencies:
|
|
32
21
|
version: '2.4'
|
33
22
|
type: :development
|
34
23
|
prerelease: false
|
35
|
-
version_requirements: *
|
24
|
+
version_requirements: *13944620
|
36
25
|
- !ruby/object:Gem::Dependency
|
37
26
|
name: yard
|
38
|
-
requirement: &
|
27
|
+
requirement: &13944020 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
29
|
requirements:
|
41
30
|
- - ~>
|
@@ -43,7 +32,7 @@ dependencies:
|
|
43
32
|
version: '0.6'
|
44
33
|
type: :development
|
45
34
|
prerelease: false
|
46
|
-
version_requirements: *
|
35
|
+
version_requirements: *13944020
|
47
36
|
description: Allows access to the query component of the URI as a Hash.
|
48
37
|
email: postmodern.mod3@gmail.com
|
49
38
|
executables: []
|
@@ -62,13 +51,15 @@ files:
|
|
62
51
|
- gemspec.yml
|
63
52
|
- lib/uri/query_params.rb
|
64
53
|
- lib/uri/query_params/extensions.rb
|
65
|
-
- lib/uri/query_params/extensions/
|
66
|
-
- lib/uri/query_params/extensions/
|
54
|
+
- lib/uri/query_params/extensions/addressable/uri.rb
|
55
|
+
- lib/uri/query_params/extensions/uri.rb
|
56
|
+
- lib/uri/query_params/extensions/uri/generic.rb
|
67
57
|
- lib/uri/query_params/mixin.rb
|
68
58
|
- lib/uri/query_params/query_params.rb
|
69
59
|
- lib/uri/query_params/version.rb
|
70
|
-
- spec/extensions/
|
71
|
-
- spec/extensions/
|
60
|
+
- spec/extensions/addressable/uri_spec.rb
|
61
|
+
- spec/extensions/uri/generic_spec.rb
|
62
|
+
- spec/extensions/uri/http_spec.rb
|
72
63
|
- spec/query_params_mixin_examples.rb
|
73
64
|
- spec/query_params_spec.rb
|
74
65
|
- spec/spec_helper.rb
|
@@ -99,7 +90,8 @@ signing_key:
|
|
99
90
|
specification_version: 3
|
100
91
|
summary: Access the query parameters of a URI, just like $_GET in PHP.
|
101
92
|
test_files:
|
102
|
-
- spec/extensions/
|
103
|
-
- spec/extensions/
|
93
|
+
- spec/extensions/addressable/uri_spec.rb
|
94
|
+
- spec/extensions/uri/generic_spec.rb
|
95
|
+
- spec/extensions/uri/http_spec.rb
|
104
96
|
- spec/query_params_spec.rb
|
105
97
|
has_rdoc:
|