Permalink
Browse files

Added the Cameraplus::Request class.

  • Loading branch information...
1 parent b226d0f commit 28c84a868a92673fc0dfcca7c0050cf89f0bb665 @kevintuhumury kevintuhumury committed Mar 16, 2012
Showing with 140 additions and 4 deletions.
  1. +3 −4 lib/cameraplus.rb
  2. +25 −0 lib/cameraplus/request.rb
  3. +39 −0 spec/cameraplus/request_spec.rb
  4. +73 −0 spec/vcr_cassettes/request_api.yml
View
@@ -1,5 +1,4 @@
-require "cameraplus/version"
+require "httparty"
-module Cameraplus
- # Your code goes here...
-end
+require "cameraplus/request"
+require "cameraplus/version"
View
@@ -0,0 +1,25 @@
+module Cameraplus
+ class Request
+ include HTTParty
+
+ base_uri "http://camerapl.us"
+
+ format :json
+
+ def initialize(url, options = {})
+ @url = url
+ @options = options
+ end
+
+ def response
+ request.parsed_response
+ end
+
+ private
+
+ def request
+ self.class.get(@url, query: @options)
+ end
+
+ end
+end
@@ -0,0 +1,39 @@
+require "spec_helper"
+
+describe Cameraplus::Request do
+
+ subject { Cameraplus::Request }
+
+ context "configuration" do
+
+ it "should know it's base URI" do
+ subject.base_uri.should eq "http://camerapl.us"
+ end
+
+ it "should know it's response format" do
+ subject.format.should eq :json
+ end
+
+ end
+
+ context "connecting with the api" do
+
+ use_vcr_cassette :request_api
+
+ let(:response) { subject.new("/user/mostlylisa:pages").response }
+
+ it "should have a response" do
+ response.should_not be_nil
+ end
+
+ it "should contain user data" do
+ response.should have_key "user"
+ end
+
+ it "should contain user pages" do
+ response.should have_key "pages"
+ end
+
+ end
+
+end

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 28c84a8

Please sign in to comment.