16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/plataforma_social/request.rb', line 16
def self.request url, params = {}, method = "get"
secret = PlataformaSocial.secret
platform_api_key = PlataformaSocial.api_key
secret_key = OpenSSL::PKey::RSA.new(File.read("#{Rails.root}/plataforma_social/keys/public.pem")).public_encrypt secret
params_name = method == 'get' ? :query : :body
params = { :network_name => "fb", :platform_api_key => platform_api_key, :signature => secret_key }.merge(params)
begin
response = HTTParty.send(method.to_sym, url, params_name => params)
rescue => e
return e.to_s
end
return nil if response.nil?
response = response.parsed_response["data"]
response = JSON.parse(response) if response.present? && response.is_a?(String)
return response
end
|