twitter 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/lib/twitter/api/direct_messages.rb +150 -0
  3. data/lib/twitter/api/favorites.rb +132 -0
  4. data/lib/twitter/api/friends_and_followers.rb +259 -0
  5. data/lib/twitter/api/help.rb +64 -0
  6. data/lib/twitter/api/lists.rb +570 -0
  7. data/lib/twitter/api/places_and_geo.rb +121 -0
  8. data/lib/twitter/api/saved_searches.rb +98 -0
  9. data/lib/twitter/api/search.rb +37 -0
  10. data/lib/twitter/api/spam_reporting.rb +30 -0
  11. data/lib/twitter/api/suggested_users.rb +54 -0
  12. data/lib/twitter/api/timelines.rb +213 -0
  13. data/lib/twitter/api/trends.rb +63 -0
  14. data/lib/twitter/api/tweets.rb +284 -0
  15. data/lib/twitter/api/undocumented.rb +116 -0
  16. data/lib/twitter/api/users.rb +427 -0
  17. data/lib/twitter/api/utils.rb +111 -0
  18. data/lib/twitter/client.rb +41 -13
  19. data/lib/twitter/core_ext/enumerable.rb +1 -1
  20. data/lib/twitter/default.rb +16 -18
  21. data/lib/twitter/error/already_favorited.rb +1 -1
  22. data/lib/twitter/error/already_retweeted.rb +1 -1
  23. data/lib/twitter/profile_banner.rb +18 -0
  24. data/lib/twitter/version.rb +1 -1
  25. data/spec/fixtures/profile_banner.json +1 -0
  26. data/spec/twitter/api/direct_messages_spec.rb +32 -32
  27. data/spec/twitter/api/favorites_spec.rb +114 -0
  28. data/spec/twitter/api/{friendships_spec.rb → friends_and_followers_spec.rb} +146 -146
  29. data/spec/twitter/api/geo_spec.rb +28 -28
  30. data/spec/twitter/api/help_spec.rb +1 -1
  31. data/spec/twitter/api/lists_spec.rb +82 -82
  32. data/spec/twitter/api/saved_searches_spec.rb +1 -1
  33. data/spec/twitter/api/search_spec.rb +1 -17
  34. data/spec/twitter/api/{report_spam_spec.rb → spam_reporting_spec.rb} +1 -1
  35. data/spec/twitter/api/suggested_users_spec.rb +94 -0
  36. data/spec/twitter/api/timelines_spec.rb +138 -0
  37. data/spec/twitter/api/trends_spec.rb +1 -1
  38. data/spec/twitter/api/tweets_spec.rb +249 -0
  39. data/spec/twitter/api/undocumented_spec.rb +103 -0
  40. data/spec/twitter/api/users_spec.rb +308 -17
  41. data/spec/twitter/client_spec.rb +1 -1
  42. data/spec/twitter/profile_banner_spec.rb +13 -0
  43. data/twitter.gemspec +3 -2
  44. metadata +44 -21
  45. data/lib/twitter/api.rb +0 -2558
  46. data/spec/twitter/api/account_spec.rb +0 -152
  47. data/spec/twitter/api/activity_spec.rb +0 -37
  48. data/spec/twitter/api/blocks_spec.rb +0 -122
  49. data/spec/twitter/api/statuses_spec.rb +0 -541
@@ -1,6 +1,20 @@
1
1
  require 'faraday'
2
2
  require 'multi_json'
3
- require 'twitter/api'
3
+ require 'twitter/api/direct_messages'
4
+ require 'twitter/api/favorites'
5
+ require 'twitter/api/friends_and_followers'
6
+ require 'twitter/api/help'
7
+ require 'twitter/api/lists'
8
+ require 'twitter/api/places_and_geo'
9
+ require 'twitter/api/saved_searches'
10
+ require 'twitter/api/search'
11
+ require 'twitter/api/spam_reporting'
12
+ require 'twitter/api/suggested_users'
13
+ require 'twitter/api/timelines'
14
+ require 'twitter/api/trends'
15
+ require 'twitter/api/tweets'
16
+ require 'twitter/api/undocumented'
17
+ require 'twitter/api/users'
4
18
  require 'twitter/configurable'
5
19
  require 'twitter/error/client_error'
6
20
  require 'twitter/error/decode_error'
@@ -14,6 +28,21 @@ module Twitter
14
28
  # @see http://dev.twitter.com/pages/every_developer
15
29
  class Client
16
30
  include Twitter::API
