Sha256: 3def5e083675ff4e222ffa8b7664596b4338854e92720a50de1d093500b38263

Contents?: true

Size: 900 Bytes

Versions: 1

Compression:

Stored size: 900 Bytes

Contents

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.0 lib/guanyi_erp/request.rb