From 3b2aa69e5d16b738b386b9a1120b24a3eac9b437 Mon Sep 17 00:00:00 2001 From: Tyler Montgomery Date: Mon, 10 Oct 2011 11:39:10 -0600 Subject: [PATCH 1/2] Added response object that returns body and status (as an integer no way!), so HEAD works, which is cool --- .rvmrc | 1 + lib/http.rb | 2 ++ lib/http/client.rb | 3 ++- lib/http/response.rb | 11 +++++++++++ spec/http_spec.rb | 6 +++--- 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .rvmrc create mode 100644 lib/http/response.rb diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 00000000..66b93623 --- /dev/null +++ b/.rvmrc @@ -0,0 +1 @@ +rvm 1.9.2@http --create diff --git a/lib/http.rb b/lib/http.rb index 07e80a7c..325b19f2 100644 --- a/lib/http.rb +++ b/lib/http.rb @@ -3,6 +3,8 @@ require 'http/client' require 'http/mime_type' require 'http/parameters' +require 'http/response' + # THIS IS ENTIRELY TEMPORARY, I ASSURE YOU require 'net/https' diff --git a/lib/http/client.rb b/lib/http/client.rb index 949fe86f..f388109a 100644 --- a/lib/http/client.rb +++ b/lib/http/client.rb @@ -81,10 +81,11 @@ def request(verb, options = {}) case options[:response] when :parsed_body - parse_response response + response.body = parse_response(response) else response.body end + Http::Response.new(response.body, response.code) end # Parse the response body according to its content type diff --git a/lib/http/response.rb b/lib/http/response.rb new file mode 100644 index 00000000..fd7613ff --- /dev/null +++ b/lib/http/response.rb @@ -0,0 +1,11 @@ +module Http + class Response + attr_accessor :body + attr_accessor :status + + def initialize(body, status) + @body = body + @status = status.to_i + end + end +end diff --git a/spec/http_spec.rb b/spec/http_spec.rb index 7a17eed0..65ef9d13 100644 --- a/spec/http_spec.rb +++ b/spec/http_spec.rb @@ -6,7 +6,7 @@ it "should be easy" do # Fuck it, we'll do it live! (Testing against WEBRick or something coming soon) response = Http.get "http://www.google.com" - response.should match(//) + response.body.should match(//) end context "with headers" do @@ -14,7 +14,7 @@ response = Http.accept(:json).get("https://github.com/tarcieri/http/commit/HEAD") # Congratulations first committer, your prize is to break the build! - response['commit']['author']['name'].should == "Tony Arcieri" + response.body['commit']['author']['name'].should == "Tony Arcieri" end end end @@ -24,7 +24,7 @@ fragment = "example" response = Http.post "http://validator.w3.org/check", :form => {:fragment => fragment} - response.should match(/HTML5/) + response.body.should match(/HTML5/) end end end From 68f56e41f0dd513a5f531d9fb25b394d437669cc Mon Sep 17 00:00:00 2001 From: Tyler Montgomery Date: Tue, 11 Oct 2011 11:21:43 -0600 Subject: [PATCH 2/2] Ignore rvmrc --- .gitignore | 1 + .rvmrc | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 .rvmrc diff --git a/.gitignore b/.gitignore index d87d4be6..f1fdeb51 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ spec/reports test/tmp test/version_tmp tmp +.rvmrc diff --git a/.rvmrc b/.rvmrc deleted file mode 100644 index 66b93623..00000000 --- a/.rvmrc +++ /dev/null @@ -1 +0,0 @@ -rvm 1.9.2@http --create