yammer-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.gitignore +29 -0
  2. data/.travis.yml +9 -0
  3. data/.yardopts +10 -0
  4. data/CHANGELOG.md +0 -0
  5. data/Gemfile +13 -0
  6. data/LICENSE.md +20 -0
  7. data/README.md +265 -0
  8. data/Rakefile +12 -0
  9. data/certs/tiabas-public.pem +21 -0
  10. data/lib/yammer.rb +28 -0
  11. data/lib/yammer/api.rb +10 -0
  12. data/lib/yammer/api/autocomplete.rb +25 -0
  13. data/lib/yammer/api/group.rb +78 -0
  14. data/lib/yammer/api/group_membership.rb +32 -0
  15. data/lib/yammer/api/message.rb +196 -0
  16. data/lib/yammer/api/network.rb +21 -0
  17. data/lib/yammer/api/notification.rb +18 -0
  18. data/lib/yammer/api/search.rb +28 -0
  19. data/lib/yammer/api/thread.rb +23 -0
  20. data/lib/yammer/api/topic.rb +21 -0
  21. data/lib/yammer/api/user.rb +156 -0
  22. data/lib/yammer/client.rb +101 -0
  23. data/lib/yammer/configurable.rb +46 -0
  24. data/lib/yammer/error.rb +61 -0
  25. data/lib/yammer/http_connection.rb +184 -0
  26. data/lib/yammer/identity_map.rb +42 -0
  27. data/lib/yammer/model.rb +6 -0
  28. data/lib/yammer/model/base.rb +133 -0
  29. data/lib/yammer/model/group.rb +13 -0
  30. data/lib/yammer/model/group_membership.rb +11 -0
  31. data/lib/yammer/model/message.rb +17 -0
  32. data/lib/yammer/model/message_body.rb +13 -0
  33. data/lib/yammer/model/thread.rb +44 -0
  34. data/lib/yammer/model/user.rb +46 -0
  35. data/lib/yammer/response.rb +43 -0
  36. data/lib/yammer/version.rb +18 -0
  37. data/spec/api/autocomplete_spec.rb +23 -0
  38. data/spec/api/group_membership_spec.rb +30 -0
  39. data/spec/api/group_spec.rb +58 -0
  40. data/spec/api/message_spec.rb +118 -0
  41. data/spec/api/network_spec.rb +23 -0
  42. data/spec/api/notification_spec.rb +23 -0
  43. data/spec/api/search_spec.rb +23 -0
  44. data/spec/api/thread_spec.rb +23 -0
  45. data/spec/api/topic_spec.rb +23 -0
  46. data/spec/api/user_spec.rb +76 -0
  47. data/spec/client_spec.rb +208 -0
  48. data/spec/connection_spec.rb +280 -0
  49. data/spec/error_spec.rb +69 -0
  50. data/spec/fixtures/group.json +1 -0
  51. data/spec/fixtures/message.json +1 -0
  52. data/spec/fixtures/messages_in_thread.json +1 -0
  53. data/spec/fixtures/portal_thread.json +1 -0
  54. data/spec/fixtures/private_thread.json +1 -0
  55. data/spec/fixtures/public_thread.json +1 -0
  56. data/spec/fixtures/user.json +1 -0
  57. data/spec/identity_map_spec.rb +108 -0
  58. data/spec/model/base_spec.rb +155 -0
  59. data/spec/model/group_membership_spec.rb +27 -0
  60. data/spec/model/group_spec.rb +44 -0
  61. data/spec/model/message_spec.rb +45 -0
  62. data/spec/model/thread_spec.rb +66 -0
  63. data/spec/model/user_spec.rb +150 -0
  64. data/spec/response_spec.rb +66 -0
  65. data/spec/spec_helper.rb +42 -0
  66. data/yammer.gemspec +29 -0
  67. metadata +270 -0
