plataforma_social 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module PlataformaSocial
2
+ class Configuration
3
+ attr_accessor :api_key, :facebook_app_secret, :facebook_app_id, :facebook_app_namespace
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ module PlataformaSocial
2
+ class Facebook
3
+ def self.parse_signed_request signed_request, max_age = 3600
4
+ secret = PlataformaSocial.facebook_app_secret
5
+ encoded_sig, encoded_envelope = signed_request.split('.', 2)
6
+ envelope = JSON.parse(base64_url_decode(encoded_envelope))
7
+ algorithm = envelope['algorithm']
8
+
9
+ raise 'Invalid request. (Unsupported algorithm.)' \
10
+ if algorithm != 'HMAC-SHA256'
11
+
12
+ raise 'Invalid request. (Too old.)' \
13
+ if envelope['issued_at'] < Time.now.to_i - max_age
14
+
15
+ raise 'Invalid request. (Invalid signature.)' \
16
+ if base64_url_decode(encoded_sig) != OpenSSL::HMAC.hexdigest('sha256', secret, encoded_envelope).split.pack('H*')
17
+
18
+ envelope
19
+ end
20
+
21
+ private
22
+
23
+ def self.base64_url_decode(str)
24
+ str += '=' * (4 - str.length.modulo(4))
25
+ Base64.decode64(str.tr('-_','+/'))
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module PlataformaSocial
2
+ module Helpers
3
+ def plataforma_social_script_tag
4
+ "<script src=\"#{PlataformaSocial.domains('js')}/socialp.js\" type=\"text/javascript\" charset=\"utf-8\"></script>".html_safe
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ require 'rsa'
2
+ require 'openssl'
3
+
4
+ module PlataformaSocial
5
+ class Request
6
+
7
+ def self.post url, params = {}
8
+ request url, params, 'post'
9
+ end
10
+
11
+ def self.get url, params = {}
12
+ request url, params, 'get'
13
+ end
14
+
15
+ def self.request url, params = {}, method = "get"
16
+ secret = PlataformaSocial.facebook_app_secret
17
+ platform_api_key = PlataformaSocial.api_key
18
+ secret_key = OpenSSL::PKey::RSA.new(File.read("#{Rails.root}/plataforma_social/keys/public.pem")).public_encrypt secret
19
+ params_name = method == 'get' ? :query : :body
20
+ params = { :network_name => "fb", :platform_api_key => platform_api_key, :signature => secret_key }.merge(params)
21
+
22
+ begin
23
+ response = HTTParty.send(method.to_sym, url, params_name => params)
24
+ rescue
25
+ return nil
26
+ end
27
+
28
+ return nil if response.nil?
29
+
30
+ response = response.parsed_response["data"]
31
+ response = JSON.parse(response) unless response.blank? || response.is_a?(Array)
32
+ return response
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module PlataformaSocial
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -40,6 +40,10 @@ files:
40
40
  - README.md
41
41
  - Rakefile
42
42
  - lib/plataforma_social.rb
43
+ - lib/plataforma_social/configuration.rb
44
+ - lib/plataforma_social/facebook.rb
45
+ - lib/plataforma_social/helpers.rb
46
+ - lib/plataforma_social/request.rb
43
47
  - lib/plataforma_social/version.rb
44
48
  - plataforma_social.gemspec
45
49
  homepage: http://www.dito.com.br/