Permalink
Browse files

Adding support for the new rate_limit_status method.

  • Loading branch information...
1 parent 27745af commit 2b5325b1875574805fde77f30d0df84e423272e5 @danielmorrison danielmorrison committed Jun 29, 2008
Showing with 60 additions and 1 deletion.
  1. +2 −1 lib/twitter.rb
  2. +4 −0 lib/twitter/base.rb
  3. +19 −0 lib/twitter/rate_limit_status.rb
  4. +28 −0 spec/base_spec.rb
  5. +7 −0 spec/fixtures/rate_limit_status.xml
View
@@ -5,4 +5,5 @@
require 'twitter/base'
require 'twitter/user'
require 'twitter/status'
-require 'twitter/direct_message'
+require 'twitter/direct_message'
+require 'twitter/rate_limit_status'
View
@@ -68,6 +68,10 @@ def destroy(id)
call("destroy/#{id}")
end
+ def rate_limit_status
+ RateLimitStatus.new_from_xml request("account/rate_limit_status.xml", :auth => true)
+ end
+
# waiting for twitter to correctly implement this in the api as it is documented
def featured
users(call(:featured))
@@ -0,0 +1,19 @@
+module Twitter
+ class RateLimitStatus
+ include EasyClassMaker
+
+ attributes :reset_time_in_seconds, :reset_time, :remaining_hits, :hourly_limit
+
+ class << self
+ # Creates a new rate limi status from a piece of xml
+ def new_from_xml(xml)
+ RateLimitStatus.new do |s|
+ s.reset_time_in_seconds = xml.at('reset-time-in-seconds').inner_html.to_i
+ s.reset_time = Time.parse xml.at('reset-time').inner_html
+ s.remaining_hits = xml.at('remaining-hits').inner_html.to_i
+ s.hourly_limit = xml.at('hourly-limit').inner_html.to_i
+ end
+ end
+ end
+ end
+end
View
@@ -84,4 +84,32 @@
@base.should_receive(:request).and_return(Hpricot::XML(data))
@base.user('4243').name.should == 'John Nunemaker'
end
+
+ describe "rate limit status" do
+ before do
+ @data = open(File.dirname(__FILE__) + '/fixtures/rate_limit_status.xml').read
+ @base.stub!(:request).and_return(Hpricot::XML(@data))
+ end
+
+ it "should request the status" do
+ @base.should_receive(:request).and_return(Hpricot::XML(@data))
+ @base.rate_limit_status
+ end
+
+ it "should have an hourly limit" do
+ @base.rate_limit_status.hourly_limit.should == 20
+ end
+
+ it "should have a reset time in seconds" do
+ @base.rate_limit_status.reset_time_in_seconds.should == 1214757610
+ end
+
+ it "should have a reset time" do
+ @base.rate_limit_status.reset_time.should == Time.parse('2008-06-29T16:40:10+00:00')
+ end
+
+ it "should have remaining hits" do
+ @base.rate_limit_status.remaining_hits.should == 5
+ end
+ end
end
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hash>
+ <hourly-limit type="integer">20</hourly-limit>
+ <reset-time-in-seconds type="integer">1214757610</reset-time-in-seconds>
+ <reset-time type="datetime">2008-06-29T16:40:10+00:00</reset-time>
+ <remaining-hits type="integer">5</remaining-hits>
+</hash>

0 comments on commit 2b5325b

Please sign in to comment.