Sha256: 0daa9f595b3d055af247d7381daeb7535d49f67f1b7c4a5f5881bab1197be34d

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 Bytes

Contents

require 'umengo/res'

module Umengo
  module Util
    def generate_sign(uri, params)
      method = 'POST'
      url = [Umengo::UMENG_HOST, '/', uri]
      post_body = JSON.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

1 entries across 1 versions & 1 rubygems

Version Path
umengo-0.3.0 lib/umengo/util.rb