faraday 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,12 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ # Bundle gems for the local environment. Make sure to
4
+ # put test-only gems in this group so their generators
5
+ # and rake tasks are available in development mode:
6
+ group :development, :test do
7
+ gem 'patron', '~> 0.4'
8
+ gem 'sinatra', '~> 1.0'
9
+ gem 'typhoeus', '~> 0.1'
10
+ end
11
+
3
12
  gemspec
@@ -1,28 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faraday (0.4.6)
5
- addressable (~> 2.1.1)
4
+ faraday (0.5.1)
5
+ addressable (~> 2.2.2)
6
6
  multipart-post (~> 1.0.1)
7
- rack (~> 1.0.1)
7
+ rack (~> 1.2.1)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- addressable (2.1.2)
12
+ addressable (2.2.2)
13
13
  multipart-post (1.0.1)
14
- rack (1.0.1)
14
+ patron (0.4.9)
15
+ rack (1.2.1)
15
16
  rake (0.8.7)
16
17
  sinatra (1.0)
17
18
  rack (>= 1.0)
19
+ typhoeus (0.1.31)
20
+ rack
18
21
 
19
22
  PLATFORMS
20
23
  ruby
21
24
 
22
25
  DEPENDENCIES
23
- addressable (~> 2.1.1)
26
+ addressable (~> 2.2.2)
24
27
  faraday!
25
28
  multipart-post (~> 1.0.1)
26
- rack (~> 1.0.1)
27
- rake (~> 0.8.7)
28
- sinatra (~> 1.0.0)
29
+ patron (~> 0.4)
30
+ rack (~> 1.2.1)
31
+ rake (~> 0.8)
32
+ sinatra (~> 1.0)
33
+ typhoeus (~> 0.1)
data/README.md CHANGED
@@ -22,7 +22,7 @@ This mess is gonna get raw, like sushi. So, haters to the left.
22
22
  resp1 = conn.get '/nigiri/sake.json'
23
23
  resp2 = conn.post do |req|
24
24
  req.url "/nigiri.json", :page => 2
25
- req[:content_type] = 'application/json'
25
+ req["Content-Type"] = 'application/json'
26
26
  req.body = {:name => 'Unagi'}
27
27
  end
28
28
 
@@ -32,7 +32,7 @@ This mess is gonna get raw, like sushi. So, haters to the left.
32
32
  ## Testing
33
33
 
34
34
  # It's possible to define stubbed request outside a test adapter block.
35
- stubs = Faraday::Test::Stubs.new do |stub|
35
+ stubs = Faraday::Adapter::Test::Stubs.new do |stub|
36
36
  stub.get('/tamago') { [200, {}, 'egg'] }
37
37
  end
38
38
 
data/Rakefile CHANGED
@@ -71,6 +71,7 @@ end
71
71
  #
72
72
  #############################################################################
73
73
 
74
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
74
75
  task :release => :build do
75
76
  unless `git branch` =~ /^\* master$/
76
77
  puts "You must be on the master branch to release!"
@@ -80,15 +81,17 @@ task :release => :build do
80
81
  sh "git tag v#{version}"
81
82
  sh "git push origin master"
82
83
  sh "git push origin v#{version}"
83
- sh "gem push pkg/#{name}-#{version}.gem"
84
+ sh "gem push pkg/#{gem_file}"
84
85
  end
85
86
 
87
+ desc "Build #{gem_file} into the pkg directory"
86
88
  task :build => :gemspec do
87
89
  sh "mkdir -p pkg"
88
90
  sh "gem build #{gemspec_file}"
89
91
  sh "mv #{gem_file} pkg"
90
92
  end
91
93
 
94
+ desc "Generate #{gemspec_file}"
92
95
  task :gemspec => :validate do
93
96
  # read spec file and split out manifest section
94
97
  spec = File.read(gemspec_file)
@@ -117,6 +120,7 @@ task :gemspec => :validate do
117
120
  puts "Updated #{gemspec_file}"
118
121
  end
119
122
 