31
+ include Twitter::API::DirectMessages
32
+ include Twitter::API::Favorites
33
+ include Twitter::API::FriendsAndFollowers
34
+ include Twitter::API::Help
35
+ include Twitter::API::Lists
36
+ include Twitter::API::PlacesAndGeo
37
+ include Twitter::API::SavedSearches
38
+ include Twitter::API::Search
39
+ include Twitter::API::SpamReporting
40
+ include Twitter::API::SuggestedUsers
41
+ include Twitter::API::Timelines
42
+ include Twitter::API::Trends
43
+ include Twitter::API::Tweets
44
+ include Twitter::API::Undocumented
45
+ include Twitter::API::Users
17
46
  include Twitter::Configurable
18
47
 
19
48
  # Initializes a new Client object
@@ -27,23 +56,23 @@ module Twitter
27
56
  end
28
57
 
29
58
  # Perform an HTTP DELETE request
30
- def delete(path, params={}, options={})
31
- request(:delete, path, params, options)
59
+ def delete(path, params={})
60
+ request(:delete, path, params)
32
61
  end
33
62
 
34
63
  # Perform an HTTP GET request
35
- def get(path, params={}, options={})
36
- request(:get, path, params, options)
64
+ def get(path, params={})
65
+ request(:get, path, params)
37
66
  end
38
67
 
39
68
  # Perform an HTTP POST request
40
- def post(path, params={}, options={})
41
- request(:post, path, params, options)
69
+ def post(path, params={})
70
+ request(:post, path, params)
42
71
  end
43
72
 
44
73
  # Perform an HTTP UPDATE request
45
- def put(path, params={}, options={})
46
- request(:put, path, params, options)
74
+ def put(path, params={})
75
+ request(:put, path, params)
47
76
  end
48
77
 
49
78
  private
@@ -58,16 +87,15 @@ module Twitter
58
87
  # Perform an HTTP request
59
88
  #
60
89
  # @raise [Twitter::Error::ClientError, Twitter::Error::DecodeError]
61
- def request(method, path, params={}, options={})
62
- uri = options[:endpoint] || @endpoint
63
- uri = URI(uri) unless uri.respond_to?(:host)
90
+ def request(method, path, params={})
91
+ uri = URI(@endpoint) unless uri.respond_to?(:host)
64
92
  uri += path
65
93
  request_headers = {}
66
94
  if credentials?
67
95
  authorization = auth_header(method, uri, params)
68
96
  request_headers[:authorization] = authorization.to_s
69
97
  end
70
- connection.url_prefix = options[:endpoint] || @endpoint
98
+ connection.url_prefix = @endpoint
71
99
  response = connection.run_request(method.to_sym, path, nil, request_headers) do |request|
72
100
  unless params.empty?
73
101
  case request.method
@@ -10,7 +10,7 @@ module Enumerable
10
10
  end
11
11
  end
12
12
 
13
- private
13
+ private
14
14
 
15
15
  def abort_on_exception
16
16
  initial_abort_on_exception = Thread.abort_on_exception
@@ -22,24 +22,22 @@ module Twitter
22
22
  :timeout => 10,
23
23
  } unless defined? CONNECTION_OPTIONS
24
24
  IDENTITY_MAP = false unless defined? IDENTITY_MAP
25
- MIDDLEWARE = Faraday::Builder.new(
26
- &Proc.new do |builder|
27
- # Convert file uploads to Faraday::UploadIO objects
28
- builder.use Twitter::Request::MultipartWithFile
29
- # Checks for files in the payload
30
- builder.use Faraday::Request::Multipart
31
- # Convert request params to "www-form-urlencoded"
32
- builder.use Faraday::Request::UrlEncoded
33
- # Handle 4xx server responses
34
- builder.use Twitter::Response::RaiseError, Twitter::Error::ClientError
35
- # Parse JSON response bodies using MultiJson
36
- builder.use Twitter::Response::ParseJson
37
- # Handle 5xx server responses
38
- builder.use Twitter::Response::RaiseError, Twitter::Error::ServerError
39
- # Set Faraday's HTTP adapter
40
- builder.adapter Faraday.default_adapter
41
- end
42
- )
25
+ MIDDLEWARE = Faraday::Builder.new do |builder|
26
+ # Convert file uploads to Faraday::UploadIO objects
27
+ builder.use Twitter::Request::MultipartWithFile
28
+ # Checks for files in the payload
29
+ builder.use Faraday::Request::Multipart
30
+ # Convert request params to "www-form-urlencoded"
31
+ builder.use Faraday::Request::UrlEncoded
32
+ # Handle 4xx server responses
33
+ builder.use Twitter::Response::RaiseError, Twitter::Error::ClientError
34
+ # Parse JSON response bodies using MultiJson
35
+ builder.use Twitter::Response::ParseJson
36
+ # Handle 5xx server responses
37
+ builder.use Twitter::Response::RaiseError, Twitter::Error::ServerError
38
+ # Set Faraday's HTTP adapter
39
+ builder.adapter Faraday.default_adapter
40
+ end
43
41
 
