uri-query_params 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ -
3
+ ChangeLog.*
4
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/ChangeLog.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.5.0 / 2010-11-07
2
+
3
+ * Added {URI::QueryParams.dump}.
4
+ * Added `uri/query_params/extensions/https.rb`.
5
+ * Fixed a bug in {URI::QueryParams.parse}, where query param values
6
+ containing `=` characters were not properly parsed.
7
+
1
8
  ### 0.4.0 / 2010-08-28
2
9
 
3
10
  * Initial release.
data/README.md CHANGED
@@ -13,11 +13,12 @@ to `$_GET` from PHP, except available on any {URI::HTTP} object.
13
13
 
14
14
  Inspecting the URI query_params:
15
15
 
16
+ require 'uri/query_params'
17
+
16
18
  url = URI('http://www.google.com/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=1HY&q=bob+ross&btnG=Search')
17
19
  url.query_params
18
20
  # => {"btnG"=>"Search", "hs"=>"1HY", "rls"=>"org.mozilla:en-US:official", "client"=>"firefox-a", "hl"=>"en", "q"=>"bob+ross"}
19
21
 
20
-
21
22
  url.query_params['q']
22
23
  # => "bob+ross"
23
24
 
data/Rakefile CHANGED
@@ -2,45 +2,34 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = 'uri-query_params'
8
- gem.license = 'MIT'
9
- gem.summary = %Q{Access the query parameters of a URI, just like $_GET in PHP.}
10
- gem.description = %Q{Allows access to the query component of the URI as a Hash.}
11
- gem.email = 'postmodern.mod3@gmail.com'
12
- gem.homepage = 'http://github.com/postmodern/uri-query_params'
13
- gem.authors = ['Postmodern']
14
- gem.add_development_dependency 'rspec', '>= 1.3.0'
15
- gem.add_development_dependency 'yard', '>= 0.5.3'
16
- gem.has_rdoc = 'yard'
17
- end
18
- Jeweler::GemcutterTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
5
+ gem 'ore-tasks', '~> 0.2.0'
6
+ require 'ore/tasks'
7
+
8
+ Ore::Tasks.new
9
+ rescue LoadError => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Run `gem install ore-tasks` to install 'ore/tasks'."
21
12
  end
22
13
 
23
14
  begin
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs += ['lib', 'spec']
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- spec.spec_opts = ['--options', '.specopts']
29
- end
15
+ gem 'rspec', '~> 2.0.0'
16
+ require 'rspec/core/rake_task'
30
17
 
31
- task :spec => :check_dependencies
32
- task :default => :spec
33
- rescue LoadError
18
+ RSpec::Core::RakeTask.new
19
+ rescue LoadError => e
34
20
  task :spec do
35
- abort "RSpec is not available. In order to run `rake spec`, you must: gem install rspec"
21
+ abort "Please run `gem install rspec` to install RSpec."
36
22
  end
37
23
  end
24
+ task :default => :spec
38
25
 
39
26
  begin
27
+ gem 'yard', '~> 0.6.0'
40
28
  require 'yard'
41
- YARD::Rake::YardocTask.new
42
- rescue LoadError
29
+
30
+ YARD::Rake::YardocTask.new
31
+ rescue LoadError => e
43
32
  task :yard do
44
- abort "YARD is not available. In order to run yard, you must: gem install yard"
33
+ abort "Please run `gem install yard` to install YARD."
45
34
  end
46
35
  end
data/gemspec.yml ADDED
@@ -0,0 +1,13 @@
1
+ name: uri-query_params
2
+ summary: Access the query parameters of a URI, just like $_GET in PHP.
3
+ description: Allows access to the query component of the URI as a Hash.
4
+ license: MIT
5
+ homepage: http://github.com/postmodern/uri-query_params
6
+ authors: Postmodern
7
+ email: postmodern.mod3@gmail.com
8
+ has_yard: true
9
+
10
+ development_dependencies:
11
+ ore-tasks: ~> 0.2.0
12
+ rspec: ~> 2.0.0
13
+ yard: ~> 0.6.0
@@ -0,0 +1,3 @@
1
+ require 'uri/query_params/extensions/http'
2
+
3
+ require 'uri/https'
@@ -1 +1,2 @@
1
1
  require 'uri/query_params/extensions/http'
2
+ require 'uri/query_params/extensions/https'
@@ -76,23 +76,11 @@ module URI
76
76
  private
77
77
 
78
78
  def path_query
79
- if @query_params
79
+ unless (@query_params.nil? || @query_params.empty?)
80
80
  str = @path
81
81
 
82
82
  unless @query_params.empty?
