-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathprovider.rb
48 lines (40 loc) · 1.35 KB
/
provider.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
class Provider
def self.email_regex
/mailto:\/?\/?(.+@.+\..+)/
end
def self.email_from_mailto_uri(uri)
uri.gsub /mailto:\/?\/?/, ''
end
def self.provider_for_url(url)
if url.match Provider.email_regex
return 'email'
end
Provider.regexes.each do |code,regex|
if regex != '' && url.match(Regexp.new(regex))
return code
end
end
nil
end
def self.regexes
{
#'beeminder' => 'https?:\/\/(?:www\.)?beeminder\.com\/(.+)',
#'eventbrite' => 'https?:\/\/(.+)\.eventbrite\.com',
#'flickr' => 'https?:\/\/(?:www\.)?flickr\.com\/(?:people\/)?([^\/]+)',
'github' => 'https?:\/\/(?:www\.)?github\.com\/([^\/]+)',
'gitlab' => 'https?:\/\/(?:www\.)?gitlab\.com\/([^\/]+)',
#'google_oauth2' => 'https?:\/\/(?:www\.)?(?:profiles\.|plus\.|)google\.com\/([^\/]+)',
#'lastfm' => 'https?:\/\/(?:www\.)?last\.fm\/user\/(.+)',
'twitter' => 'https?:\/\/(?:www\.)?twitter\.com\/([^\/]+)'
}
end
def self.auth_path(provider, profile, me)
path = "/auth/start?me=#{URI.encode_www_form_component me}&provider=#{provider}&profile=#{URI.encode_www_form_component profile}"
if provider == 'twitter'
match = profile.match Regexp.new(self.regexes['twitter'])
twitter_username = match[1]
path = "#{path}&screen_name=#{twitter_username}"
end
path
end
end