Skip to content

Commit

Permalink
Remove Twitter::Client#rate_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Sep 17, 2012
1 parent b2ec010 commit 3a4be52
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/twitter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -16,7 +15,6 @@ module Twitter
class Client
include Twitter::API
include Twitter::Configurable
attr_reader :rate_limit

# Initializes a new Client object
#
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/twitter/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'twitter/rate_limit'

module Twitter
# Custom error class for rescuing from all Twitter errors
class Error < StandardError
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rate_limit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 0 additions & 8 deletions spec/twitter/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down
17 changes: 17 additions & 0 deletions spec/twitter/rate_limit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3a4be52

Please sign in to comment.