From 3a4be52a50ad20875b1cf48871f7754944593c95 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 10 Sep 2012 10:13:28 -0700 Subject: [PATCH] Remove Twitter::Client#rate_limit --- README.md | 2 +- lib/twitter/client.rb | 4 ---- lib/twitter/error.rb | 2 ++ lib/twitter/rate_limit.rb | 2 +- spec/twitter/client_spec.rb | 8 -------- spec/twitter/rate_limit_spec.rb | 17 +++++++++++++++++ 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 51d9a04f7..8603af245 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ Here are some fun facts about the 3.0 release: * The entire library is implemented in just 2,000 lines of code * With over 5,000 lines of specs, the spec-to-code ratio is over 2.5:1 -* The spec suite contains 649 examples and runs in under 2 seconds on a MacBook +* The spec suite contains 648 examples and runs in under 2 seconds on a MacBook * This project has 100% C0 code coverage (the tests execute every line of source code at least once) * At the time of release, this library is comprehensive: you can request all diff --git a/lib/twitter/client.rb b/lib/twitter/client.rb index bb8ebb007..4b8cb39f0 100644 --- a/lib/twitter/client.rb +++ b/lib/twitter/client.rb @@ -4,7 +4,6 @@ require 'twitter/configurable' require 'twitter/error/client_error' require 'twitter/error/decode_error' -require 'twitter/rate_limit' require 'simple_oauth' require 'uri' @@ -16,7 +15,6 @@ module Twitter class Client include Twitter::API include Twitter::Configurable - attr_reader :rate_limit # Initializes a new Client object # @@ -26,7 +24,6 @@ def initialize(options={}) Twitter::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", options[key] || Twitter.instance_variable_get(:"@#{key}")) end - @rate_limit = Twitter::RateLimit.new end # Perform an HTTP DELETE request @@ -82,7 +79,6 @@ def request(method, path, params={}, options={}) end yield request if block_given? end.env - @rate_limit.update(response[:response_headers]) response rescue Faraday::Error::ClientError raise Twitter::Error::ClientError diff --git a/lib/twitter/error.rb b/lib/twitter/error.rb index 1e4062264..fd625e065 100644 --- a/lib/twitter/error.rb +++ b/lib/twitter/error.rb @@ -1,3 +1,5 @@ +require 'twitter/rate_limit' + module Twitter # Custom error class for rescuing from all Twitter errors class Error < StandardError diff --git a/lib/twitter/rate_limit.rb b/lib/twitter/rate_limit.rb index 06d89df3a..1978f2489 100644 --- a/lib/twitter/rate_limit.rb +++ b/lib/twitter/rate_limit.rb @@ -32,7 +32,7 @@ def reset_in end alias retry_after reset_in - # Update the attributes of a Relationship + # Update the attributes of a RateLimit # # @param attrs [Hash] # @return [Twitter::RateLimit] diff --git a/spec/twitter/client_spec.rb b/spec/twitter/client_spec.rb index 7677fcd91..824459c7e 100644 --- a/spec/twitter/client_spec.rb +++ b/spec/twitter/client_spec.rb @@ -82,14 +82,6 @@ client2.verify_credentials.id.should eq 14100886 end - describe "#initalize" do - it "returns a different rate limit object for a new client" do - client1 = Twitter::Client.new - client2 = Twitter::Client.new - client1.rate_limit.should_not eq client2.rate_limit - end - end - describe "#delete" do before do stub_delete("/custom/delete"). diff --git a/spec/twitter/rate_limit_spec.rb b/spec/twitter/rate_limit_spec.rb index 5c02f908b..7fac6154f 100644 --- a/spec/twitter/rate_limit_spec.rb +++ b/spec/twitter/rate_limit_spec.rb @@ -56,4 +56,21 @@ end end + describe "#update" do + before do + Timecop.freeze(Time.utc(2012, 6, 6, 17, 22, 0)) + end + after do + Timecop.return + end + it "updates a rate limit" do + rate_limit = Twitter::RateLimit.new('x-rate-limit-reset' => "1339019097") + rate_limit.reset_in.should be_an Integer + rate_limit.reset_in.should eq 15777 + rate_limit.update({'x-rate-limit-reset' => "1339019098"}) + rate_limit.reset_in.should be_an Integer + rate_limit.reset_in.should eq 15778 + end + end + end