omnicontacts 0.3.2 → 0.3.3
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/Gemfile.lock +1 -1
- data/lib/omnicontacts.rb +1 -1
- data/lib/omnicontacts/http_utils.rb +0 -37
- data/lib/omnicontacts/importer/facebook.rb +2 -0
- data/lib/omnicontacts/importer/gmail.rb +2 -0
- data/lib/omnicontacts/importer/hotmail.rb +2 -0
- data/lib/omnicontacts/importer/yahoo.rb +2 -0
- data/lib/omnicontacts/parse_utils.rb +42 -0
- metadata +3 -2
data/Gemfile.lock
CHANGED
data/lib/omnicontacts.rb
CHANGED
@@ -11,43 +11,6 @@ module OmniContacts
|
|
11
11
|
|
12
12
|
module_function
|
13
13
|
|
14
|
-
# return has of birthday day, month and year
|
15
|
-
def birthday_format month, day, year
|
16
|
-
return {:day => day.to_i, :month => month.to_i, :year => year.to_i}if year && month && day
|
17
|
-
return {:day => day.to_i, :month => month.to_i, :year => nil} if !year && month && day
|
18
|
-
return nil if (!year && !month) || (!year && !day)
|
19
|
-
end
|
20
|
-
|
21
|
-
# normalize the name
|
22
|
-
def normalize_name name
|
23
|
-
return nil if name.nil?
|
24
|
-
name.chomp!
|
25
|
-
name = name.split(' ').map(&:capitalize).join(' ')
|
26
|
-
name.squeeze!(' ')
|
27
|
-
name.strip!
|
28
|
-
return name
|
29
|
-
end
|
30
|
-
|
31
|
-
# create a full name given the individual first and last name
|
32
|
-
def full_name first_name, last_name
|
33
|
-
return "#{first_name} #{last_name}" if first_name && last_name
|
34
|
-
return "#{first_name}" if first_name && !last_name
|
35
|
-
return "#{last_name}" if !first_name && last_name
|
36
|
-
return nil
|
37
|
-
end
|
38
|
-
|
39
|
-
# create a username/name from a given email
|
40
|
-
def email_to_name username_or_email
|
41
|
-
username_or_email = username_or_email.split('@').first if username_or_email.include?('@')
|
42
|
-
if group = (/(?<first>[a-z|A-Z]+)[\.|_](?<last>[a-z|A-Z]+)/).match(username_or_email)
|
43
|
-
first_name = normalize_name(group[:first])
|
44
|
-
last_name = normalize_name(group[:last])
|
45
|
-
return first_name, last_name, "#{first_name} #{last_name}"
|
46
|
-
end
|
47
|
-
username = normalize_name(username_or_email)
|
48
|
-
return username, nil, username
|
49
|
-
end
|
50
|
-
|
51
14
|
def query_string_to_map query_string
|
52
15
|
query_string.split('&').reduce({}) do |memo, key_value|
|
53
16
|
(key, value) = key_value.split('=')
|
@@ -1,9 +1,11 @@
|
|
1
|
+
require "omnicontacts/parse_utils"
|
1
2
|
require "omnicontacts/middleware/oauth2"
|
2
3
|
require "json"
|
3
4
|
|
4
5
|
module OmniContacts
|
5
6
|
module Importer
|
6
7
|
class Facebook < Middleware::OAuth2
|
8
|
+
include ParseUtils
|
7
9
|
|
8
10
|
attr_reader :auth_host, :authorize_path, :auth_token_path, :scope
|
9
11
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
require "omnicontacts/middleware/oauth2"
|
2
|
+
require "omnicontacts/parse_utils"
|
2
3
|
require "json"
|
3
4
|
|
4
5
|
module OmniContacts
|
5
6
|
module Importer
|
6
7
|
class Hotmail < Middleware::OAuth2
|
8
|
+
include ParseUtils
|
7
9
|
|
8
10
|
attr_reader :auth_host, :authorize_path, :auth_token_path, :scope
|
9
11
|
|
@@ -1,9 +1,11 @@
|
|
1
|
+
require "omnicontacts/parse_utils"
|
1
2
|
require "omnicontacts/middleware/oauth1"
|
2
3
|
require "json"
|
3
4
|
|
4
5
|
module OmniContacts
|
5
6
|
module Importer
|
6
7
|
class Yahoo < Middleware::OAuth1
|
8
|
+
include ParseUtils
|
7
9
|
|
8
10
|
attr_reader :auth_host, :auth_token_path, :auth_path, :access_token_path
|
9
11
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module OmniContacts
|
2
|
+
module ParseUtils
|
3
|
+
|
4
|
+
# return has of birthday day, month and year
|
5
|
+
def birthday_format month, day, year
|
6
|
+
return {:day => day.to_i, :month => month.to_i, :year => year.to_i}if year && month && day
|
7
|
+
return {:day => day.to_i, :month => month.to_i, :year => nil} if !year && month && day
|
8
|
+
return nil if (!year && !month) || (!year && !day)
|
9
|
+
end
|
10
|
+
|
11
|
+
# normalize the name
|
12
|
+
def normalize_name name
|
13
|
+
return nil if name.nil?
|
14
|
+
name.chomp!
|
15
|
+
name = name.split(' ').map(&:capitalize).join(' ')
|
16
|
+
name.squeeze!(' ')
|
17
|
+
name.strip!
|
18
|
+
return name
|
19
|
+
end
|
20
|
+
|
21
|
+
# create a full name given the individual first and last name
|
22
|
+
def full_name first_name, last_name
|
23
|
+
return "#{first_name} #{last_name}" if first_name && last_name
|
24
|
+
return "#{first_name}" if first_name && !last_name
|
25
|
+
return "#{last_name}" if !first_name && last_name
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
|
29
|
+
# create a username/name from a given email
|
30
|
+
def email_to_name username_or_email
|
31
|
+
username_or_email = username_or_email.split('@').first if username_or_email.include?('@')
|
32
|
+
if group = (/(?<first>[a-z|A-Z]+)[\.|_](?<last>[a-z|A-Z]+)/).match(username_or_email)
|
33
|
+
first_name = normalize_name(group[:first])
|
34
|
+
last_name = normalize_name(group[:last])
|
35
|
+
return first_name, last_name, "#{first_name} #{last_name}"
|
36
|
+
end
|
37
|
+
username = normalize_name(username_or_email)
|
38
|
+
return username, nil, username
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnicontacts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/omnicontacts/middleware/base_oauth.rb
|
105
105
|
- lib/omnicontacts/middleware/oauth1.rb
|
106
106
|
- lib/omnicontacts/middleware/oauth2.rb
|
107
|
+
- lib/omnicontacts/parse_utils.rb
|
107
108
|
- omnicontacts.gemspec
|
108
109
|
- spec/omnicontacts/authorization/oauth1_spec.rb
|
109
110
|
- spec/omnicontacts/authorization/oauth2_spec.rb
|