Sha256: 3a979050e2a9159cbd262078c27bf49d8f68f12b2ef6d34a4b7c539a9fbfbc54

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

# coding: utf-8

module KuaiJieQian
  module Http

    def self.post(host, project_id, path, params, content_type='application/json')
      final_url = "#{host}/#{path}"
      header = {
        "X-timevale-mode" => "package",
        "X-timevale-project-id" => project_id,
        "X-timevale-signature-algorithm" => "hmac-sha256",
      }.merge({'Content-Type' => content_type})

      if "application/json" == content_type
        request_body = params.to_json
      else
        request_body = params
      end

      KuaiJieQian.logger.info "post [#{final_url}] with header: [#{header}], params: [#{params}]"

      response = RestClient.post(final_url, request_body, header)

      KuaiJieQian.logger.info "post [#{final_url}] got result: [#{response}]\n"

      begin
        res = Utils.symbolize_keys(JSON.parse(response))
      rescue
        raise "post [#{final_url}] 解析结果出错"
      end

      KuaiJieQian.logger.info "res: [#{res}]\n"
      res
    end

  end # end module
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kuai_jie_qian-0.1.0 lib/kuai_jie_qian/http.rb