Sha256: 1b0c8681acdb20efaac29ad6de4620a91a8f96b8edbd88cbba7fd7d852e56619

Contents?: true

Size: 916 Bytes

Versions: 1

Compression:

Stored size: 916 Bytes

Contents

# coding: utf-8
module GuanyiErp
  class Request

    def self.post(params)

      response = Faraday.new(:url => GuanyiErp::Config.api_host).post do |req|
        req.url GuanyiErp::Config.api_path
        req.headers['Content-Type'] = 'application/json'
        body_hash = {
            appkey: GuanyiErp::Config.app_key,
            sessionkey: GuanyiErp::Config.session_key
        }.merge(params)
        body_hash = body_hash.merge({sign: sign(body_hash)})
        puts body_hash.to_json
        req.body= body_hash.to_json
      end
      body = parse_json(response.body)
      return nil unless body
      body

    end

    def self.parse_json(json_data_str)
      begin
        return JSON.parse(json_data_str)
      rescue
      end
      nil
    end

    def self.sign(body_hash)
      Digest::MD5.hexdigest("#{GuanyiErp::Config.secret}#{body_hash.to_json}#{GuanyiErp::Config.secret}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guanyi-erp-1.0.1 lib/guanyi_erp/request.rb