123
+ desc "Validate #{gemspec_file}"
120
124
  task :validate do
121
125
  libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
122
126
  unless libfiles.empty?
@@ -127,4 +131,4 @@ task :validate do
127
131
  puts "A `VERSION` file at root level violates Gem best practices."
128
132
  exit!
129
133
  end
130
- end
134
+ end
@@ -6,15 +6,14 @@
6
6
  ## http://docs.rubygems.org/read/chapter/20
7
7
  Gem::Specification.new do |s|
8
8
  s.specification_version = 2 if s.respond_to? :specification_version=
9
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
- s.rubygems_version = '1.3.5'
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
11
10
 
12
11
  ## Leave these as is they will be modified for you by the rake gemspec task.
13
12
  ## If your rubyforge_project name is different, then edit it and comment out
14
13
  ## the sub! line in the Rakefile
15
14
  s.name = 'faraday'
16
- s.version = '0.5.0'
17
- s.date = '2010-10-08'
15
+ s.version = '0.5.1'
16
+ s.date = '2010-10-15'
18
17
  s.rubyforge_project = 'faraday'
19
18
 
20
19
  ## Make sure your summary is short. The description may be as long
@@ -33,11 +32,10 @@ Gem::Specification.new do |s|
33
32
  ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
33
  s.require_paths = %w[lib]
35
34
 
36
- s.add_development_dependency('rake', ['~> 0.8.7'])
37
- s.add_development_dependency('sinatra', ['~> 1.0.0'])
38
- s.add_runtime_dependency('addressable', ['~> 2.1.1'])
39
- s.add_runtime_dependency('multipart-post', ['~> 1.0.1'])
40
- s.add_runtime_dependency('rack', ['~> 1.2.1'])
35
+ s.add_development_dependency('rake', '~> 0.8')
36
+ s.add_runtime_dependency('addressable', '~> 2.2.2')
37
+ s.add_runtime_dependency('multipart-post', '~> 1.0.1')
38
+ s.add_runtime_dependency('rack', '~> 1.2.1')
41
39
 
42
40
  ## Leave this section as-is. It will be automatically generated from the
43
41
  ## contents of your Git repository via the gemspec task. DO NOT REMOVE
@@ -87,4 +85,4 @@ Gem::Specification.new do |s|
87
85
  ## Test files will be grabbed from the file list. Make sure the path glob
88
86
  ## matches what you actually use.
89
87
  s.test_files = s.files.select { |path| path =~ /^test\/.*_test\.rb/ }
90
- end
88
+ end
@@ -1,5 +1,5 @@
1
1
  module Faraday
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
 
4
4
  class << self
5
5
  attr_accessor :default_adapter
@@ -105,14 +105,16 @@ module Faraday
105
105
  end
106
106
 
107
107
  def call(env)
108
- if stub = stubs.match(env[:method], Faraday::Utils.normalize_path(env[:url]), env[:body])
108
+ normalized_path = Faraday::Utils.normalize_path(env[:url])
109
+
110
+ if stub = stubs.match(env[:method], normalized_path, env[:body])
109
111
  status, headers, body = stub.block.call(env)
110
112
  env.update \
111
113
  :status => status,
112
114
  :response_headers => headers,
113
115
  :body => body
114
116
  else
115
- raise "no stubbed request for #{env[:method]} #{request_uri(env[:url])} #{env[:body]}"
117
+ raise "no stubbed request for #{env[:method]} #{normalized_path} #{env[:body]}"
116
118
  end
117
119
  @app.call(env)
118
120
  end
@@ -56,9 +56,10 @@ module Faraday
56
56
  def parse_response_headers(header_string)
57
57
  return {} unless header_string && !header_string.empty?
58
58
  Hash[*header_string.split(/\r\n/).
59
- tap { |a| a.shift }. # drop the HTTP status line
60
- map! { |h| h.split(/:\s+/,2) }. # split key and value
61
- map! { |(k, v)| [k.downcase, v] }.flatten!]
59
+ tap { |a| a.shift }. # drop the HTTP status line
60
+ map { |h| h.split(/:\s+/,2) }. # split key and value
61
+ reject { |(k, v)| k.nil? }. # Ignore blank lines
62
+ map { |(k, v)| [k.downcase, v] }.flatten]
62
63
  end
