Permalink
Browse files

Created an API namespace with API Requests.

  • Loading branch information...
1 parent 3e7ee26 commit c914b1d83a1c5221e86e7fe124ecf485b7b9c7d8 @kevintuhumury kevintuhumury committed Mar 18, 2012
View
@@ -1,6 +1,7 @@
require "httparty"
require "core_ext/hash"
-require "cameraplus/request"
+require "cameraplus/api/request"
+require "cameraplus/api/user"
require "cameraplus/user"
require "cameraplus/version"
@@ -0,0 +1,31 @@
+module Cameraplus
+ module API
+ class Request
+ include HTTParty
+
+ base_uri "http://camerapl.us"
+
+ format :json
+
+ def self.call(url, options = {})
+ new(url, options).response
+ end
+
+ 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
+end
@@ -0,0 +1,17 @@
+module Cameraplus
+ module API
+ class User
+
+ def self.find(identifier, options = {})
+ Request.call(uri(identifier), options)
+ end
+
+ private
+
+ def self.uri(identifier)
+ "/user/#{identifier}:pages"
+ end
+
+ end
+ end
+end
@@ -1,29 +0,0 @@
-module Cameraplus
- class Request
- include HTTParty
-
- base_uri "http://camerapl.us"
-
- format :json
-
- def self.call(url, options = {})
- new(url, options).response
- end
-
- 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
@@ -13,7 +13,7 @@ def initialize(data)
end
def self.find(identifier, options = {})
- new Request.new("/user/#{identifier}:pages", options).response
+ new Cameraplus::API::User.find(identifier, options)
end
end
@@ -1,8 +1,8 @@
require "spec_helper"
-describe Cameraplus::Request do
+describe Cameraplus::API::Request do
- subject { Cameraplus::Request }
+ subject { Cameraplus::API::Request }
context "configuration" do
@@ -0,0 +1,17 @@
+require "spec_helper"
+
+describe Cameraplus::API::User do
+
+ use_vcr_cassette :user
+
+ it "should be a hash" do
+ response = Cameraplus::API::User.find("mostlylisa")
+ response.should be_a Hash
+ end
+
+ it "should make a request to the Camera+ API" do
+ Cameraplus::API::Request.should_receive(:call).with("/user/mostlylisa:pages", {})
+ Cameraplus::API::User.find("mostlylisa")
+ end
+
+end
@@ -6,28 +6,36 @@
let(:user) { Cameraplus::User.find "mostlylisa" }
- it "finds the id of the specified user" do
- user.id.should eq 6978642
+ it "should be a User" do
+ user.class.should eq Cameraplus::User
end
- it "finds the username of the specified user" do
- user.username.should eq "mostlylisa"
- end
+ context ".find" do
- it "finds the name of the specified user" do
- user.name.should eq "Lisa Bettany"
- end
+ it "finds the id of the specified user" do
+ user.id.should eq 6978642
+ end
- it "finds the avatar of the specified user" do
- user.avatar.should eq "http://a0.twimg.com/profile_images/1767370289/284161_10150711631895637_674215636_19658534_6246798_n_normal.jpeg"
- end
+ it "finds the username of the specified user" do
+ user.username.should eq "mostlylisa"
+ end
- it "finds the number of pages of the specified user" do
- user.page_count.should eq 120
- end
+ it "finds the name of the specified user" do
+ user.name.should eq "Lisa Bettany"
+ end
+
+ it "finds the avatar of the specified user" do
+ user.avatar.should eq "http://a0.twimg.com/profile_images/1767370289/284161_10150711631895637_674215636_19658534_6246798_n_normal.jpeg"
+ end
+
+ it "finds the number of pages of the specified user" do
+ user.page_count.should eq 120
+ end
+
+ it "finds the number of photos of the specified user" do
+ user.photo_count.should eq 874
+ end
- it "finds the number of photos of the specified user" do
- user.photo_count.should eq 874
end
end
@@ -17,17 +17,17 @@ http_interactions:
Content-Type:
- application/json
Date:
- - Fri, 16 Mar 2012 23:03:17 GMT
+ - Sat, 17 Mar 2012 09:21:59 GMT
Expires:
- Thu, 19 Nov 1981 08:52:00 GMT
Pragma:
- no-cache
Server:
- Apache/2.2.21 (Amazon)
Set-Cookie:
- - PHPSESSID=qsnqtmblp2ks0pr5d4grlelkm5; expires=Wed, 12-Sep-2012 23:03:18 GMT;
+ - PHPSESSID=ognro869qkal3uoebh365mhpv7; expires=Thu, 13-Sep-2012 09:21:59 GMT;
path=/; domain=.campl.us
- - PHPSESSID=qsnqtmblp2ks0pr5d4grlelkm5; expires=Wed, 12-Sep-2012 23:03:18 GMT;
+ - PHPSESSID=ognro869qkal3uoebh365mhpv7; expires=Thu, 13-Sep-2012 09:21:59 GMT;
path=/; domain=.campl.us
X-Powered-By:
- PHP/5.3.10
@@ -40,7 +40,7 @@ http_interactions:
string: ! '{"user":{"userid":6978642,"username":"mostlylisa","realname":"Lisa
Bettany","avatar":"http:\/\/a0.twimg.com\/profile_images\/1767370289\/284161_10150711631895637_674215636_19658534_6246798_n_normal.jpeg","pages":120,"pictures":874},"pages":[{"url":"http:\/\/campl.us\/iao4","tweettext":"Carnival
in Venice, a travel photographer''s dream shoot!","tweetid":"180064216093437954","timestamp":"2012-03-14
- 22:53:49","views":1895,"comments":1,"location":"45.43383498680353 12.34226474539595","locationname":"Venice,
+ 22:53:49","views":1951,"comments":1,"location":"45.43383498680353 12.34226474539595","locationname":"Venice,
Venice","images":[{"800px":"http:\/\/pics.campl.us\/f\/0\/0b497f01791c851db1a17f81e0621a5c.jpg","120px":"http:\/\/pics.campl.us\/t\/0\/0b497f01791c851db1a17f81e0621a5c.jpg","480px":"http:\/\/pics.campl.us\/iphone\/0\/0b497f01791c851db1a17f81e0621a5c.jpg","fullwidth":800,"fullheight":590,"location":"45.43383498680353
12.34226474539595"},{"800px":"http:\/\/pics.campl.us\/f\/a\/a2fb3bfe849f16f5420f4ca8348f33a0.jpg","120px":"http:\/\/pics.campl.us\/t\/a\/a2fb3bfe849f16f5420f4ca8348f33a0.jpg","480px":"http:\/\/pics.campl.us\/iphone\/a\/a2fb3bfe849f16f5420f4ca8348f33a0.jpg","fullwidth":800,"fullheight":601,"location":"45.43305496689438
12.33965336346285"},{"800px":"http:\/\/pics.campl.us\/f\/e\/e40e677a67af931391d1b0c2fdebc6f9.jpg","120px":"http:\/\/pics.campl.us\/t\/e\/e40e677a67af931391d1b0c2fdebc6f9.jpg","480px":"http:\/\/pics.campl.us\/iphone\/e\/e40e677a67af931391d1b0c2fdebc6f9.jpg","fullwidth":800,"fullheight":600,"location":"45.43375707701355
@@ -69,5 +69,5 @@ http_interactions:
12.34029692598837"},{"800px":"http:\/\/pics.campl.us\/f\/e\/e8170f8e597d23a45eafba6be863607c.jpg","120px":"http:\/\/pics.campl.us\/t\/e\/e8170f8e597d23a45eafba6be863607c.jpg","480px":"http:\/\/pics.campl.us\/iphone\/e\/e8170f8e597d23a45eafba6be863607c.jpg","fullwidth":655,"fullheight":800,"location":""},{"800px":"http:\/\/pics.campl.us\/f\/c\/c783e4c9dd68ec7dc2cc6aa390c2df81.jpg","120px":"http:\/\/pics.campl.us\/t\/c\/c783e4c9dd68ec7dc2cc6aa390c2df81.jpg","480px":"http:\/\/pics.campl.us\/iphone\/c\/c783e4c9dd68ec7dc2cc6aa390c2df81.jpg","fullwidth":600,"fullheight":800,"location":"45.45624578150769
12.35432020530416"}]}],"next":"http:\/\/camerapl.us\/user\/mostlylisa:pages?continue=iao4"}'
http_version:
- recorded_at: Fri, 16 Mar 2012 23:03:18 GMT
+ recorded_at: Sat, 17 Mar 2012 09:22:00 GMT
recorded_with: VCR 2.0.0

0 comments on commit c914b1d

Please sign in to comment.