Class: UmengMsg::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/umeng_msg/subject.rb

Constant Summary collapse

CAST_TYPE =
%w|unicast listcast filecast broadcast groupcast customizedcast|
PUSH_URL =
'http://msg.umeng.com/api/send'
CHECK_URL =
'http://msg.umeng.com/api/status'
CANCEL_URL =
'http://msg.umeng.com/api/cancel'
UPLOAD_URL =
'http://msg.umeng.com/upload'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform, **options) ⇒ Subject

Returns a new instance of Subject.



13
14
15
16
17
18
19
20
# File 'lib/umeng_msg/subject.rb', line 13

def initialize(platform, **options)
  @platform          = platform
  @payload           = Params.push_params(platform, **options)
  @content           = options['content']
  @file_id, @task_id = nil
  @ret               = { push: nil, check: nil, cancel: nil, upload: nil }
  @error_code        = { push: nil, check: nil, cancel: nil, upload: nil }
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/umeng_msg/subject.rb', line 6

def content
  @content
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



6
7
8
# File 'lib/umeng_msg/subject.rb', line 6

def error_code
  @error_code
end

#file_idObject (readonly)

Returns the value of attribute file_id.



6
7
8
# File 'lib/umeng_msg/subject.rb', line 6

def file_id
  @file_id
end

#payloadObject (readonly)

Returns the value of attribute payload.



6
7
8
# File 'lib/umeng_msg/subject.rb', line 6

def payload
  @payload
end

#platformObject (readonly)

Returns the value of attribute platform.



6
7
8
# File 'lib/umeng_msg/subject.rb', line 6

def platform
  @platform
end

#retObject (readonly)

Returns the value of attribute ret.



6
7
8
# File 'lib/umeng_msg/subject.rb', line 6

def ret
  @ret
end

#task_idObject (readonly)

Returns the value of attribute task_id.



6
7
8
# File 'lib/umeng_msg/subject.rb', line 6

def task_id
  @task_id
end

Instance Method Details

#cancelObject



41
42
43
44
45
46
47
48
49
# File 'lib/umeng_msg/subject.rb', line 41

def cancel
  @cancel_payload = Params.cancel_params(@platform, @task_id)
  sign = Sign.generate @platform, CANCEL_URL, @cancel_payload
  begin
    parse_res RestClient.post("#{CANCEL_URL}?sign=#{sign}", @cancel_payload.to_json, content_type: :json, accept: :json)
  rescue => e
    parse_res e.response
  end
end

#checkObject



31
32
33
34
35
36
37
38
39
# File 'lib/umeng_msg/subject.rb', line 31

def check
  @check_payload = Params.check_params(@platform, @task_id)
  sign = Sign.generate @platform, CHECK_URL, @check_payload
  begin
    parse_res RestClient.post("#{CHECK_URL}?sign=#{sign}", @check_payload.to_json, content_type: :json, accept: :json)
  rescue => e
    parse_res e.response
  end
end

#pushObject



22
23
24
25
26
27
28
29
# File 'lib/umeng_msg/subject.rb', line 22

def push
  sign = Sign.generate @platform, PUSH_URL, @payload
  begin
    parse_res RestClient.post("#{PUSH_URL}?sign=#{sign}", @payload.to_json, content_type: :json, accept: :json)
  rescue => e
    parse_res e.response
  end
end

#uploadObject



51
52
53
54
55
56
57
58
59
# File 'lib/umeng_msg/subject.rb', line 51

def upload
  @upload_payload = Params.upload_params(@platform, @content)
  sign = Sign.generate @platform, CANCEL_URL, @upload_payload
  begin
    parse_res RestClient.post("#{UPLOAD_URL}?sign=#{sign}", @upload_payload.to_json, content_type: :json, accept: :json)
  rescue => e
    parse_res e.response
  end
end