63
64
 
64
65
  # TODO: build in support for multipart streaming if typhoeus supports it.
@@ -19,7 +19,7 @@ if Faraday::TestCase::LIVE_SERVER
19
19
  end
20
20
 
21
21
  define_method "test_#{adapter}_GET_retrieves_the_response_headers" do
22
- assert_equal 'text/html', create_connection(adapter).get('hello_world').headers['content-type']
22
+ assert_match /text\/html/, create_connection(adapter).get('hello_world').headers['content-type']
23
23
  end
24
24
 
25
25
  define_method "test_#{adapter}_POST_send_url_encoded_params" do
@@ -39,7 +39,7 @@ if Faraday::TestCase::LIVE_SERVER
39
39
  end
40
40
 
41
41
  define_method "test_#{adapter}_POST_retrieves_the_response_headers" do
42
- assert_equal 'text/html', create_connection(adapter).post('echo_name').headers['content-type']
42
+ assert_match /text\/html/, create_connection(adapter).post('echo_name').headers['content-type']
43
43
  end
44
44
 
45
45
  define_method "test_#{adapter}_POST_sends_files" do
@@ -70,7 +70,7 @@ if Faraday::TestCase::LIVE_SERVER
70
70
  end
71
71
 
72
72
  define_method "test_#{adapter}_PUT_retrieves_the_response_headers" do
73
- assert_equal 'text/html', create_connection(adapter).put('echo_name').headers['content-type']
73
+ assert_match /text\/html/, create_connection(adapter).put('echo_name').headers['content-type']
74
74
  end
75
75
  end
76
76
 
@@ -78,7 +78,7 @@ if Faraday::TestCase::LIVE_SERVER
78
78
  resp = create_connection(adapter).head do |req|
79
79
  req.url 'hello', 'name' => 'zack'
80
80
  end
81
- assert_equal 'text/html', resp.headers['content-type']
81
+ assert_match /text\/html/, resp.headers['content-type']
82
82
  end
83
83
 
84
84
  define_method "test_#{adapter}_HEAD_retrieves_no_response_body" do
@@ -86,11 +86,11 @@ if Faraday::TestCase::LIVE_SERVER
86
86
  end
87
87
 
88
88
  define_method "test_#{adapter}_HEAD_retrieves_the_response_headers" do
89
- assert_equal 'text/html', create_connection(adapter).head('hello_world').headers['content-type']
89
+ assert_match /text\/html/, create_connection(adapter).head('hello_world').headers['content-type']
90
90
  end
91
91
 
92
92
  define_method "test_#{adapter}_DELETE_retrieves_the_response_headers" do
93
- assert_equal 'text/html', create_connection(adapter).delete('delete_with_json').headers['content-type']
93
+ assert_match /text\/html/, create_connection(adapter).delete('delete_with_json').headers['content-type']
94
94
  end
95
95
 
96
96
  define_method "test_#{adapter}_DELETE_retrieves_the_body" do
@@ -147,4 +147,4 @@ if Faraday::TestCase::LIVE_SERVER
147
147
  end
148
148
  end
149
149
  end
150
- end
150
+ end
@@ -33,5 +33,11 @@ module Adapters
33
33
  assert_equal 'hello', @conn.get("/hello").body
34
34
  assert_equal 'world', @conn.get("/hello").body
35
35
  end
36
+
37
+ def test_raises_an_error_if_no_stub_is_found_for_request
38
+ assert_raise RuntimeError do
39
+ @conn.get('/invalid'){ [200, {}, []] }
40
+ end
41
+ end
36
42
  end
37
43
  end
@@ -21,6 +21,11 @@ if Faraday::Adapter::Typhoeus.loaded?
21
21
  headers = @adapter.parse_response_headers("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nLocation: http://sushi.com/\r\n\r\n")
