plataforma_social 0.0.30 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,9 +6,9 @@ module PlataformaSocial
6
6
  def facebook_login
7
7
  load_oauth
8
8
  load_graph
9
-
9
+
10
10
  redirect = false
11
-
11
+
12
12
  if params[:code]
13
13
  begin
14
14
  @oauth.get_access_token(params[:code])
@@ -18,12 +18,12 @@ module PlataformaSocial
18
18
  else
19
19
  redirect = true if parse_facebook_signed_request && !parse_facebook_signed_request['oauth_token']
20
20
  end
21
-
21
+
22
22
  if parse_facebook_signed_request && parse_facebook_signed_request['oauth_token']
23
23
  if !session[:not_verify_facebook_permissions] === true
24
24
  permissions = @graph.get_object('me', :fields => 'permissions')['permissions']['data'][0]
25
25
  session[:not_verify_facebook_permissions] = true
26
-
26
+
27
27
  PlataformaSocial.facebook_scope.split(',').each do |permission|
28
28
  redirect = true unless permissions[permission.strip]
29
29
  end
@@ -32,7 +32,7 @@ module PlataformaSocial
32
32
 
33
33
  render :text => %|<script type="text/javascript">window.top.location.href="#{@oauth.url_for_oauth_code(:permissions => PlataformaSocial.configuration.facebook_scope)}";</script>| if redirect
34
34
  end
35
-
35
+
36
36
  def load_user_data options = {}
37
37
  settings = {
38
38
  referral_code: params[:gm_referral_code],
@@ -45,13 +45,13 @@ module PlataformaSocial
45
45
  referrer: request.referer,
46
46
  signed_request: params[:signed_request]
47
47
  }.merge options
48
-
48
+
49
49
  facebook_data = facebook_user_data.try(:symbolize_keys)
50
50
  plataforma_social_data = plataforma_social_user_data(settings).try(:symbolize_keys)
51
-
51
+
52
52
  @user_data = { :facebook => facebook_data, :plataforma_social => plataforma_social_data }
53
53
  end
54
-
54
+
55
55
  def plataforma_social_user_data options = {}
56
56
  settings = {
57
57
  referral_code: params[:gm_referral_code],
@@ -64,28 +64,28 @@ module PlataformaSocial
64
64
  referrer: request.referer,
65
65
  signed_request: params[:signed_request]
66
66
  }.merge options
67
-
67
+
68
68
  if settings[:signed_request]
69
69
  response = Request.post("#{PlataformaSocial.domains('login')}/register", settings)
70
-
70
+
71
71
  data = {}
72
72
  data[:reference] = response['id'] if response.present? && response['id']
73
-
73
+
74
74
  data
75
75
  end
76
76
  end
77
-
77
+
78
78
  def facebook_user_data
79
79
  if load_graph
80
80
  @graph.get_object('me')
81
81
  end
82
82
  end
83
-
83
+
84
84
  def parse_facebook_signed_request
85
85
  load_oauth
86
86
  @oauth.parse_signed_request params[:signed_request] if params[:signed_request].present?
87
87
  end
88
-
88
+
89
89
  def load_oauth
90
90
  if params[:callback_url].present?
91
91
  callback_url = params[:callback_url]
@@ -94,19 +94,27 @@ module PlataformaSocial
94
94
  else
95
95
  callback_url = PlataformaSocial.facebook_callback_url.to_s
96
96
  end
97
-
97
+
98
98
  uri = URI.parse(callback_url)
99
-
99
+
100
100
  callback_url = if uri && uri.scheme.present?
101
- uri.query = [uri.query, "gm_referral_code=#{params[:gm_referral_code]}", "utm_source=#{params[:utm_source]}", "campaign=#{params[:utm_campaign]}", "medium=#{params[:utm_medium]}", "source=#{params[:utm_source]}"].compact.join('&')
101
+ uri.query = [
102
+ uri.query,
103
+ "gm_referral_code=#{URI.encode(params[:gm_referral_code] || '')}",
104
+ "utm_source=#{URI.encode(params[:utm_source] || '')}",
105
+ "campaign=#{URI.encode(params[:utm_campaign] || '')}",
106
+ "medium=#{URI.encode(params[:utm_medium] || '')}",
107
+ "source=#{URI.encode(params[:utm_source] || '')}"
108
+ ].compact.join('&')
109
+
102
110
  uri.to_s
103
111
  else
104
112
  nil
105
113
  end
106
-
114
+
107
115
  @oauth = Koala::Facebook::OAuth.new(PlataformaSocial.facebook_app_id, PlataformaSocial.facebook_app_secret, callback_url)
108
116
  end
109
-
117
+
110
118
  def load_graph
111
119
  @graph = Koala::Facebook::API.new parse_facebook_signed_request['oauth_token'] if parse_facebook_signed_request.present? && parse_facebook_signed_request['oauth_token']
112
120
  end
@@ -115,4 +123,4 @@ end
115
123
 
116
124
  class ActionController::Base
117
125
  include PlataformaSocial::Facebook
118
- end
126
+ end
@@ -5,15 +5,15 @@ require 'httparty'
5
5
  module PlataformaSocial
6
6
  class Request
7
7
 
8
- def self.post url, params = {}
9
- request url, params, 'post'
8
+ def self.post url, params = {}, headers = {}
9
+ request url, params, headers, 'post'
10
10
  end
11
11
 
12
- def self.get url, params = {}
13
- request url, params, 'get'
12
+ def self.get url, params = {}, headers = {}
13
+ request url, params, headers, 'get'
14
14
  end
15
15
 
16
- def self.request url, params = {}, method = "get"
16
+ def self.request url, params = {}, headers = {}, method = "get"
17
17
  secret = PlataformaSocial.secret
18
18
  platform_api_key = PlataformaSocial.api_key
19
19
  secret_key = OpenSSL::PKey::RSA.new(File.read("#{Rails.root}/plataforma_social/keys/public.pem")).public_encrypt secret
@@ -21,7 +21,7 @@ module PlataformaSocial
21
21
  params = { :network_name => "fb", :platform_api_key => platform_api_key, :signature => secret_key }.merge(params)
22
22
 
23
23
  begin
24
- response = HTTParty.send(method.to_sym, url, params_name => params)
24
+ response = HTTParty.send(method.to_sym, url, params_name => params, :headers => headers.stringify_keys)
25
25
  rescue => e
26
26
  return e.to_s
27
27
  end
@@ -33,4 +33,7 @@ module PlataformaSocial
33
33
  return response
34
34
  end
35
35
  end
36
+
37
+
38
+
36
39
  end
@@ -1,3 +1,3 @@
1
1
  module PlataformaSocial
2
- VERSION = "0.0.30"
2
+ VERSION = "0.0.32"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plataforma_social
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.32
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-12-06 00:00:00.000000000 Z
12
+ date: 2014-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano