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,122 @@
|
|
|
1
|
+
require_relative '../../spec_helper'
|
|
2
|
+
require 'trubl/client'
|
|
3
|
+
require 'webmock'
|
|
4
|
+
|
|
5
|
+
describe Trubl::API::Users do
|
|
6
|
+
|
|
7
|
+
let(:client) { Trubl::Client.new }
|
|
8
|
+
|
|
9
|
+
it '.retrieve_user returns a Trubl::User' do
|
|
10
|
+
stub_get("https://api.tout.com/api/v1/users/karmin").to_return(:body => fixture("user.json"))
|
|
11
|
+
user = client.retrieve_user("karmin")
|
|
12
|
+
expect(user).to be_a Trubl::User
|
|
13
|
+
expect(user.uid).to eq("karmin")
|
|
14
|
+
some_request(:get, "/api/v1/users/karmin").should have_been_made
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#retrieve_users' do
|
|
18
|
+
subject { client.retrieve_users(uids) }
|
|
19
|
+
|
|
20
|
+
context 'providing an array of users uids' do
|
|
21
|
+
let(:sorted_uids) { 125.times.collect { |i| "test_user_#{i}" }.sort }
|
|
22
|
+
let(:uids) { sorted_uids.shuffle }
|
|
23
|
+
|
|
24
|
+
before do
|
|
25
|
+
sorted_uids.in_groups_of(100, false) do |uid_group|
|
|
26
|
+
fake_user_response = {users: uid_group.collect { |uid| {user: {uid: uid} } } }
|
|
27
|
+
|
|
28
|
+
stub_request(:get, "https://api.tout.com/api/v1/users?uids=#{uid_group.join(',')}").
|
|
29
|
+
to_return(
|
|
30
|
+
status: 200,
|
|
31
|
+
body: fake_user_response.to_json,
|
|
32
|
+
headers: {}
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
its(:size) { should == uids.size }
|
|
38
|
+
it 'should contain the users' do
|
|
39
|
+
expect(subject.map(&:uid).sort).to eq sorted_uids
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context 'providing a single uid as string' do
|
|
44
|
+
let(:uids) { 'zackryder' }
|
|
45
|
+
before do
|
|
46
|
+
stub_request(:get, "https://api.tout.com/api/v1/users?uids=#{uids}").
|
|
47
|
+
to_return(
|
|
48
|
+
status: 200,
|
|
49
|
+
body: {users: [{user: {uid: uids}}]}.to_json,
|
|
50
|
+
headers: {}
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
its(:size) { should == 1 }
|
|
54
|
+
its('first.uid') { should == uids }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context 'providing a blank list' do
|
|
58
|
+
let(:uids) { nil }
|
|
59
|
+
before do
|
|
60
|
+
client.should_not_receive(:multi_request)
|
|
61
|
+
end
|
|
62
|
+
it { should == [] }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
it '.retrieve_user_likes returns a Collection of Touts liked by the specified user' do
|
|
68
|
+
stub_get("https://api.tout.com/api/v1/users/karmin/likes").to_return(:body => fixture("touts_liked_by_user_response.json"))
|
|
69
|
+
touts = client.retrieve_user_likes("karmin")
|
|
70
|
+
expect(touts).to be_a Trubl::Touts
|
|
71
|
+
#expect(touts.pagination).to be_a Trubl::Pagination
|
|
72
|
+
touts.each do |u|
|
|
73
|
+
expect(u).to be_a Trubl::Tout
|
|
74
|
+
end
|
|
75
|
+
some_request(:get, "/api/v1/users/karmin/likes").should have_been_made
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it '.retrieve_user_touts returns a Collection of Touts created by the specified user' do
|
|
79
|
+
stub_get("https://api.tout.com/api/v1/users/teamtout/touts").to_return(:body => fixture("user_touts_response.json"))
|
|
80
|
+
touts = client.retrieve_user_touts("teamtout")
|
|
81
|
+
expect(touts).to be_a Trubl::Touts
|
|
82
|
+
#expect(touts.pagination).to be_a Trubl::Pagination
|
|
83
|
+
touts.each do |u|
|
|
84
|
+
expect(u).to be_a Trubl::Tout
|
|
85
|
+
end
|
|
86
|
+
some_request(:get, "/api/v1/users/teamtout/touts").should have_been_made
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it '.retrieve_user_followers returns the Users following the specified user' do
|
|
90
|
+
stub_get("https://api.tout.com/api/v1/users/teamtout/followers").to_return(:body => fixture("user_followers.json"))
|
|
91
|
+
users = client.retrieve_user_followers("teamtout")
|
|
92
|
+
expect(users).to be_a Trubl::Users
|
|
93
|
+
#expect(users.pagination).to be_a Trubl::Pagination
|
|
94
|
+
users.each do |u|
|
|
95
|
+
expect(u).to be_a Trubl::User
|
|
96
|
+
end
|
|
97
|
+
some_request(:get, "/api/v1/users/teamtout/followers").should have_been_made
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it '.follow_user executes a follow for the specified user with a user authed token' do
|
|
101
|
+
stub_post("https://api.tout.com/api/v1/users/teamtout/follow").to_return(:body => "")
|
|
102
|
+
client.follow_user('teamtout')
|
|
103
|
+
some_request(:post, "/api/v1/users/teamtout/follow").should have_been_made
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe '.retrieve_user_widgets' do
|
|
107
|
+
let(:user_uid) { 'teamtout'}
|
|
108
|
+
let(:path) { "https://api.tout.com/api/v1/users/#{user_uid}/widgets" }
|
|
109
|
+
before do
|
|
110
|
+
stub_get(path).to_return(body: fixture("widgets.json"))
|
|
111
|
+
end
|
|
112
|
+
subject { Trubl::Client.new.retrieve_user_widgets(user_uid) }
|
|
113
|
+
it { should be_kind_of Trubl::Widgets }
|
|
114
|
+
it 'does the right api call' do
|
|
115
|
+
subject
|
|
116
|
+
some_request(:get,path).should have_been_made
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'trubl/base'
|
|
3
|
+
|
|
4
|
+
describe Trubl::Base do
|
|
5
|
+
|
|
6
|
+
subject{ Trubl::Base.new }
|
|
7
|
+
|
|
8
|
+
let(:response){
|
|
9
|
+
resp = double("Response")
|
|
10
|
+
resp.stub(:body).and_return('{"base": {}}')
|
|
11
|
+
resp
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let(:missing_response){
|
|
15
|
+
resp = double("Response")
|
|
16
|
+
resp.stub(:body).and_return('{"error": "resource not found"}')
|
|
17
|
+
resp.stub(:code).and_return(404)
|
|
18
|
+
resp
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let(:error_response){
|
|
22
|
+
resp = double("Response")
|
|
23
|
+
resp.stub(:body).and_return('{"error": "kaboom"}')
|
|
24
|
+
resp.stub(:code).and_return(500)
|
|
25
|
+
resp
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
it "inherits from Hash" do
|
|
30
|
+
subject.is_a? Hash
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "inherits from Hashie::Mash" do
|
|
34
|
+
subject.is_a? Hashie::Mash
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "#from_response" do
|
|
38
|
+
|
|
39
|
+
it "returns nil if response code is 4xx" do
|
|
40
|
+
missing_response.should_receive(:code)
|
|
41
|
+
instance = subject.from_response(missing_response)
|
|
42
|
+
instance.should be_nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "returns nil if response code is 5xx" do
|
|
46
|
+
error_response.should_receive(:code)
|
|
47
|
+
instance = subject.from_response(error_response)
|
|
48
|
+
instance.should be_nil
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "parses the response body" do
|
|
52
|
+
response.should_receive(:code)
|
|
53
|
+
subject.should_receive(:parse).with(response)
|
|
54
|
+
subject.from_response(response)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "uses the inferred class name" do
|
|
58
|
+
response.should_receive(:code)
|
|
59
|
+
subject.should_receive(:klass_name)
|
|
60
|
+
subject.from_response(response)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "re-initializes the instance" do
|
|
64
|
+
response.should_receive(:code)
|
|
65
|
+
subject.should_receive :initialize
|
|
66
|
+
subject.from_response(response)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "#parse" do
|
|
72
|
+
|
|
73
|
+
it "parses the response body into a json object" do
|
|
74
|
+
JSON.should_receive(:parse).with(response.body).and_return({})
|
|
75
|
+
subject.parse(response)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "klass_name" do
|
|
81
|
+
|
|
82
|
+
it "downcases the class name " do
|
|
83
|
+
subject.klass_name.should == 'base'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'trubl/category'
|
|
3
|
+
|
|
4
|
+
describe Trubl::Category do
|
|
5
|
+
# this is the silly namespace one
|
|
6
|
+
# this is also an example of the simple OpenStruct usage, to be replaced eventually
|
|
7
|
+
|
|
8
|
+
let(:category_uid){"music"}
|
|
9
|
+
|
|
10
|
+
it "magically creates a Tout object from json" do
|
|
11
|
+
category = Trubl::Category.new(json_fixture("category_response.json")["category"])
|
|
12
|
+
expect(category.uid).to eq(category_uid)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
require 'trubl/channel'
|
|
4
|
+
|
|
5
|
+
describe Trubl::Channel do
|
|
6
|
+
# this is the silly namespace one
|
|
7
|
+
# this is also an example of the simple OpenStruct usage, to be replaced eventually
|
|
8
|
+
|
|
9
|
+
let(:channel_uid){"new-york-fashion-week"}
|
|
10
|
+
|
|
11
|
+
it "magically creates a Tout object from json" do
|
|
12
|
+
channel = Trubl::Channel.new(json_fixture("channel_response.json")["channel"])
|
|
13
|
+
expect(channel.uid).to eq(channel_uid)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
require_relative "../spec_helper"
|
|
2
|
+
require "trubl/client"
|
|
3
|
+
|
|
4
|
+
describe Trubl::Client do
|
|
5
|
+
|
|
6
|
+
let(:client) { Trubl::Client.new() }
|
|
7
|
+
|
|
8
|
+
describe '#new' do
|
|
9
|
+
subject { client }
|
|
10
|
+
it { should be_a Trubl::Client }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe ".auth" do
|
|
14
|
+
it "stores access_token" do
|
|
15
|
+
body = "client_id=&client_secret=&grant_type=client_credentials"
|
|
16
|
+
headers = {'Accept'=>'application/json', 'Authorization'=>'Bearer', 'Connection'=>'keep-alive'}
|
|
17
|
+
stub_post("https://www.tout.com/oauth/token").with(body: body, headers: headers).to_return(body: fixture("client1_auth_resp.json"))
|
|
18
|
+
client.client_auth()
|
|
19
|
+
expect(client.access_token).to eq "6bffd46fca32a9dc640a7f2284edd55b5175d59323923f984b92ee5ec6a0a9e4"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe ".credentials" do
|
|
24
|
+
it "returns a hash of creds" do
|
|
25
|
+
body = "client_id=client_id&client_secret=client_sekrit&grant_type=client_credentials"
|
|
26
|
+
headers = {'Accept'=>'application/json', 'Authorization'=>'Bearer', 'Connection'=>'keep-alive'}
|
|
27
|
+
stub_post("https://www.tout.com/oauth/token").with(body: body, headers: headers).to_return(body: fixture("client1_auth_resp.json"))
|
|
28
|
+
client = Trubl::Client.new("client_id", "client_sekrit")
|
|
29
|
+
client.client_auth()
|
|
30
|
+
expect(client.credentials).to eq({client_id:"client_id", client_secret:"client_sekrit", access_token:"6bffd46fca32a9dc640a7f2284edd55b5175d59323923f984b92ee5ec6a0a9e4"})
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe ".api_uri_root" do
|
|
36
|
+
let(:port) { nil }
|
|
37
|
+
let(:host) { nil }
|
|
38
|
+
let(:uri_scheme) { nil }
|
|
39
|
+
subject { Trubl::Client.new(:fake_id, :fake_secret, nil, uri_port: port, uri_host: host, uri_scheme: uri_scheme) }
|
|
40
|
+
|
|
41
|
+
its(:api_uri_root) { should == 'https://api.tout.com/api/v1/' }
|
|
42
|
+
|
|
43
|
+
context 'setting a port' do
|
|
44
|
+
let(:port) { 3000 }
|
|
45
|
+
its(:api_uri_root) { should == 'https://api.tout.com:3000/api/v1/' }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context 'setting a host and protocol' do
|
|
49
|
+
let(:host) { 'localhost' }
|
|
50
|
+
let(:uri_scheme) { 'http' }
|
|
51
|
+
its(:api_uri_root) { should == 'http://localhost/api/v1/' }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe ".delete" do
|
|
56
|
+
it "processes a delete" do
|
|
57
|
+
path = "toutitout"
|
|
58
|
+
stub_delete(path).to_return(:status => 200, :body => "", :headers => {})
|
|
59
|
+
client.delete(path)
|
|
60
|
+
some_request(:delete, path).should have_been_made
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe ".post" do
|
|
65
|
+
it "processes a post" do
|
|
66
|
+
path = "toutitout"
|
|
67
|
+
stub_post(path).to_return(:status => 200, :body => "", :headers => {})
|
|
68
|
+
client.post(path)
|
|
69
|
+
some_request(:post, path).should have_been_made
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
describe ".get" do
|
|
74
|
+
it "processes a get" do
|
|
75
|
+
path = "toutitout"
|
|
76
|
+
stub_get(path).to_return(:status => 200, :body => "", :headers => {})
|
|
77
|
+
client.get(path)
|
|
78
|
+
some_request(:get, path).should have_been_made
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe ".put" do
|
|
83
|
+
it "processes a put" do
|
|
84
|
+
path = "toutitout"
|
|
85
|
+
stub_put(path).to_return(:status => 200, :body => "", :headers => {})
|
|
86
|
+
client.put(path)
|
|
87
|
+
some_request(:put, path).should have_been_made
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe ".multi_request" do
|
|
92
|
+
# See https://github.com/typhoeus/typhoeus/issues/278
|
|
93
|
+
# there might be a bug then requests.size > max_concurrency while running specs
|
|
94
|
+
let(:uids) { 9.times.collect { |i| "random-user-#{i}" } }
|
|
95
|
+
let(:requests) { uids.collect { |uid| { path: "/users/#{uid}" } } }
|
|
96
|
+
let(:method) { :get }
|
|
97
|
+
let(:multi_request) { client.multi_request(method, requests)}
|
|
98
|
+
subject { multi_request }
|
|
99
|
+
|
|
100
|
+
context 'with a valid request method' do
|
|
101
|
+
before do
|
|
102
|
+
(requests || []).each_with_index do |request, index|
|
|
103
|
+
uid = request[:path].split('/').last
|
|
104
|
+
request_stub(method, request[:path]).to_return(status: 200 + index, body: "fake-#{uid}", headers: {})
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
its(:size) { should == uids.size }
|
|
109
|
+
|
|
110
|
+
describe 'response bodies' do
|
|
111
|
+
subject { multi_request.map(&:body).sort }
|
|
112
|
+
it { should == uids.collect { |u| "fake-#{u}"} }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe 'response status codes' do
|
|
116
|
+
subject do
|
|
117
|
+
RUBY_ENGINE == 'ruby' ? multi_request.map(&:status).sort : multi_request.map(&:code).sort
|
|
118
|
+
end
|
|
119
|
+
it { should == uids.size.times.collect { |i| 200+i } }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context 'with a blank request list' do
|
|
123
|
+
let(:requests) { nil }
|
|
124
|
+
before do
|
|
125
|
+
Typhoeus::Hydra.should_not_receive(:new) if RUBY_ENGINE == 'ruby'
|
|
126
|
+
end
|
|
127
|
+
it { should == [] }
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context 'with an invalid request method' do
|
|
133
|
+
let(:method) { :unsupported }
|
|
134
|
+
before do
|
|
135
|
+
Typhoeus::Hydra.should_not_receive(:new) if RUBY_ENGINE == 'ruby'
|
|
136
|
+
end
|
|
137
|
+
it { should == [] }
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'trubl/conversation'
|
|
3
|
+
|
|
4
|
+
describe Trubl::Conversation do
|
|
5
|
+
# this is the silly namespace one
|
|
6
|
+
# this is also an example of the simple OpenStruct usage, to be replaced eventually
|
|
7
|
+
|
|
8
|
+
it "magically creates a Tout object from json" do
|
|
9
|
+
conversation = Trubl::Conversation.new(json_fixture("conversation_response.json")["conversation"])
|
|
10
|
+
expect(conversation.uid).to eq("iummti53")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require_relative "../spec_helper"
|
|
2
|
+
require "trubl/hashtag"
|
|
3
|
+
|
|
4
|
+
describe Trubl::Hashtag do
|
|
5
|
+
|
|
6
|
+
it "magically creates a Hashtag object from json" do
|
|
7
|
+
hashtag = Trubl::Hashtag.new(json_fixture("hashtag_response.json")["hashtag"])
|
|
8
|
+
expect(hashtag.uid).to eq("pets")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'trubl/oauth'
|
|
3
|
+
|
|
4
|
+
describe Trubl::OAuth do
|
|
5
|
+
|
|
6
|
+
describe ".auth" do
|
|
7
|
+
|
|
8
|
+
it "parses json and stores attributes properly" do
|
|
9
|
+
stub_post("https://www.tout.com/oauth/token").with(:body => /.*/).to_return(body: fixture("client1_auth_resp.json"))
|
|
10
|
+
@client = Trubl.client()
|
|
11
|
+
@client.client_auth()
|
|
12
|
+
expect(@client.access_token).to eq("6bffd46fca32a9dc640a7f2284edd55b5175d59323923f984b92ee5ec6a0a9e4")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe ".user_auth" do
|
|
18
|
+
|
|
19
|
+
it "handles the password auth scheme properly" do
|
|
20
|
+
stub_post("https://www.tout.com/oauth/token").with(:body => /.*/).to_return(body: fixture("client1_auth_resp.json"))
|
|
21
|
+
@client = Trubl.client('client_id', 'client_secret', 'callback_url', email: 'fake@tout.com', password: 'password')
|
|
22
|
+
@client.user_auth()
|
|
23
|
+
expect(@client.access_token).to eq("6bffd46fca32a9dc640a7f2284edd55b5175d59323923f984b92ee5ec6a0a9e4")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require_relative "../spec_helper"
|
|
2
|
+
require "trubl/tout"
|
|
3
|
+
|
|
4
|
+
describe Trubl::Tout do
|
|
5
|
+
# this is also an example of the simple OpenStruct usage, to be replaced eventually
|
|
6
|
+
|
|
7
|
+
it "magically creates a Tout object from json" do
|
|
8
|
+
tout = Trubl::Tout.new(json_fixture("tout.json")["tout"])
|
|
9
|
+
expect(tout.uid).to eq("fhcl57")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it ".delete is a usable verb when created via a client" do
|
|
13
|
+
stub_post("https://api.tout.com/api/v1/touts").to_return(:body => fixture('tout.json'))
|
|
14
|
+
file = File.join(File.dirname(__FILE__), '../fixtures/test.mp4')
|
|
15
|
+
payload = {tout: { data: file, text: 'Some text here'}}
|
|
16
|
+
tout = Trubl::Client.new.create_tout(payload)
|
|
17
|
+
stub_delete("https://api.tout.com/api/v1/touts")
|
|
18
|
+
result = tout.delete
|
|
19
|
+
expect(result). to eq(true)
|
|
20
|
+
some_request(:delete, "/api/v1/touts/fhcl57").should have_been_made
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it ".like is a usable verb when created via a client" do
|
|
24
|
+
stub_get("https://api.tout.com/api/v1/touts/fhcl57").to_return(:body => fixture("retrieve_tout.json"))
|
|
25
|
+
tout = Trubl::Client.new.retrieve_tout("fhcl57")
|
|
26
|
+
stub_post("https://api.tout.com/api/v1/touts/fhcl57/likes").to_return(:body => fixture("like_tout_response.json"))
|
|
27
|
+
result = tout.like
|
|
28
|
+
expect(result). to eq(true)
|
|
29
|
+
some_request(:post, "/api/v1/touts/fhcl57/likes").should have_been_made
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it ".unlike is a usable verb when created via a client" do
|
|
33
|
+
stub_get("https://api.tout.com/api/v1/touts/fhcl57").to_return(:body => fixture("retrieve_tout.json"))
|
|
34
|
+
tout = Trubl::Client.new.retrieve_tout("fhcl57")
|
|
35
|
+
stub_delete("https://api.tout.com/api/v1/touts/fhcl57/likes").to_return(:body => fixture("unlike_tout_response.json"))
|
|
36
|
+
result = tout.unlike
|
|
37
|
+
expect(result). to eq(true)
|
|
38
|
+
some_request(:delete, "/api/v1/touts/fhcl57/likes").should have_been_made
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|