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,152 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::API do
4
-
5
- before do
6
- @client = Twitter::Client.new
7
- end
8
-
9
- describe "#verify_credentials" do
10
- before do
11
- stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
- end
13
- it "requests the correct resource" do
14
- @client.verify_credentials
15
- expect(a_get("/1.1/account/verify_credentials.json")).to have_been_made
16
- end
17
- it "returns the requesting user" do
18
- user = @client.verify_credentials
19
- expect(user).to be_a Twitter::User
20
- expect(user.id).to eq 7505382
21
- end
22
- end
23
-
24
- describe "#update_delivery_device" do
25
- before do
26
- stub_post("/1.1/account/update_delivery_device.json").with(:body => {:device => "sms"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
27
- end
28
- it "requests the correct resource" do
29
- @client.update_delivery_device("sms")
30
- expect(a_post("/1.1/account/update_delivery_device.json").with(:body => {:device => "sms"})).to have_been_made
31
- end
32
- it "returns a user" do
33
- user = @client.update_delivery_device("sms")
34
- expect(user).to be_a Twitter::User
35
- expect(user.id).to eq 7505382
36
- end
37
- end
38
-
39
- describe "#update_profile" do
40
- before do
41
- stub_post("/1.1/account/update_profile.json").with(:body => {:url => "http://github.com/sferik/"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
42
- end
43
- it "requests the correct resource" do
44
- @client.update_profile(:url => "http://github.com/sferik/")
45
- expect(a_post("/1.1/account/update_profile.json").with(:body => {:url => "http://github.com/sferik/"})).to have_been_made
46
- end
47
- it "returns a user" do
48
- user = @client.update_profile(:url => "http://github.com/sferik/")
49
- expect(user).to be_a Twitter::User
50
- expect(user.id).to eq 7505382
51
- end
52
- end
53
-
54
- describe "#update_profile_background_image" do
55
- before do
56
- stub_post("/1.1/account/update_profile_background_image.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
57
- end
58
- it "requests the correct resource" do
59
- @client.update_profile_background_image(fixture("we_concept_bg2.png"))
60
- expect(a_post("/1.1/account/update_profile_background_image.json")).to have_been_made
61
- end
62
- it "returns a user" do
63
- user = @client.update_profile_background_image(fixture("we_concept_bg2.png"))
64
- expect(user).to be_a Twitter::User
65
- expect(user.id).to eq 7505382
66
- end
67
- end
68
-
69
- describe "#update_profile_colors" do
70
- before do
71
- stub_post("/1.1/account/update_profile_colors.json").with(:body => {:profile_background_color => "000000"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
72
- end
73
- it "requests the correct resource" do
74
- @client.update_profile_colors(:profile_background_color => "000000")
75
- expect(a_post("/1.1/account/update_profile_colors.json").with(:body => {:profile_background_color => "000000"})).to have_been_made
76
- end
77
- it "returns a user" do
78
- user = @client.update_profile_colors(:profile_background_color => "000000")
79
- expect(user).to be_a Twitter::User
80
- expect(user.id).to eq 7505382
81
- end
82
- end
83
-
84
- describe "#update_profile_image" do
85
- before do
86
- stub_post("/1.1/account/update_profile_image.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
87
- end
88
- it "requests the correct resource" do
89
- @client.update_profile_image(fixture("me.jpeg"))
90
- expect(a_post("/1.1/account/update_profile_image.json")).to have_been_made
91
- end
92
- it "returns a user" do
93
- user = @client.update_profile_image(fixture("me.jpeg"))
94
- expect(user).to be_a Twitter::User
95
- expect(user.id).to eq 7505382
96
- end
97
- end
98
-
99
- describe "#update_profile_banner" do
100
- before do
101
- stub_post("/1.1/account/update_profile_banner.json").to_return(:body => fixture("empty.json"), :headers => {:content_type => "application/json; charset=utf-8"})
102
- end
103
- it "requests the correct resource" do
104
- @client.update_profile_banner(fixture("me.jpeg"))
105
- expect(a_post("/1.1/account/update_profile_banner.json")).to have_been_made
106
- end
107
- it "returns a user" do
108
- user = @client.update_profile_banner(fixture("me.jpeg"))
109
- expect(user).to be_nil
110
- end
111
- end
112
-
113
- describe "#remove_profile_banner" do
114
- before do
115
- stub_post("/1.1/account/remove_profile_banner.json").to_return(:body => fixture("empty.json"), :headers => {:content_type => "application/json; charset=utf-8"})
116
- end
117
- it "requests the correct resource" do
118
- @client.remove_profile_banner
119
- expect(a_post("/1.1/account/remove_profile_banner.json")).to have_been_made
120
- end
121
- it "returns a user" do
122
- user = @client.remove_profile_banner
123
- expect(user).to be_nil
124
- end
125
- end
126
-
127
- describe "#settings" do
128
- before do
129
- stub_get("/1.1/account/settings.json").to_return(:body => fixture("settings.json"), :headers => {:content_type => "application/json; charset=utf-8"})
130
- stub_post("/1.1/account/settings.json").with(:body => {:trend_location_woeid => "23424803"}).to_return(:body => fixture("settings.json"), :headers => {:content_type => "application/json; charset=utf-8"})
131
- end
132
- it "requests the correct resource on GET" do
133
- @client.settings
134
- expect(a_get("/1.1/account/settings.json")).to have_been_made
135
- end
136
- it "returns settings" do
137
- settings = @client.settings
138
- expect(settings).to be_a Twitter::Settings
139
- expect(settings.language).to eq 'en'
140
- end
141
- it "requests the correct resource on POST" do
142
- @client.settings(:trend_location_woeid => "23424803")
143
- expect(a_post("/1.1/account/settings.json").with(:body => {:trend_location_woeid => "23424803"})).to have_been_made
144
- end
145
- it "returns settings" do
146
- settings = @client.settings(:trend_location_woeid => "23424803")
147
- expect(settings).to be_a Twitter::Settings
148
- expect(settings.language).to eq 'en'
149
- end
150
- end
151
-
152
- end
@@ -1,37 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::API do
4
-
5
- before do
6
- @client = Twitter::Client.new
7
- end
8
-
9
- describe "#activity_about_me" do
10
- before do
11
- stub_get("/i/activity/about_me.json").to_return(:body => fixture("about_me.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
- end
13
- it "requests the correct resource" do
14
- @client.activity_about_me
15
- expect(a_get("/i/activity/about_me.json")).to have_been_made
16
- end
17
- it "returns activity about me" do
18
- activity_about_me = @client.activity_about_me
19
- expect(activity_about_me.first).to be_a Twitter::Action::Mention
20
- end
21
- end
22
-
23
- describe "#activity_by_friends" do
24
- before do
25
- stub_get("/i/activity/by_friends.json").to_return(:body => fixture("by_friends.json"), :headers => {:content_type => "application/json; charset=utf-8"})
26
- end
27
- it "requests the correct resource" do
28
- @client.activity_by_friends
29
- expect(a_get("/i/activity/by_friends.json")).to have_been_made
30
- end
31
- it "returns activity by friends" do
32
- activity_by_friends = @client.activity_by_friends
33
- expect(activity_by_friends.first).to be_a Twitter::Action::Favorite
34
- end
35
- end
36
-
37
- end
@@ -1,122 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::API do
4
-
5
- before do
6
- @client = Twitter::Client.new
7
- end
8
-
9
- describe "#blocking" do
10
- before do
11
- stub_get("/1.1/blocks/list.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
12
- end
13
- it "requests the correct resource" do
14
- @client.blocking
15
- expect(a_get("/1.1/blocks/list.json").with(:query => {:cursor => "-1"})).to have_been_made
16
- end
17
- it "returns an array of user objects that the authenticating user is blocking" do
18
- blocking = @client.blocking
19
- expect(blocking).to be_a Twitter::Cursor
20
- expect(blocking.users).to be_an Array
21
- expect(blocking.users.first).to be_a Twitter::User
22
- expect(blocking.users.first.id).to eq 7505382
23
- end
24
- end
25
-
26
- describe "#blocked_ids" do
27
- before do
28
- stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
29
- end
30
- it "requests the correct resource" do
31
- @client.blocked_ids
32
- expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
33
- end
34
- it "returns an array of numeric user IDs the authenticating user is blocking" do
35
- blocked_ids = @client.blocked_ids
36
- expect(blocked_ids).to be_a Twitter::Cursor
37
- expect(blocked_ids.ids).to be_an Array
38
- expect(blocked_ids.ids.first).to eq 14100886
39
- end
40
- end
41
-
42
- describe "#block?" do
43
- context "with a screen name passed" do
44
- before do
45
- stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
46
- stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
47
- stub_get("/1.1/users/show.json").with(:query => {:screen_name => "pengwynn"}).to_return(:body => fixture("pengwynn.json"), :headers => {:content_type => "application/json; charset=utf-8"})
48
- stub_get("/1.1/users/show.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
49
- end
50
- it "requests the correct resource" do
51
- @client.block?("sferik")
52
- expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
53
- expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"})).to have_been_made
54
- expect(a_get("/1.1/users/show.json").with(:query => {:screen_name => "sferik"})).to have_been_made
55
- end
56
- it "returns true if block exists" do
57
- block = @client.block?("pengwynn")
58
- expect(block).to be_true
59
- end
60
- it "returns false if block does not exist" do
61
- block = @client.block?("sferik")
62
- expect(block).to be_false
63
- end
64
- end
65
- context "with a user ID passed" do
66
- before do
67
- stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
68
- stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
69
- end
70
- it "requests the correct resources" do
71
- @client.block?(7505382)
72
- expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
73
- expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"})).to have_been_made
74
- end
75
- end
76
- context "with a user object passed" do
77
- before do
78
- stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
79
- stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"})
80
- end
81
- it "requests the correct resources" do
82
- user = Twitter::User.new(:id => '7505382')
83
- @client.block?(user)
84
- expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made
85
- expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"})).to have_been_made
86
- end
87
- end
88
- end
89
-
90
- describe "#block" do
91
- before do
92
- stub_post("/1.1/blocks/create.json").with(:body => {:screen_name => "sferik"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
93
- end
94
- it "requests the correct resource" do
95
- @client.block("sferik")
96
- expect(a_post("/1.1/blocks/create.json")).to have_been_made
97
- end
98
- it "returns an array of blocked users" do
99
- users = @client.block("sferik")
100
- expect(users).to be_an Array
101
- expect(users.first).to be_a Twitter::User
102
- expect(users.first.id).to eq 7505382
103
- end
104
- end
105
-
106
- describe "#unblock" do
107
- before do
108
- stub_post("/1.1/blocks/destroy.json").with(:body => {:screen_name => "sferik"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
109
- end
110
- it "requests the correct resource" do
111
- @client.unblock("sferik")
112
- expect(a_post("/1.1/blocks/destroy.json").with(:body => {:screen_name => "sferik"})).to have_been_made
113
- end
114
- it "returns an array of un-blocked users" do
115
- users = @client.unblock("sferik")
116
- expect(users).to be_an Array
117
- expect(users.first).to be_a Twitter::User
118
- expect(users.first.id).to eq 7505382
119
- end
120
- end
121
-
122
- end
@@ -1,541 +0,0 @@
1
- require 'helper'
2
-
3
- describe Twitter::API 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 "#favorite" do
43
- before do
44
- 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"})
45
- end
46
- it "requests the correct resource" do
47
- @client.favorite(25938088801)
48
- expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
49
- end
50
- it "returns an array of favorited Tweets" do
51
- tweets = @client.favorite(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
- context "already favorited" do
57
- before do
58
- 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"})
59
- end
60
- it "does not raises an error" do
61
- expect{@client.favorite(25938088801)}.not_to raise_error
62
- end
63
- end
64
- end
65
-
66
- describe "#favorite!" do
67
- before do
68
- 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"})
69
- end
70
- it "requests the correct resource" do
71
- @client.favorite!(25938088801)
72
- expect(a_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"})).to have_been_made
73
- end
74
- it "returns an array of favorited Tweets" do
75
- tweets = @client.favorite!(25938088801)
76
- expect(tweets).to be_an Array
77
- expect(tweets.first).to be_a Twitter::Tweet
78
- expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
79
- end
80
- context "forbidden" do
81
- before do
82
- stub_post("/1.1/favorites/create.json").with(:body => {:id => "25938088801"}).to_return(:status => 403, :headers => {:content_type => "application/json; charset=utf-8"})
83
- end
84
- it "raises a Forbidden error" do
85
- expect{@client.favorite!(25938088801)}.to raise_error(Twitter::Error::Forbidden)
86
- end
87
- end
88
- context "already favorited" do
89
- before do
90
- 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"})
91
- end
92
- it "raises an AlreadyFavorited error" do
93
- expect{@client.favorite!(25938088801)}.to raise_error(Twitter::Error::AlreadyFavorited, "Tweet with the ID 25938088801 has already been favorited by the authenticated user.")
94
- end
95
- end
96
- end
97
-
98
- describe "#unfavorite" do
99
- before do
100
- 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"})
101
- end
102
- it "requests the correct resource" do
103
- @client.unfavorite(25938088801)
104
- expect(a_post("/1.1/favorites/destroy.json").with(:body => {:id => "25938088801"})).to have_been_made
105
- end
106
- it "returns an array of un-favorited Tweets" do
107
- tweets = @client.unfavorite(25938088801)
108
- expect(tweets).to be_an Array
109
- expect(tweets.first).to be_a Twitter::Tweet
110
- expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
111
- end
112
- end
113
-
114
- describe "#home_timeline" do
115
- before do
116
- stub_get("/1.1/statuses/home_timeline.json").to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
117
- end
118
- it "requests the correct resource" do
119
- @client.home_timeline
120
- expect(a_get("/1.1/statuses/home_timeline.json")).to have_been_made
121
- end
122
- it "returns the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the user's they follow" do
123
- tweets = @client.home_timeline
124
- expect(tweets).to be_an Array
125
- expect(tweets.first).to be_a Twitter::Tweet
126
- expect(tweets.first.text).to eq "Happy Birthday @imdane. Watch out for those @rally pranksters!"
127
- end
128
- end
129
-
130
- describe "#mentions_timeline" do
131
- before do
132
- stub_get("/1.1/statuses/mentions_timeline.json").to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
133
- end
134
- it "requests the correct resource" do
135
- @client.mentions_timeline
136
- expect(a_get("/1.1/statuses/mentions_timeline.json")).to have_been_made
137
- end
138
- it "returns the 20 most recent mentions (status containing @username) for the authenticating user" do
139
- tweets = @client.mentions_timeline
140
- expect(tweets).to be_an Array
141
- expect(tweets.first).to be_a Twitter::Tweet
142
- expect(tweets.first.text).to eq "Happy Birthday @imdane. Watch out for those @rally pranksters!"
143
- end
144
- end
145
-
146
- describe "#retweeted_by_user" do
147
- before do
148
- stub_get("/1.1/statuses/user_timeline.json").with(:query => {:include_rts => "true", :screen_name => "sferik", :count => "200"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
149
- stub_get("/1.1/statuses/user_timeline.json").with(:query => {:include_rts => "true", :screen_name => "sferik", :count => "200", :max_id => "244102729860009983"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
150
- end
151
- it "requests the correct resource" do
152
- @client.retweeted_by_user("sferik")
153
- expect(a_get("/1.1/statuses/user_timeline.json").with(:query => {:include_rts => "true", :screen_name => "sferik", :count => "200"})).to have_been_made
154
- expect(a_get("/1.1/statuses/user_timeline.json").with(:query => {:include_rts => "true", :screen_name => "sferik", :count => "200", :max_id => "244102729860009983"})).to have_been_made.times(3)
155
- end
156
- it "returns the 20 most recent retweets posted by the authenticating user" do
157
- tweets = @client.retweeted_by_user("sferik")
158
- expect(tweets).to be_an Array
159
- expect(tweets.first).to be_a Twitter::Tweet
160
- expect(tweets.first.text).to eq "RT @olivercameron: Mosaic looks cool: http://t.co/A8013C9k"
161
- end
162
- end
163
-
164
- describe "#retweeted_by_me" do
165
- before do
166
- stub_get("/1.1/statuses/user_timeline.json").with(:query => {:include_rts => "true", :count => "200"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
167
- stub_get("/1.1/statuses/user_timeline.json").with(:query => {:include_rts => "true", :count => "200", :max_id => "244102729860009983"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
168
- end
169
- it "requests the correct resource" do
170
- @client.retweeted_by_me
171
- expect(a_get("/1.1/statuses/user_timeline.json").with(:query => {:include_rts => "true", :count => "200"})).to have_been_made
172
- expect(a_get("/1.1/statuses/user_timeline.json").with(:query => {:include_rts => "true", :count => "200", :max_id => "244102729860009983"})).to have_been_made.times(3)
173
- end
174
- it "returns the 20 most recent retweets posted by the authenticating user" do
175
- tweets = @client.retweeted_by_me
176
- expect(tweets).to be_an Array
177
- expect(tweets.first).to be_a Twitter::Tweet
178
- expect(tweets.first.text).to eq "RT @olivercameron: Mosaic looks cool: http://t.co/A8013C9k"
179
- end
180
- end
181
-
182
- describe "#retweeted_to_me" do
183
- before do
184
- stub_get("/1.1/statuses/home_timeline.json").with(:query => {:include_rts => "true", :count => "200"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
185
- stub_get("/1.1/statuses/home_timeline.json").with(:query => {:include_rts => "true", :count => "200", :max_id => "244102729860009983"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
186
- end
187
- it "requests the correct resource" do
188
- @client.retweeted_to_me
189
- expect(stub_get("/1.1/statuses/home_timeline.json").with(:query => {:include_rts => "true", :count => "200"})).to have_been_made
190
- expect(stub_get("/1.1/statuses/home_timeline.json").with(:query => {:include_rts => "true", :count => "200", :max_id => "244102729860009983"})).to have_been_made.times(3)
191
- end
192
- it "returns the 20 most recent retweets posted by users the authenticating user follow" do
193
- tweets = @client.retweeted_to_me
194
- expect(tweets).to be_an Array
195
- expect(tweets.first).to be_a Twitter::Tweet
196
- expect(tweets.first.text).to eq "RT @olivercameron: Mosaic looks cool: http://t.co/A8013C9k"
197
- end
198
- end
199
-
200
- describe "#retweets_of_me" do
201
- before do
202
- stub_get("/1.1/statuses/retweets_of_me.json").to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
203
- end
204
- it "requests the correct resource" do
205
- @client.retweets_of_me
206
- expect(a_get("/1.1/statuses/retweets_of_me.json")).to have_been_made
207
- end
208
- it "returns the 20 most recent tweets of the authenticated user that have been retweeted by others" do
209
- tweets = @client.retweets_of_me
210
- expect(tweets).to be_an Array
211
- expect(tweets.first).to be_a Twitter::Tweet
212
- expect(tweets.first.text).to eq "Happy Birthday @imdane. Watch out for those @rally pranksters!"
213
- end
214
- end
215
-
216
- describe "#user_timeline" do
217
- context "with a screen name passed" do
218
- before do
219
- stub_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
220
- end
221
- it "requests the correct resource" do
222
- @client.user_timeline("sferik")
223
- expect(a_get("/1.1/statuses/user_timeline.json").with(:query => {:screen_name => "sferik"})).to have_been_made
224
- end
225
- it "returns the 20 most recent Tweets posted by the user specified by screen name or user id" do
226
- tweets = @client.user_timeline("sferik")
227
- expect(tweets).to be_an Array
228
- expect(tweets.first).to be_a Twitter::Tweet
229
- expect(tweets.first.text).to eq "Happy Birthday @imdane. Watch out for those @rally pranksters!"
230
- end
231
- end
232
- context "without a screen name passed" do
233
- before do
234
- stub_get("/1.1/statuses/user_timeline.json").to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
235
- end
236
- it "requests the correct resource" do
237
- @client.user_timeline
238
- expect(a_get("/1.1/statuses/user_timeline.json")).to have_been_made
239
- end
240
- end
241
- end
242
-
243
- describe "#media_timeline" do
244
- context "with a screen name passed" do
245
- before do
246
- stub_get("/1.1/statuses/media_timeline.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("media_timeline.json"), :headers => {:content_type => "application/json; charset=utf-8"})
247
- end
248
- it "requests the correct resource" do
249
- @client.media_timeline("sferik")
250
- expect(a_get("/1.1/statuses/media_timeline.json").with(:query => {:screen_name => "sferik"})).to have_been_made
251
- end
252
- it "returns the 20 most recent images posted by the user specified by screen name or user id" do
253
- tweets = @client.media_timeline("sferik")
254
- expect(tweets).to be_an Array
255
- expect(tweets.first).to be_a Twitter::Tweet
256
- expect(tweets.first.text).to eq "Google is throwing up a question mark for Sunday's weather in Boston. At least they're being honest. http://t.co/Jh7bAhS"
257
- end
258
- end
259
- context "without a screen name passed" do
260
- before do
261
- stub_get("/1.1/statuses/media_timeline.json").to_return(:body => fixture("media_timeline.json"), :headers => {:content_type => "application/json; charset=utf-8"})
262
- end
263
- it "requests the correct resource" do
264
- @client.media_timeline
265
- expect(a_get("/1.1/statuses/media_timeline.json")).to have_been_made
266
- end
267
- end
268
- end
269
-
270
- describe "#retweeters_of" do
271
- context "with ids_only passed" do
272
- before do
273
- stub_get("/1.1/statuses/retweets/28561922516.json").to_return(:body => fixture("retweets.json"), :headers => {:content_type => "application/json; charset=utf-8"})
274
- end
275
- it "requests the correct resource" do
276
- @client.retweeters_of(28561922516, :ids_only => true)
277
- expect(a_get("/1.1/statuses/retweets/28561922516.json")).to have_been_made
278
- end
279
- it "returns an array of numeric user IDs of retweeters of a Tweet" do
280
- ids = @client.retweeters_of(28561922516, :ids_only => true)
281
- expect(ids).to be_an Array
282
- expect(ids.first).to eq 7505382
283
- end
284
- end
285
- context "without ids_only passed" do
286
- before do
287
- stub_get("/1.1/statuses/retweets/28561922516.json").to_return(:body => fixture("retweets.json"), :headers => {:content_type => "application/json; charset=utf-8"})
288
- end
289
- it "requests the correct resource" do
290
- @client.retweeters_of(28561922516)
291
- expect(a_get("/1.1/statuses/retweets/28561922516.json")).to have_been_made
292
- end
293
- it "returns an array of user of retweeters of a Tweet" do
294
- users = @client.retweeters_of(28561922516)
295
- expect(users).to be_an Array
296
- expect(users.first).to be_a Twitter::User
297
- expect(users.first.id).to eq 7505382
298
- end
299
- end
300
- end
301
-
302
- describe "#retweets" do
303
- before do
304
- stub_get("/1.1/statuses/retweets/28561922516.json").to_return(:body => fixture("retweets.json"), :headers => {:content_type => "application/json; charset=utf-8"})
305
- end
306
- it "requests the correct resource" do
307
- @client.retweets(28561922516)
308
- expect(a_get("/1.1/statuses/retweets/28561922516.json")).to have_been_made
309
- end
310
- it "returns up to 100 of the first retweets of a given tweet" do
311
- tweets = @client.retweets(28561922516)
312
- expect(tweets).to be_an Array
313
- expect(tweets.first).to be_a Twitter::Tweet
314
- expect(tweets.first.text).to eq "RT @gruber: As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
315
- end
316
- end
317
-
318
- describe "#status" do
319
- before do
320
- stub_get("/1.1/statuses/show/25938088801.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
321
- end
322
- it "requests the correct resource" do
323
- @client.status(25938088801)
324
- expect(a_get("/1.1/statuses/show/25938088801.json")).to have_been_made
325
- end
326
- it "returns a Tweet" do
327
- tweet = @client.status(25938088801)
328
- expect(tweet).to be_a Twitter::Tweet
329
- expect(tweet.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
330
- end
331
- end
332
-
333
- describe "#statuses" do
334
- before do
335
- stub_get("/1.1/statuses/show/25938088801.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
336
- end
337
- it "requests the correct resource" do
338
- @client.statuses(25938088801)
339
- expect(a_get("/1.1/statuses/show/25938088801.json")).to have_been_made
340
- end
341
- it "returns an array of Tweets" do
342
- tweets = @client.statuses(25938088801)
343
- expect(tweets).to be_an Array
344
- expect(tweets.first).to be_a Twitter::Tweet
345
- expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
346
- end
347
- end
348
-
349
- describe "#status_activity" do
350
- before do
351
- stub_get("/i/statuses/25938088801/activity/summary.json").to_return(:body => fixture("activity_summary.json"), :headers => {:content_type => "application/json; charset=utf-8"})
352
- end
353
- it "requests the correct resource" do
354
- @client.status_activity(25938088801)
355
- expect(a_get("/i/statuses/25938088801/activity/summary.json")).to have_been_made
356
- end
357
- it "returns a Tweet" do
358
- tweet = @client.status_activity(25938088801)
359
- expect(tweet).to be_a Twitter::Tweet
360
- expect(tweet.retweeters_count).to eq 1
361
- end
362
- end
363
-
364
- describe "#statuses_activity" do
365
- before do
366
- stub_get("/i/statuses/25938088801/activity/summary.json").to_return(:body => fixture("activity_summary.json"), :headers => {:content_type => "application/json; charset=utf-8"})
367
- end
368
- it "requests the correct resource" do
369
- @client.statuses_activity(25938088801)
370
- expect(a_get("/i/statuses/25938088801/activity/summary.json")).to have_been_made
371
- end
372
- it "returns an array of Tweets" do
373
- tweets = @client.statuses_activity(25938088801)
374
- expect(tweets).to be_an Array
375
- expect(tweets.first).to be_a Twitter::Tweet
376
- expect(tweets.first.retweeters_count).to eq 1
377
- end
378
- end
379
-
380
- describe "#status_destroy" do
381
- before do
382
- stub_post("/1.1/statuses/destroy/25938088801.json").to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
383
- end
384
- it "requests the correct resource" do
385
- @client.status_destroy(25938088801)
386
- expect(a_post("/1.1/statuses/destroy/25938088801.json")).to have_been_made
387
- end
388
- it "returns an array of Tweets" do
389
- tweets = @client.status_destroy(25938088801)
390
- expect(tweets).to be_an Array
391
- expect(tweets.first).to be_a Twitter::Tweet
392
- expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
393
- end
394
- end
395
-
396
- describe "#retweet" do
397
- before do
398
- stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:body => fixture("retweet.json"), :headers => {:content_type => "application/json; charset=utf-8"})
399
- end
400
- it "requests the correct resource" do
401
- @client.retweet(28561922516)
402
- expect(a_post("/1.1/statuses/retweet/28561922516.json")).to have_been_made
403
- end
404
- it "returns an array of Tweets with retweet details embedded" do
405
- tweets = @client.retweet(28561922516)
406
- expect(tweets).to be_an Array
407
- expect(tweets.first).to be_a Twitter::Tweet
408
- expect(tweets.first.text).to eq "As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
409
- expect(tweets.first.retweeted_tweet.text).to eq "RT @gruber: As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
410
- expect(tweets.first.retweeted_tweet.id).not_to eq tweets.first.id
411
- end
412
- context "already retweeted" do
413
- before do
414
- stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:status => 403, :body => fixture("already_retweeted.json"), :headers => {:content_type => "application/json; charset=utf-8"})
415
- end
416
- it "does not raise an error" do
417
- expect{@client.retweet(28561922516)}.not_to raise_error
418
- end
419
- end
420
- end
421
-
422
- describe "#retweet!" do
423
- before do
424
- stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:body => fixture("retweet.json"), :headers => {:content_type => "application/json; charset=utf-8"})
425
- end
426
- it "requests the correct resource" do
427
- @client.retweet!(28561922516)
428
- expect(a_post("/1.1/statuses/retweet/28561922516.json")).to have_been_made
429
- end
430
- it "returns an array of Tweets with retweet details embedded" do
431
- tweets = @client.retweet!(28561922516)
432
- expect(tweets).to be_an Array
433
- expect(tweets.first).to be_a Twitter::Tweet
434
- expect(tweets.first.text).to eq "As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
435
- expect(tweets.first.retweeted_tweet.text).to eq "RT @gruber: As for the Series, I'm for the Giants. Fuck Texas, fuck Nolan Ryan, fuck George Bush."
436
- expect(tweets.first.retweeted_tweet.id).not_to eq tweets.first.id
437
- end
438
- context "fobidden" do
439
- before do
440
- stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:status => 403, :headers => {:content_type => "application/json; charset=utf-8"})
441
- end
442
- it "raises a Forbidden error" do
443
- expect{@client.retweet!(28561922516)}.to raise_error(Twitter::Error::Forbidden)
444
- end
445
- end
446
- context "already retweeted" do
447
- before do
448
- stub_post("/1.1/statuses/retweet/28561922516.json").to_return(:status => 403, :body => fixture("already_retweeted.json"), :headers => {:content_type => "application/json; charset=utf-8"})
449
- end
450
- it "raises an AlreadyRetweeted error" do
451
- expect{@client.retweet!(28561922516)}.to raise_error(Twitter::Error::AlreadyRetweeted, "Tweet with the ID 28561922516 has already been retweeted by the authenticated user.")
452
- end
453
- end
454
- end
455
-
456
- describe "#tweet" do
457
- before do
458
- stub_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do."}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
459
- end
460
- it "requests the correct resource" do
461
- @client.update("The problem with your code is that it's doing exactly what you told it to do.")
462
- expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do."})).to have_been_made
463
- end
464
- it "returns a Tweet" do
465
- tweet = @client.update("The problem with your code is that it's doing exactly what you told it to do.")
466
- expect(tweet).to be_a Twitter::Tweet
467
- expect(tweet.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
468
- end
469
- end
470
-
471
- describe "#update_with_media" do
472
- before do
473
- stub_post("/1.1/statuses/update_with_media.json").to_return(:body => fixture("status_with_media.json"), :headers => {:content_type => "application/json; charset=utf-8"})
474
- end
475
- context "a gif image" do
476
- it "requests the correct resource" do
477
- @client.update_with_media("You always have options", fixture("pbjt.gif"))
478
- expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
479
- end
480
- it "returns a Tweet" do
481
- tweet = @client.update_with_media("You always have options", fixture("pbjt.gif"))
482
- expect(tweet).to be_a Twitter::Tweet
483
- expect(tweet.text).to eq "You always have options http://t.co/CBYa7Ri"
484
- end
485
- end
486
- context "a jpe image" do
487
- it "requests the correct resource" do
488
- @client.update_with_media("You always have options", fixture("wildcomet2.jpe"))
489
- expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
490
- end
491
- end
492
- context "a jpeg image" do
493
- it "requests the correct resource" do
494
- @client.update_with_media("You always have options", fixture("me.jpeg"))
495
- expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
496
- end
497
- end
498
- context "a png image" do
499
- it "requests the correct resource" do
500
- @client.update_with_media("You always have options", fixture("we_concept_bg2.png"))
501
- expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
502
- end
503
- end
504
- context "a Tempfile" do
505
- it "requests the correct resource" do
506
- @client.update_with_media("You always have options", Tempfile.new("tmp"))
507
- expect(a_post("/1.1/statuses/update_with_media.json")).to have_been_made
508
- end
509
- end
510
- end
511
-
512
- describe "#oembed" do
513
- before do
514
- stub_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"}).to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
515
- end
516
- it "requests the correct resource" do
517
- @client.oembed(25938088801)
518
- expect(a_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"})).to have_been_made
519
- end
520
- it "returns an array of OEmbed instances" do
521
- oembed = @client.oembed(25938088801)
522
- expect(oembed).to be_a Twitter::OEmbed
523
- end
524
- end
525
-
526
- describe "#oembeds" do
527
- before do
528
- stub_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"}).to_return(:body => fixture("oembed.json"), :headers => {:content_type => "application/json; charset=utf-8"})
529
- end
530
- it "requests the correct resource" do
531
- @client.oembeds(25938088801)
532
- expect(a_get("/1.1/statuses/oembed.json").with(:query => {:id => "25938088801"})).to have_been_made
533
- end
534
- it "returns an array of OEmbed instances" do
535
- oembeds = @client.oembeds(25938088801)
536
- expect(oembeds).to be_an Array
537
- expect(oembeds.first).to be_a Twitter::OEmbed
538
- end
539
- end
540
-
541
- end