Sha256: 117cb589cbfcf988da39a07db6d094d160fff9c2817337628aea1044692e0b06

Contents?: true

Size: 908 Bytes

Versions: 1

Compression:

Stored size: 908 Bytes

Contents

require "edm/version"
require "net/http"

module Edm
  class EdmClient
    def initialize(account, key)
      @account = account
      @key = key
    end

    attr_accessor :account, :key

    def api_request(url, http_method, options = {})
      sign = generate_sign(options)
      options["sign"] = sign
      Rails.logger.debug "-------------"
      result = remote_request(http_method, 'http://0.0.0.0:3000' + url, options)
      return result.body
    end

    def generate_sign(options = {})
      if options.length > 0
        str = options.to_a.sort.map { |c| "#{c[0]}=#{c[1]}" }.join('&')
        sign = Digest::SHA1.hexdigest("#{str}#{key}")
      end
    end

    def remote_request(http_method, url, options = {})
      case http_method
      when 'post'
        Net::HTTP.post_form(URI.parse(url), options)
      when 'get'
        Net::HTTP.get(URI.parse(url))
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
edm-0.0.4 lib/edm.rb