83
- str += '?' + @query_params.to_a.map { |name,value|
84
- if value==true
85
- "#{name}=active"
86
- elsif value
87
- if value.kind_of?(Array)
88
- "#{name}=#{CGI.escape(value.join(' '))}"
89
- else
90
- "#{name}=#{CGI.escape(value.to_s)}"
91
- end
92
- else
93
- "#{name}="
94
- end
95
- }.join('&')
83
+ str += '?' + QueryParams.dump(@query_params)
96
84
  end
97
85
 
98
86
  str
@@ -16,7 +16,7 @@ module URI
16
16
 
17
17
  if query_string
18
18
  query_string.split('&').each do |param|
19
- name, value = param.split('=')
19
+ name, value = param.split('=',2)
20
20
 
21
21
  if value
22
22
  query_params[name] = URI.decode(value)
@@ -29,5 +29,37 @@ module URI
29
29
  return query_params
30
30
  end
31
31
 
32
+ #
33
+ # Dumps the URI query params.
34
+ #
35
+ # @param [Hash{String => String}] query_params
36
+ # The query params.
37
+ #
38
+ # @return [String]
39
+ # The dumped URI query string.
40
+ #
41
+ # @since 0.5.0
42
+ #
43
+ def QueryParams.dump(query_params)
44
+ query = []
45
+
46
+ query_params.each do |name,value|
47
+ param = case value
48
+ when Array
49
+ "#{name}=#{CGI.escape(value.join(' '))}"
50
+ when true
51
+ "#{name}=active"
52
+ when false, nil
53
+ "#{name}="
54
+ else
55
+ "#{name}=#{CGI.escape(value.to_s)}"
56
+ end
57
+
58
+ query << param
59
+ end
60
+
61
+ return query.join('&')
62
+ end
63
+
32
64
  end
33
65
  end
@@ -0,0 +1,6 @@
1
+ module URI
2
+ module QueryParams
3
+ # uri-query_params version
4
+ VERSION = '0.5.0'
5
+ end
6
+ end
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
+ require 'query_params_mixin_examples'
2
3
  require 'uri/query_params/extensions/http'
3
4
 
4
5
  describe URI::HTTP do
5
- it "should include QueryParams" do
6
- URI::HTTP.should include(URI::QueryParams::Mixin)
7
- end
6
+ let(:uri) { URI('http://www.example.com/page.php') }
7
+
8
+ it_should_behave_like "URI::QueryParams::Mixin"
8
9
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+ require 'query_params_mixin_examples'
3
+ require 'uri/query_params/extensions/http'
4
+
5
+ describe URI::HTTPS do
6
+ let(:uri) { URI('https://www.example.com/page.php') }
7
+
8
+ it_should_behave_like "URI::QueryParams::Mixin"
9
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'uri/query_params'
3
+
4
+ require 'uri'
5
+
6
+ shared_examples_for "URI::QueryParams::Mixin" do
7
+ subject { uri }
8
+
9
+ before(:each) do
10
+ uri.query = 'x=1&y=one%20two&z'
11
+ end
12
+
13
+ it "should include QueryParams" do
14
+ subject.class.should include(URI::QueryParams::Mixin)
15
+ end
16
+
17
+ it "should provide #query_params" do
18
+ should respond_to(:query_params)
19
+ end
20
+
21
+ it "should update #query_params after #query is set" do
22
+ subject.query = 'u=3'
23
+ subject.query_params['u'].should == '3'
24
+ end
25
+
26
+ it "should properly escape query param values" do
27
+ subject.query_params = {'x' => '1&2', 'y' => 'one=two', 'z' => '?'}
28
+
29
+ subject.to_s.match(/\?(.+)$/)[1].should == "x=1%262&y=one%3Dtwo&z=%3F"
30
+ end
31
+
32
+ describe "#query_params" do
33
+ subject { uri.query_params }
34
+
35
+ it "should be a Hash" do
36
+ subject.class.should == Hash
37
+ end
38
+
39
+ it "should contain params" do
40
+ should_not be_empty
41
+ end
42
+
43
+ it "can contain single-word params" do
44
+ subject['x'].should == '1'
45
+ end
46
+
47
+ it "can contain multi-word params" do
48
+ subject['y'].should == 'one two'
49
+ end
50
+
51
+ it "can contain empty params" do
52
+ subject['z'].should be_empty
53
+ end
54
+ end
55
+ end
@@ -4,45 +4,69 @@ require 'uri/query_params'
4
4
  require 'uri'
5
5
 
6
6
  describe URI::QueryParams do
