This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| 87a2fe2f » | jnewland | 2008-02-21 | 1 | require File.dirname(__FILE__) + '/spec_helper.rb' | |
| 2 | |||||
| 32afa859 » | jnewland | 2008-02-21 | 3 | describe "FireEagle" do | |
| 5136b32c » | jnewland | 2008-02-22 | 4 | ||
| 32afa859 » | jnewland | 2008-02-21 | 5 | describe "being initialized" do | |
| 6 | |||||
| 7 | it "should require OAuth Consumer Key and Secret" do | ||||
| 8 | lambda do | ||||
| 705df51c » | jnewland | 2008-02-22 | 9 | client = FireEagle::Client.new({}) | |
| 10 | end.should raise_error(FireEagle::ArgumentError) | ||||
| 32afa859 » | jnewland | 2008-02-21 | 11 | end | |
| 5136b32c » | jnewland | 2008-02-22 | 12 | ||
| 32afa859 » | jnewland | 2008-02-21 | 13 | it "should initialize an OAuth::Consumer" do | |
| 14 | @consumer = mock(OAuth::Consumer) | ||||
| 4dc8c948 » | kamal | 2008-03-13 | 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 | 16 | client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret') | |
| 17 | end | ||||
| 5136b32c » | jnewland | 2008-02-22 | 18 | ||
| 32afa859 » | jnewland | 2008-02-21 | 19 | end | |
| 5136b32c » | jnewland | 2008-02-22 | 20 | ||
| 32afa859 » | jnewland | 2008-02-21 | 21 | describe "web app authentication scenario" do | |
| 5136b32c » | jnewland | 2008-02-22 | 22 | ||
| 4dc8c948 » | kamal | 2008-03-13 | 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 | 26 | client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret', :access_token => 'toke', :access_token_secret => 'sekret') | |
| e6ca7341 » | jnewland | 2008-02-27 | 27 | client.access_token.should == @access_token | |
| 28 | end | ||||
| 29 | |||||
| 4dc8c948 » | kamal | 2008-03-13 | 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 | 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 | 35 | end | |
| 36 | end | ||||
| 5136b32c » | jnewland | 2008-02-22 | 37 | ||
| 32afa859 » | jnewland | 2008-02-21 | 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 | 41 | client.access_token.should be_nil | |
| 32afa859 » | jnewland | 2008-02-21 | 42 | end | |
| 5136b32c » | jnewland | 2008-02-22 | 43 | ||
| 705df51c » | jnewland | 2008-02-22 | 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 | 51 | it "should generate a Request Token URL" do | |
| 4dc8c948 » | kamal | 2008-03-13 | 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 | 57 | client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret') | |
| 4dc8c948 » | kamal | 2008-03-13 | 58 | client.should_receive(:consumer).and_return(consumer) | |
| 601b21c1 » | jnewland | 2008-02-27 | 59 | client.get_request_token | |
| 4dc8c948 » | kamal | 2008-03-13 | 60 | client.authorization_url | |
| 32afa859 » | jnewland | 2008-02-21 | 61 | end | |
| 5136b32c » | jnewland | 2008-02-22 | 62 | ||
| 9ef1a48b » | jnewland | 2008-02-27 | 63 | it "should require #get_request_token be called before #convert_to_access_token" do | |
| 32afa859 » | jnewland | 2008-02-21 | 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 | 69 | ||
| 9ef1a48b » | jnewland | 2008-02-27 | 70 | it "should require #get_request_token be called before #authorization_url" do | |
| 601b21c1 » | jnewland | 2008-02-27 | 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 | 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 | 84 | client = FireEagle::Client.new(:consumer_key => 'key', :consumer_secret => 'sekret') | |
| 4dc8c948 » | kamal | 2008-03-13 | 85 | client.should_receive(:consumer).and_return(consumer) | |
| 86 | |||||
| 601b21c1 » | jnewland | 2008-02-27 | 87 | client.get_request_token | |
| 32afa859 » | jnewland | 2008-02-21 | 88 | client.convert_to_access_token | |
| 4dc8c948 » | kamal | 2008-03-13 | 89 | client.access_token.should == acc_token | |
| 32afa859 » | jnewland | 2008-02-21 | 90 | end | |
| 5136b32c » | jnewland | 2008-02-22 | 91 | ||
| e360613c » | jnewland | 2008-02-22 | 92 | end | |
| 93 | |||||
| 8a4ebbaf » | jnewland | 2008-02-25 | 94 | describe "update method" do | |
| 38f4508c » | jnewland | 2008-02-22 | 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 | 98 | @response = stub('response', :body => XML_SUCCESS_RESPONSE) | |
| 90239b73 » | kamal | 2008-03-13 | 99 | @client.stub!(:request).and_return(@response) | |
| 38f4508c » | jnewland | 2008-02-22 | 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 | 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 | 110 | end | |
| 111 | |||||
| 5136b32c » | jnewland | 2008-02-22 | 112 | it "should wrap the result" do | |
| b9616fa6 » | kamal | 2008-03-11 | 113 | @client.update(:mcc => 123, :mnc => 123123, :lac => "whatever", :cellid => true).users.first.token.should == "16w3z6ysudxt" | |
| 5136b32c » | jnewland | 2008-02-22 | 114 | end | |
| 115 | |||||
| 116 | end | ||||
| 117 | |||||
| 8a4ebbaf » | jnewland | 2008-02-25 | 118 | describe "user method" do | |
| 5136b32c » | jnewland | 2008-02-22 | 119 | ||
| 120 | before(:each) do | ||||
| 5131d65e » | kamal | 2008-03-13 | 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 | 123 | @client.stub!(:request).and_return(response) | |
| 5136b32c » | jnewland | 2008-02-22 | 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 | 130 | it "should return several locations" do | |
| c16538d3 » | kamal | 2008-03-11 | 131 | @client.user.should have(4).locations | |
| 5136b32c » | jnewland | 2008-02-22 | 132 | end | |
| 133 | |||||
| 38f4508c » | jnewland | 2008-02-22 | 134 | end | |
| 2f3b6d28 » | kamal | 2008-03-10 | 135 | ||
| 8a4ebbaf » | jnewland | 2008-02-25 | 136 | describe "lookup method" do | |
| 137 | before(:each) do | ||||
| e61e6882 » | kamal | 2008-03-13 | 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 | 143 | end | |
| 144 | |||||
| 145 | it "should return an array of Locations" do | ||||
| 2f3b6d28 » | kamal | 2008-03-10 | 146 | @client.lookup(:q => "30022").should have(9).items | |
| 8a4ebbaf » | jnewland | 2008-02-25 | 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 | 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 | 162 | end | |
| 38f4508c » | jnewland | 2008-02-22 | 163 | ||
| 32e763c6 » | kamal | 2008-03-11 | 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 | 168 | @client.stub!(:request).and_return(@response) | |
| 32e763c6 » | kamal | 2008-03-11 | 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 | 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 | 180 | @client.stub!(:request).and_return(@response) | |
| 5b62d4eb » | kamal | 2008-03-11 | 181 | end | |
| 182 | |||||
| 183 | it "should return an array of Users" do | ||||
| 75194727 » | jnewland | 2008-08-12 | 184 | @client.recent('yesterday', 3, 1).should have(3).users | |
| 5b62d4eb » | kamal | 2008-03-11 | 185 | end | |
| 186 | |||||
| 543627a7 » | jnewland | 2008-07-31 | 187 | it "should have an 'located_at' timestamp for each user" do | |
| 75194727 » | jnewland | 2008-08-12 | 188 | @client.recent('yesterday', 3, 1).first.located_at.should == Time.parse('2008-07-31T22:31:37+12:00') | |
| 5b62d4eb » | kamal | 2008-03-11 | 189 | end | |
| 190 | end | ||||
| 191 | |||||
| a904e42d » | kamal | 2008-03-13 | 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 | 225 | end | |