44
42
  class << self
45
43
 
@@ -3,7 +3,7 @@ require 'twitter/error/forbidden'
3
3
  module Twitter
4
4
  class Error
5
5
  # Raised when a Tweet has already been favorited
6
- class AlreadyFavorited < Twitter::Error::Forbidden
6
+ class AlreadyFavorited < Twitter::Error
7
7
  MESSAGE = "You have already favorited this status"
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ require 'twitter/error/forbidden'
3
3
  module Twitter
4
4
  class Error
5
5
  # Raised when a Tweet has already been retweeted
6
- class AlreadyRetweeted < Twitter::Error::Forbidden
6
+ class AlreadyRetweeted < Twitter::Error
7
7
  MESSAGE = "sharing is not permissible for this status (Share validations failed)"
8
8
  end
9
9
  end
@@ -0,0 +1,18 @@
1
+ require 'twitter/base'
2
+ require 'twitter/size'
3
+
4
+ module Twitter
5
+ class ProfileBanner < Twitter::Base
6
+
7
+ # Returns an array of photo sizes
8
+ #
9
+ # @return [Array<Twitter::Size>]
10
+ def sizes
11
+ @sizes ||= Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
12
+ object[key] = Twitter::Size.fetch_or_new(value)
13
+ object
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -1,7 +1,7 @@
1
1
  module Twitter
2
2
  class Version
3
3
  MAJOR = 4 unless defined? Twitter::MAJOR
4
- MINOR = 2 unless defined? Twitter::MINOR
4
+ MINOR = 3 unless defined? Twitter::MINOR
5
5
  PATCH = 0 unless defined? Twitter::PATCH
6
6
  PRE = nil unless defined? Twitter::PRE
7
7
 
@@ -0,0 +1 @@
1
+ {"sizes":{"mobile_retina":{"h":320,"w":640,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/mobile_retina"},"ipad":{"h":313,"w":626,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/ipad"},"mobile":{"h":160,"w":320,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/mobile"},"ipad_retina":{"h":626,"w":1252,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/ipad_retina"},"web_retina":{"h":520,"w":1040,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/web_retina"},"web":{"h":260,"w":520,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/web"}}}
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- describe Twitter::API do
3
+ describe Twitter::API::DirectMessages do
4
4
 
5
5
  before do
6
6
  @client = Twitter::Client.new
@@ -38,37 +38,6 @@ describe Twitter::API do
38
38
  end
39
39
  end
40
40
 
41
- describe "#direct_message_destroy" do
42
- before do
43
- stub_post("/1.1/direct_messages/destroy.json").with(:body => {:id => "1825785544"}).to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
44
- end
45
- it "requests the correct resource" do
46
- @client.direct_message_destroy(1825785544)
47
- expect(a_post("/1.1/direct_messages/destroy.json").with(:body => {:id => "1825785544"})).to have_been_made
48
- end
49
- it "returns an array of deleted messages" do
50
- direct_messages = @client.direct_message_destroy(1825785544)
51
- expect(direct_messages).to be_an Array
52
- expect(direct_messages.first).to be_a Twitter::DirectMessage
53
- expect(direct_messages.first.sender.id).to eq 7505382
54
- end
55
- end
56
-
57
- describe "#direct_message_create" do
58
- before do
59
- stub_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"}).to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
60
- end
61
- it "requests the correct resource" do
62
- @client.direct_message_create("pengwynn", "Creating a fixture for the Twitter gem")
63
- expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made
64
- end
65
- it "returns the sent message" do
66
- direct_message = @client.direct_message_create("pengwynn", "Creating a fixture for the Twitter gem")
67
- expect(direct_message).to be_a Twitter::DirectMessage
68
- expect(direct_message.text).to eq "Creating a fixture for the Twitter gem"
69
- end
70
- end
71
-
72
41
  describe "#direct_message" do
73
42
  before do
