public
Description: Ruby wrapper for Yahoo!'s FireEagle
Homepage: http://fireeagle.rubyforge.org/
Clone URL: git://github.com/jnewland/fireeagle.git
mojodna (author)
Wed Jun 10 15:45:11 -0700 2009
jnewland (committer)
Thu Jul 30 07:06:19 -0700 2009
fireeagle / spec / fireeagle_spec.rb
87a2fe2f » jnewland 2008-02-21 rubyforge jumping jacks. gi... 1 require File.dirname(__FILE__) + '/spec_helper.rb'
2
32afa859 » jnewland 2008-02-21 specs for the authorization... 3 describe "FireEagle" do
5136b32c » jnewland 2008-02-22 works. docs next 4
32afa859 » jnewland 2008-02-21 specs for the authorization... 5 describe "being initialized" do
6
7 it "should require OAuth Consumer Key and Secret" do
8 lambda do
705df51c » jnewland 2008-02-22 pretty happy with the auth ... 9 client = FireEagle::Client.new({})
10 end.should raise_error(FireEagle::ArgumentError)
32afa859 » jnewland 2008-02-21 specs for the authorization... 11 end
5136b32c » jnewland 2008-02-22 works. docs next 12
32afa859 » jnewland 2008-02-21 specs for the authorization... 13 it "should initialize an OAuth::Consumer" do
14 @consumer = mock(OAuth::Consumer)
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 15 OAuth::Consumer.should_receive(:new).with('key', 'sekret', :site => FireEagle::API_SERVER, :authorize_url => FireEagle::AUTHORIZATION_URL).and_return(@consumer)
32afa859 » jnewland 2008-02-21 specs for the authorization... 16 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret')
17 end
5136b32c » jnewland 2008-02-22 works. docs next 18
32afa859 » jnewland 2008-02-21 specs for the authorization... 19 end
5136b32c » jnewland 2008-02-22 works. docs next 20
32afa859 » jnewland 2008-02-21 specs for the authorization... 21 describe "web app authentication scenario" do
5136b32c » jnewland 2008-02-22 works. docs next 22
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 23 it "should initialize an OAuth::AccessToken if given its token and secret" do
24 @access_token = mock(OAuth::AccessToken)
25 OAuth::AccessToken.stub!(:new).and_return(@access_token)
32afa859 » jnewland 2008-02-21 specs for the authorization... 26 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :access_token => 'toke', :access_token_secret => 'sekret')
e6ca7341 » jnewland 2008-02-27 allow client init with :req... 27 client.access_token.should == @access_token
28 end
29
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 30 it "should initialize an OAuth::RequestToken if given its token and secret" do
31 @request_token = mock(OAuth::RequestToken)
32 OAuth::RequestToken.stub!(:new).and_return(@request_token)
e6ca7341 » jnewland 2008-02-27 allow client init with :req... 33 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :request_token => 'toke', :request_token_secret => 'sekret')
34 client.request_token.should == @request_token
32afa859 » jnewland 2008-02-21 specs for the authorization... 35 end
36 end
5136b32c » jnewland 2008-02-22 works. docs next 37
32afa859 » jnewland 2008-02-21 specs for the authorization... 38 describe "request token scenario" do
39 it "shouldn't initialize with a access_token" do
40 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret')
2f3b6d28 » kamal 2008-03-10 Convert some specs to use r... 41 client.access_token.should be_nil
32afa859 » jnewland 2008-02-21 specs for the authorization... 42 end
5136b32c » jnewland 2008-02-22 works. docs next 43
705df51c » jnewland 2008-02-22 pretty happy with the auth ... 44 it "should require token exchange before calling any API methods" do
45 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret')
46 lambda do
47 client.user
48 end.should raise_error(FireEagle::ArgumentError)
49 end
50
32afa859 » jnewland 2008-02-21 specs for the authorization... 51 it "should generate a Request Token URL" do
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 52 consumer = mock(OAuth::Consumer)
53 token = mock(OAuth::RequestToken)
54 consumer.should_receive(:get_request_token).and_return(token)
55 token.should_receive(:authorize_url)
56
32afa859 » jnewland 2008-02-21 specs for the authorization... 57 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret')
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 58 client.should_receive(:consumer).and_return(consumer)
601b21c1 » jnewland 2008-02-27 make things match up with t... 59 client.get_request_token
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 60 client.authorization_url
32afa859 » jnewland 2008-02-21 specs for the authorization... 61 end
5136b32c » jnewland 2008-02-22 works. docs next 62
9ef1a48b » jnewland 2008-02-27 typozzzz 63 it "should require #get_request_token be called before #convert_to_access_token" do
32afa859 » jnewland 2008-02-21 specs for the authorization... 64 lambda do
65 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret')
66 client.convert_to_access_token
67 end.should raise_error(FireEagle::ArgumentError)
68 end
5136b32c » jnewland 2008-02-22 works. docs next 69
9ef1a48b » jnewland 2008-02-27 typozzzz 70 it "should require #get_request_token be called before #authorization_url" do
601b21c1 » jnewland 2008-02-27 make things match up with t... 71 lambda do
72 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret')
73 client.authorization_url
74 end.should raise_error(FireEagle::ArgumentError)
75 end
76
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 77 it "should generate an Access Token" do
78 consumer = mock(OAuth::Consumer)
79 req_token = mock(OAuth::RequestToken)
80 acc_token = mock(OAuth::AccessToken)
81 consumer.should_receive(:get_request_token).and_return(req_token)
82 req_token.should_receive(:get_access_token).and_return(acc_token)
83
32afa859 » jnewland 2008-02-21 specs for the authorization... 84 client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret')
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 85 client.should_receive(:consumer).and_return(consumer)
86
601b21c1 » jnewland 2008-02-27 make things match up with t... 87 client.get_request_token
32afa859 » jnewland 2008-02-21 specs for the authorization... 88 client.convert_to_access_token
4dc8c948 » kamal 2008-03-13 Get OAuth do the heavy lift... 89 client.access_token.should == acc_token
32afa859 » jnewland 2008-02-21 specs for the authorization... 90 end
5136b32c » jnewland 2008-02-22 works. docs next 91
e360613c » jnewland 2008-02-22 add the location class and ... 92 end
93
8a4ebbaf » jnewland 2008-02-25 specs and thus fixes for #l... 94 describe "update method" do
38f4508c » jnewland 2008-02-22 refactor the updating code ... 95
96 before(:each) do
97 @client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :access_token => 'toke', :access_token_secret => 'sekret')
321baa21 » kamal 2008-03-10 mock() doesn't stub methods... 98 @response = stub('response', :body => XML_SUCCESS_RESPONSE)
90239b73 » kamal 2008-03-13 Go back to stubbing request... 99 @client.stub!(:request).and_return(@response)
38f4508c » jnewland 2008-02-22 refactor the updating code ... 100 end
101
102 it "requires all or none of :lat, :lon" do
103 lambda { @client.update(:lat => 1) }.should raise_error(FireEagle::ArgumentError)
104 lambda { @client.update(:lat => 1, :lon => 2) }.should_not raise_error(FireEagle::ArgumentError)
105 end
106
b9616fa6 » kamal 2008-03-11 Fire Eagle changed the look... 107 it "requires all or none of :mnc, :mcc, :lac, :cellid" do
108 lambda { @client.update(:mcc => 123, :lac => "whatever", :cellid => true) }.should raise_error(FireEagle::ArgumentError)
109 lambda { @client.update(:mcc => 123, :mnc => 123123, :lac => "whatever", :cellid => true) }.should_not raise_error(FireEagle::ArgumentError)
38f4508c » jnewland 2008-02-22 refactor the updating code ... 110 end
111
5136b32c » jnewland 2008-02-22 works. docs next 112 it "should wrap the result" do
b9616fa6 » kamal 2008-03-11 Fire Eagle changed the look... 113 @client.update(:mcc => 123, :mnc => 123123, :lac => "whatever", :cellid => true).users.first.token.should == "16w3z6ysudxt"
5136b32c » jnewland 2008-02-22 works. docs next 114 end
115
116 end
117
8a4ebbaf » jnewland 2008-02-25 specs and thus fixes for #l... 118 describe "user method" do
5136b32c » jnewland 2008-02-22 works. docs next 119
120 before(:each) do
5131d65e » kamal 2008-03-13 Use access token to perform... 121 @client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :access_token => 'toke', :access_token_secret => 'sekret')
122 response = stub('response', :body => XML_LOCATION_RESPONSE)
90239b73 » kamal 2008-03-13 Go back to stubbing request... 123 @client.stub!(:request).and_return(response)
5136b32c » jnewland 2008-02-22 works. docs next 124 end
125
126 it "should return a best guess" do
127 @client.user.best_guess.name.should == "Yolo County, California"
128 end
129
8a4ebbaf » jnewland 2008-02-25 specs and thus fixes for #l... 130 it "should return several locations" do
c16538d3 » kamal 2008-03-11 Take advantage of more RSpe... 131 @client.user.should have(4).locations
5136b32c » jnewland 2008-02-22 works. docs next 132 end
133
38f4508c » jnewland 2008-02-22 refactor the updating code ... 134 end
2f3b6d28 » kamal 2008-03-10 Convert some specs to use r... 135
8a4ebbaf » jnewland 2008-02-25 specs and thus fixes for #l... 136 describe "lookup method" do
137 before(:each) do
e61e6882 » kamal 2008-03-13 Let FireEagle::Response.new... 138 @client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :access_token => 'toke', :access_token_secret => 'sekret')
139 response = stub('response', :body => XML_LOOKUP_RESPONSE)
140 fail_response = stub('fail response', :body => XML_FAIL_LOOKUP_RESPONSE)
141 @client.stub!(:request).with(:get, FireEagle::LOOKUP_API_PATH, :params => {:q => "30022"}).and_return(response)
142 @client.stub!(:request).with(:get, FireEagle::LOOKUP_API_PATH, :params => {:mnc => 12, :mcc => 502, :lac => 2051, :cellid => 39091}).and_return(fail_response)
8a4ebbaf » jnewland 2008-02-25 specs and thus fixes for #l... 143 end
144
145 it "should return an array of Locations" do
2f3b6d28 » kamal 2008-03-10 Convert some specs to use r... 146 @client.lookup(:q => "30022").should have(9).items
8a4ebbaf » jnewland 2008-02-25 specs and thus fixes for #l... 147 end
148
149 it "should return a place id for each" do
150 @client.lookup(:q => "30022").first.place_id.should == "IrhZMHuYA5s1fFi4Qw"
151 end
152
153 it "should return a name for each" do
154 @client.lookup(:q => "30022").first.name.should == "Alpharetta, GA 30022"
155 end
156
e61e6882 » kamal 2008-03-13 Let FireEagle::Response.new... 157 it "should raise an exception if the lookup failed" do
158 lambda {
159 @client.lookup(:mnc => 12, :mcc => 502, :lac => 2051, :cellid => 39091)
160 }.should raise_error(FireEagle::FireEagleException, "Place can't be identified.")
161 end
8a4ebbaf » jnewland 2008-02-25 specs and thus fixes for #l... 162 end
38f4508c » jnewland 2008-02-22 refactor the updating code ... 163
32e763c6 » kamal 2008-03-11 Spec Client#within 164 describe "within method" do
165 before do
166 @client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :access_token => 'toke', :access_token_secret => 'sekret')
167 @response = stub('response', :body => XML_WITHIN_RESPONSE)
90239b73 » kamal 2008-03-13 Go back to stubbing request... 168 @client.stub!(:request).and_return(@response)
32e763c6 » kamal 2008-03-11 Spec Client#within 169 end
170
171 it "should return an array of Users" do
172 @client.within(:woe => "12796255").should have(2).users
173 end
174 end
5b62d4eb » kamal 2008-03-11 Add time parameter to Clien... 175
176 describe "recent method" do
177 before do
178 @client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :access_token => 'toke', :access_token_secret => 'sekret')
179 @response = stub('response', :body => XML_RECENT_RESPONSE)
90239b73 » kamal 2008-03-13 Go back to stubbing request... 180 @client.stub!(:request).and_return(@response)
5b62d4eb » kamal 2008-03-11 Add time parameter to Clien... 181 end
182
183 it "should return an array of Users" do
75194727 » jnewland 2008-08-12 A couple changes: 184 @client.recent('yesterday', 3, 1).should have(3).users
5b62d4eb » kamal 2008-03-11 Add time parameter to Clien... 185 end
186
543627a7 » jnewland 2008-07-31 update 'recent' method to s... Comment 187 it "should have an 'located_at' timestamp for each user" do
75194727 » jnewland 2008-08-12 A couple changes: 188 @client.recent('yesterday', 3, 1).first.located_at.should == Time.parse('2008-07-31T22:31:37+12:00')
5b62d4eb » kamal 2008-03-11 Add time parameter to Clien... 189 end
190 end
191
a904e42d » kamal 2008-03-13 Handle 404 Not Found respon... 192 describe "making a request" do
193 before do
194 @client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :access_token => 'toke', :access_token_secret => 'sekret')
195 @access_token = stub('access token')
196 @client.stub!(:access_token).and_return(@access_token)
197 end
198
199 it "should not raise any exception when response is OK" do
200 response = stub('response', :code => '200', :body => XML_RECENT_RESPONSE)
201 @access_token.stub!(:request).and_return(response)
202 lambda { @client.recent }.should_not raise_error
203 end
204
205 it "should raise an exception when requesting to a resource that doesn't exist (404)" do
206 response = stub('response', :code => '404', :body => '')
207 @access_token.stub!(:request).and_return(response)
208 lambda { @client.recent }.should raise_error(FireEagle::FireEagleException, 'Not Found')
209 end
210
211 it "should raise an exception when requesting to a resource that hit an internal server error (500)" do
212 response = stub('response', :code => '500', :body => '')
213 @access_token.stub!(:request).and_return(response)
214 lambda { @client.recent }.should raise_error(FireEagle::FireEagleException, 'Internal Server Error')
215 end
216
217 it "should raise an exception when response is apart from 200, 404 and 500" do
218 %w{401 403 405}.each do |code|
219 response = stub('response', :code => code, :body => XML_ERROR_RESPONSE)
220 @access_token.stub!(:request).and_return(response)
221 lambda { @client.recent }.should raise_error(FireEagle::FireEagleException, 'Something bad happened')
222 end
223 end
224 end
32e763c6 » kamal 2008-03-11 Spec Client#within 225 end