adamwiggins-rest-client 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,24 @@
1
1
  require 'rake'
2
+
3
+ require 'jeweler'
4
+
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "rest-client"
7
+ s.description = "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
8
+ s.summary = "Simple REST client for Ruby, inspired by microframework syntax for specifying actions."
9
+ s.author = "Adam Wiggins"
10
+ s.email = "adam@heroku.com"
11
+ s.homepage = "http://rest-client.heroku.com/"
12
+ s.rubyforge_project = "rest-client"
13
+ s.has_rdoc = true
14
+ s.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
15
+ s.executables = %w(restclient)
16
+ end
17
+
18
+ Jeweler::RubyforgeTasks.new
19
+
20
+ ############################
21
+
2
22
  require 'spec/rake/spectask'
3
23
 
4
24
  desc "Run all specs"
@@ -22,54 +42,9 @@ end
22
42
 
23
43
  task :default => :spec
24
44
 
25
- ######################################################
45
+ ############################
26
46
 
27
- require 'rake'
28
- require 'rake/testtask'
29
- require 'rake/clean'
30
- require 'rake/gempackagetask'
31
47
  require 'rake/rdoctask'
32
- require 'fileutils'
33
-
34
- version = "1.0.1"
35
- name = "rest-client"
36
-
37
- spec = Gem::Specification.new do |s|
38
- s.name = name
39
- s.version = version
40
- s.summary = "Simple REST client for Ruby, inspired by microframework syntax for specifying actions."
41
- s.description = "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
42
- s.author = "Adam Wiggins"
43
- s.email = "adam@heroku.com"
44
- s.homepage = "http://rest-client.heroku.com/"
45
- s.rubyforge_project = "rest-client"
46
-
47
- s.platform = Gem::Platform::RUBY
48
- s.has_rdoc = true
49
-
50
- s.files = %w(Rakefile README.rdoc) + Dir.glob("{lib,spec}/**/*")
51
- s.executables = ['restclient']
52
-
53
- s.require_path = "lib"
54
- end
55
-
56
- Rake::GemPackageTask.new(spec) do |p|
57
- p.need_tar = true if RUBY_PLATFORM !~ /mswin/
58
- end
59
-
60
- task :install => [ :package ] do
61
- sh %{sudo gem install pkg/#{name}-#{version}.gem}
62
- end
63
-
64
- task :uninstall => [ :clean ] do
65
- sh %{sudo gem uninstall #{name}}
66
- end
67
-
68
- Rake::TestTask.new do |t|
69
- t.libs << "spec"
70
- t.test_files = FileList['spec/*_spec.rb']
71
- t.verbose = true
72
- end
73
48
 
74
49
  Rake::RDocTask.new do |t|
75
50
  t.rdoc_dir = 'rdoc'
@@ -81,5 +56,3 @@ Rake::RDocTask.new do |t|
81
56
  t.rdoc_files.include('lib/restclient/*.rb')
82
57
  end
83
58
 
84
- CLEAN.include [ 'pkg', '*.gem', '.config' ]
85
-
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/mixin/response'
2
+
3
+ module RestClient
4
+ # The response from RestClient on a raw request looks like a string, but is
5
+ # actually one of these. 99% of the time you're making a rest call all you
6
+ # care about is the body, but on the occassion you want to fetch the
7
+ # headers you can:
8
+ #
9
+ # RestClient.get('http://example.com').headers[:content_type]
10
+ #
11
+ # In addition, if you do not use the response as a string, you can access
12
+ # a Tempfile object at res.file, which contains the path to the raw
13
+ # downloaded request body.
14
+ class RawResponse
15
+ include RestClient::Mixin::Response
16
+
17
+ attr_reader :file
18
+
19
+ def initialize(tempfile, net_http_res)
20
+ @net_http_res = net_http_res
21
+ @file = tempfile
22
+ end
23
+
24
+ def to_s
25
+ @file.open
26
+ @file.read
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/../base'
2
+
3
+ class MockResponse
4
+ include RestClient::Mixin::Response
5
+
6
+ def initialize(body, res)
7
+ @net_http_res = res
8
+ @body = @body
9
+ end
10
+ end
11
+
12
+ describe RestClient::Mixin::Response do
13
+ before do
14
+ @net_http_res = mock('net http response')
15
+ @response = MockResponse.new('abc', @net_http_res)
16
+ end
17
+
18
+ it "fetches the numeric response code" do
19
+ @net_http_res.should_receive(:code).and_return('200')
20
+ @response.code.should == 200
21
+ end
22
+
23
+ it "beautifies the headers by turning the keys to symbols" do
24
+ h = RestClient::Response.beautify_headers('content-type' => [ 'x' ])
25
+ h.keys.first.should == :content_type
26
+ end
27
+
28
+ it "beautifies the headers by turning the values to strings instead of one-element arrays" do
29
+ h = RestClient::Response.beautify_headers('x' => [ 'text/html' ] )
30
+ h.values.first.should == 'text/html'
31
+ end
32
+
33
+ it "fetches the headers" do
34
+ @net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
35
+ @response.headers.should == { :content_type => 'text/html' }
36
+ end
37
+
38
+ it "extracts cookies from response headers" do
39
+ @net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
40
+ @response.cookies.should == { 'session_id' => '1' }
41
+ end
42
+
43
+ it "can access the net http result directly" do
44
+ @response.net_http_res.should == @net_http_res
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ describe RestClient::RawResponse do
4
+ before do
5
+ @tf = mock("Tempfile", :read => "the answer is 42", :open => true)
6
+ @net_http_res = mock('net http response')
7
+ @response = RestClient::RawResponse.new(@tf, @net_http_res)
8
+ end
9
+
10
+ it "behaves like string" do
11
+ @response.to_s.should == 'the answer is 42'
12
+ end
13
+
14
+ it "exposes a Tempfile" do
15
+ @response.file.should == @tf
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adamwiggins-rest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Wiggins
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-16 00:00:00 -07:00
13
- default_executable:
12
+ date: 2009-06-20 00:00:00 -07:00
13
+ default_executable: restclient
14
14
  dependencies: []
15
15
 
16
16
  description: "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
@@ -19,31 +19,34 @@ executables:
19
19
  - restclient
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
24
  files:
25
- - Rakefile
26
25
  - README.rdoc
27
- - rest-client.gemspec
26
+ - Rakefile
27
+ - VERSION
28
+ - bin/restclient
28
29
  - lib/rest_client.rb
29
30
  - lib/restclient.rb
30
- - lib/restclient/request.rb
31
- - lib/restclient/response.rb
32
31
  - lib/restclient/exceptions.rb
33
- - lib/restclient/resource.rb
34
32
  - lib/restclient/mixin/response.rb
33
+ - lib/restclient/raw_response.rb
34
+ - lib/restclient/request.rb
35
+ - lib/restclient/resource.rb
36
+ - lib/restclient/response.rb
35
37
  - spec/base.rb
36
- - spec/request_spec.rb
37
- - spec/response_spec.rb
38
38
  - spec/exceptions_spec.rb
39
+ - spec/mixin/response_spec.rb
40
+ - spec/raw_response_spec.rb
41
+ - spec/request_spec.rb
39
42
  - spec/resource_spec.rb
43
+ - spec/response_spec.rb
40
44
  - spec/restclient_spec.rb
41
- - bin/restclient
42
45
  has_rdoc: true
43
46
  homepage: http://rest-client.heroku.com/
44
47
  post_install_message:
45
- rdoc_options: []
46
-
48
+ rdoc_options:
49
+ - --charset=UTF-8
47
50
  require_paths:
48
51
  - lib
49
52
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -65,5 +68,12 @@ rubygems_version: 1.2.0
65
68
  signing_key:
66
69
  specification_version: 2
67
70
  summary: Simple REST client for Ruby, inspired by microframework syntax for specifying actions.
68
- test_files: []
69
-
71
+ test_files:
72
+ - spec/base.rb
73
+ - spec/exceptions_spec.rb
74
+ - spec/mixin/response_spec.rb
75
+ - spec/raw_response_spec.rb
76
+ - spec/request_spec.rb
77
+ - spec/resource_spec.rb
78
+ - spec/response_spec.rb
79
+ - spec/restclient_spec.rb
data/rest-client.gemspec DELETED
@@ -1,22 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "rest-client"
3
- s.version = "1.0.1"
4
- s.summary = "Simple REST client for Ruby, inspired by microframework syntax for specifying actions."
5
- s.description = "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
6
- s.author = "Adam Wiggins"
7
- s.email = "adam@heroku.com"
8
- s.rubyforge_project = "rest-client"
9
- s.homepage = "http://rest-client.heroku.com/"
10
- s.has_rdoc = true
11
- s.platform = Gem::Platform::RUBY
12
- s.files = %w(Rakefile README.rdoc rest-client.gemspec
13
- lib/rest_client.rb lib/restclient.rb
14
- lib/restclient/request.rb lib/restclient/response.rb
15
- lib/restclient/exceptions.rb lib/restclient/resource.rb
16
- lib/restclient/mixin/response.rb
17
- spec/base.rb spec/request_spec.rb spec/response_spec.rb
18
- spec/exceptions_spec.rb spec/resource_spec.rb spec/restclient_spec.rb
19
- bin/restclient)
20
- s.executables = ['restclient']
21
- s.require_path = "lib"
22
- end