Sha256: c88a6b008bf2be662ec3cdb271f66841be31829fe6a91571c166fae80588a1ec

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

require 'rsa'
require 'openssl'
require 'httparty'

module PlataformaSocial
  class Request
    
    def self.post url, params = {}, headers = {}
      request url, params, headers, 'post'
    end
    
    def self.get url, params = {}, headers = {}
      request url, params, headers, 'get'
    end
    
    def self.request url, params = {}, headers = {}, 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, :headers => headers.stringify_keys)
      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  
  end
  
  
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
plataforma_social-0.0.36 lib/plataforma_social/request.rb
plataforma_social-0.0.35 lib/plataforma_social/request.rb
plataforma_social-0.0.34 lib/plataforma_social/request.rb
plataforma_social-0.0.33 lib/plataforma_social/request.rb
plataforma_social-0.0.32 lib/plataforma_social/request.rb