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
-
#request_params ⇒ Object
Returns the value of attribute request_params.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #general_params(params) ⇒ Object
-
#initialize(params = {}) ⇒ General
constructor
A new instance of General.
- #param_sign(params) ⇒ Object
- #request(params = {}) ⇒ Object
- #request_url(params) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ General
Returns a new instance of General.
29 30 31 32 33 |
# File 'lib/qqpush/general.rb', line 29 def initialize(params = {}) @settings = File.exist?('settings.yml') ? YAML.load_file('settings.yml') : {} @request_params = params end |
Instance Attribute Details
#request_params ⇒ Object
Returns the value of attribute request_params.
9 10 11 |
# File 'lib/qqpush/general.rb', line 9 def request_params @request_params end |
#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
48 49 50 51 52 53 54 55 |
# File 'lib/qqpush/general.rb', line 48 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
57 58 59 60 61 62 63 64 |
# File 'lib/qqpush/general.rb', line 57 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
35 36 37 38 39 |
# File 'lib/qqpush/general.rb', line 35 def request(params = {}) response = RestClient.send( params[:param_request], request_url(params)) JSON.parse response end |
#request_url(params) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/qqpush/general.rb', line 41 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 |