7
- let(:uri) { URI('http://www.example.com/page.php?x=1&y=one%20two&z') }
8
- subject { uri }
7
+ describe "parse" do
8
+ it "should not parse an empty String" do
9
+ subject.parse('').should be_empty
10
+ end
9
11
 
10
- it "should provide #query_params" do
11
- should respond_to(:query_params)
12
- end
12
+ it "should parse a single query param name" do
13
+ subject.parse('x').should have_key('x')
14
+ end
13
15
 
14
- it "should update #query_params after #query is set" do
15
- subject.query = 'u=3'
16
- subject.query_params['u'].should == '3'
17
- end
16
+ it "should parse a query param with an empty value" do
17
+ query_params = subject.parse('x=')
18
+
19
+ query_params.should have_key('x')
20
+ query_params['x'].should be_empty
21
+ end
22
+
23
+ it "should URI decode query param values" do
24
+ query_params = subject.parse('x=1%202')
25
+
26
+ query_params['x'].should == '1 2'
27
+ end
28
+
29
+ it "should ignore multiple '=' characters in query param values" do
30
+ query_params = subject.parse('x=1=2')
31
+
32
+ query_params['x'].should == '1=2'
33
+ end
18
34
 
19
- it "should properly escape query param values" do
20
- subject.query_params = {'x' => '1&2', 'y' => 'one=two', 'z' => '?'}
35
+ it "should parse multiple query params" do
36
+ query_params = subject.parse('x=1&y=2')
21
37
 
22
- subject.to_s.should == "http://www.example.com/page.php?x=1%262&y=one%3Dtwo&z=%3F"
38
+ query_params['x'].should == '1'
39
+ query_params['y'].should == '2'
40
+ end
23
41
  end
24
42
 
25
- describe "#query_params" do
26
- subject { uri.query_params }
43
+ describe "dump" do
44
+ it "should not dump an empty Hash" do
45
+ subject.dump({}).should be_empty
46
+ end
47
+
48
+ it "should dump query params with no values" do
49
+ subject.dump({'x' => nil}).should == 'x='
50
+ end
27
51
 
28
- it "should be a Hash" do
29
- subject.class.should == Hash
52
+ it "should dump query params with empty values" do
53
+ subject.dump({'x' => ''}).should == 'x='
30
54
  end
31
55
 
32
- it "should contain params" do
33
- should_not be_empty
56
+ it "should dump query params with true values" do
57
+ subject.dump({'x' => true}).should == 'x=active'
34
58
  end
35
59
 
36
- it "can contain single-word params" do
37
- subject['x'].should == '1'
60
+ it "should dump query params with non String values" do
61
+ subject.dump({'x' => 1}).should == 'x=1'
38
62
  end
39
63
 
40
- it "can contain multi-word params" do
41
- subject['y'].should == 'one two'
64
+ it "should dump query params with Array values" do
65
+ subject.dump({'x' => [1,2]}).should == 'x=1+2'
42
66
  end
43
67
 
44
- it "can contain empty params" do
45
- subject['z'].should be_empty
68
+ it "should dump multiple query params" do
69
+ subject.dump({'x' => '1', 'y' => '2'}).should == 'x=1&y=2'
46
70
  end
47
71
  end
48
72
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'rubygems'
2
2
 
3
- gem 'rspec', '>= 1.3.0'
4
- require 'spec'
3
+ gem 'rspec', '~> 2.0.0'
4
+ require 'rspec'
@@ -1,68 +1,10 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{uri-query_params}
8
- s.version = "0.4.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Postmodern"]
12
- s.date = %q{2010-08-28}
13
- s.description = %q{Allows access to the query component of the URI as a Hash.}
14
- s.email = %q{postmodern.mod3@gmail.com}
15
- s.extra_rdoc_files = [
16
- "ChangeLog.md",
17
- "LICENSE.txt",
18
- "README.md"
19
- ]
20
- s.files = [
21
- ".gitignore",
22
- ".specopts",
23
- ".yardopts",
24
- "ChangeLog.md",
25
- "LICENSE.txt",
26
- "README.md",
27
- "Rakefile",
28
- "VERSION",
29
- "lib/uri/query_params.rb",
30
- "lib/uri/query_params/extensions.rb",
31
- "lib/uri/query_params/extensions/http.rb",
32
- "lib/uri/query_params/mixin.rb",
33
- "lib/uri/query_params/query_params.rb",
34
- "spec/extensions/http_spec.rb",
35
- "spec/query_params_spec.rb",
36
- "spec/spec_helper.rb",
37
- "uri-query_params.gemspec"
38
- ]
39
- s.has_rdoc = %q{yard}
40
- s.homepage = %q{http://github.com/postmodern/uri-query_params}
41
- s.licenses = ["MIT"]
42
- s.rdoc_options = ["--charset=UTF-8"]
43
- s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.7}
45
- s.summary = %q{Access the query parameters of a URI, just like $_GET in PHP.}
46
- s.test_files = [
47
- "spec/extensions/http_spec.rb",
48
- "spec/query_params_spec.rb",
49
- "spec/spec_helper.rb"
50
- ]
51
-
52
- if s.respond_to? :specification_version then
53
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
- s.specification_version = 3
55
-
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
58
- s.add_development_dependency(%q<yard>, [">= 0.5.3"])
59
- else
60
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
61
- s.add_dependency(%q<yard>, [">= 0.5.3"])
62
- end
63
- else
64
- s.add_dependency(%q<rspec>, [">= 1.3.0"])
65
- s.add_dependency(%q<yard>, [">= 0.5.3"])
3
+ begin
4
+ Ore::Specification.new do |gemspec|
5
+ # custom logic here
66
6
  end