74
43
  stub_get("/1.1/direct_messages/show.json").with(:query => {:id => "1825786345"}).to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -117,4 +86,35 @@ describe Twitter::API do
117
86
  end
118
87
  end
119
88
 
89
+ describe "#direct_message_destroy" do
90
+ before do
91
+ stub_post("/1.1/direct_messages/destroy.json").with(:body => {:id => "1825785544"}).to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
92
+ end
93
+ it "requests the correct resource" do
94
+ @client.direct_message_destroy(1825785544)
95
+ expect(a_post("/1.1/direct_messages/destroy.json").with(:body => {:id => "1825785544"})).to have_been_made
96
+ end
97
+ it "returns an array of deleted messages" do
98
+ direct_messages = @client.direct_message_destroy(1825785544)
99
+ expect(direct_messages).to be_an Array
100
+ expect(direct_messages.first).to be_a Twitter::DirectMessage
101
+ expect(direct_messages.first.sender.id).to eq 7505382
102
+ end
103
+ end
104
+
105
+ describe "#direct_message_create" do
106
+ before do
107
+ stub_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"}).to_return(:body => fixture("direct_message.json"), :headers => {:content_type => "application/json; charset=utf-8"})
108
+ end
109
+ it "requests the correct resource" do
110
+ @client.direct_message_create("pengwynn", "Creating a fixture for the Twitter gem")
111
+ expect(a_post("/1.1/direct_messages/new.json").with(:body => {:screen_name => "pengwynn", :text => "Creating a fixture for the Twitter gem"})).to have_been_made
112
+ end
113
+ it "returns the sent message" do
114
+ direct_message = @client.direct_message_create("pengwynn", "Creating a fixture for the Twitter gem")
115
+ expect(direct_message).to be_a Twitter::DirectMessage
116
+ expect(direct_message.text).to eq "Creating a fixture for the Twitter gem"
117
+ end
118
+ end
119
+
120
120
  end
