Sha256: 1345b13ef1eea79fb2c8a698fb9a4fbfe0060163a5a56caecf25d3c6629fe2af

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'rsa'
require 'openssl'

module PlataformaSocial
  class Request
    
    def self.post url, params = {}
      request url, params, 'post'
    end
    
    def self.get url, params = {}
      request url, params, 'get'
    end
    
    def self.request url, params = {}, method = "get"
      secret           = PlataformaSocial.facebook_app_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
        return nil
      end
      
      return nil if response.nil?
      
      response = response.parsed_response["data"]
      response = JSON.parse(response) unless response.blank? || response.is_a?(Array)
      return response
    end  
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plataforma_social-0.0.3 lib/plataforma_social/request.rb
plataforma_social-0.0.2 lib/plataforma_social/request.rb