Sha256: 7e2d5ab26b330b22b9656734600d981ce43a415d78f57f76db7afe9effb7df2f

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

# -*- encoding : utf-8 -*-

require 'rsa'
require 'openssl'
require 'faraday'
require 'faraday_middleware'

module Dito
  class Request

    def self.post module_name, path, params = {}, headers = {}
      make_request module_name, path, params, headers, 'post'
    end

    def self.get module_name, path, params = {}, headers = {}
      make_request module_name, path, params, headers, 'get'
    end

    def self.put module_name, path, params = {}, headers = {}
      make_request module_name, path, params, headers, 'put'
    end

    def self.delete module_name, path, params = {}, headers = {}
      make_request module_name, path, params, headers, 'delete'
    end

    def self.make_request module_name, path, params = {}, headers = {}, method = "get"
      conn = Faraday.new(:url => Dito.domains(module_name)) do |faraday|
        faraday.request :url_encoded # form-encode POST params
        faraday.response :json, :content_type => 'application/json'
        faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
      end

      signature = OpenSSL::PKey::RSA.new(File.read("#{Dito.root}/dito.pem")).public_encrypt Dito.secret

      params = {
        :network_name => "fb",
        :platform_api_key => Dito.api_key,
        :signature => signature
      }.merge(params)

      response = conn.send method, path, params, headers
      response.body
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dito-0.0.2 lib/dito/request.rb
dito-0.0.1 lib/dito/request.rb