22
22
  assert_equal 'http://sushi.com/', headers['location']
23
23
  end
24
+
25
+ def test_parse_response_headers_parses_blank_lines
26
+ headers = @adapter.parse_response_headers("HTTP/1.1 200 OK\r\n\r\nContent-Type: text/html\r\n\r\n")
27
+ assert_equal 'text/html', headers['content-type']
28
+ end
24
29
  end
25
30
  end
26
31
  end
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
- gem 'rack', '>= 1.0.1'
3
- gem 'addressable', '>= 2.1.1'
2
+ gem 'rack', '>= 1.2.1'
3
+ gem 'addressable', '>= 2.2.2'
4
4
 
5
5
  require 'test/unit'
6
6
  if ENV['LEFTRIGHT']
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 9
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 5
8
- - 0
9
- version: 0.5.0
9
+ - 1
10
+ version: 0.5.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Rick Olson
@@ -14,79 +15,72 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-10-08 00:00:00 -07:00
18
+ date: 2010-10-15 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rake
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 27
27
30
  segments:
28
31
  - 0
29
32
  - 8
30
- - 7
31
- version: 0.8.7
33
+ version: "0.8"
32
34
  type: :development
33
35
  version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: sinatra
36
- prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 1
43
- - 0
44
- - 0
45
- version: 1.0.0
46
- type: :development
47
- version_requirements: *id002
48
36
  - !ruby/object:Gem::Dependency
49
37
  name: addressable
50
38
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
52
41
  requirements:
53
42
  - - ~>
54
43
  - !ruby/object:Gem::Version
44
+ hash: 3
55
45
  segments:
56
46
  - 2
57
- - 1
58
- - 1
59
- version: 2.1.1
47
+ - 2
48
+ - 2
49
+ version: 2.2.2
60
50
  type: :runtime
61
- version_requirements: *id003
51
+ version_requirements: *id002
62
52
  - !ruby/object:Gem::Dependency
63
53
  name: multipart-post
64
54
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
66
57
  requirements:
67
58
  - - ~>
68
59
  - !ruby/object:Gem::Version
60
+ hash: 21
69
61
  segments:
70
62
  - 1
71
63
  - 0
72
64
  - 1
73
65
  version: 1.0.1
74
66
  type: :runtime
75
- version_requirements: *id004
67
+ version_requirements: *id003
76
68
  - !ruby/object:Gem::Dependency
77
69
  name: rack
78
70
  prerelease: false
79
- requirement: &id005 !ruby/object:Gem::Requirement
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
80
73
  requirements:
81
74
  - - ~>
82
75
  - !ruby/object:Gem::Version
76
+ hash: 29
83
77
  segments:
84
78
  - 1
85
79
  - 2
86
80
  - 1
87
81
  version: 1.2.1
88
82
  type: :runtime
89
- version_requirements: *id005
83
+ version_requirements: *id004
90
84
  description: HTTP/REST API client library.
91
85
  email: technoweenie@gmail.com
92
86
  executables: []
@@ -143,23 +137,29 @@ rdoc_options: []
143
137
  require_paths:
144
138
  - lib
145
139
  required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
146
141
  requirements:
147
142
  - - ">="
148
143
  - !ruby/object:Gem::Version
144
+ hash: 3
149
145
  segments:
150
146
  - 0
151
147
  version: "0"
152
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
153
150
  requirements:
154
151
  - - ">="
155
152
  - !ruby/object:Gem::Version
153
+ hash: 23
156
154
  segments:
157
- - 0
158
- version: "0"
155
+ - 1
156
+ - 3
157
+ - 6
158
+ version: 1.3.6
159
159
  requirements: []
160
160
 
161
161
  rubyforge_project: faraday
162
- rubygems_version: 1.3.6
162
+ rubygems_version: 1.3.7
163
163
  signing_key:
164
164
  specification_version: 2
165
165
  summary: HTTP/REST API client library.