Class: JpushRubySdk::Client

Inherits:
Object
  • Object
show all
Includes:
ApiHelper
Defined in:
lib/jpush_ruby_sdk/client.rb

Constant Summary

Constants included from ApiHelper

ApiHelper::HTTPS_BASE_URL, ApiHelper::HTTPS_JPUSH_API_URL, ApiHelper::HTTPS_JPUSH_API_URL_CUSTOM_MESSAGE, ApiHelper::HTTPS_JPUSH_API_URL_NOTIFICATION, ApiHelper::HTTP_BASE_URL, ApiHelper::HTTP_JPUSH_API_URL, ApiHelper::HTTP_JPUSH_API_URL_CUSTOM_MESSAGE, ApiHelper::HTTP_JPUSH_API_URL_NOTIFICATION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_key, master_secret, opts = {}, &block) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/jpush_ruby_sdk/client.rb', line 9

def initialize(app_key, master_secret, opts={}, &block)
  @app_key       = app_key
  @master_secret = master_secret
end

Instance Attribute Details

#app_keyObject

Returns the value of attribute app_key.



7
8
9
# File 'lib/jpush_ruby_sdk/client.rb', line 7

def app_key
  @app_key
end

#master_secretObject

Returns the value of attribute master_secret.



7
8
9
# File 'lib/jpush_ruby_sdk/client.rb', line 7

def master_secret
  @master_secret
end

Instance Method Details

#pushNotification(sendno, receiver, msg, https = false, options = {}) ⇒ Object

推送全功能接口 url: docs.jpush.cn/display/dev/Send+API+v2#SendAPIv2-推送全功能接口 api: sendmsg/v2/sendmsg options: send_description, time_to_live, override_msg_id



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jpush_ruby_sdk/client.rb', line 20

def pushNotification(sendno, receiver, msg, https=false, options={})
  # default: HTTP
  api_url = https == true ? HTTPS_JPUSH_API_URL_NOTIFICATION : HTTP_JPUSH_API_URL

  post_body = {}
  post_body[:app_key] = app_key
  post_body[:sendno]  = sendno
  post_body[:receiver_type]     = receiver[:receiver_type]
  post_body[:receiver_value]    = receiver[:receiver_value]
  post_body[:verification_code] = buildVerifcation(sendno,
                                                   receiver[:receiver_type],
                                                   receiver[:receiver_value],
                                                   master_secret)
  post_body[:msg_type]    = msg[:msg_type]
  post_body[:msg_content] = msg[:msg_content]
  post_body[:platform]    = msg[:platform]
  post_body.merge!(options)

  postJPushApi(api_url, post_body)
end