yammer-client 0.1.0

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.
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,155 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Model::Base do
4
+ class DummyModel < Yammer::Model::Base
5
+ attr_accessor_deffered :first_name, :last_name
6
+ end
7
+
8
+ class Yammer::Client
9
+ def update_dummy_model(id, opts={})
10
+ put("/api/v1/dummy_models/#{id}", opts)
11
+ end
12
+ end
13
+
14
+ context 'new user object with id' do
15
+
16
+ subject { DummyModel.new(:id => 42) }
17
+
18
+ describe "#id" do
19
+ it 'should be 42' do
20
+ expect(subject.id).to eq 42
21
+ end
22
+ end
23
+
24
+ describe "#id=" do
25
+ it 'sets id' do
26
+ # subject.send(:id, 2)
27
+ # expect(subject.id).to eq 2
28
+ end
29
+ end
30
+
31
+ describe "#new_record?" do
32
+ it 'returns false' do
33
+ expect(subject.new_record?).to eq false
34
+ end
35
+ end
36
+
37
+ describe "#modified?" do
38
+
39
+ context 'new model and no changes' do
40
+ it 'returns false' do
41
+ model = DummyModel.new(:first_name => 'jim', :last_name => 'peters')
42
+ expect(model.modified?).to eq false
43
+ end
44
+ end
45
+
46
+ context 'new model and no changes' do
47
+ it 'returns false' do
48
+ model = DummyModel.new(:first_name => 'mary', :last_name => 'jane')
49
+ model.last_name = 'jim'
50
+ model.last_name = 'smithy'
51
+ expect(model.modified?).to eq false
52
+ end
53
+ end
54
+
55
+ context 'persisted model and no changes' do
56
+ it 'returns true' do
57
+ model = DummyModel.new(:id => 12, :first_name => 'jim', :last_name => 'peters')
58
+ expect(model.modified?).to eq false
59
+ end
60
+ end
61
+
62
+ context 'persisted model and changes' do
63
+ it 'returns true' do
64
+ model = DummyModel.new(:id => 42, :first_name => 'jim', :last_name => 'peters')
65
+ model.last_name = 'smithy'
66
+ expect(model.modified?).to eq true
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#changes" do
72
+ it 'returns empty hash' do
73
+ expect(subject.changes).to eq({})
74
+ end
75
+ end
76
+
77
+ describe "#save" do
78
+ it 'returns true' do
79
+ stub_request(:put, "https://www.yammer.com/api/v1/dummy_models/42").with(
80
+ :body => {"last_name"=>"smithy"},
81
+ :headers => {
82
+ 'Accept' =>'application/json',
83
+ 'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
84
+ 'Content-Type' =>'application/x-www-form-urlencoded',
85
+ 'User-Agent' =>"Yammer Ruby Gem #{Yammer::Version}"})
86
+ model = DummyModel.new(:id => 42, :first_name => 'jim', :last_name => 'peters')
87
+ model.last_name = 'smithy'
88
+ model.save
89
+ end
90
+ end
91
+
92
+ describe "#update" do
93
+ it 'should update the attributes' do
94
+ # implement
95
+ end
96
+ end
97
+
98
+ describe "#base_name" do
99
+ it 'returns true' do
100
+ expect(subject.base_name).to eq 'dummy_model'
101
+ end
102
+ end
103
+
104
+ describe "setters" do
105
+ it 'should update modified attributes hash' do
106
+ subject
107
+ end
108
+ end
109
+
110
+ describe "#save" do
111
+ context 'unmodified model' do
112
+ it 'does nothing' do
113
+ expect(subject.save).to eq subject
114
+ end
115
+ end
116
+
117
+ context 'modified model' do
118
+ subject { DummyModel.new(:id => 42, :first_name => 'jim', :last_name => 'peters') }
119
+
120
+ it 'should update model' do
121
+ Yammer.should_receive(:update_dummy_model).with(42, hash_including(
122
+ :first_name =>'john',
123
+ :last_name => 'smith')
124
+ ).and_return(double('Response', :success? => true, :created? => true, :body => {:id => 2}))
125
+ subject.first_name = 'john'
126
+ subject.last_name = 'smith'
127
+ subject.save
128
+ end
129
+ end
130
+
131
+ context 'unmodified new model' do
132
+ subject { DummyModel.new(:first_name => 'jim', :last_name => 'peters') }
133
+
134
+ it 'should do nothing' do
135
+ Yammer.should_receive(:create_dummy_model).with(
136
+ hash_including(:first_name =>'jim', :last_name => 'peters')
137
+ ).and_return(double('Response', :success? => true, :created? => true, :body => {:id => '2'}))
138
+ subject.save
139
+ end
140
+ end
141
+
142
+ context 'modified new model' do
143
+ subject { DummyModel.new(:first_name => 'jim', :last_name => 'peters') }
144
+
145
+ it 'should create model' do
146
+ Yammer.should_receive(:create_dummy_model).with(
147
+ hash_including(:first_name =>'john', :last_name => 'peters')
148
+ ).and_return(double('Response', :success? => true, :created? => true, :body => {:id => 2}))
149
+ subject.first_name = 'john'
150
+ subject.save
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::GroupMembership do
4
+ context 'class methods' do
5
+
6
+ subject { Yammer::GroupMembership }
7
+
8
+ describe '#create_group_membership' do
9
+ it 'creates a new group membership' do
10
+ stub_request(:post, "https://www.yammer.com/api/v1/group_memberships").with(
11
+ :body => { :group_id => '6' },
12
+ :headers => {
13
+ 'Accept' => 'application/json',
14
+ 'Authorization' => "Bearer #{Yammer.access_token}",
15
+ 'Content-Type' => 'application/x-www-form-urlencoded',
16
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
17
+ }
18
+ ).to_return(
19
+ :status => 201,
20
+ :body => '',
21
+ :headers => {}
22
+ )
23
+ subject.create(6)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Group do
4
+ context 'class methods' do
5
+
6
+ subject { Yammer::Group }
7
+
8
+ describe '#create' do
9
+ it 'creates a new group' do
10
+ stub_request(:post, "https://www.yammer.com/api/v1/groups").with(
11
+ :body => { :name => 'rails team', :privacy => 'public' },
12
+ :headers => {
13
+ 'Accept' => 'application/json',
14
+ 'Authorization' => "Bearer #{Yammer.access_token}",
15
+ 'Content-Type' => 'application/x-www-form-urlencoded',
16
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
17
+ }
18
+ ).to_return(
19
+ :status => 201,
20
+ :body => '',
21
+ :headers => {'Location' => 'https://www.yammer.com/api/v1/groups/2'}
22
+ )
23
+ subject.create(:name => 'rails team', :privacy => 'public')
24
+ end
25
+ end
26
+
27
+ describe '#get' do
28
+ it 'returns group response' do
29
+ stub_request(:get, "https://www.yammer.com/api/v1/groups/1").with(
30
+ :headers => {
31
+ 'Accept' => 'application/json',
32
+ 'Authorization' => "Bearer #{Yammer.access_token}",
33
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
34
+ }
35
+ ).to_return(
36
+ :status => 200,
37
+ :body => fixture('group.json'),
38
+ :headers => {}
39
+ )
40
+ subject.get(1)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Message do
4
+
5
+ context 'class methods' do
6
+
7
+ subject { Yammer::Message }
8
+
9
+ describe '#create' do
10
+ it 'creates a new group' do
11
+ stub_request(:post, "https://www.yammer.com/api/v1/messages").with(
12
+ :body => { :name => 'rails team', :privacy => 'public' },
13
+ :headers => {
14
+ 'Accept' => 'application/json',
15
+ 'Authorization' => "Bearer #{Yammer.access_token}",
16
+ 'Content-Type' => 'application/x-www-form-urlencoded',
17
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
18
+ }
19
+ ).to_return(
20
+ :status => 201,
21
+ :body => '',
22
+ :headers => {'Location' => 'https://www.yammer.com/api/v1/messages/2'}
23
+ )
24
+ subject.create(:name => 'rails team', :privacy => 'public')
25
+ end
26
+ end
27
+
28
+ describe '#get' do
29
+ it 'returns message response' do
30
+ stub_request(:get, "https://www.yammer.com/api/v1/messages/1").with(
31
+ :headers => {
32
+ 'Accept' => 'application/json',
33
+ 'Authorization' => "Bearer #{Yammer.access_token}",
34
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
35
+ }
36
+ ).to_return(
37
+ :status => 200,
38
+ :body => fixture('message.json'),
39
+ :headers => {}
40
+ )
41
+ subject.get(1)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::Thread do
4
+
5
+ before :all do
6
+ Yammer.configure do |conf|
7
+ conf.access_token = 'TolNOFka9Uls2DxahNi78A'
8
+ end
9
+ end
10
+
11
+ context 'existing public thread' do
12
+ subject { Yammer::Thread.new(MultiJson.load(fixture("public_thread.json"), :symbolize_keys => true)) }
13
+
14
+ describe "#id" do
15
+ it 'returns id' do
16
+ expect(subject.id).to eq 11
17
+ end
18
+ end
19
+
20
+ describe "#first_reply" do
21
+ it 'returns first_reply' do
22
+ expect(subject.first_reply).to be_instance_of(Yammer::Message)
23
+ expect(subject.first_reply.id).to eq 11
24
+ end
25
+ end
26
+
27
+ describe "#last_reply" do
28
+ it 'returns last_reply' do
29
+ expect(subject.last_reply).to be_instance_of(Yammer::Message)
30
+ expect(subject.last_reply.id).to eq 13
31
+ end
32
+ end
33
+
34
+ describe "messages" do
35
+ it 'makes an http request and hydrates object' do
36
+ stub_request(:get, "https://www.yammer.com/api/v1/messages/in_thread/11").with(
37
+ :headers => {
38
+ 'Accept' => 'application/json',
39
+ 'Authorization' => "Bearer #{Yammer.access_token}",
40
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
41
+ }
42
+ ).to_return(
43
+ :status => 200,
44
+ :body => fixture("messages_in_thread.json"),
45
+ :headers => {:content_type => "application/json; charset=utf-8"}
46
+ )
47
+
48
+ stub_request(:get, "https://www.yammer.com/api/v1/messages/in_thread/11").
49
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer', 'User-Agent'=>'Yammer Ruby Gem 0.1.5'}).
50
+ to_return(:status => 200, :body => "", :headers => {})
51
+ subject.messages
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'existing private thread' do
57
+ subject { Yammer::Thread.new(MultiJson.load(fixture("private_thread.json"), :symbolize_keys => true)) }
58
+ describe "people" do
59
+ it 'makes an http request and hydrates object' do
60
+ subject.people.each do |person|
61
+ expect(person).to be_instance_of(Yammer::User)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,150 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Yammer::User do
4
+
5
+ before :all do
6
+ Yammer.configure do |conf|
7
+ conf.access_token = 'TolNOFka9Uls2DxahNi78A'
8
+ end
9
+ end
10
+
11
+ context 'class methods' do
12
+
13
+ subject { Yammer::User }
14
+
15
+ describe '#create' do
16
+ it 'creates a new user' do
17
+ stub_request(:post, "https://www.yammer.com/api/v1/users").with(
18
+ :body => { :email => 'hacker@yammer-inc.com' },
19
+ :headers => {
20
+ 'Accept' => 'application/json',
21
+ 'Authorization' => "Bearer #{Yammer.access_token}",
22
+ 'Content-Type' => 'application/x-www-form-urlencoded',
23
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
24
+ }
25
+ ).to_return(
26
+ :status => 201,
27
+ :body => '',
28
+ :headers => { 'Location' => 'https://www.yammer.com/api/v1/users/364'}
29
+ )
30
+ subject.create('hacker@yammer-inc.com')
31
+ end
32
+ end
33
+ end
34
+
35
+ context 'new user object with id' do
36
+
37
+ before :each do
38
+ Yammer::User.identity_map.purge!
39
+ end
40
+
41
+ subject { Yammer::User.new(:id => 1) }
42
+
43
+ describe "#id" do
44
+ it 'returns id' do
45
+ expect(subject.id).to eq 1
46
+ end
47
+ end
48
+
49
+ describe "calling getter method" do
50
+ it 'makes an http request and hydrates object' do
51
+ stub_request(:get, "https://www.yammer.com/api/v1/users/1").with(
52
+ :headers => {
53
+ 'Accept' => 'application/json',
54
+ 'Authorization' => "Bearer #{Yammer.access_token}",
55
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
56
+ }
57
+ ).to_return(
58
+ :status => 200,
59
+ :body => fixture('user.json'),
60
+ :headers => {}
61
+ )
62
+ subject.full_name
63
+ end
64
+ end
65
+
66
+ describe "creating duplicate object" do
67
+ it 'retrieves data from identitymap' do
68
+ user = Yammer::User.new(:id => 1)
69
+ stub_request(:get, "https://www.yammer.com/api/v1/users/1").with(
70
+ :headers => {
71
+ 'Accept' => 'application/json',
72
+ 'Authorization' => "Bearer #{Yammer.access_token}",
73
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
74
+ }
75
+ ).to_return(
76
+ :status => 200,
77
+ :body => fixture('user.json'),
78
+ :headers => {}
79
+ )
80
+ expect(user.full_name).to eq 'John Smith'
81
+
82
+ duplicate = Yammer::User.new(:id => 1)
83
+ expect(duplicate.full_name).to eq 'John Smith'
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'hygrated user object' do
89
+ subject { Yammer::User.new(MultiJson.load(fixture('user.json'), :symbolize_keys => true)) }
90
+
91
+ describe "#id" do
92
+ it 'returns id' do
93
+ expect(subject.id).to eq 2
94
+ end
95
+ end
96
+
97
+ describe "#email" do
98
+ it 'returns email addresses' do
99
+ stub_request(:get, "https://www.yammer.com/api/v1/users/2").
100
+ with(:headers => {
101
+ 'Accept'=>'application/json',
102
+ 'Authorization'=>"Bearer #{Yammer.access_token}",
103
+ 'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
104
+ }).to_return(
105
+ :status => 200,
106
+ :body => fixture('user.json'),
107
+ :headers => {}
108
+ )
109
+ expect(subject.email).to eq 'jsmith@yammer-inc.com'
110
+ end
111
+ end
112
+
113
+ describe "#delete" do
114
+ it 'deletes user' do
115
+ stub_request(:delete, "https://www.yammer.com/api/v1/users/2").
116
+ with(:headers => {
117
+ 'Accept'=>'application/json',
118
+ 'Authorization'=>"Bearer #{Yammer.access_token}",
119
+ 'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
120
+ }).to_return(
121
+ :status => 200,
122
+ :body => '',
123
+ :headers => {}
124
+ )
125
+ subject.delete!
126
+ end
127
+ end
128
+
129
+ describe '#update' do
130
+ context 'with id as an integer' do
131
+ it 'updates user' do
132
+ stub_request(:put, "https://www.yammer.com/api/v1/users/2").with(
133
+ :body => { :last_name => 'tiabas' },
134
+ :headers => {
135
+ 'Accept' => 'application/json',
136
+ 'Authorization' => "Bearer #{Yammer.access_token}",
137
+ 'Content-Type' => 'application/x-www-form-urlencoded',
138
+ 'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
139
+ }
140
+ ).to_return(
141
+ :status => 200,
142
+ :body => '',
143
+ :headers => { 'Location' => 'https://www.yammer.com/api/v1/users/2'}
144
+ )
145
+ subject.update!(:last_name => 'tiabas')
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end