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.
- data/.gitignore +29 -0
- data/.travis.yml +9 -0
- data/.yardopts +10 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +13 -0
- data/LICENSE.md +20 -0
- data/README.md +265 -0
- data/Rakefile +12 -0
- data/certs/tiabas-public.pem +21 -0
- data/lib/yammer.rb +28 -0
- data/lib/yammer/api.rb +10 -0
- data/lib/yammer/api/autocomplete.rb +25 -0
- data/lib/yammer/api/group.rb +78 -0
- data/lib/yammer/api/group_membership.rb +32 -0
- data/lib/yammer/api/message.rb +196 -0
- data/lib/yammer/api/network.rb +21 -0
- data/lib/yammer/api/notification.rb +18 -0
- data/lib/yammer/api/search.rb +28 -0
- data/lib/yammer/api/thread.rb +23 -0
- data/lib/yammer/api/topic.rb +21 -0
- data/lib/yammer/api/user.rb +156 -0
- data/lib/yammer/client.rb +101 -0
- data/lib/yammer/configurable.rb +46 -0
- data/lib/yammer/error.rb +61 -0
- data/lib/yammer/http_connection.rb +184 -0
- data/lib/yammer/identity_map.rb +42 -0
- data/lib/yammer/model.rb +6 -0
- data/lib/yammer/model/base.rb +133 -0
- data/lib/yammer/model/group.rb +13 -0
- data/lib/yammer/model/group_membership.rb +11 -0
- data/lib/yammer/model/message.rb +17 -0
- data/lib/yammer/model/message_body.rb +13 -0
- data/lib/yammer/model/thread.rb +44 -0
- data/lib/yammer/model/user.rb +46 -0
- data/lib/yammer/response.rb +43 -0
- data/lib/yammer/version.rb +18 -0
- data/spec/api/autocomplete_spec.rb +23 -0
- data/spec/api/group_membership_spec.rb +30 -0
- data/spec/api/group_spec.rb +58 -0
- data/spec/api/message_spec.rb +118 -0
- data/spec/api/network_spec.rb +23 -0
- data/spec/api/notification_spec.rb +23 -0
- data/spec/api/search_spec.rb +23 -0
- data/spec/api/thread_spec.rb +23 -0
- data/spec/api/topic_spec.rb +23 -0
- data/spec/api/user_spec.rb +76 -0
- data/spec/client_spec.rb +208 -0
- data/spec/connection_spec.rb +280 -0
- data/spec/error_spec.rb +69 -0
- data/spec/fixtures/group.json +1 -0
- data/spec/fixtures/message.json +1 -0
- data/spec/fixtures/messages_in_thread.json +1 -0
- data/spec/fixtures/portal_thread.json +1 -0
- data/spec/fixtures/private_thread.json +1 -0
- data/spec/fixtures/public_thread.json +1 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/identity_map_spec.rb +108 -0
- data/spec/model/base_spec.rb +155 -0
- data/spec/model/group_membership_spec.rb +27 -0
- data/spec/model/group_spec.rb +44 -0
- data/spec/model/message_spec.rb +45 -0
- data/spec/model/thread_spec.rb +66 -0
- data/spec/model/user_spec.rb +150 -0
- data/spec/response_spec.rb +66 -0
- data/spec/spec_helper.rb +42 -0
- data/yammer.gemspec +29 -0
- metadata +270 -0
data/.gitignore
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.lock
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
coverage
|
7
|
+
InstalledFiles
|
8
|
+
lib/bundler/man
|
9
|
+
pkg
|
10
|
+
rdoc
|
11
|
+
spec/reports
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tmp
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
# OS generated files #
|
22
|
+
.DS_Store
|
23
|
+
.DS_Store?
|
24
|
+
._*
|
25
|
+
.Spotlight-V100
|
26
|
+
.Trashes
|
27
|
+
Icon?
|
28
|
+
ehthumbs.db
|
29
|
+
Thumbs.db
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Kevin Mutyaba
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
Yammer Client
|
2
|
+
=============
|
3
|
+
|
4
|
+
[](https://travis-ci.org/tiabas/yammer-client)
|
5
|
+
|
6
|
+
A Yammer Ruby gem
|
7
|
+
|
8
|
+
## Documentation
|
9
|
+
|
10
|
+
[http://rdoc.info/github/tiabas/yammer-client][documentation]
|
11
|
+
|
12
|
+
[documentation]: http://rdoc.info/github/tiabas/yammer-client
|
13
|
+
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'yammer-client'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
```sh
|
26
|
+
$ bundle
|
27
|
+
```
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
```sh
|
32
|
+
$ gem install yammer-client
|
33
|
+
```
|
34
|
+
|
35
|
+
## Configuration
|
36
|
+
|
37
|
+
The Yammer API requires authentication for access to certain endpoints. Below are the basic steps to get this done. For more information, take a look at Yammer's Developer Guide <http://developer.yammer.com/files/2012/10/PlatformDeveloperGuide.pdf>
|
38
|
+
|
39
|
+
|
40
|
+
### Register your application
|
41
|
+
|
42
|
+
1. Sign in to Yammer
|
43
|
+
|
44
|
+
2. Go to `https://www.yammer.com/client_applications`
|
45
|
+
|
46
|
+
3. Click on 'Register New App' and fill out the registration form
|
47
|
+
|
48
|
+
4. Make note of your client_id and client_secret they will be needed for token authorization
|
49
|
+
|
50
|
+
|
51
|
+
### Obtaining an access token
|
52
|
+
|
53
|
+
1. Construct the following URL using the client_id you received `https://www.yammer.com/dialog/oauth?client_id=[:client_id]`
|
54
|
+
|
55
|
+
2. Have your users follow the URL you constructed above to allow your application to access their data
|
56
|
+
|
57
|
+
3. After allowing access, your users will be redirected to your callback URL `http://[:redirect_uri]?code=[:code]`
|
58
|
+
|
59
|
+
4. Exchange the code for an access token by making an HTTP GET request to `https://www.yammer.com/oauth2/access_token.json?client_id=[:client_id]&client_secret=[:client_secret]&code=[:code]`
|
60
|
+
|
61
|
+
5. The authorization server will respond with an access token
|
62
|
+
|
63
|
+
```
|
64
|
+
"access_token": {
|
65
|
+
"view_subscriptions": true,
|
66
|
+
"expires_at": null,
|
67
|
+
authorized_at": "2011/04/06 16:25:46 +0000",
|
68
|
+
"modify_subscriptions": true,
|
69
|
+
"modify_messages": true,
|
70
|
+
"network_permalink": "yammer-inc.com",
|
71
|
+
"view_members": true,
|
72
|
+
"view_tags": true,
|
73
|
+
"network_id": 155465488,
|
74
|
+
"user_id": 1014216,
|
75
|
+
"view_groups": true,
|
76
|
+
"token": "abcdefghijklmn",
|
77
|
+
"network_name": "Yammer",
|
78
|
+
"view_messages": true,
|
79
|
+
"created_at": "2011/04/06 16:25:46 +0000"
|
80
|
+
}
|
81
|
+
```
|
82
|
+
|
83
|
+
### Configuring yammer-client
|
84
|
+
|
85
|
+
To view the current state of the client use the `options` method
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
require 'yammer'
|
89
|
+
|
90
|
+
Yammer.options
|
91
|
+
|
92
|
+
# => {:site_url=>"https://www.yammer.com", :client_id=>nil, :client_secret=>nil, :access_token=>nil, :http_adapter=>Yammer::HttpConnection, :connection_options=>{:max_redirects=>5, :use_ssl=>true}}
|
93
|
+
```
|
94
|
+
|
95
|
+
You may change this configuration by using the `configure` method
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
Yammer.configure do |c|
|
99
|
+
c.client_id = '[client_id]'
|
100
|
+
c.client_secret = '[client_secret]'
|
101
|
+
c.token = '[access_token]'
|
102
|
+
end
|
103
|
+
|
104
|
+
# => Yammer
|
105
|
+
```
|
106
|
+
|
107
|
+
At this point, your new settings will take effect
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
Yammer.options
|
111
|
+
|
112
|
+
# => {:site_url=>"https://www.yammer.com", :client_id=>'[client_id]', :client_secret=>'[client_secret]', :access_token=>'[access_token]', :http_adapter=>Yammer::HttpConnection, :connection_options=>{ :max_redirects=>5, :use_ssl=>true }}
|
113
|
+
```
|
114
|
+
|
115
|
+
## Usage
|
116
|
+
|
117
|
+
`yammer-client` provides two ways to access Yammer's API. One of these ways is by using HTTP helper methods on and instance of `Yammer::Client`. The other
|
118
|
+
way is using methods on the object models that come bundled with this gem.
|
119
|
+
|
120
|
+
### Using the client
|
121
|
+
|
122
|
+
1. Create an instance of the Yammer client
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
yamr = Yammer::Client.new(
|
126
|
+
:client_id => 'vAbMcg9qjgKsp4jjpm1pw',
|
127
|
+
:client_secret => 'Wn0kp7Lu0TCY4GtZWkmSsqGErg10DmMADyjWkf2U',
|
128
|
+
:access_token => 'HqsKG3ka9Uls2DxahNi78A'
|
129
|
+
)
|
130
|
+
```
|
131
|
+
|
132
|
+
2. Call methods on the instance:
|
133
|
+
|
134
|
+
**User**
|
135
|
+
|
136
|
+
*find a user by email*
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
yamr.get_user_by_email('user@example.com')
|
140
|
+
```
|
141
|
+
|
142
|
+
*find a user by user id*
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
yamr.get_user('1588')
|
146
|
+
```
|
147
|
+
|
148
|
+
*get the current user*
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
yamr.current_user
|
152
|
+
```
|
153
|
+
|
154
|
+
|
155
|
+
**Message**
|
156
|
+
|
157
|
+
*post a update as the current user*
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
yamr.create_message(:body => 'status update')
|
161
|
+
```
|
162
|
+
|
163
|
+
*send a private message to another Yammer user*
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
yamr.create_message(:body => 'private message', :direct_to_id => 24)
|
167
|
+
```
|
168
|
+
|
169
|
+
*send a message with an Open Graph Object as an attachment*
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
yamr.create_message(:body => 'here is my open graph object', og_url: "https://www.yammer.com/example/graph/31415926")
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
**Search**
|
177
|
+
|
178
|
+
*search for a term within the context of current user*
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
yamr.search(:search => 'thekev', :model_types => 'users;groups')
|
182
|
+
```
|
183
|
+
|
184
|
+
**Thread**
|
185
|
+
*fetch a thread with a given id*
|
186
|
+
```ruby
|
187
|
+
yamr.get_thread(42, :model_types => 'users;groups')
|
188
|
+
```
|
189
|
+
|
190
|
+
|
191
|
+
### Using the object models
|
192
|
+
|
193
|
+
Object models are classes that take away the hussle of having to deal with parsing the JSON that Yammer returns for
|
194
|
+
any given request. Each model has accessor metods for all keys contained in the JSON response for a given model type.
|
195
|
+
|
196
|
+
|
197
|
+
**User**
|
198
|
+
|
199
|
+
*get the current user*
|
200
|
+
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
u = Yammer::User.current
|
204
|
+
|
205
|
+
#=> #<Yammer::User:0x007f9f4b0c39c8>
|
206
|
+
|
207
|
+
u.full_name
|
208
|
+
|
209
|
+
#=> 'Kevin Mutyaba'
|
210
|
+
|
211
|
+
u.update!(:job_title => 'k0dR')
|
212
|
+
|
213
|
+
```
|
214
|
+
|
215
|
+
|
216
|
+
**Thread**
|
217
|
+
|
218
|
+
*fetch a thread with a given id*
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
|
222
|
+
t = Yammer::Thread.get(3)
|
223
|
+
|
224
|
+
# view the participants in the thread
|
225
|
+
|
226
|
+
parts = t.participants
|
227
|
+
#=> [{:type=>"user", :id=>18}, {:type=>"user", :id=>64}]
|
228
|
+
|
229
|
+
|
230
|
+
# view the participants in the thread as user object models
|
231
|
+
|
232
|
+
peepl = t.people
|
233
|
+
#=> [#<Yammer::User:0x007f9f4c086630 @modified_attributes={}, @attrs={}, @new_record=false, @id=18>, #<Yammer::User:0x007f9f4c086568 @modified_attributes={}, @attrs={}, @new_record=false, @id=64>]
|
234
|
+
|
235
|
+
|
236
|
+
# object models are lazyly loaded
|
237
|
+
|
238
|
+
peepl[0]
|
239
|
+
#=> #<Yammer::User:0x007f9f4c086568 @modified_attributes={}, @attrs={}, @new_record=false, @id=18>
|
240
|
+
|
241
|
+
# calling an accessor on a model will hydrate it
|
242
|
+
|
243
|
+
peepl[0].permalink
|
244
|
+
#=> 'thekev'
|
245
|
+
|
246
|
+
peepl[0]
|
247
|
+
#=> #<Yammer::User:0x007f9f4c086630 @modified_attributes={}, @attrs={:last_name=>"Mutyaba", :network_id=>1, :first_name=>"Kevin", :id => 18, :permalink=>"thekev" }, @network_id=1, @first_name="Kev", @full_name="Tiaba", @permalink="thekev", @id=18 >
|
248
|
+
```
|
249
|
+
|
250
|
+
## Supported Ruby Versions
|
251
|
+
This library aims to support and is [tested against][travis] the following Ruby
|
252
|
+
version:
|
253
|
+
|
254
|
+
* Ruby 1.8.7
|
255
|
+
* Ruby 1.9.2
|
256
|
+
* Ruby 1.9.3
|
257
|
+
|
258
|
+
This library may inadvertently work (or seem to work) on other Ruby
|
259
|
+
implementations, however support will only be provided for the versions listed
|
260
|
+
above.
|
261
|
+
|
262
|
+
## Copyright
|
263
|
+
Copyright (c) 2013 Kevin Mutyaba
|
264
|
+
See [LICENSE][license] for details.
|
265
|
+
[license]: https://github.com/tiabas/yammer-client/blob/master/LICENSE.md
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAh0aWFi
|
3
|
+
YXNuazEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
4
|
+
MB4XDTEzMDMwMzA2MjAxNVoXDTE0MDMwMzA2MjAxNVowPzERMA8GA1UEAwwIdGlh
|
5
|
+
YmFzbmsxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
6
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMsmVsErcNuwQLKLh9T6
|
7
|
+
a57QiK35g9zjpID2pUBn4alMTmIeAXg2bXWLdAzU0swcjmaGBWz5AaZeqTnnBveO
|
8
|
+
ZDoH6e811uuRjJMYCkLQxhlghEB0TQkAqOnxlj80TN2jFw+YFWLmSnxR4PBonvpp
|
9
|
+
YwWAY0ylqM54FPRhaAIYC5/3Pvx1SYL9/Us0376HEpV0Rty6VXz7tUzv8vFki5ot
|
10
|
+
gyfp5ceWiYIZjQ9Uvhm4luJSfXci13UHZ0AeO7E1padWlx3z8hZIvjawueTGRe5p
|
11
|
+
BgZlI0+xV2ogvAlu8/NCy0hWUwcpnvRdPyBVDRMli8gXGE9jNv8dBWe67vdjzGSk
|
12
|
+
YDUCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFInh
|
13
|
+
qvJkuISNqDOcsrBRotZC0qolMB0GA1UdEQQWMBSBEnRpYWJhc25rQGdtYWlsLmNv
|
14
|
+
bTAdBgNVHRIEFjAUgRJ0aWFiYXNua0BnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
|
15
|
+
ggEBAEGb4gRDulJ9jkf5oRLydfw9UZi6fVWj6aaiJfbbT5NLotpVaWnWdCOO7hy8
|
16
|
+
HDPYWN430zLwr0ODOU9XNueKnEkhnBRiYkcQ0JmYddPkL57kp0qlH4g2IqQfQV2W
|
17
|
+
1b7sE410zFHn55B5nihQY3c0MMSL7wq9Dz2EktbIMikf6sG6zfUgYFE4IQGi2RbO
|
18
|
+
xa5fnTWt7KB5DD02HnHLTZ9Hl2kxlPyWwyjREwNwEjPoSUJFEBiosvAml8frUDA9
|
19
|
+
j6fATg/4fqpgILPVqFIGZOMJDFcJy/oehwwxLu5XMx88WFD9jT1vRj77D7iPLbXd
|
20
|
+
rfGs/qCJKgifXd/1am5hlAH5jXU=
|
21
|
+
-----END CERTIFICATE-----
|
data/lib/yammer.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'yammer/version'
|
2
|
+
require 'yammer/error'
|
3
|
+
require 'yammer/http_connection'
|
4
|
+
require 'yammer/configurable'
|
5
|
+
require 'yammer/response'
|
6
|
+
require 'yammer/client'
|
7
|
+
require 'yammer/identity_map'
|
8
|
+
require 'yammer/model'
|
9
|
+
require 'yammer/api'
|
10
|
+
|
11
|
+
module Yammer
|
12
|
+
class << self
|
13
|
+
include Configurable
|
14
|
+
|
15
|
+
def client
|
16
|
+
@client = Yammer::Client.new
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def method_missing(method_name, *args, &block)
|
22
|
+
return super unless client.respond_to?(method_name)
|
23
|
+
client.send(method_name, *args, &block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Yammer.reset!
|
data/lib/yammer/api.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'yammer/api/user'
|
2
|
+
require 'yammer/api/group'
|
3
|
+
require 'yammer/api/group_membership'
|
4
|
+
require 'yammer/api/message'
|
5
|
+
require 'yammer/api/thread'
|
6
|
+
require 'yammer/api/search'
|
7
|
+
require 'yammer/api/topic'
|
8
|
+
require 'yammer/api/autocomplete'
|
9
|
+
require 'yammer/api/network'
|
10
|
+
require 'yammer/api/notification'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Yammer
|
2
|
+
module Api
|
3
|
+
module Autocomplete
|
4
|
+
|
5
|
+
# @see https://developer.yammer.com/restapi/#rest-search
|
6
|
+
# @api_path /api/v1/autocomplete/ranked
|
7
|
+
# @rate_limited Yes
|
8
|
+
# @authentication authenticated user context
|
9
|
+
# @raise [Yammer::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
10
|
+
# @return [Yammer::Response]
|
11
|
+
# @param [Hash] opts the options to fetch a thread with
|
12
|
+
# @option opts [String] :prefix
|
13
|
+
# @option opts [String] :models
|
14
|
+
# @option opts [Integer] :network_id
|
15
|
+
# @option opts [Integer] :include_site_actions
|
16
|
+
# @option opts [Boolean] :extended]
|
17
|
+
# @option opts [Boolean] :include_network_domainss
|
18
|
+
# @example Fetch data for the thread
|
19
|
+
# Yammer.search(:prefix => 'pizza', :models => 'user:3,group:8,topic:10')
|
20
|
+
def autocomplete(opts={})
|
21
|
+
get('/api/v1/autocomplete', opts)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|