Class: AliyunPush::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun-push/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, access_key_secret, region = 'cn-hangzhou') ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
# File 'lib/aliyun-push/client.rb', line 7

def initialize(access_key_id, access_key_secret, region = 'cn-hangzhou')
  @base_url = "https://cloudpush.aliyuncs.com/"
  @region = region
  @access_key_id = access_key_id
  @access_key_secret = access_key_secret
end

Instance Method Details

#send_request(params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aliyun-push/client.rb', line 14

def send_request(params)
  default_params = {
    Format: 'JSON',
    RegionId: @region,
    Version: '2015-08-27',
    AccessKeyId: @access_key_id,
    SignatureMethod: 'HMAC-SHA1',
    Timestamp: Time.now.utc.iso8601,
    SignatureVersion: '1.0',
    SignatureNonce: SecureRandom.uuid
  }

  params.each do |key, val|
    default_params[key.to_sym] = val
  end

  ps = ParameterSet.new
  default_params.each do |key, val| 
    ps.add key.to_s, val.to_s
  end
  ps.add 'Signature', ps.sign(@access_key_secret)
  request_url = "#{@base_url}?#{ps.concatenate}"
  HTTParty.get request_url
end