@@ -0,0 +1,114 @@
1
+ require 'helper'
2
+
3
+ describe Twitter::API::Favorites do
4
+
5
+ before do
6
+ @client = Twitter::Client.new
7
+ end
8
+
9
+ describe "#favorites" do
10
+ context "with a screen name passed" do
11
+ before do
12
+ stub_get("/1.1/favorites/list.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("favorites.json"), :headers => {:content_type => "application/json; charset=utf-8"})
13
+ end
14
+ it "requests the correct resource" do
15
+ @client.favorites("sferik")
16
+ expect(a_get("/1.1/favorites/list.json").with(:query => {:screen_name => "sferik"})).to have_been_made
17
+ end
18
+ it "returns the 20 most recent favorite Tweets for the authenticating user or user specified by the ID parameter" do
19
+ favorites = @client.favorites("sferik")
20
+ expect(favorites).to be_an Array
21
+ expect(favorites.first).to be_a Twitter::Tweet
22
+ expect(favorites.first.user.id).to eq 2404341
23
+ end
24
+ end
25
+ context "without arguments passed" do
26
+ before do
27
+ stub_get("/1.1/favorites/list.json").to_return(:body => fixture("favorites.json"), :headers => {:content_type => "application/json; charset=utf-8"})
28
+ end
29
+ it "requests the correct resource" do
30
+ @client.favorites
31
+ expect(a_get("/1.1/favorites/list.json")).to have_been_made
32
+ end
33
+ it "returns the 20 most recent favorite Tweets for the authenticating user or user specified by the ID parameter" do
34
+ favorites = @client.favorites
35
+ expect(favorites).to be_an Array
36
+ expect(favorites.first).to be_a Twitter::Tweet
37
+ expect(favorites.first.user.id).to eq 2404341
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#unfavorite" do
43
+ before do
44
+ stub_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
45
+ end
46
+ it "requests the correct resource" do
47
+ @client.unfavorite(25938088801)
48
+ expect(a_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"})).to have_been_made
49
+ end
50
+ it "returns an array of un-favorited Tweets" do
51
+ tweets = @client.unfavorite(25938088801)
52
+ expect(tweets).to be_an Array
53
+ expect(tweets.first).to be_a Twitter::Tweet
54
+ expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
55
+ end
56
+ end
57
+
58
+ describe "#favorite" do
59
+ before do
60
+ stub_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
61
+ end
62
+ it "requests the correct resource" do
63
+ @client.favorite(25938088801)
64
+ expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
65
+ end
66
+ it "returns an array of favorited Tweets" do
67
+ tweets = @client.favorite(25938088801)
68
+ expect(tweets).to be_an Array
69
+ expect(tweets.first).to be_a Twitter::Tweet
70
+ expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
71
+ end
72
+ context "already favorited" do
73
+ before do
74
+ stub_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"}).to_return(:status => 403, :body => fixture("already_favorited.json"), :headers => {:content_type => "application/json; charset=utf-8"})
75
+ end
76
+ it "does not raises an error" do
77
+ expect{@client.favorite(25938088801)}.not_to raise_error
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#favorite!" do
83
+ before do
84
+ stub_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
85
+ end
86
+ it "requests the correct resource" do
87
+ @client.favorite!(25938088801)
88
+ expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
89
+ end
90
+ it "returns an array of favorited Tweets" do
91
+ tweets = @client.favorite!(25938088801)
92
+ expect(tweets).to be_an Array
93
+ expect(tweets.first).to be_a Twitter::Tweet
94
+ expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
95
+ end
96
+ context "forbidden" do
97
+ before do
98
+ stub_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"}).to_return(:status => 403, :headers => {:content_type => "application/json; charset=utf-8"})
99
+ end
100
+ it "raises a Forbidden error" do
101
+ expect{@client.favorite!(25938088801)}.to raise_error(Twitter::Error::Forbidden)
102
+ end
103
+ end
104
+ context "already favorited" do
105
+ before do
106
+ stub_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"}).to_return(:status => 403, :body => fixture("already_favorited.json"), :headers => {:content_type => "application/json; charset=utf-8"})
107
+ end
108
+ it "raises an AlreadyFavorited error" do
109
+ expect{@client.favorite!(25938088801)}.to raise_error(Twitter::Error::AlreadyFavorited, "Tweet with the ID 25938088801 has already been favorited by the authenticated user.")
110
+ end
111
+ end
112
+ end
113
+
114
+ end
@@ -1,11 +1,44 @@
1
1
  require 'helper'
2
2
 
3
- describe Twitter::API do
3
+ describe Twitter::API::FriendsAndFollowers do
4
4
 
5
5
  before do
6
6
  @client = Twitter::Client.new
7
7
  end
8
8
 
9
+ describe "#friend_ids" do
10
+ context "with a screen_name passed" do
11
+ before do
12
+ stub_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
13
+ end
14
+ it "requests the correct resource" do
15
+ @client.friend_ids("sferik")
16
+ expect(a_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
17
+ end
18
+ it "returns an array of numeric IDs for every user the specified user is following" do
19
+ friend_ids = @client.friend_ids("sferik")
20
+ expect(friend_ids).to be_a Twitter::Cursor
21
+ expect(friend_ids.ids).to be_an Array
22
+ expect(friend_ids.ids.first).to eq 14100886
23
+ end
24
+ end
25
+ context "without arguments passed" do
26
+ before do
27
+ stub_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
28
+ end
29
+ it "requests the correct resource" do
30
+ @client.friend_ids
31
+ expect(a_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
32
+ end
33
+ it "returns an array of numeric IDs for every user the specified user is following" do
34
+ friend_ids = @client.friend_ids
35
+ expect(friend_ids).to be_a Twitter::Cursor
36
+ expect(friend_ids.ids).to be_an Array
37
+ expect(friend_ids.ids.first).to eq 14100886
38
+ end
39
+ end
40
+ end
41
+
9
42
  describe "#follower_ids" do
10
43
  context "with a screen_name passed" do
11
44
  before do
@@ -39,76 +72,94 @@ describe Twitter::API do
39
72
  end
40
73
  end
41
74
 
42
- describe "#friend_ids" do
43
- context "with a screen_name passed" do
75
+ describe "#friendships" do
76
+ context "with screen names passed" do
44
77
  before do
45
- stub_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
78
+ stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
46
79
  end
47
80
  it "requests the correct resource" do
48
- @client.friend_ids("sferik")
49
- expect(a_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made
81
+ @client.friendships("sferik", "pengwynn")
82
+ expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"})).to have_been_made
50
83
  end
51
- it "returns an array of numeric IDs for every user the specified user is following" do
52
- friend_ids = @client.friend_ids("sferik")
53
- expect(friend_ids).to be_a Twitter::Cursor
54
- expect(friend_ids.ids).to be_an Array
55
- expect(friend_ids.ids.first).to eq 14100886
84
+ it "returns up to 100 users worth of extended information" do
85
+ friendships = @client.friendships("sferik", "pengwynn")
86
+ expect(friendships).to be_an Array
87
+ expect(friendships.first).to be_a Twitter::User
88
+ expect(friendships.first.id).to eq 7505382
89
+ expect(friendships.first.connections).to eq ["none"]
56
90
  end
57
91
  end
58
- context "without arguments passed" do
92
+ context "with numeric screen names passed" do
59
93
  before do
60
- stub_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
94
+ stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "0,311"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
61
95
  end
62
96
  it "requests the correct resource" do
63
- @client.friend_ids
64
- expect(a_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
97
+ @client.friendships("0", "311")
98
+ expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "0,311"})).to have_been_made
65
99
  end
66
- it "returns an array of numeric IDs for every user the specified user is following" do
67
- friend_ids = @client.friend_ids
68
- expect(friend_ids).to be_a Twitter::Cursor
69
- expect(friend_ids.ids).to be_an Array
70
- expect(friend_ids.ids.first).to eq 14100886
100
+ end
101
+ context "with user IDs passed" do
102
+ before do
103
+ stub_get("/1.1/friendships/lookup.json").with(:query => {:user_id => "7505382,14100886"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
104
+ end
105
+ it "requests the correct resource" do
106
+ @client.friendships(7505382, 14100886)
107
+ expect(a_get("/1.1/friendships/lookup.json").with(:query => {:user_id => "7505382,14100886"})).to have_been_made
108
+ end
109
+ end
110
+ context "with both screen names and user IDs passed" do
111
+ before do
112
+ stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik", :user_id => "14100886"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
113
+ end
114
+ it "requests the correct resource" do
115
+ @client.friendships("sferik", 14100886)
116
+ expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik", :user_id => "14100886"})).to have_been_made
71
117
  end
72
118
  end
73
119
  end
74
120
 
75
- describe "#friendship?" do
121
+ describe "#friendships" do
76
122
  context "with screen names passed" do
77
123
  before do
78
- stub_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
79
- stub_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "pengwynn", :target_screen_name => "sferik"}).to_return(:body => fixture("not_following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
124
+ stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
80
125
  end
81
126
  it "requests the correct resource" do
82
- @client.friendship?("sferik", "pengwynn")
83
- expect(a_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"})).to have_been_made
127
+ @client.friendships("sferik", "pengwynn")
128
+ expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"})).to have_been_made
84
129
  end
85
- it "returns true if user A follows user B" do
86
- friendship = @client.friendship?("sferik", "pengwynn")
87
- expect(friendship).to be_true
130
+ it "returns up to 100 users worth of extended information" do
131
+ friendships = @client.friendships("sferik", "pengwynn")
132
+ expect(friendships).to be_an Array
133
+ expect(friendships.first).to be_a Twitter::User
134
+ expect(friendships.first.id).to eq 7505382
135
+ expect(friendships.first.connections).to eq ["none"]
88
136
  end
89
- it "returns false if user A does not follow user B" do
90
- friendship = @client.friendship?("pengwynn", "sferik")
91
- expect(friendship).to be_false
137
+ end
138
+ context "with numeric screen names passed" do
139
+ before do
140
+ stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "0,311"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
141
+ end
142
+ it "requests the correct resource" do
143
+ @client.friendships("0", "311")
144
+ expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "0,311"})).to have_been_made
92
145
  end
93
146
  end
94
147
  context "with user IDs passed" do
95
148
  before do
96
- stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
149
+ stub_get("/1.1/friendships/lookup.json").with(:query => {:user_id => "7505382,14100886"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
97
150
  end
98
151
  it "requests the correct resource" do
99
- @client.friendship?(7505382, 14100886)
100
- expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made
152
+ @client.friendships(7505382, 14100886)
153
+ expect(a_get("/1.1/friendships/lookup.json").with(:query => {:user_id => "7505382,14100886"})).to have_been_made
101
154
  end
102
155
  end
103
- context "with user objects passed" do
156
+ context "with both screen names and user IDs passed" do
104
157
  before do
105
- stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
158
+ stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik", :user_id => "14100886"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
106
159
  end
107
160
  it "requests the correct resource" do
108
- user1 = Twitter::User.new(:id => '7505382')
109
- user2 = Twitter::User.new(:id => '14100886')
110
- @client.friendship?(user1, user2)
111
- expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made
161
+ @client.friendships("sferik", 14100886)
162
+ expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik", :user_id => "14100886"})).to have_been_made
112
163
  end
113
164
  end
114
165
  end
@@ -145,52 +196,6 @@ describe Twitter::API do
145
196
  end
146
197
  end
147
198
 
148
- describe "#friendship" do
149
- context "with screen names passed" do
150
- before do
151
- stub_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
152
- end
153
- it "requests the correct resource" do
154
- @client.friendship("sferik", "pengwynn")
155
- expect(a_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"})).to have_been_made
156
- end
157
- it "returns detailed information about the relationship between two users" do
158
- relationship = @client.friendship("sferik", "pengwynn")
159
- expect(relationship).to be_a Twitter::Relationship
160
- expect(relationship.source.id).to eq 7505382
161
- end
162
- end
163
- context "with numeric screen names passed" do
164
- before do
165
- stub_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "0", :target_screen_name => "311"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
166
- end
167
- it "requests the correct resource" do
168
- @client.friendship("0", "311")
169
- expect(a_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "0", :target_screen_name => "311"})).to have_been_made
170
- end
171
- end
172
- context "with user IDs passed" do
173
- before do
174
- stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
175
- end
176
- it "requests the correct resource" do
177
- @client.friendship(7505382, 14100886)
178
- expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made
179
- end
180
- end
181
- context "with user objects passed" do
182
- before do
183
- stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
184
- end
185
- it "requests the correct resource" do
186
- user1 = Twitter::User.new(:id => '7505382')
187
- user2 = Twitter::User.new(:id => '14100886')
188
- @client.friendship(user1, user2)
189
- expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made
190
- end
191
- end
192
- end
193
-
194
199
  describe "#follow" do
195
200
  context "with :follow => true passed" do
196
201
  before do
@@ -315,111 +320,106 @@ describe Twitter::API do
315
320
  end
316
321
  end
317
322
 
318
- describe "#friendships" do
323
+ describe "#friendship_update" do
324
+ before do
325
+ stub_post("/1.1/friendships/update.json").with(:body => {:screen_name => "sferik", :retweets => "true"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
326
+ end
327
+ it "requests the correct resource" do
328
+ @client.friendship_update("sferik", :retweets => true)
329
+ expect(a_post("/1.1/friendships/update.json").with(:body => {:screen_name => "sferik", :retweets => "true"})).to have_been_made
330
+ end
331
+ it "returns detailed information about the relationship between two users" do
332
+ relationship = @client.friendship_update("sferik", :retweets => true)
333
+ expect(relationship).to be_a Twitter::Relationship
334
+ expect(relationship.source.id).to eq 7505382
335
+ end
336
+ end
337
+
338
+ describe "#friendship" do
319
339
  context "with screen names passed" do
320
340
  before do
321
- stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
341
+ stub_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
322
342
  end
323
343
  it "requests the correct resource" do
324
- @client.friendships("sferik", "pengwynn")
325
- expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"})).to have_been_made
344
+ @client.friendship("sferik", "pengwynn")
345
+ expect(a_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"})).to have_been_made
326
346
  end
327
- it "returns up to 100 users worth of extended information" do
328
- friendships = @client.friendships("sferik", "pengwynn")
329
- expect(friendships).to be_an Array
330
- expect(friendships.first).to be_a Twitter::User
331
- expect(friendships.first.id).to eq 7505382
332
- expect(friendships.first.connections).to eq ["none"]
347
+ it "returns detailed information about the relationship between two users" do
348
+ relationship = @client.friendship("sferik", "pengwynn")
349
+ expect(relationship).to be_a Twitter::Relationship
350
+ expect(relationship.source.id).to eq 7505382
333
351
  end
334
352
  end
335
353
  context "with numeric screen names passed" do
336
354
  before do
337
- stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "0,311"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
355
+ stub_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "0", :target_screen_name => "311"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
338
356
  end
339
357
  it "requests the correct resource" do
340
- @client.friendships("0", "311")
341
- expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "0,311"})).to have_been_made
358
+ @client.friendship("0", "311")
359
+ expect(a_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "0", :target_screen_name => "311"})).to have_been_made
342
360
  end
343
361
  end
344
362
  context "with user IDs passed" do
345
363
  before do
346
- stub_get("/1.1/friendships/lookup.json").with(:query => {:user_id => "7505382,14100886"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
364
+ stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
347
365
  end
348
366
  it "requests the correct resource" do
349
- @client.friendships(7505382, 14100886)
350
- expect(a_get("/1.1/friendships/lookup.json").with(:query => {:user_id => "7505382,14100886"})).to have_been_made
367
+ @client.friendship(7505382, 14100886)
368
+ expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made
351
369
  end
352
370
  end
353
- context "with both screen names and user IDs passed" do
371
+ context "with user objects passed" do
354
372
  before do
355
- stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik", :user_id => "14100886"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
373
+ stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
356
374
  end
357
375
  it "requests the correct resource" do
358
- @client.friendships("sferik", 14100886)
359
- expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik", :user_id => "14100886"})).to have_been_made
376
+ user1 = Twitter::User.new(:id => '7505382')
377
+ user2 = Twitter::User.new(:id => '14100886')
378
+ @client.friendship(user1, user2)
379
+ expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made
360
380
  end
361
381
  end
362
382
  end
363
383
 
364
- describe "#friendships" do
384
+ describe "#friendship?" do
365
385
  context "with screen names passed" do
366
386
  before do
367
- stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
387
+ stub_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
388
+ stub_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "pengwynn", :target_screen_name => "sferik"}).to_return(:body => fixture("not_following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
368
389
  end
369
390
  it "requests the correct resource" do
370
- @client.friendships("sferik", "pengwynn")
371
- expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik,pengwynn"})).to have_been_made
372
- end
373
- it "returns up to 100 users worth of extended information" do
374
- friendships = @client.friendships("sferik", "pengwynn")
375
- expect(friendships).to be_an Array
376
- expect(friendships.first).to be_a Twitter::User
377
- expect(friendships.first.id).to eq 7505382
378
- expect(friendships.first.connections).to eq ["none"]
391
+ @client.friendship?("sferik", "pengwynn")
392
+ expect(a_get("/1.1/friendships/show.json").with(:query => {:source_screen_name => "sferik", :target_screen_name => "pengwynn"})).to have_been_made
379
393
  end
380
- end
381
- context "with numeric screen names passed" do
382
- before do
383
- stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "0,311"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
394
+ it "returns true if user A follows user B" do
395
+ friendship = @client.friendship?("sferik", "pengwynn")
396
+ expect(friendship).to be_true
384
397
  end
385
- it "requests the correct resource" do
386
- @client.friendships("0", "311")
387
- expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "0,311"})).to have_been_made
398
+ it "returns false if user A does not follow user B" do
399
+ friendship = @client.friendship?("pengwynn", "sferik")
400
+ expect(friendship).to be_false
388
401
  end
389
402
  end
390
403
  context "with user IDs passed" do
391
404
  before do
392
- stub_get("/1.1/friendships/lookup.json").with(:query => {:user_id => "7505382,14100886"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
405
+ stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
393
406
  end
394
407
  it "requests the correct resource" do
395
- @client.friendships(7505382, 14100886)
396
- expect(a_get("/1.1/friendships/lookup.json").with(:query => {:user_id => "7505382,14100886"})).to have_been_made
408
+ @client.friendship?(7505382, 14100886)
409
+ expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made
397
410
  end
398
411
  end
399
- context "with both screen names and user IDs passed" do
412
+ context "with user objects passed" do
400
413
  before do
401
- stub_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik", :user_id => "14100886"}).to_return(:body => fixture("friendships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
414
+ stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
402
415
  end
403
416
  it "requests the correct resource" do
404
- @client.friendships("sferik", 14100886)
405
- expect(a_get("/1.1/friendships/lookup.json").with(:query => {:screen_name => "sferik", :user_id => "14100886"})).to have_been_made
417
+ user1 = Twitter::User.new(:id => '7505382')
418
+ user2 = Twitter::User.new(:id => '14100886')
419
+ @client.friendship?(user1, user2)
420
+ expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made
406
421
  end
407
422
  end
408
423
  end
409
424
 
410
- describe "#friendship_update" do
411
- before do
412
- stub_post("/1.1/friendships/update.json").with(:body => {:screen_name => "sferik", :retweets => "true"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"})
413
- end
414
- it "requests the correct resource" do
415
- @client.friendship_update("sferik", :retweets => true)
416
- expect(a_post("/1.1/friendships/update.json").with(:body => {:screen_name => "sferik", :retweets => "true"})).to have_been_made
417
- end
418
- it "returns detailed information about the relationship between two users" do
419
- relationship = @client.friendship_update("sferik", :retweets => true)
420
- expect(relationship).to be_a Twitter::Relationship
421
- expect(relationship.source.id).to eq 7505382
422
- end
423
- end
424
-
425
425
  end