Module: OpenQq

Defined in:
lib/open_qq/error.rb,
lib/open_qq.rb,
lib/open_qq/railtie.rb,
lib/open_qq/request.rb,
lib/open_qq/version.rb,
lib/open_qq/gateway.rb,
lib/open_qq/signature.rb,
lib/open_qq/rails/action_controller.rb,
lib/generators/open_qq/install_generator.rb

Overview

Author:

  • zires

Defined Under Namespace

Modules: Generators, Rails, Signature Classes: Error, Gateway, Railtie, Request

Constant Summary collapse

VERSION =

3.0表示OpenAPI版本, 小数点第二位表示SDK版本

"3.0.3"

Class Method Summary collapse

Class Method Details

.call(url, options) ⇒ Object Also known as: start

Examples:

OpenQq.call('/v3/user/get_info', { :appid => 123 }) do |request|
  request.get({:openid => '111'})
end

28
29
30
31
32
33
34
35
# File 'lib/open_qq.rb', line 28

def call(url, options)
  request = OpenQq::Request.new(options.with_indifferent_access)
  if block_given?
    yield request
  else
    request
  end
end

.setup(options = {}) {|@gateway| ... } ⇒ Object

Yields:

  • (@gateway)

15
16
17
18
19
# File 'lib/open_qq.rb', line 15

def setup(options = {})
  options    = options.with_indifferent_access
  @gateway ||= OpenQq::Gateway.new(options[:appid], options[:appkey], options[:env])
  yield @gateway if block_given?
end

.verify_callback_sig(http_method, url, params, key = nil) ⇒ Boolean

Examples:

params = {openid: 'test001', appid: '33758', sig: 'VvKwcaMqUNpKhx0XfCvOqPRiAnU%3D'}
OpenQq.verify_callback_sig(:get, '/cgi-bin/temp.py', params)
#diffenert key
OpenQq.verify_callback_sig(:get, '/cgi-bin/temp.py', params, 'xxxxxx')

46
47
48
49
50
51
# File 'lib/open_qq.rb', line 46

def verify_callback_sig(http_method, url, params, key = nil)
  key  ||= appkey
  params = params.dup
  sig    = params.delete('sig') || params.delete(:sig)
  Gateway.verify_sig(sig, "#{key}&", http_method.to_s.upcase, url, params)
end