forked from omniauth/omniauth
/
meetup.rb
56 lines (50 loc) · 1.84 KB
/
meetup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'omniauth/oauth'
require 'multi_json'
module OmniAuth
module Strategies
#
# Authenticate with Meetup via OAuth and retrieve an access token for API usage
#
# Usage:
#
# use OmniAuth::Strategies::Meetup, 'consumerkey', 'consumersecret'
#
class Meetup < OmniAuth::Strategies::OAuth
# Initialize meetup middleware
# @param [Rack Application] app standard middleware application parameter
# @param [String] consumer_key the application consumer id
# @param [String] consumer_secret the application consumer secret
# @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
auth_path = (options[:sign_in] == false) ? 'http://www.meetup.com/authorize' : 'http://www.meetup.com/authenticate'
super(app, :meetup, consumer_key, consumer_secret,
{ :request_token_path => "https://api.meetup.com/oauth/request",
:access_token_path => "https://api.meetup.com/oauth/access",
:authorize_path => auth_path }, options)
end
def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => member['id'],
'user_info' => user_info,
'extra' => { 'user_hash' => member }
})
end
def user_info
{
'name' => member['name'],
'image' => member['photo_url'],
'location' => member['city'],
'urls' => {
'profile' => member['link']
}
}
end
def member
@member ||= parse(@access_token.get('https://api.meetup.com/members.json?relation=self').body)['results'][0]
end
def parse(response)
MultiJson.decode(response)
end
end
end
end