Sha256: 4afede620717cd5bea863b75c09033daaf57a311115ab55f609c01f0fd2cfc4c

Contents?: true

Size: 737 Bytes

Versions: 2

Compression:

Stored size: 737 Bytes

Contents

require 'umengo/res'

module Umengo
  module Util
    def generate_sign(uri, params)
      method = 'POST'
      url = [Umengo::UMENG_HOST, '/', uri]
      post_body = Oj.dump(params)
      Digest::MD5.hexdigest([method, url, post_body, @app_master_secret].join)
    end

    def perform(uri, params)
      conn = Faraday.new(:url => Umengo::UMENG_HOST) do |faraday|
        faraday.request  :url_encoded
        faraday.response :logger
        faraday.adapter  Faraday.default_adapter
      end

      response = conn.post do |req|
        req.url uri, sign: generate_sign(uri, params)
        req.headers['Content-Type'] = 'application/json'
        req.body = params.to_json
      end

      Res.new(response, uri)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
umengo-0.2.0 lib/umengo/util.rb
umengo-0.1.0 lib/umengo/util.rb