paul-resourceful 0.5.4 → 0.6.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.
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+ require 'tempfile'
3
+ require "resourceful/urlencoded_form_data.rb"
4
+
5
+ describe Resourceful::UrlencodedFormData do
6
+
7
+ before do
8
+ @form_data = Resourceful::UrlencodedFormData.new
9
+ end
10
+
11
+ it "should know its content-type" do
12
+ @form_data.content_type.should match(/^application\/x-www-form-urlencoded$/i)
13
+ end
14
+
15
+ describe "instantiation" do
16
+ it "should be creatable with hash" do
17
+ Resourceful::UrlencodedFormData.new(:foo => 'testing').read.should eql("foo=testing")
18
+ end
19
+ end
20
+
21
+ describe "with simple parameters" do
22
+ it "should all simple parameters to be added" do
23
+ @form_data.add(:foo, "testing")
24
+ end
25
+
26
+ it "should render a multipart form-data document when #read is called" do
27
+ @form_data.add('foo', 'bar')
28
+ @form_data.add('baz', 'this')
29
+
30
+ @form_data.read.should eql("foo=bar&baz=this")
31
+ end
32
+
33
+ it "should escape character in values that are unsafe" do
34
+ @form_data.add('foo', 'this & that')
35
+
36
+ @form_data.read.should eql("foo=this+%26+that")
37
+ end
38
+
39
+ it "should escape character in names that are unsafe" do
40
+ @form_data.add('foo=bar', 'this')
41
+ @form_data.read.should eql("foo%3Dbar=this")
42
+ end
43
+ end
44
+ end
@@ -69,6 +69,6 @@ get '/cached' do
69
69
  end
70
70
 
71
71
  Sinatra::Default.set(
72
- :port => 3000
72
+ :port => 42682
73
73
  )
74
74
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
+ require 'pp'
3
4
 
4
5
  $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
5
6
  require 'resourceful'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paul-resourceful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Sadauskas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-28 00:00:00 -07:00
12
+ date: 2009-08-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 2.1.0
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httpauth
@@ -81,34 +81,42 @@ extensions: []
81
81
  extra_rdoc_files:
82
82
  - lib/resourceful.rb
83
83
  - lib/resourceful/net_http_adapter.rb
84
+ - lib/resourceful/options_interpretation.rb
84
85
  - lib/resourceful/stubbed_resource_proxy.rb
86
+ - lib/resourceful/urlencoded_form_data.rb
85
87
  - lib/resourceful/header.rb
86
88
  - lib/resourceful/memcache_cache_manager.rb
87
89
  - lib/resourceful/response.rb
88
90
  - lib/resourceful/util.rb
89
- - lib/resourceful/options_interpreter.rb
91
+ - lib/resourceful/abstract_form_data.rb
90
92
  - lib/resourceful/cache_manager.rb
91
93
  - lib/resourceful/request.rb
92
94
  - lib/resourceful/resource.rb
93
95
  - lib/resourceful/exceptions.rb
96
+ - lib/resourceful/multipart_form_data.rb
94
97
  - lib/resourceful/http_accessor.rb
95
98
  - lib/resourceful/authentication_manager.rb
96
99
  - README.markdown
97
100
  files:
98
101
  - lib/resourceful.rb
99
102
  - lib/resourceful/net_http_adapter.rb
103
+ - lib/resourceful/options_interpretation.rb
100
104
  - lib/resourceful/stubbed_resource_proxy.rb
105
+ - lib/resourceful/urlencoded_form_data.rb
101
106
  - lib/resourceful/header.rb
102
107
  - lib/resourceful/memcache_cache_manager.rb
103
108
  - lib/resourceful/response.rb
104
109
  - lib/resourceful/util.rb
105
- - lib/resourceful/options_interpreter.rb
110
+ - lib/resourceful/abstract_form_data.rb
106
111
  - lib/resourceful/cache_manager.rb
107
112
  - lib/resourceful/request.rb
108
113
  - lib/resourceful/resource.rb
109
114
  - lib/resourceful/exceptions.rb
115
+ - lib/resourceful/multipart_form_data.rb
110
116
  - lib/resourceful/http_accessor.rb
111
117
  - lib/resourceful/authentication_manager.rb
118
+ - History.txt
119
+ - resourceful.gemspec
112
120
  - README.markdown
113
121
  - MIT-LICENSE
114
122
  - Rakefile
@@ -123,8 +131,12 @@ files:
123
131
  - spec/acceptance/resource_spec.rb
124
132
  - spec/acceptance/caching_spec.rb
125
133
  - spec/acceptance/redirecting_spec.rb
134
+ - spec/resourceful/multipart_form_data_spec.rb
135
+ - spec/resourceful/header_spec.rb
136
+ - spec/resourceful/resource_spec.rb
137
+ - spec/resourceful/urlencoded_form_data_spec.rb
138
+ - spec/caching_spec.rb
126
139
  - spec/spec.opts
127
- - resourceful.gemspec
128
140
  has_rdoc: false
129
141
  homepage: http://github.com/paul/resourceful
130
142
  licenses:
@@ -1,78 +0,0 @@
1
- require 'set'
2
-
3
- module Resourceful
4
- # Class that supports a declarative way to pick apart an options
5
- # hash.
6
- #
7
- # OptionsInterpreter.new do
8
- # option(:accept) { |accept| [accept].flatten.map{|m| m.to_str} }
9
- # option(:http_header_fields, :default => {})
10
- # end.interpret(:accept => 'this/that')
11
- # # => {:accept => ['this/that'], :http_header_fields => { } }
12
- #
13
- # The returned hash contains :accept with the pass accept option
14
- # value transformed into an array and :http_header_fields with its
15
- # default value.
16
- #
17
- # OptionsInterpreter.new do
18
- # option(:max_redirects)
19
- # end.interpret(:foo => 1, :bar => 2)
20
- # # Raises ArgumentError: Unrecognized options: foo, bar
21
- #
22
- # If options are passed that are not defined an exception is raised.
23
- #
24
- class OptionsInterpreter
25
- def self.interpret(options_hash, &block)
26
- interpreter = self.new(options_hash)
27
- interpreter.instance_eval(&block)
28
-
29
- interpreter.interpret
30
- end
31
-
32
- def initialize(&block)
33
- @handlers = Hash.new
34
-
35
- instance_eval(&block) if block_given?
36
- end
37
-
38
- def interpret(options_hash, &block)
39
- unless (unrecognized_options = (options_hash.keys - supported_options)).empty?
40
- raise ArgumentError, "Unrecognized options: #{unrecognized_options.join(", ")}"
41
- end
42
-
43
- options = Hash.new
44
- handlers.each do |opt_name, a_handler|
45
- opt_val = a_handler.call(options_hash)
46
- options[opt_name] = opt_val if opt_val
47
- end
48
-
49
- yield(options) if block_given?
50
-
51
- options
52
- end
53
-
54
- def option(name, opts = {}, &block)
55
-
56
- passed_value_fetcher = if opts[:default]
57
- default_value = opts[:default]
58
- lambda{|options_hash| options_hash[name] || default_value}
59
- else
60
- lambda{|options_hash| options_hash[name]}
61
- end
62
-
63
- handlers[name] = if block_given?
64
- lambda{|options_hash| (val = passed_value_fetcher.call(options_hash)) ? block.call(val) : nil}
65
- else
66
- passed_value_fetcher
67
- end
68
- end
69
-
70
- def supported_options
71
- handlers.keys
72
- end
73
-
74
- private
75
-
76
- attr_reader :handlers
77
- end
78
- end