Sha256: b1638a0c4c7489231ac38e834bb24dbe1b83d31e08fa40dbc2ea8b0e41c07664

Contents?: true

Size: 1.08 KB

Versions: 23

Compression:

Stored size: 1.08 KB

Contents

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

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.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  
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
plataforma_social-0.0.30 lib/plataforma_social/request.rb
plataforma_social-0.0.29 lib/plataforma_social/request.rb
plataforma_social-0.0.28 lib/plataforma_social/request.rb
plataforma_social-0.0.27 lib/plataforma_social/request.rb
plataforma_social-0.0.26 lib/plataforma_social/request.rb
plataforma_social-0.0.25 lib/plataforma_social/request.rb
plataforma_social-0.0.24 lib/plataforma_social/request.rb
plataforma_social-0.0.23 lib/plataforma_social/request.rb
plataforma_social-0.0.22 lib/plataforma_social/request.rb
plataforma_social-0.0.21 lib/plataforma_social/request.rb
plataforma_social-0.0.20 lib/plataforma_social/request.rb
plataforma_social-0.0.19 lib/plataforma_social/request.rb
plataforma_social-0.0.18 lib/plataforma_social/request.rb
plataforma_social-0.0.17 lib/plataforma_social/request.rb
plataforma_social-0.0.16 lib/plataforma_social/request.rb
plataforma_social-0.0.15 lib/plataforma_social/request.rb
plataforma_social-0.0.14 lib/plataforma_social/request.rb
plataforma_social-0.0.12 lib/plataforma_social/request.rb
plataforma_social-0.0.11 lib/plataforma_social/request.rb
plataforma_social-0.0.10 lib/plataforma_social/request.rb