Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Several authenticated/unauthenticated method additions #96

Closed
wants to merge 8 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  lib/twitter.rb
@@ -8,7 +8,7 @@
module Twitter
extend SingleForwardable
- def_delegators :client, :firehose, :user, :suggestions, :retweeted_to_user, :retweeted_by_user, :status, :friend_ids, :follower_ids, :timeline, :lists_subscribed, :list_timeline, :profile_image
+ def_delegators :client, :firehose, :user, :profile_image, :suggestions, :retweeted_to_user, :retweeted_by_user, :status, :friend_ids, :follower_ids, :timeline, :lists_subscribed, :list_timeline, :retweets, :friends, :followers, :tos, :privacy
class << self
attr_accessor :consumer_key, :consumer_secret, :access_key, :access_secret
View
32 lib/twitter/authenticated.rb
@@ -357,9 +357,9 @@ def list_remove_member(list_owner_screen_name, slug, id, options={})
perform_delete("#{list_owner_screen_name}/#{slug}/members.#{@format}", options)
end
- def is_list_member?(list_owner_screen_name, slug, user_id_or_screen_name, options={})
+ def is_list_member?(list_owner_screen_name, slug, id, options={})
begin
- perform_get("#{list_owner_screen_name}/#{slug}/members/#{user_id_or_screen_name}.#{@format}", options)
+ perform_get("#{list_owner_screen_name}/#{slug}/members/#{id}.#{@format}", options)
true
rescue Twitter::NotFound
false
@@ -411,6 +411,34 @@ def rate_limit_status(options={})
perform_get("account/rate_limit_status.#{@format}", options)
end
+ def friendships_outgoing(options={})
+ perform_get("friendships/outgoing.#{@format}", options)
+ end
+
+ def list_add_members(list_owner_screen_name, slug, new_ids, options={})
+ merge_users_into_options!(Array(new_ids), options)
+ perform_post("#{list_owner_screen_name}/#{slug}/create_all.#{@format}", options)
+ end
+
+ def is_subscriber?(list_owner_screen_name, slug, id, options={})
+ begin
+ perform_get("#{list_owner_screen_name}/#{slug}/subscribers/#{id}.#{@format}", options)
+ true
+ rescue Twitter::NotFound
+ false
+ end
+ end
+
+ def block_exists?(user_id_or_screen_name, options={})
+ merge_user_into_options!(user_id_or_screen_name, options)
+ begin
+ perform_get("blocks/exists.#{@format}", options)
+ true
+ rescue Twitter::NotFound
+ false
+ end
+ end
+
protected
def self.mime_type(file)
View
26 lib/twitter/unauthenticated.rb
@@ -13,7 +13,7 @@ def initialize(options={})
@user_agent = options[:user_agent] || Twitter.user_agent
end
- def firehose(options = {})
+ def firehose(options={})
perform_get("statuses/public_timeline.#{@format}", options)
end
@@ -77,10 +77,32 @@ def lists_subscribed(user_id_or_screen_name, options={})
# :per_page = max number of statues to get at once
# :page = which page of tweets you wish to get
- def list_timeline(list_owner_screen_name, slug, options = {})
+ def list_timeline(list_owner_screen_name, slug, options={})
perform_get("#{list_owner_screen_name}/lists/#{slug}/statuses.#{@format}", options)
end
+ def retweets(id, options={})
+ perform_get("statuses/retweets/#{id}.#{@format}", options)
+ end
+
+ def friends(user_id_or_screen_name, options={})
+ merge_user_into_options!(user_id_or_screen_name, options)
+ perform_get("statuses/friends.#{@format}", options)
+ end
+
+ def followers(user_id_or_screen_name, options={})
+ merge_user_into_options!(user_id_or_screen_name, options)
+ perform_get("statuses/followers.#{@format}", options)
+ end
+
+ def tos
+ perform_get("legal/tos.#{@format}")
+ end
+
+ def privacy
+ perform_get("legal/privacy.#{@format}")
+ end
+
private
def merge_user_into_options!(user_id_or_screen_name, options={})
View
34 test/twitter/authenticated_test.rb
@@ -276,6 +276,21 @@ class AuthenticatedTest < Test::Unit::TestCase
assert @client.rate_limit_status
end
+ should "get outgoing friendships" do
+ stub_get("friendships/outgoing.#{format}", "hash.#{format}")
+ assert @client.friendships_outgoing
+ end
+
+ should "return true if a user is blocked" do
+ stub_get("blocks/exists.#{format}?user_id=1234", "hash.#{format}")
+ assert @client.block_exists?(1234)
+ end
+
+ should "return false if a user is not blocked" do
+ stub_get("blocks/exists.#{format}?screen_name=laserlemon", "not_found.#{format}", 404)
+ assert @client.block_exists?('laserlemon')
+ end
+
should "get totals" do
stub_get("account/totals.#{format}", "hash.#{format}")
assert @client.totals
@@ -432,12 +447,12 @@ class AuthenticatedTest < Test::Unit::TestCase
should "be true if user is a member of a list" do
stub_get("pengwynn/rubyists/members/4243.#{format}", "hash.#{format}")
- assert_true @client.is_list_member?('pengwynn', 'rubyists', 4243)
+ assert @client.is_list_member?('pengwynn', 'rubyists', 4243)
end
should "be false if user is not a member of a list" do
stub_get("pengwynn/rubyists/members/1234.#{format}", "not_found.#{format}", 404)
- assert_false @client.is_list_member?('pengwynn', 'rubyists', 1234)
+ assert !@client.is_list_member?('pengwynn', 'rubyists', 1234)
end
should "get list subscribers" do
@@ -459,6 +474,21 @@ class AuthenticatedTest < Test::Unit::TestCase
stub_get("pengwynn/lists/subscriptions.#{format}", "hash.#{format}")
assert @client.subscriptions('pengwynn')
end
+
+ should "add members to a list" do
+ stub_post("pengwynn/rubyists/create_all.#{format}", "hash.#{format}")
+ assert @client.list_add_members('pengwynn', 'rubyists', [4243, 27748704424])
+ end
+
+ should "be true if user subscribes to a list" do
+ stub_get("pengwynn/rubyists/subscribers/4243.#{format}", "hash.#{format}")
+ assert @client.is_subscriber?('pengwynn', 'rubyists', 4243)
+ end
+
+ should "be false if user does not subscribe to a list" do
+ stub_get("pengwynn/rubyists/subscribers/1234.#{format}", "not_found.#{format}", 404)
+ assert !@client.is_subscriber?('pengwynn', 'rubyists', 1234)
+ end
end
context "when using saved searches" do
View
24 test/twitter/unauthenticated_test.rb
@@ -117,6 +117,30 @@ class UnauthenticatedTest < Test::Unit::TestCase
end
end
+ should "get retweets" do
+ stub_get("statuses/retweets/1533815199.#{format}", "hash.#{format}")
+ assert Twitter.retweets(1533815199)
+ end
+
+ should "get friends" do
+ stub_get("statuses/friends.#{format}?screen_name=laserlemon", "hash.#{format}")
+ assert Twitter.friends('laserlemon')
+ end
+
+ should "get followers" do
+ stub_get("statuses/followers.#{format}?screen_name=laserlemon", "hash.#{format}")
+ assert Twitter.followers('laserlemon')
+ end
+
+ should "get terms of service" do
+ stub_get("legal/tos.#{format}", "hash.#{format}")
+ assert Twitter.tos
+ end
+
+ should "get privacy policy" do
+ stub_get("legal/privacy.#{format}", "hash.#{format}")
+ assert Twitter.privacy
+ end
end
end
end
Something went wrong with that request. Please try again.