Skip to content

Commit

Permalink
Add support for new account methods.
Browse files Browse the repository at this point in the history
- GET account/totals
- GET account/settings
- POST account/settings
  • Loading branch information
englishm committed Aug 27, 2011
1 parent ee81f06 commit 6496e31
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/twitter/client/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,53 @@ def update_profile(options={})
response = post('account/update_profile', options)
format.to_s.downcase == 'xml' ? response['user'] : response
end

# Returns the current count of friends, followers, updates (statuses) and favorites of the authenticating user.
#
# @see https://dev.twitter.com/docs/api/1/get/account/totals
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @return [Hashie::Mash] the current count of friends, followers, updates, and favorites of the authenticating user.
# @raise [Twitter::Unauthorized] Error raised when supplied user credentials are not valid.
# @example Return the totals for the authenticating user.
# Twitter.totals
def totals()
response = get('account/totals')
format.to_s.downcase == 'xml' ? response['hash'] : response
end

# Updates the authenticating user's settings.
# Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
#
# @see https://dev.twitter.com/docs/api/1/post/account/settings
# @see https://dev.twitter.com/docs/api/1/get/account/settings
# @rate_limited Yes
# @requires_authentication Yes
# @response_format `json`
# @response_format `xml`
# @param options [Hash] A customizable set of options.
# @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID to use as the user's default trend location. Global information is available by using 1 as the WOEID. The woeid must be one of the locations returned by {https://dev.twitter.com/docs/api/1/get/trends/available GET trends/available}.
# @option options [Boolean, String, Integer] :sleep_time_enabled When set to true, 't' or 1, will enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.
# @option options [Integer] :start_sleep_time The hour that sleep time should begin if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
# @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
# @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names.
# @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1/get/help/languages GET help/languages}.
# @return [Hashie::Mash]
# @raise [Twitter::Unauthorized] Error raised when supplied user credentials are not valid.
# @example Return the settings for the authenticating user.
# Twitter.settings
def settings(options = {})
case options.length
when 0
response = get('account/settings')
else
response = post('account/settings', options)
end
format.to_s.downcase == 'xml' ? response['hash'] : response
end

end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/settings_GET.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"language":"en","discoverable_by_email":true,"trend_location":[{"url":"http:\/\/where.yahooapis.com\/v1\/place\/23424977","placeType":{"name":"Country","code":12},"name":"United States","countryCode":"US","woeid":23424977,"country":"United States","parentid":1}],"always_use_https":true,"sleep_time":{"enabled":false,"start_time":0,"end_time":0},"geo_enabled":true,"time_zone":{"name":"Eastern Time (US & Canada)","utc_offset":-18000,"tzinfo_name":"America\/New_York"}}
25 changes: 25 additions & 0 deletions spec/fixtures/settings_GET.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<trend_location>
<woeid>23424977</woeid>
<name>United States</name>
<placeTypeName code="12">Country</placeTypeName>
<country type="Country" code="US">United States</country>
<url>http://where.yahooapis.com/v1/place/23424977</url>
<parentid>1</parentid>
</trend_location>
<geo_enabled>true</geo_enabled>
<discoverable_by_email>true</discoverable_by_email>
<sleep_time>
<enabled>false</enabled>
<start_time>0</start_time>
<end_time>0</end_time>
</sleep_time>
<always_use_https>true</always_use_https>
<time_zone>
<name>Eastern Time (US &amp; Canada)</name>
<utc_offset>-18000</utc_offset>
<tzinfo_name>America/New_York</tzinfo_name>
</time_zone>
<language>en</language>
</settings>
1 change: 1 addition & 0 deletions spec/fixtures/settings_POST.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"language":"en","discoverable_by_email":true,"trend_location":[{"url":"http:\/\/where.yahooapis.com\/v1\/place\/23424803","parentid":1,"name":"Ireland","countryCode":"IE","placeType":{"name":"Country","code":12},"woeid":23424803,"country":"Ireland"}],"sleep_time":{"enabled":false,"start_time":0,"end_time":0},"geo_enabled":true,"time_zone":{"name":"Eastern Time (US & Canada)","utc_offset":-18000,"tzinfo_name":"America\/New_York"},"always_use_https":true}
25 changes: 25 additions & 0 deletions spec/fixtures/settings_POST.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<trend_location>
<woeid>23424803</woeid>
<name>Ireland</name>
<placeTypeName code="12">Country</placeTypeName>
<country type="Country" code="IE">Ireland</country>
<url>http://where.yahooapis.com/v1/place/23424803</url>
<parentid>1</parentid>
</trend_location>
<geo_enabled>true</geo_enabled>
<discoverable_by_email>true</discoverable_by_email>
<sleep_time>
<enabled>false</enabled>
<start_time>0</start_time>
<end_time>0</end_time>
</sleep_time>
<always_use_https>true</always_use_https>
<time_zone>
<name>Eastern Time (US &amp; Canada)</name>
<utc_offset>-18000</utc_offset>
<tzinfo_name>America/New_York</tzinfo_name>
</time_zone>
<language>en</language>
</settings>
1 change: 1 addition & 0 deletions spec/fixtures/totals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"favorites":2811,"updates":4109,"followers":475,"friends":1994}
7 changes: 7 additions & 0 deletions spec/fixtures/totals.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<favorites type="integer">2811</favorites>
<updates type="integer">4109</updates>
<followers type="integer">475</followers>
<friends type="integer">1994</friends>
</hash>
42 changes: 42 additions & 0 deletions spec/twitter/client/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,48 @@
user.name.should == "Erik Michaels-Ober"
end
end

describe ".totals" do

before do
stub_get("account/totals.#{format}").
to_return(:body => fixture("totals.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end

it "should get the correct resource" do
@client.totals
a_get("account/totals.#{format}").
should have_been_made
end

end

# TODO: make this describe both GET and POST verbs
describe ".settings" do

before do
stub_get("account/settings.#{format}").
to_return(:body => fixture("settings_GET.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
stub_post("account/settings.#{format}").
with(:body => {:trend_location_woeid => "23424803"}).
to_return(:body => fixture("settings_POST.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end

it "should get the correct resource on GET" do
@client.settings
a_get("account/settings.#{format}").
should have_been_made
end

it "should get the correct resource on POST" do
@client.settings(:trend_location_woeid => "23424803")
a_post("account/settings.#{format}").
with(:body => {:trend_location_woeid => "23424803"}).
should have_been_made
end

end

end
end
end

0 comments on commit 6496e31

Please sign in to comment.