7
+ rescue NameError
8
+ STDERR.puts "The 'uri-query_params.gemspec' file requires Ore."
9
+ STDERR.puts "Run `gem install ore-core` to install Ore."
67
10
  end
68
-
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
7
+ - 5
8
8
  - 0
9
- version: 0.4.0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Postmodern
@@ -14,39 +14,54 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-28 00:00:00 -07:00
17
+ date: 2010-11-07 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: rspec
21
+ name: ore-tasks
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
- - 1
30
- - 3
31
29
  - 0
32
- version: 1.3.0
30
+ - 2
31
+ - 0
32
+ version: 0.2.0
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: yard
36
+ name: rspec
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ">="
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
43
  segments:
44
+ - 2
45
+ - 0
44
46
  - 0
45
- - 5
46
- - 3
47
- version: 0.5.3
47
+ version: 2.0.0
48
48
  type: :development
49
49
  version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: yard
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 6
61
+ - 0
62
+ version: 0.6.0
63
+ type: :development
64
+ version_requirements: *id003
50
65
  description: Allows access to the query component of the URI as a Hash.
51
66
  email: postmodern.mod3@gmail.com
52
67
  executables: []
@@ -54,24 +69,28 @@ executables: []
54
69
  extensions: []
55
70
 
56
71
  extra_rdoc_files:
72
+ - README.md
57
73
  - ChangeLog.md
58
74
  - LICENSE.txt
59
- - README.md
60
75
  files:
61
- - .gitignore
62
- - .specopts
76
+ - .document
77
+ - .rspec
63
78
  - .yardopts
64
79
  - ChangeLog.md
65
80
  - LICENSE.txt
66
81
  - README.md
67
82
  - Rakefile
68
- - VERSION
83
+ - gemspec.yml
69
84
  - lib/uri/query_params.rb
70
85
  - lib/uri/query_params/extensions.rb
71
86
  - lib/uri/query_params/extensions/http.rb
87
+ - lib/uri/query_params/extensions/https.rb
72
88
  - lib/uri/query_params/mixin.rb
73
89
  - lib/uri/query_params/query_params.rb
90
+ - lib/uri/query_params/version.rb
74
91
  - spec/extensions/http_spec.rb
92
+ - spec/extensions/https_spec.rb
93
+ - spec/query_params_mixin_examples.rb
75
94
  - spec/query_params_spec.rb
76
95
  - spec/spec_helper.rb
77
96
  - uri-query_params.gemspec
@@ -80,8 +99,8 @@ homepage: http://github.com/postmodern/uri-query_params
80
99
  licenses:
81
100
  - MIT
82
101
  post_install_message:
83
- rdoc_options:
84
- - --charset=UTF-8
102
+ rdoc_options: []
103
+
85
104
  require_paths:
86
105
  - lib
87
106
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -102,12 +121,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
121
  version: "0"
103
122
  requirements: []
104
123
 
105
- rubyforge_project:
124
+ rubyforge_project: uri-query_params
106
125
  rubygems_version: 1.3.7
107
126
  signing_key:
108
127
  specification_version: 3
109
128
  summary: Access the query parameters of a URI, just like $_GET in PHP.
110
129
  test_files:
111
130
  - spec/extensions/http_spec.rb
131
+ - spec/extensions/https_spec.rb
112
132
  - spec/query_params_spec.rb
113
- - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- doc
2
- pkg
3
- tmp/*
4
- .DS_Store
5
- .bundle
6
- .yardoc
7
- *.db
8
- *.log
9
- *.swp
10
- *~
data/.specopts DELETED
@@ -1 +0,0 @@
1
- --colour --format specdoc
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.4.0