yam 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTORS +4 -0
- data/Gemfile +0 -1
- data/README.md +47 -0
- data/lib/yammer.rb +1 -0
- data/lib/yammer/oauth2_client.rb +122 -0
- data/lib/yammer/version.rb +2 -2
- data/spec/oauth2_client_spec.rb +123 -0
- data/spec/spec_helper.rb +1 -1
- data/yam.gemspec +2 -2
- metadata +8 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0e5efea2af8ae9081156643e602122768245e7f
|
4
|
+
data.tar.gz: ad3067915dda2084e593b184a2e32fa56bed1b18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d6562a49ee934050eafbcbac4c99ca98fc7f712574eff6582d8c4cc27b45db832155eef8777c290cefdd4e984785a51ab63c6212d7868082257f83913e4b269
|
7
|
+
data.tar.gz: b0c26a07fec043005483b21072bcb36c19ff6c8e6c3e1bbeada98289ae59c01999c1add376545c2eafc91e0d895c6251a5e6a14b100e0e2ffb931e6308e008db
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTORS
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -83,6 +83,53 @@ Setup a Yammer client application as described on the [Yammer Developer site](ht
|
|
83
83
|
}
|
84
84
|
```
|
85
85
|
|
86
|
+
## Using bundled Yammer OAuth2 Client
|
87
|
+
This gem comes bundled with an OAuth2 wrapper that makes provides convenience methods for getting through the OAuth2 flow
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
|
91
|
+
require 'yammer-oauth2/client'
|
92
|
+
|
93
|
+
yammer_client = Yammmer::OAuth2Client.new('PRbTcg9qjgKsp4jjpm1pw', 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U')
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
## Authorization Grants
|
98
|
+
The client wraps around the creation of any given grant and passing in the parameters defined in the configuration
|
99
|
+
file. The supported grants include Authorization Code and Implicit. They are available via the `authorization_code` and `implicit` methods on a client object.
|
100
|
+
|
101
|
+
# Authorization Code grant (Server-side authorization)
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
|
105
|
+
# generate authorization url
|
106
|
+
auth_url = yammer_client.webserver_authorization_url
|
107
|
+
# => https://www.yammer.com/dialog/oauth/authorize?client_id=PRbTcg9qjgKsp4jjpm1pw&response_type=code
|
108
|
+
|
109
|
+
# exchange authorization code for access token. we will get back a Net::HTTPResponse
|
110
|
+
response = yammer_client.exchange_auth_code_for_token({
|
111
|
+
:code => '11a0b0b64db56c30e2ef',
|
112
|
+
:redirect_uri => 'https://localhost/callback',
|
113
|
+
})
|
114
|
+
|
115
|
+
response.inspect
|
116
|
+
# => #<Net::HTTPOK:0x007ff8bc7c1200>
|
117
|
+
|
118
|
+
response.body
|
119
|
+
# => {
|
120
|
+
# "access_token" : {
|
121
|
+
# "token": "e409f4272fe539166a77c42479de030e7660812a",
|
122
|
+
# "token_type" : "bearer"
|
123
|
+
# }
|
124
|
+
# }"
|
125
|
+
```
|
126
|
+
|
127
|
+
# Implicit Grant (Client-side authorization)
|
128
|
+
```ruby
|
129
|
+
authorization_url = yammer_client.clientside_authorization_url(:redirect_uri => 'http://localhost/oauth2/callback')
|
130
|
+
# => "https://www.yammer.com/dialog/oauth/?client_id=PRbTcg9qjgKsp4jjpm1pw&redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcallback&response_type=token"
|
131
|
+
```
|
132
|
+
|
86
133
|
### Configuring yammer-client
|
87
134
|
|
88
135
|
To view the current state of the client use the `options` method
|
data/lib/yammer.rb
CHANGED
@@ -0,0 +1,122 @@
|
|
1
|
+
# Copyright (c) Microsoft Corporation
|
2
|
+
# All rights reserved.
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
#
|
7
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR
|
8
|
+
# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
|
9
|
+
# WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE,
|
10
|
+
# FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
11
|
+
|
12
|
+
# See the Apache Version 2.0 License for specific language governing
|
13
|
+
# permissions and limitations under the License.
|
14
|
+
|
15
|
+
require 'oauth2'
|
16
|
+
|
17
|
+
module Yammer
|
18
|
+
class OAuth2Client < OAuth2::Client
|
19
|
+
|
20
|
+
SITE_URL = 'https://www.yammer.com'
|
21
|
+
TOKEN_PATH = '/oauth2/token'
|
22
|
+
AUTHORIZE_PATH = '/dialog/oauth'
|
23
|
+
|
24
|
+
def initialize(client_id, client_secret, opts={})
|
25
|
+
site_url = opts.delete(:site_url) || SITE_URL
|
26
|
+
opts[:token_path] ||= TOKEN_PATH
|
27
|
+
opts[:authorize_path] ||= AUTHORIZE_PATH
|
28
|
+
super(site_url, client_id, client_secret, opts)
|
29
|
+
yield self if block_given?
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
# Generates the Yammer URL that the user will be redirected to in order to
|
34
|
+
# authorize your application
|
35
|
+
#
|
36
|
+
# @see https://developer.yammer.com/api/oauth2.html#client-side
|
37
|
+
#
|
38
|
+
# @opts [Hash] additional parameters to be include in URL eg. scope, state, etc
|
39
|
+
#
|
40
|
+
# client = YammerClient.new(config)
|
41
|
+
# client.clientside_authorization_url({
|
42
|
+
# :redirect_uri => 'https://localhost/oauth/cb',
|
43
|
+
# })
|
44
|
+
# >> https://www.yammer.com/dialog/oauth/?client_id={client_id}&
|
45
|
+
# redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&response_type=token
|
46
|
+
#
|
47
|
+
def webclient_authorization_url(opts={})
|
48
|
+
implicit.token_url(opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generates the Yammer URL that the user will be redirected to in order to
|
52
|
+
# authorize your application
|
53
|
+
#
|
54
|
+
# @see https://developer.yammer.com/api/oauth2.html#server-side
|
55
|
+
#
|
56
|
+
# @opts [Hash] additional parameters to be include in URL eg. scope, state, etc
|
57
|
+
#
|
58
|
+
# >> client = YammerClient.new(config)
|
59
|
+
# >> client.webserver_authorization_url({
|
60
|
+
# :redirect_uri => 'https://localhost/oauth/cb',
|
61
|
+
# })
|
62
|
+
# >> https://www.yammer.com/dialog/oauth/?client_id={client_id}&
|
63
|
+
# redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&response_type=code
|
64
|
+
#
|
65
|
+
def webserver_authorization_url(opts={})
|
66
|
+
opts[:scope] = normalize_scope(opts[:scope]) if opts[:scope]
|
67
|
+
authorization_code.authorization_url(opts)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Makes a request to Yammer server that will swap your authorization code for an access
|
71
|
+
# token
|
72
|
+
#
|
73
|
+
# @see https://developer.yammer.com/api/oauth2.html#server-side
|
74
|
+
#
|
75
|
+
# @opts [Hash] may include redirect uri and other query parameters
|
76
|
+
#
|
77
|
+
# >> client = YammerClient.new(config)
|
78
|
+
# >> client.exchange_auth_code_for_token({
|
79
|
+
# :redirect_uri => 'https://localhost:3000/oauth/v2/callback',
|
80
|
+
# :code => 'G3Y6jU3a',
|
81
|
+
# })
|
82
|
+
#
|
83
|
+
# POST /oauth2/access_token HTTP/1.1
|
84
|
+
# Host: www.yammer.com
|
85
|
+
# Content-Type: application/x-www-form-urlencoded
|
86
|
+
|
87
|
+
# client_id={client_id}&code=G3Y6jU3a&grant_type=authorization_code&
|
88
|
+
# redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&client_secret={client_secret}
|
89
|
+
def access_token_from_authorization_code(code, opts={})
|
90
|
+
opts[:authenticate] ||= :body
|
91
|
+
authorization_code.get_token(code, opts)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Makes a request to Yammer server that will swap client credential for an access token
|
95
|
+
#
|
96
|
+
# @opts [Hash] parameters that will be added to URL query string
|
97
|
+
#
|
98
|
+
# POST /oauth2/access_token HTTP/1.1
|
99
|
+
# Host: www.yammer.com
|
100
|
+
# Content-Type: application/x-www-form-urlencoded
|
101
|
+
#
|
102
|
+
# client_id={client_id}&client_secret={client_secret}
|
103
|
+
def access_token_from_client_credentials(opts={})
|
104
|
+
opts[:authenticate] ||= :body
|
105
|
+
client_credentials.get_token(opts)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Makes a request to Yammer server that will swap resource owner credentials for an access token
|
109
|
+
#
|
110
|
+
# @opts [Hash] parameters that will be added to URL query string
|
111
|
+
#
|
112
|
+
# POST /oauth2/access_token HTTP/1.1
|
113
|
+
# Host: www.yammer.com
|
114
|
+
# Content-Type: application/x-www-form-urlencoded
|
115
|
+
#
|
116
|
+
# client_id={client_id}&client_secret={client_secret}&username={username}&password={passwort}
|
117
|
+
def access_token_from_resource_owner_credentials(username, password, opts={})
|
118
|
+
opts[:authenticate] ||= :body
|
119
|
+
self.password.get_token(username, password, opts)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/lib/yammer/version.rb
CHANGED
@@ -15,8 +15,8 @@
|
|
15
15
|
module Yammer
|
16
16
|
class Version
|
17
17
|
MAJOR = 2 unless defined? Yammer::MAJOR
|
18
|
-
MINOR =
|
19
|
-
PATCH =
|
18
|
+
MINOR = 1 unless defined? Yammer::MINOR
|
19
|
+
PATCH = 0 unless defined? Yammer::PATCH
|
20
20
|
PRE = nil unless defined? Yammer::PRE
|
21
21
|
|
22
22
|
class << self
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../spec_helper', __FILE__)
|
21
|
+
|
22
|
+
describe Yammer::OAuth2Client do
|
23
|
+
|
24
|
+
subject do
|
25
|
+
Yammer::OAuth2Client.new('PRbTcg9qjgKsp4jjpm1pw', 'a2nQpcUm2Dgq1chWdAvbXGTk', {
|
26
|
+
:connection_options => {
|
27
|
+
:headers => {
|
28
|
+
'User-Agent' => "Yammer OAuth2 Client #{Yammer::Version}",
|
29
|
+
"Accept" => "application/json"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#webserver_authorization_url" do
|
36
|
+
it "returns the authorization url" do
|
37
|
+
params = {
|
38
|
+
"client_id" => "PRbTcg9qjgKsp4jjpm1pw",
|
39
|
+
"redirect_uri" => "https://localhost/callback",
|
40
|
+
"response_type" =>"code",
|
41
|
+
"state" => "12345"
|
42
|
+
}
|
43
|
+
|
44
|
+
auth_url = subject.webserver_authorization_url(
|
45
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
46
|
+
:state => '12345',
|
47
|
+
:redirect_uri => 'https://localhost/callback'
|
48
|
+
)
|
49
|
+
|
50
|
+
parsed_url = Addressable::URI.parse(auth_url)
|
51
|
+
expect(parsed_url.path).to eq '/dialog/oauth'
|
52
|
+
expect(parsed_url.query_values).to eq params
|
53
|
+
expect(parsed_url.scheme).to eq 'https'
|
54
|
+
expect(parsed_url.host).to eq 'www.yammer.com'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#access_token_from_authorization_code" do
|
59
|
+
it "makes a POST request to exchange authorization code for access token" do
|
60
|
+
|
61
|
+
stub_request(:post, "https://www.yammer.com/oauth2/token").with(
|
62
|
+
:body => {
|
63
|
+
:grant_type => 'authorization_code',
|
64
|
+
:code => 'MmOGL795LbIZuJJVnL49Cc',
|
65
|
+
:redirect_uri => 'https://localhost',
|
66
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
67
|
+
:client_secret => 'a2nQpcUm2Dgq1chWdAvbXGTk'
|
68
|
+
},
|
69
|
+
:headers => {
|
70
|
+
'Accept' =>'application/json',
|
71
|
+
'Content-Type' =>'application/x-www-form-urlencoded',
|
72
|
+
'User-Agent' =>"Yammer OAuth2 Client #{Yammer::Version}"
|
73
|
+
})
|
74
|
+
|
75
|
+
subject.access_token_from_authorization_code(
|
76
|
+
'MmOGL795LbIZuJJVnL49Cc',
|
77
|
+
:params => {
|
78
|
+
:redirect_uri => 'https://localhost'
|
79
|
+
}
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#access_token_from_client_credentials" do
|
85
|
+
it "makes a POST request to exchange client credentiaks for access token" do
|
86
|
+
|
87
|
+
stub_request(:post, "https://www.yammer.com/oauth2/token").with(
|
88
|
+
:body => {
|
89
|
+
:grant_type => 'client_credentials',
|
90
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
91
|
+
:client_secret => 'a2nQpcUm2Dgq1chWdAvbXGTk'
|
92
|
+
},
|
93
|
+
:headers => {
|
94
|
+
'Accept' =>'application/json',
|
95
|
+
'Content-Type' =>'application/x-www-form-urlencoded',
|
96
|
+
'User-Agent' =>"Yammer OAuth2 Client #{Yammer::Version}"
|
97
|
+
})
|
98
|
+
|
99
|
+
subject.access_token_from_client_credentials
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#access_token_from_resource_owner_credentials" do
|
104
|
+
it "makes a POST request to exchange client credentiaks for access token" do
|
105
|
+
|
106
|
+
stub_request(:post, "https://www.yammer.com/oauth2/token").with(
|
107
|
+
:body => {
|
108
|
+
:grant_type => 'password',
|
109
|
+
:username => 'thekev',
|
110
|
+
:password => 'h4x0r',
|
111
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
112
|
+
:client_secret => 'a2nQpcUm2Dgq1chWdAvbXGTk'
|
113
|
+
},
|
114
|
+
:headers => {
|
115
|
+
'Accept' =>'application/json',
|
116
|
+
'Content-Type' =>'application/x-www-form-urlencoded',
|
117
|
+
'User-Agent' =>"Yammer OAuth2 Client #{Yammer::Version}"
|
118
|
+
})
|
119
|
+
|
120
|
+
subject.access_token_from_resource_owner_credentials('thekev', 'h4x0r')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/yam.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.name = 'yam'
|
26
26
|
s.version = Yammer::Version
|
27
27
|
|
28
|
-
s.date = %q{2013-12-
|
28
|
+
s.date = %q{2013-12-16}
|
29
29
|
s.summary = "Yammer API Client"
|
30
30
|
|
31
31
|
s.description = "A Ruby wrapper for accessing Yammer's REST API"
|
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
|
|
43
43
|
s.signing_key = File.expand_path("~/.gem/certs/private_key.pem") if $0 =~ /gem\z/
|
44
44
|
|
45
45
|
s.add_dependency 'oj', '~> 2.0.10'
|
46
|
-
s.add_dependency 'multi_json', '~> 1.
|
46
|
+
s.add_dependency 'multi_json', '~> 1.8.2'
|
47
47
|
s.add_dependency 'rest-client', '~> 1.6.7'
|
48
48
|
s.add_dependency 'addressable', '~> 2.3.3'
|
49
49
|
s.add_dependency 'oauth2-client', '~> 1.1.2'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Mutyaba
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
B+kZ9/4dAvmKkr2NPSoxBQtO7Rz0HDNLtjMxkXbQUWMDsGnB6Kk1WUBb/w3kQ9Ah
|
30
30
|
JgIHF4cG
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-12-
|
32
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: oj
|
@@ -51,14 +51,14 @@ dependencies:
|
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.8.2
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.8.2
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rest-client
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- AUTHORS
|
184
184
|
- CHANGELOG.md
|
185
185
|
- CONTRIBUTING.md
|
186
|
+
- CONTRIBUTORS
|
186
187
|
- Gemfile
|
187
188
|
- LICENSE.txt
|
188
189
|
- README.md
|
@@ -212,6 +213,7 @@ files:
|
|
212
213
|
- lib/yammer/configurable.rb
|
213
214
|
- lib/yammer/error.rb
|
214
215
|
- lib/yammer/http_adapter.rb
|
216
|
+
- lib/yammer/oauth2_client.rb
|
215
217
|
- lib/yammer/resources.rb
|
216
218
|
- lib/yammer/resources/base.rb
|
217
219
|
- lib/yammer/resources/group.rb
|
@@ -253,6 +255,7 @@ files:
|
|
253
255
|
- spec/fixtures/users_following.json
|
254
256
|
- spec/http_adapter_spec.rb
|
255
257
|
- spec/mocks/attachment.txt
|
258
|
+
- spec/oauth2_client_spec.rb
|
256
259
|
- spec/resources/base_spec.rb
|
257
260
|
- spec/resources/group_membership_spec.rb
|
258
261
|
- spec/resources/group_spec.rb
|
@@ -317,6 +320,7 @@ test_files:
|
|
317
320
|
- spec/fixtures/users_following.json
|
318
321
|
- spec/http_adapter_spec.rb
|
319
322
|
- spec/mocks/attachment.txt
|
323
|
+
- spec/oauth2_client_spec.rb
|
320
324
|
- spec/resources/base_spec.rb
|
321
325
|
- spec/resources/group_membership_spec.rb
|
322
326
|
- spec/resources/group_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|