trubl 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.yardopts +8 -0
- data/LICENSE.md +20 -0
- data/README.md +72 -0
- data/Rakefile +11 -0
- data/lib/trubl.rb +30 -0
- data/lib/trubl/api/category.rb +33 -0
- data/lib/trubl/api/channel.rb +32 -0
- data/lib/trubl/api/conversation.rb +31 -0
- data/lib/trubl/api/hashtags.rb +45 -0
- data/lib/trubl/api/me.rb +68 -0
- data/lib/trubl/api/search.rb +35 -0
- data/lib/trubl/api/streams.rb +14 -0
- data/lib/trubl/api/suggested_users.rb +16 -0
- data/lib/trubl/api/touts.rb +143 -0
- data/lib/trubl/api/users.rb +79 -0
- data/lib/trubl/authorization.rb +7 -0
- data/lib/trubl/authorizations.rb +8 -0
- data/lib/trubl/base.rb +37 -0
- data/lib/trubl/category.rb +7 -0
- data/lib/trubl/channel.rb +7 -0
- data/lib/trubl/client.rb +252 -0
- data/lib/trubl/collection.rb +43 -0
- data/lib/trubl/conversation.rb +7 -0
- data/lib/trubl/hashtag.rb +7 -0
- data/lib/trubl/hashtags.rb +8 -0
- data/lib/trubl/oauth.rb +56 -0
- data/lib/trubl/pagination.rb +17 -0
- data/lib/trubl/tout.rb +29 -0
- data/lib/trubl/touts.rb +8 -0
- data/lib/trubl/user.rb +29 -0
- data/lib/trubl/users.rb +8 -0
- data/lib/trubl/version.rb +16 -0
- data/lib/trubl/widget.rb +15 -0
- data/lib/trubl/widgets.rb +8 -0
- data/spec/fixtures/category_response.json +1 -0
- data/spec/fixtures/category_touts_response.json +689 -0
- data/spec/fixtures/category_users_response.json +1709 -0
- data/spec/fixtures/channel_response.json +1 -0
- data/spec/fixtures/channel_touts_response.json +1 -0
- data/spec/fixtures/channel_users_response.json +1 -0
- data/spec/fixtures/client1_auth_resp.json +1 -0
- data/spec/fixtures/client2_auth_resp.json +1 -0
- data/spec/fixtures/conversation_authors_response.json +37 -0
- data/spec/fixtures/conversation_response.json +41 -0
- data/spec/fixtures/conversation_touts_response.json +107 -0
- data/spec/fixtures/featured_touts_response.json +4249 -0
- data/spec/fixtures/hashtag_response.json +1 -0
- data/spec/fixtures/hashtags_touts_response.json +304 -0
- data/spec/fixtures/latest_touts_response.json +3600 -0
- data/spec/fixtures/like_tout_response.json +109 -0
- data/spec/fixtures/me_authorizations_response.json +14 -0
- data/spec/fixtures/me_fb_sharing_response.json +21 -0
- data/spec/fixtures/me_friends_response.json +121 -0
- data/spec/fixtures/me_retrieve_user_friends_response.json +174 -0
- data/spec/fixtures/me_retrieve_user_liked_touts_response.json +1255 -0
- data/spec/fixtures/me_retrieve_user_touts_response.json +479 -0
- data/spec/fixtures/retout_tout_response.json +99 -0
- data/spec/fixtures/retrieve_me_response.json +35 -0
- data/spec/fixtures/retrieve_tout.json +98 -0
- data/spec/fixtures/retrieve_tout_response.json +98 -0
- data/spec/fixtures/search_hashtags_response.json +100 -0
- data/spec/fixtures/search_touts_response.json +304 -0
- data/spec/fixtures/search_users_response.json +37 -0
- data/spec/fixtures/suggested_hashtags_response.json +137 -0
- data/spec/fixtures/suggested_users_response.json +1 -0
- data/spec/fixtures/test.mp4 +0 -0
- data/spec/fixtures/tout.json +98 -0
- data/spec/fixtures/tout_conversation_response.json +41 -0
- data/spec/fixtures/touts_liked_by_response.json +65 -0
- data/spec/fixtures/touts_liked_by_user_response.json +106 -0
- data/spec/fixtures/touts_me_updates_response.json +357 -0
- data/spec/fixtures/touts_search_results.json +304 -0
- data/spec/fixtures/trending_hashtags_response.json +149 -0
- data/spec/fixtures/unlike_tout_response.json +109 -0
- data/spec/fixtures/update_me_response.json +35 -0
- data/spec/fixtures/user.json +28 -0
- data/spec/fixtures/user_followers.json +1409 -0
- data/spec/fixtures/user_touts_response.json +479 -0
- data/spec/fixtures/user_with_utf8.json +29 -0
- data/spec/fixtures/users.json +58 -0
- data/spec/fixtures/users_search_results.json +37 -0
- data/spec/fixtures/widgets.json +142 -0
- data/spec/spec_helper.rb +61 -0
- data/spec/trubl/api/category_spec.rb +39 -0
- data/spec/trubl/api/channel_spec.rb +39 -0
- data/spec/trubl/api/conversation_spec.rb +38 -0
- data/spec/trubl/api/hashtags_spec.rb +60 -0
- data/spec/trubl/api/me_spec.rb +98 -0
- data/spec/trubl/api/search_spec.rb +40 -0
- data/spec/trubl/api/streams_spec.rb +18 -0
- data/spec/trubl/api/suggested_users_spec.rb +17 -0
- data/spec/trubl/api/touts_spec.rb +215 -0
- data/spec/trubl/api/users_spec.rb +122 -0
- data/spec/trubl/base_spec.rb +88 -0
- data/spec/trubl/category_spec.rb +15 -0
- data/spec/trubl/channel_spec.rb +16 -0
- data/spec/trubl/client_spec.rb +141 -0
- data/spec/trubl/conversation_spec.rb +13 -0
- data/spec/trubl/hashtag_spec.rb +11 -0
- data/spec/trubl/oauth_spec.rb +27 -0
- data/spec/trubl/tout_spec.rb +41 -0
- data/spec/trubl/user_spec.rb +65 -0
- data/spec/trubl_spec.rb +23 -0
- data/trubl.gemspec +41 -0
- metadata +494 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require_relative '../../spec_helper'
|
|
2
|
+
require 'trubl/client'
|
|
3
|
+
require 'webmock'
|
|
4
|
+
|
|
5
|
+
describe Trubl::API::Hashtags do
|
|
6
|
+
|
|
7
|
+
it 'retrieve_hashtag returns a Hashtag' do
|
|
8
|
+
stub_get("https://api.tout.com/api/v1/hashtags/pets").to_return(:body => fixture("hashtag_response.json"))
|
|
9
|
+
hashtag = Trubl::Client.new.retrieve_hashtag("pets")
|
|
10
|
+
expect(hashtag).to be_a Trubl::Hashtag
|
|
11
|
+
some_request(:get, "/api/v1/hashtags/pets").should have_been_made
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'retrieve_hashtag_touts returns Touts::Collection matching a hashtag' do
|
|
15
|
+
stub_get("https://api.tout.com/api/v1/hashtags/ows/touts").to_return(:body => fixture("hashtags_touts_response.json"))
|
|
16
|
+
touts = Trubl::Client.new.retrieve_hashtag_touts("ows")
|
|
17
|
+
expect(touts).to be_a Trubl::Touts
|
|
18
|
+
#expect(touts.pagination).to be_a Trubl::Pagination
|
|
19
|
+
touts.each do |u|
|
|
20
|
+
expect(u).to be_a Trubl::Tout
|
|
21
|
+
end
|
|
22
|
+
some_request(:get, "/api/v1/hashtags/ows/touts").should have_been_made
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'retrieve_trending_hashtags returns json describing hashtags' do
|
|
26
|
+
stub_get("https://api.tout.com/api/v1/trending_hashtags").to_return(:body => fixture("trending_hashtags_response.json"))
|
|
27
|
+
hashtags = Trubl::Client.new.retrieve_trending_hashtags()
|
|
28
|
+
expect(hashtags).to be_a Trubl::Hashtags
|
|
29
|
+
#expect(hashtags.pagination).to be_a Trubl::Pagination
|
|
30
|
+
hashtags.each do |h|
|
|
31
|
+
expect(h).to be_a Trubl::Hashtag
|
|
32
|
+
end
|
|
33
|
+
some_request(:get, "/api/v1/trending_hashtags").should have_been_made
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'retrieve_suggested_hashtags returns json describing hashtags' do
|
|
37
|
+
stub_get("https://api.tout.com/api/v1/suggested_hashtags").to_return(:body => fixture("suggested_hashtags_response.json"))
|
|
38
|
+
hashtags = Trubl::Client.new.retrieve_suggested_hashtags("arc", 5)
|
|
39
|
+
expect(hashtags).to be_a Trubl::Hashtags
|
|
40
|
+
hashtags.each do |h|
|
|
41
|
+
expect(h).to be_a Trubl::Hashtag
|
|
42
|
+
end
|
|
43
|
+
some_request(:get, "/api/v1/suggested_hashtags").should have_been_made
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it '.follow_hashtag executes a follow for the specified user with a user authed token' do
|
|
47
|
+
client = Trubl::Client.new
|
|
48
|
+
stub_post("https://api.tout.com/api/v1/hashtags/pets/subscribes").to_return(:body => "")
|
|
49
|
+
client.follow_hashtag('pets')
|
|
50
|
+
some_request(:post, "/api/v1/hashtags/pets/subscribes").should have_been_made
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it '.unfollow_hashtag executes an unfollow for the specified user with a user authed token' do
|
|
54
|
+
client = Trubl::Client.new
|
|
55
|
+
stub_delete("https://api.tout.com/api/v1/hashtags/pets/subscribes").to_return(:body => "")
|
|
56
|
+
client.unfollow_hashtag('pets')
|
|
57
|
+
some_request(:delete, "/api/v1/hashtags/pets/subscribes").should have_been_made
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require 'trubl/client'
|
|
2
|
+
|
|
3
|
+
describe Trubl::API::Me do
|
|
4
|
+
|
|
5
|
+
it "retrieve_me returns my Trubl::User" do
|
|
6
|
+
stub_get("https://api.tout.com/api/v1/me").to_return(:body => fixture("retrieve_me_response.json"))
|
|
7
|
+
user = Trubl::Client.new.get_me()
|
|
8
|
+
expect(user).to be_a Trubl::User
|
|
9
|
+
some_request(:get, "/api/v1/me").should have_been_made
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe '.update_me' do
|
|
13
|
+
subject { Trubl::Client.new.update_me(params) }
|
|
14
|
+
|
|
15
|
+
context 'updating email and password' do
|
|
16
|
+
let(:params) { {user: {email: 'user@example.com', password: '123456', password_confirmation: '123456'}} }
|
|
17
|
+
let(:url) { "/api/v1/me" }
|
|
18
|
+
before { stub_put("https://api.tout.com#{url}").to_return(result) }
|
|
19
|
+
after { some_request(:put, url).should have_been_made }
|
|
20
|
+
|
|
21
|
+
context 'a success' do
|
|
22
|
+
let(:result) { {status: 200, body: fixture('update_me_response.json')} }
|
|
23
|
+
it { should be_a Trubl::User }
|
|
24
|
+
end
|
|
25
|
+
context 'a failure' do
|
|
26
|
+
let(:result) { {status: 500} }
|
|
27
|
+
it { should be_nil }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'not even hitting the api' do
|
|
32
|
+
context 'blank payload' do
|
|
33
|
+
let(:params) { {} }
|
|
34
|
+
it { should be_nil }
|
|
35
|
+
end
|
|
36
|
+
context 'updating nothing' do
|
|
37
|
+
let(:params) { {user: nil} }
|
|
38
|
+
it { should be_nil }
|
|
39
|
+
end
|
|
40
|
+
context 'updating unallowed property' do
|
|
41
|
+
let(:params) { {user: {email: 'user@example.com', password: '123456', password_confirmation: '123456', friends_count: 1}} }
|
|
42
|
+
it 'should raise' do
|
|
43
|
+
expect { subject }.to raise_exception
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it ".get_my_authorizations returns my Trubl::Authorizations" do
|
|
50
|
+
stub_get("https://api.tout.com/api/v1/me/authorizations").to_return(:body => fixture("me_authorizations_response.json"))
|
|
51
|
+
authorizations = Trubl::Client.new.get_my_authorizations
|
|
52
|
+
some_request(:get, "/api/v1/me/authorizations").should have_been_made
|
|
53
|
+
expect(authorizations).to be_a Trubl::Authorizations
|
|
54
|
+
expect(authorizations.size).to eq 1
|
|
55
|
+
expect(authorizations.first.name).to eq 'Facebook'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it ".get_my_fb_sharing_settings returns json rep of fb settings" do
|
|
59
|
+
stub_get("https://api.tout.com/api/v1/me/sharing/facebook").to_return(:body => fixture("me_fb_sharing_response.json"))
|
|
60
|
+
json = Trubl::Client.new.get_my_fb_sharing_settings
|
|
61
|
+
expect(json).to be_a Hash
|
|
62
|
+
expect(json["via"]["name"]).to eq("Facebook")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it ".get_my_touts returns Touts instance" do
|
|
66
|
+
stub_get("https://api.tout.com/api/v1/me/touts").to_return(:body => fixture("me_retrieve_user_touts_response.json"))
|
|
67
|
+
touts = Trubl::Client.new.get_my_touts()
|
|
68
|
+
expect(touts).to be_a Trubl::Touts
|
|
69
|
+
some_request(:get, "/api/v1/me/touts").should have_been_made
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it ".get_my_liked_touts returns Touts instance" do
|
|
73
|
+
stub_get("https://api.tout.com/api/v1/me/likes").to_return(:body => fixture("me_retrieve_user_liked_touts_response.json"))
|
|
74
|
+
touts = Trubl::Client.new.get_my_liked_touts()
|
|
75
|
+
expect(touts).to be_a Trubl::Touts
|
|
76
|
+
some_request(:get, "/api/v1/me/likes").should have_been_made
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it ".friends returns Users instance" do
|
|
80
|
+
stub_get("https://api.tout.com/api/v1/me/friends").to_return(:body => fixture("me_friends_response.json"))
|
|
81
|
+
users = Trubl::Client.new.friends()
|
|
82
|
+
expect(users).to be_a Trubl::Users
|
|
83
|
+
some_request(:get, "/api/v1/me/friends").should have_been_made
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe '.widgets' do
|
|
87
|
+
before do
|
|
88
|
+
stub_get("https://api.tout.com/api/v1/me/widgets").to_return(body: fixture("widgets.json"))
|
|
89
|
+
end
|
|
90
|
+
subject { Trubl::Client.new.widgets() }
|
|
91
|
+
it { should be_kind_of Trubl::Widgets }
|
|
92
|
+
it 'does the right api call' do
|
|
93
|
+
subject
|
|
94
|
+
some_request(:get, "https://api.tout.com/api/v1/me/widgets").should have_been_made
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require_relative '../../spec_helper'
|
|
2
|
+
require 'trubl/client'
|
|
3
|
+
require 'webmock'
|
|
4
|
+
|
|
5
|
+
describe Trubl::API::Search do
|
|
6
|
+
|
|
7
|
+
it '.search_hashtags returns hashtag search results properly' do
|
|
8
|
+
stub_get("https://api.tout.com/api/v1/search/hashtags").to_return(:body => fixture("search_hashtags_response.json"))
|
|
9
|
+
hashtags = Trubl::Client.new.search_hashtags("arch")
|
|
10
|
+
expect(hashtags).to be_a Trubl::Hashtags
|
|
11
|
+
#expect(hashtags.pagination).to be_a Trubl::Pagination
|
|
12
|
+
hashtags.each do |h|
|
|
13
|
+
expect(h).to be_a Trubl::Hashtag
|
|
14
|
+
end
|
|
15
|
+
some_request(:get, "/api/v1/search/hashtags").should have_been_made
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it '.search_users returns user search results properly' do
|
|
19
|
+
stub_get("https://api.tout.com/api/v1/search/users").to_return(:body => fixture("search_users_response.json"))
|
|
20
|
+
users = Trubl::Client.new.search_users("melissa joan")
|
|
21
|
+
expect(users).to be_a Trubl::Users
|
|
22
|
+
#expect(users.pagination).to be_a Trubl::Pagination
|
|
23
|
+
users.each do |u|
|
|
24
|
+
expect(u).to be_a Trubl::User
|
|
25
|
+
end
|
|
26
|
+
some_request(:get, "/api/v1/search/users").should have_been_made
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it '.search_touts returns user search results properly' do
|
|
30
|
+
stub_get("https://api.tout.com/api/v1/search/touts").to_return(:body => fixture("search_touts_response.json"))
|
|
31
|
+
touts = Trubl::Client.new.search_touts("shaq")
|
|
32
|
+
expect(touts).to be_a Trubl::Touts
|
|
33
|
+
#expect(touts.pagination).to be_a Trubl::Pagination
|
|
34
|
+
touts.each do |t|
|
|
35
|
+
expect(t).to be_a Trubl::Tout
|
|
36
|
+
end
|
|
37
|
+
some_request(:get, "/api/v1/search/touts").should have_been_made
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require_relative '../../spec_helper'
|
|
2
|
+
require 'trubl/client'
|
|
3
|
+
require 'webmock'
|
|
4
|
+
|
|
5
|
+
describe Trubl::API::Streams do
|
|
6
|
+
|
|
7
|
+
# todo: the fixture is not an authentic streams response, add one please
|
|
8
|
+
it '.retrieve_stream_touts returns touts included in a stream' do
|
|
9
|
+
stub_get("https://api.tout.com/api/v1/streams/fhcl57/touts").to_return(:body => fixture("featured_touts_response.json"))
|
|
10
|
+
touts = Trubl::Client.new.retrieve_stream_touts('fhcl57')
|
|
11
|
+
expect(touts).to be_a Trubl::Touts
|
|
12
|
+
#expect(touts.pagination).to be_a Trubl::Pagination
|
|
13
|
+
touts.each do |u|
|
|
14
|
+
expect(u).to be_a Trubl::Tout
|
|
15
|
+
end
|
|
16
|
+
some_request(:get, "/streams/fhcl57/touts").should have_been_made
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require_relative '../../spec_helper'
|
|
2
|
+
require 'trubl/client'
|
|
3
|
+
require 'webmock'
|
|
4
|
+
|
|
5
|
+
describe Trubl::API::Suggested_Users do
|
|
6
|
+
|
|
7
|
+
# todo: the fixture is not an authentic streams response, add one please
|
|
8
|
+
it '.retrieve_stream_touts returns touts included in a stream' do
|
|
9
|
+
stub_get("https://api.tout.com/api/v1/suggested_users.json").to_return(:body => fixture("suggested_users_response.json"))
|
|
10
|
+
touts = Trubl::Client.new.suggested_users('wwe')
|
|
11
|
+
expect(touts).to be_a Trubl::Users
|
|
12
|
+
touts.each do |u|
|
|
13
|
+
expect(u).to be_a Trubl::User
|
|
14
|
+
end
|
|
15
|
+
some_request(:get, "/suggested_users.json").should have_been_made
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
require_relative '../../spec_helper'
|
|
2
|
+
require 'trubl/client'
|
|
3
|
+
require 'webmock'
|
|
4
|
+
|
|
5
|
+
describe Trubl::API::Touts do
|
|
6
|
+
|
|
7
|
+
let(:client) { Trubl::Client.new }
|
|
8
|
+
|
|
9
|
+
it '.featured_touts returns a collection of Touts' do
|
|
10
|
+
stub_api_get("featured").to_return(:body => fixture("featured_touts_response.json"))
|
|
11
|
+
touts = client.featured_touts()
|
|
12
|
+
expect(touts).to be_a Trubl::Touts
|
|
13
|
+
#expect(touts.pagination).to be_a Trubl::Pagination
|
|
14
|
+
touts.each do |u|
|
|
15
|
+
expect(u).to be_a Trubl::Tout
|
|
16
|
+
end
|
|
17
|
+
some_request(:get, "/api/v1/featured").should have_been_made
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it '.tout_liked_by returns a Collection of Users liking the specified tout' do
|
|
21
|
+
stub_api_get("touts/fhcl57/liked_by").to_return(:body => fixture("touts_liked_by_response.json"))
|
|
22
|
+
users = client.tout_liked_by("fhcl57")
|
|
23
|
+
expect(users).to be_a Trubl::Users
|
|
24
|
+
#expect(users.pagination).to be_a Trubl::Pagination
|
|
25
|
+
users.each do |u|
|
|
26
|
+
expect(u).to be_a Trubl::User
|
|
27
|
+
end
|
|
28
|
+
some_request(:get, "/api/v1/touts/fhcl57/liked_by").should have_been_made
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it '.retrieve_tout returns a Tout object' do
|
|
32
|
+
stub_api_get("touts/fhcl57").to_return(:body => fixture("retrieve_tout.json"))
|
|
33
|
+
tout = client.retrieve_tout("fhcl57")
|
|
34
|
+
expect(tout).to be_a Trubl::Tout
|
|
35
|
+
expect(tout.uid).to eq "fhcl57"
|
|
36
|
+
some_request(:get, "/api/v1/touts/fhcl57").should have_been_made
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#retrieve_touts' do
|
|
40
|
+
subject { client.retrieve_touts(uids) }
|
|
41
|
+
|
|
42
|
+
context 'providing an array of users uids' do
|
|
43
|
+
let(:sorted_uids) { 125.times.collect { |i| "test_tout_#{i}" }.sort }
|
|
44
|
+
let(:uids) { sorted_uids.shuffle }
|
|
45
|
+
|
|
46
|
+
before do
|
|
47
|
+
sorted_uids.in_groups_of(100, false) do |uid_group|
|
|
48
|
+
fake_tout_response = {touts: uid_group.collect { |uid| {tout: {uid: uid} } } }
|
|
49
|
+
|
|
50
|
+
stub_request(:get, "https://api.tout.com/api/v1/touts?uids=#{uid_group.join(',')}").
|
|
51
|
+
to_return(
|
|
52
|
+
status: 200,
|
|
53
|
+
body: fake_tout_response.to_json,
|
|
54
|
+
headers: {}
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
its(:size) { should == uids.size }
|
|
60
|
+
it 'should contain the users' do
|
|
61
|
+
expect(subject.map(&:uid).sort).to eq sorted_uids
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'providing a single uid as string' do
|
|
66
|
+
let(:uids) { 'random_tout' }
|
|
67
|
+
before do
|
|
68
|
+
stub_request(:get, "https://api.tout.com/api/v1/touts?uids=#{uids}").
|
|
69
|
+
to_return(
|
|
70
|
+
status: 200,
|
|
71
|
+
body: {touts: [{tout: {uid: uids}}]}.to_json,
|
|
72
|
+
headers: {}
|
|
73
|
+
)
|
|
74
|
+
end
|
|
75
|
+
its(:size) { should == 1 }
|
|
76
|
+
its('first.uid') { should == uids }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context 'providing a blank list' do
|
|
80
|
+
let(:uids) { nil }
|
|
81
|
+
before do
|
|
82
|
+
client.should_not_receive(:multi_request)
|
|
83
|
+
end
|
|
84
|
+
it { should == [] }
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
it '.retrieve_tout_conversation returns the Conversation related to a Tout' do
|
|
90
|
+
stub_api_get("touts/fhcl57/conversation").to_return(:body => fixture("tout_conversation_response.json"))
|
|
91
|
+
conversation = client.retrieve_tout_conversation('fhcl57')
|
|
92
|
+
expect(conversation).to be_a Trubl::Conversation
|
|
93
|
+
expect(conversation.uid).to eq('cmbjd3xn')
|
|
94
|
+
some_request(:get, "/api/v1/touts/fhcl57/conversation").should have_been_made
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it '.retrieve_latest returns the latest Touts' do
|
|
98
|
+
stub_api_get("latest").to_return(:body => fixture("latest_touts_response.json"))
|
|
99
|
+
touts = client.latest_touts()
|
|
100
|
+
expect(touts).to be_a Trubl::Touts
|
|
101
|
+
#expect(touts.pagination).to be_a Trubl::Pagination
|
|
102
|
+
touts.each do |u|
|
|
103
|
+
expect(u).to be_a Trubl::Tout
|
|
104
|
+
end
|
|
105
|
+
some_request(:get, "/api/v1/latest").should have_been_made
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it '.retrieve_latest returns the latest Touts' do
|
|
109
|
+
stub_api_get("me/updates").to_return(:body => fixture("touts_me_updates_response.json"))
|
|
110
|
+
touts = client.retrieve_updates()
|
|
111
|
+
expect(touts).to be_a Trubl::Touts
|
|
112
|
+
#expect(touts.pagination).to be_a Trubl::Pagination
|
|
113
|
+
touts.each do |u|
|
|
114
|
+
expect(u).to be_a Trubl::Tout
|
|
115
|
+
end
|
|
116
|
+
some_request(:get, "/api/v1/me/updates").should have_been_made
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it '.create_tout returns an object representing a newly created Tout' do
|
|
120
|
+
stub_post("https://api.tout.com/api/v1/touts").to_return(:body => fixture('tout.json'))
|
|
121
|
+
file = File.join(File.dirname(__FILE__), '../../fixtures/test.mp4')
|
|
122
|
+
payload = {tout: { data: file, text: 'Some text here'}}
|
|
123
|
+
tout = client.create_tout(payload)
|
|
124
|
+
expect(tout).to be_a Trubl::Tout
|
|
125
|
+
expect(tout.uid).to eq "fhcl57"
|
|
126
|
+
some_request(:post, "/api/v1/touts").should have_been_made
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe '.update_tout' do
|
|
130
|
+
let(:tout_uid) { 'some_random_tout_uid' }
|
|
131
|
+
subject { client.update_tout(tout_uid, params) }
|
|
132
|
+
|
|
133
|
+
context 'updating just the text' do
|
|
134
|
+
let(:params) { {tout: {text: 'something new'} } }
|
|
135
|
+
let(:url) { "/api/v1/touts/#{tout_uid}" }
|
|
136
|
+
before { stub_put("https://api.tout.com#{url}").to_return(result) }
|
|
137
|
+
after { some_request(:put, url).should have_been_made }
|
|
138
|
+
|
|
139
|
+
context 'a success' do
|
|
140
|
+
let(:result) { {status: 200, body: fixture('tout.json') }}
|
|
141
|
+
it { should be_a Trubl::Tout }
|
|
142
|
+
end
|
|
143
|
+
context 'a failure' do
|
|
144
|
+
let(:result) { {status: 500} }
|
|
145
|
+
it { should be_nil }
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
context 'not even hitting the api' do
|
|
150
|
+
context 'blank payload' do
|
|
151
|
+
let(:params) { {} }
|
|
152
|
+
it { should be_nil }
|
|
153
|
+
end
|
|
154
|
+
context 'updating nothing' do
|
|
155
|
+
let(:params) { {tout: nil} }
|
|
156
|
+
it { should be_nil }
|
|
157
|
+
end
|
|
158
|
+
context 'updating more than the text' do
|
|
159
|
+
let(:params) { {tout: {text: 'something new', privacy: 'public'}}}
|
|
160
|
+
it 'should raise' do
|
|
161
|
+
expect{subject}.to raise_exception
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it ".delete_tout returns true on 200 response" do
|
|
168
|
+
stub_delete("https://api.tout.com/api/v1/touts/123456").to_return(:status => 200, :body => "true")
|
|
169
|
+
result = client.delete_tout("123456")
|
|
170
|
+
expect(result).to eq(true)
|
|
171
|
+
some_request(:delete, "/api/v1/touts/123456").should have_been_made
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it ".delete_tout returns false on non-200 response" do
|
|
175
|
+
stub_delete("https://api.tout.com/api/v1/touts/234567").to_return(:status => 404, :body => "false")
|
|
176
|
+
result = client.delete_tout("234567")
|
|
177
|
+
expect(result).to eq(false)
|
|
178
|
+
some_request(:delete, "/api/v1/touts/234567").should have_been_made
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it ".like_tout returns true on successful response" do
|
|
182
|
+
stub_post("https://api.tout.com/api/v1/touts/fhcl57/likes").to_return(:body => fixture("like_tout_response.json"))
|
|
183
|
+
result = client.like_tout("fhcl57")
|
|
184
|
+
expect(result).to eq(true)
|
|
185
|
+
some_request(:post, "/api/v1/touts/fhcl57/likes").should have_been_made
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it ".unlike_tout returns true on successful response" do
|
|
189
|
+
stub_delete("https://api.tout.com/api/v1/touts/fhcl57/likes").to_return(:body => fixture("unlike_tout_response.json"))
|
|
190
|
+
result = client.unlike_tout("fhcl57")
|
|
191
|
+
expect(result).to eq(true)
|
|
192
|
+
some_request(:delete, "/api/v1/touts/fhcl57/likes").should have_been_made
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
describe '.retout_tout' do
|
|
196
|
+
let(:tout_uid) { 'random_tout_uid' }
|
|
197
|
+
let(:url) { "/api/v1/touts/#{tout_uid}/retouts" }
|
|
198
|
+
subject { client.retout_tout(tout_uid) }
|
|
199
|
+
before { stub_post("https://api.tout.com#{url}").to_return(result) }
|
|
200
|
+
after { some_request(:post, url).should have_been_made }
|
|
201
|
+
|
|
202
|
+
context 'a success' do
|
|
203
|
+
let(:result) { {status: 200, body: fixture('tout.json') }}
|
|
204
|
+
it { should be_a Trubl::Tout }
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
context 'a failure' do
|
|
208
|
+
let(:result) { {status: 500} }
|
|
209
|
+
it { should be_nil }
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
|