Class: OmniContacts::Importer::Facebook
- Inherits:
-
Middleware::OAuth2
- Object
- Middleware::BaseOAuth
- Middleware::OAuth2
- OmniContacts::Importer::Facebook
- Includes:
- ParseUtils
- Defined in:
- lib/omnicontacts/importer/facebook.rb
Constant Summary
Constants included from HTTPUtils
Instance Attribute Summary collapse
-
#auth_host ⇒ Object
readonly
Returns the value of attribute auth_host.
-
#auth_token_path ⇒ Object
readonly
Returns the value of attribute auth_token_path.
-
#authorize_path ⇒ Object
readonly
Returns the value of attribute authorize_path.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Attributes inherited from Middleware::OAuth2
#client_id, #client_secret, #redirect_path
Attributes inherited from Middleware::BaseOAuth
Instance Method Summary collapse
- #fetch_contacts_using_access_token(access_token, access_token_secret) ⇒ Object
- #fetch_current_user(access_token) ⇒ Object
-
#initialize(*args) ⇒ Facebook
constructor
A new instance of Facebook.
Methods included from ParseUtils
#birthday_format, #email_to_name, #full_name, #image_url_from_email, #normalize_name
Methods inherited from Middleware::OAuth2
#fetch_contacts, #redirect_uri, #refresh_token_prop_name, #request_authorization_from_user
Methods included from Authorization::OAuth2
#authorization_url, #fetch_access_token, #refresh_access_token
Methods included from HTTPUtils
encode, host_url_from_rack_env, query_string_to_map, scheme, to_query_string
Methods inherited from Middleware::BaseOAuth
Constructor Details
#initialize(*args) ⇒ Facebook
Returns a new instance of Facebook.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/omnicontacts/importer/facebook.rb', line 12 def initialize *args super *args @auth_host = 'graph.facebook.com' @authorize_path = '/oauth/authorize' @scope = 'email,user_relationships,user_birthday,user_friends' @auth_token_path = '/oauth/access_token' @contacts_host = 'graph.facebook.com' @friends_path = '/v2.5/me/friends' @family_path = '/v2.5/me/family' @self_path = '/v2.5/me' end |
Instance Attribute Details
#auth_host ⇒ Object (readonly)
Returns the value of attribute auth_host.
10 11 12 |
# File 'lib/omnicontacts/importer/facebook.rb', line 10 def auth_host @auth_host end |
#auth_token_path ⇒ Object (readonly)
Returns the value of attribute auth_token_path.
10 11 12 |
# File 'lib/omnicontacts/importer/facebook.rb', line 10 def auth_token_path @auth_token_path end |
#authorize_path ⇒ Object (readonly)
Returns the value of attribute authorize_path.
10 11 12 |
# File 'lib/omnicontacts/importer/facebook.rb', line 10 def @authorize_path end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
10 11 12 |
# File 'lib/omnicontacts/importer/facebook.rb', line 10 def scope @scope end |
Instance Method Details
#fetch_contacts_using_access_token(access_token, access_token_secret) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/omnicontacts/importer/facebook.rb', line 24 def fetch_contacts_using_access_token access_token, access_token_secret self_response = fetch_current_user access_token user = current_user self_response set_current_user user spouse_id = extract_spouse_id self_response spouse_response = nil if spouse_id spouse_path = "/#{spouse_id}" spouse_response = https_get(@contacts_host, spouse_path, {:access_token => access_token, :fields => 'first_name,last_name,name,id,gender,birthday,picture'}) end family_response = https_get(@contacts_host, @family_path, {:access_token => access_token, :fields => 'first_name,last_name,name,id,gender,birthday,picture,relationship'}) friends_response = https_get(@contacts_host, @friends_path, {:access_token => access_token, :fields => 'first_name,last_name,name,id,gender,birthday,picture'}) contacts_from_response(spouse_response, family_response, friends_response) end |
#fetch_current_user(access_token) ⇒ Object
39 40 41 42 43 |
# File 'lib/omnicontacts/importer/facebook.rb', line 39 def fetch_current_user access_token self_response = https_get(@contacts_host, @self_path, {:access_token => access_token, :fields => 'first_name,last_name,name,id,gender,birthday,picture,relationship_status,significant_other,email'}) self_response = JSON.parse(self_response) if self_response self_response end |