@@ -0,0 +1,118 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Api::Message do
4
+
5
+ before :all do
6
+ @client = Yammer::Client.new(
7
+ :site_url => 'https://www.yammer.com',
8
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
9
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
10
+ :access_token => 'TolNOFka9Uls2DxahNi78A',
11
+ :connection_client => Yammer::HttpConnection
12
+ )
13
+ end
14
+
15
+ subject { @client }
16
+
17
+ describe '#all_messages' do
18
+ context 'with options' do
19
+ it 'should get_messages' do
20
+ params = { :page => 1, :letter => 'm' }
21
+ subject.should_receive(:get).with('/api/v1/messages', params)
22
+ subject.all_messages(params)
23
+ end
24
+ end
25
+
26
+ context 'without options' do
27
+ it 'should return all messages viewable by a user' do
28
+ subject.should_receive(:get).with('/api/v1/messages', {})
29
+ subject.all_messages
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#create_message' do
35
+ it 'should create_message' do
36
+ params = { :body => 'Greetings, we come in peace' }
37
+ subject.should_receive(:post).with('/api/v1/messages', params)
38
+ subject.create_message(params)
39
+ end
40
+ end
41
+
42
+ describe '#message' do
43
+ it 'should fetch a message' do
44
+ subject.should_receive(:get).with('/api/v1/messages/3', {})
45
+ subject.get_message(3)
46
+ end
47
+ end
48
+
49
+ describe '#delete_message' do
50
+ it 'should delete a message' do
51
+ subject.should_receive(:post).with('/api/v1/messages/4', {})
52
+ subject.delete_message(4)
53
+ end
54
+ end
55
+
56
+ describe '#messages_sent' do
57
+ it 'should fetch messages sent by a user' do
58
+ subject.should_receive(:get).with('/api/v1/messages/sent', {})
59
+ subject.messages_sent
60
+ end
61
+ end
62
+
63
+ describe '#messages_received' do
64
+ it 'should fetch messages received by a user' do
65
+ subject.should_receive(:get).with('/api/v1/messages/received', {})
66
+ subject.messages_received
67
+ end
68
+ end
69
+
70
+ describe '#private_messages' do
71
+ it 'should fetch private messages' do
72
+ subject.should_receive(:get).with('/api/v1/messages/private', {})
73
+ subject.private_messages
74
+ end
75
+ end
76
+
77
+ describe '#followed_messages' do
78
+ it 'should fetch messages followed by a user' do
79
+ subject.should_receive(:get).with('/api/v1/messages/following', {})
80
+ subject.followed_messages
81
+ end
82
+ end
83
+
84
+ describe '#messages_from_user' do
85
+ it 'should fetch messages created by a user' do
86
+ subject.should_receive(:get).with('/api/v1/messages/from_user/14', {})
87
+ subject.messages_from_user(14)
88
+ end
89
+ end
90
+
91
+ describe '#messages_about_topic' do
92
+ it 'should fetch messages about a topic' do
93
+ subject.should_receive(:get).with('/api/v1/messages/about_topic/19', {})
94
+ subject.messages_about_topic(19)
95
+ end
96
+ end
97
+
98
+ describe '#messages_in_group' do
99
+ it 'should fetch messages in group' do
100
+ subject.should_receive(:get).with('/api/v1/messages/in_group/26', {})
101
+ subject.messages_in_group(26)
102
+ end
103
+ end
104
+
105
+ describe '#messages_liked_by' do
106
+ it 'should fetch messages liked by user' do
107
+ subject.should_receive(:get).with('/api/v1/messages/liked_by/58', {})
108
+ subject.messages_liked_by(58)
109
+ end
110
+ end
111
+
112
+ describe '#messages_in_thread' do
113
+ it 'should fetch messages in thread' do
114
+ subject.should_receive(:get).with('/api/v1/messages/in_thread/97', {})
115
+ subject.messages_in_thread(97)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Api::Network do
4
+
5
+ before :all do
6
+ @client = Yammer::Client.new(
7
+ :site_url => 'https://www.yammer.com',
8
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
9
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
10
+ :access_token => 'TolNOFka9Uls2DxahNi78A',
11
+ :connection_client => Yammer::HttpConnection
12
+ )
13
+ end
14
+
15
+ subject { @client }
16
+
17
+ describe '#networks_current' do
18
+ it 'should fetch network data' do
19
+ subject.should_receive(:get).with('/api/v1/networks/current', { :include_suspended => true })
20
+ subject.current_networks({ :include_suspended => true })
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Api::Notification do
4
+
5
+ before :all do
6
+ @client = Yammer::Client.new(
7
+ :site_url => 'https://www.yammer.com',
8
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
9
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
10
+ :access_token => 'TolNOFka9Uls2DxahNi78A',
11
+ :connection_client => Yammer::HttpConnection
12
+ )
13
+ end
14
+
15
+ subject { @client }
16
+
17
+ describe '#search' do
18
+ it 'should search for stuff' do
19
+ subject.should_receive(:get).with('/api/v1/streams/notifications')
20
+ subject.notifications
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Api::Search do
4
+
5
+ before :all do
6
+ @client = Yammer::Client.new(
7
+ :site_url => 'https://www.yammer.com',
8
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
9
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
10
+ :access_token => 'TolNOFka9Uls2DxahNi78A',
11
+ :connection_client => Yammer::HttpConnection
12
+ )
13
+ end
14
+
15
+ subject { @client }
16
+
17
+ describe '#search' do
18
+ it 'should search for stuff' do
19
+ subject.should_receive(:get).with('/api/v1/search.json', {:search => 'money power women'})
20
+ subject.search(:search => 'money power women')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Api::Thread do
4
+
5
+ before :all do
6
+ @client = Yammer::Client.new(
7
+ :site_url => 'https://www.yammer.com',
8
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
9
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
10
+ :access_token => 'TolNOFka9Uls2DxahNi78A',
11
+ :connection_client => Yammer::HttpConnection
12
+ )
13
+ end
14
+
15
+ subject { @client }
16
+
17
+ describe '#get_thread' do
18
+ it 'should fetch a thread' do
19
+ subject.should_receive(:get).with('/api/v1/threads/1', {})
20
+ subject.get_thread(1)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Api::Topic do
4
+
5
+ before :all do
6
+ @client = Yammer::Client.new(
7
+ :site_url => 'https://www.yammer.com',
8
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
9
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
10
+ :access_token => 'TolNOFka9Uls2DxahNi78A',
11
+ :connection_client => Yammer::HttpConnection
12
+ )
13
+ end
14
+
15
+ subject { @client }
16
+
17
+ describe '#topics' do
18
+ it 'should fetch topic' do
19
+ subject.should_receive(:get).with('/api/v1/topics/1',{ :is_followed_by => 2 })
20
+ subject.get_topic(1, :is_followed_by => 2)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+ require 'ostruct'
3
+
4
+ describe Yammer::Api::User do
5
+
6
+ before :all do
7
+ @client = Yammer::Client.new(
8
+ :site_url => 'https://yammer.com',
9
+ :client_id => "PRbTcg9qjgKsp4jjpm1pw",
10
+ :client_secret => "Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U",
11
+ :access_token => "TolNOFka9Uls2DxahNi78A",
12
+ :connection_client => Yammer::HttpConnection
13
+ )
14
+ end
15
+
16
+ subject { @client }
17
+
18
+ describe "users" do
19
+ it "makes an http request" do
20
+ @client.should_receive(:get).with('/api/v1/users', { :page => 1, :letter => 'm' })
21
+ @client.all_users({:page => 1, :letter => 'm'})
22
+ end
23
+ end
24
+
25
+ describe "create_user" do
26
+ it "makes an http request" do
27
+ params = {:first_name => 'john', :last_name => 'doe', :email => 'jdoe@yammer-inc.com'}
28
+ @client.should_receive(:post).with('/api/v1/users', params)
29
+ @client.create_user(params)
30
+ end
31
+ end
32
+
33
+ describe "get_user" do
34
+ it "makes an http request" do
35
+ @client.should_receive(:get).with('/api/v1/users/1')
36
+ @client.get_user(1)
37
+ end
38
+ end
39
+
40
+ describe "update_user" do
41
+ it "makes an http request" do
42
+ params = {:first_name => 'jane', :last_name => 'smith'}
43
+ @client.should_receive(:put).with('/api/v1/users/1', params)
44
+ @client.update_user(1, params)
45
+ end
46
+
47
+ context 'with id as a string' do
48
+ it 'updates user' do
49
+ params = {:first_name => 'jane', :last_name => 'smith'}
50
+ @client.should_receive(:put).with('/api/v1/users/current', params)
51
+ subject.update_user('current', params)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "delete_user" do
57
+ it "makes an http request" do
58
+ @client.should_receive(:delete).with('/api/v1/users/1')
59
+ @client.delete_user(1)
60
+ end
61
+ end
62
+
63
+ describe "user_by_email" do
64
+ it "makes an http request" do
65
+ @client.should_receive(:get).with('/api/v1/users/by_email', :email => 'bob@yammer-inc.com')
66
+ @client.get_user_by_email('bob@yammer-inc.com')
67
+ end
68
+ end
69
+
70
+ describe "current_user" do
71
+ it "makes an http request" do
72
+ @client.should_receive(:get).with('/api/v1/users/current')
73
+ @client.current_user
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,208 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Client do
4
+
5
+ before :all do
6
+ @configuration = {
7
+ :site_url => 'https://www.yammer.com',
8
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
9
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
10
+ :access_token => 'TolNOFka9Uls2DxahNi78A'
11
+ }
12
+ end
13
+
14
+ subject { Yammer::Client.new(@configuration) }
15
+
16
+ context "with module configuration" do
17
+
18
+ before :each do
19
+ Yammer.configure do |config|
20
+ Yammer::Configurable.keys.each do |key|
21
+ config.send("#{key}=", key)
22
+ end
23
+ end
24
+ end
25
+
26
+ after do
27
+ Yammer.reset!
28
+ end
29
+
30
+ it "inherits the module configuration" do
31
+ client = Yammer::Client.new
32
+ Yammer::Configurable.keys.each do |key|
33
+ expect(client.instance_variable_get(:"@#{key}")).to eq key
34
+ end
35
+ end
36
+
37
+ context "with initialization options" do
38
+ before(:all) do
39
+ @conf = {
40
+ :site_url => 'https://www.yammer.com',
41
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
42
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
43
+ :access_token => 'TolNOFka9Uls2DxahNi78A',
44
+ :http_adapter => Struct.new('CustomHttpAdapter', :site_url, :conn_options),
45
+ :connection_options => { :max_redirects => 5, :use_ssl => true }
46
+ }
47
+ end
48
+
49
+ context "during initialization" do
50
+ it "overrides the module configuration" do
51
+ client = Yammer::Client.new(@conf)
52
+ Yammer::Configurable.keys.each do |key|
53
+ expect(client.instance_variable_get(:"@#{key}")).to eq @conf[key]
54
+ end
55
+ end
56
+ end
57
+
58
+ context "after initialization" do
59
+ it "overrides the module configuration" do
60
+ client = Yammer::Client.new
61
+ client.configure do |config|
62
+ @conf.each do |key, value|
63
+ config.send("#{key}=", value)
64
+ end
65
+ end
66
+ Yammer::Configurable.keys.each do |key|
67
+ expect(client.instance_variable_get(:"@#{key}")).to eq @conf[key]
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "connection" do
75
+ it "looks like an http connection" do
76
+ conn = subject.instance_eval{ connection }
77
+ expect(conn).to respond_to(:send_request)
78
+ end
79
+
80
+ it "gets memoized" do
81
+ c1, c2 = subject.instance_eval{ connection }, subject.instance_eval{ connection }
82
+ expect(c1.object_id).to eq c2.object_id
83
+ end
84
+ end
85
+
86
+ describe "site_url" do
87
+ it "returns site_url" do
88
+ expect(subject.site_url).to eq 'https://www.yammer.com'
89
+ end
90
+ end
91
+
92
+ describe "site_url=" do
93
+ before do
94
+ subject.site_url = 'elpmaxe.com'
95
+ end
96
+
97
+ it "sets the connection to nil" do
98
+ expect(subject.instance_variable_get(:'@connection')).to eq nil
99
+ end
100
+
101
+ it "sets new site_url on client" do
102
+ expect(subject.site_url).to eq 'elpmaxe.com'
103
+ end
104
+ end
105
+
106
+ describe "#connection_options" do
107
+ context "with default connection options" do
108
+ it "returns empty hash" do
109
+ expect(subject.connection_options).to eq ({ :max_redirects => 5, :use_ssl => true })
110
+ end
111
+ end
112
+
113
+ context "with custom connection options" do
114
+ it "returns default options" do
115
+ subject.connection_options = { :max_redirects => 5, :use_ssl => true }
116
+ expect(subject.connection_options).to eq ({:max_redirects => 5, :use_ssl => true})
117
+ end
118
+ end
119
+ end
120
+
121
+ context 'http request' do
122
+ describe "#post" do
123
+ it "makes an http POST request" do
124
+ stub_post('/users').with(
125
+ :headers => {
126
+ 'Accept'=>'application/json',
127
+ 'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
128
+ 'Content-Type'=>'application/x-www-form-urlencoded',
129
+ 'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
130
+ },
131
+ :body => { :name => 'alice' })
132
+ subject.post('/users', { :name => 'alice'})
133
+ end
134
+ end
135
+
136
+ describe "#put" do
137
+ it "makes an http PUT request" do
138
+ stub_put('/users/1').with(
139
+ :headers => {
140
+ 'Accept'=>'application/json',
141
+ 'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
142
+ 'Content-Type'=>'application/x-www-form-urlencoded',
143
+ 'User-Agent'=> "Yammer Ruby Gem #{Yammer::Version}"
144
+ },
145
+ :body => { :name => 'bob' })
146
+ subject.put('/users/1', { :name => 'bob'})
147
+ end
148
+ end
149
+
150
+ describe "#get" do
151
+ it "makes an http GET request" do
152
+ stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' })
153
+ subject.get('/users/1')
154
+ end
155
+ end
156
+
157
+ describe "#delete" do
158
+ it "makes an http DELETE request" do
159
+ stub_delete('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' })
160
+ subject.delete('/users/1')
161
+ end
162
+ end
163
+
164
+ describe 'with invalid token' do
165
+ it 'raises exception' do
166
+ stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' }).to_return(
167
+ :body => '{ "response": { "message": "Token not found.", "code": 16, "stat": "fail" } }',
168
+ :status => 401
169
+ )
170
+ expect { subject.get('/users/1') }.to raise_error(Yammer::Error::Unauthorized, 'Token not found.')
171
+ end
172
+ end
173
+
174
+ describe 'with too many requests' do
175
+ it 'raises exception' do
176
+ stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' }).to_return(
177
+ :body => '{ "response": { "message": "Rate limited due to excessive requests.", "code": 33, "stat": "fail" } }',
178
+ :status => 429
179
+ )
180
+ expect { subject.get('/users/1') }.to raise_error(Yammer::Error::RateLimitExceeded, 'Rate limited due to excessive requests.')
181
+ end
182
+ end
183
+ end
184
+
185
+ describe "#connection" do
186
+ context "with default connection options" do
187
+ it "returns HttpConnection" do
188
+ expect(subject.send(:connection)).to be_instance_of(Yammer::HttpConnection)
189
+ end
190
+ end
191
+
192
+ context "with custom connection options" do
193
+ it "returns custom connection" do
194
+ custom_http = Struct.new('CustomHttpClient', :site_url, :connection_options)
195
+ client = Yammer::Client.new(
196
+ :site_url => 'www.example.com',
197
+ :client_id => 'PRbTcg9qjgKsp4jjpm1pw',
198
+ :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
199
+ :http_adapter => custom_http,
200
+ :connection_options => { :max_redirects => 5, :use_ssl => true }
201
+ )
202
+ connection = client.send(:connection)
203
+ expect(connection.site_url).to eq "www.example.com"
204
+ expect(connection.connection_options).to eq({ :max_redirects => 5, :use_ssl => true })
205
+ end
206
+ end
207
+ end
208
+ end