Class: QQpush::General
- Inherits:
-
Object
- Object
- QQpush::General
- Defined in:
- lib/qqpush/general.rb
Constant Summary collapse
- PROTOCAL =
'http'
- ROOT_URL =
'openapi.xg.qq.com'
- VERSION =
'v2'
- SERVICES =
{ push: %w(single_device single_account account_list all_device tags_device) }
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #general_params(params) ⇒ Object
-
#initialize ⇒ General
constructor
A new instance of General.
- #param_sign(params) ⇒ Object
- #request(params = {}) ⇒ Object
- #request_url(params) ⇒ Object
Constructor Details
#initialize ⇒ General
Returns a new instance of General.
28 29 30 31 |
# File 'lib/qqpush/general.rb', line 28 def initialize @settings = File.exist?('settings.yml') ? YAML.load_file('settings.yml') : {} end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
9 10 11 |
# File 'lib/qqpush/general.rb', line 9 def settings @settings end |
Instance Method Details
#general_params(params) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/qqpush/general.rb', line 46 def general_params(params) base_params = { access_id: settings[:access_id], timestamp: params[:timestamp], valid_time: params[:valid_time] } base_params[:timestamp] ||= Time.now.to_i all_params = params.merge base_params base_params.merge(sign: param_sign(all_params)) end |
#param_sign(params) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/qqpush/general.rb', line 55 def param_sign(params) params.delete(:param_encode) sign_string = "#{params[:param_request].upcase}" \ "#{ROOT_URL}/#{VERSION}/#{params[:param_class]}/" \ "#{params[:param_method]}#{params_string(params)}" \ "#{settings[:secret_key]}" OpenSSL::Digest::MD5.new(sign_string).to_s end |
#request(params = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/qqpush/general.rb', line 33 def request(params = {}) response = RestClient.send( params[:param_request], request_url(params)) JSON.parse response end |
#request_url(params) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/qqpush/general.rb', line 39 def request_url(params) params[:param_encode] = true all_params = params.merge(general_params(params)) "#{PROTOCAL}://#{ROOT_URL}/#{VERSION}/#{params[:param_class]}/" \ "#{params[:param_method]}?#{params_string(all_params).gsub(/\&$/, '')}" end |