Class: JPushApiRubyClient::Client

Inherits:
Object
  • Object
show all
Includes:
MsgType, PlatformType, ReceiverType
Defined in:
lib/jpush_api_ruby_client/client.rb

Constant Summary

Constants included from PlatformType

PlatformType::ANDROID, PlatformType::BOTH, PlatformType::IOS

Constants included from MsgType

MsgType::MESSAGE, MsgType::NOTIFICATION

Constants included from ReceiverType

ReceiverType::ALIAS, ReceiverType::BROADCAST, ReceiverType::IMEI, ReceiverType::TAG

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

  • @param [String] app_key

    * @param [String] master_secret
    * @param [Hash] opts  opts


20
21
22
23
24
25
# File 'lib/jpush_api_ruby_client/client.rb', line 20

def initialize(app_key, master_secret, opts ={}, &block)
  @app_key = app_key
  @master_secret = master_secret
  @time_to_live = opts['time_to_live'] || 86400
  @platform = opts['platform'] || PlatformType::BOTH
end

Instance Attribute Details

#app_keyObject

Returns the value of attribute app_key.



13
14
15
# File 'lib/jpush_api_ruby_client/client.rb', line 13

def app_key
  @app_key
end

#httpsObject

Returns the value of attribute https.



13
14
15
# File 'lib/jpush_api_ruby_client/client.rb', line 13

def https
  @https
end

#master_secretObject

Returns the value of attribute master_secret.



13
14
15
# File 'lib/jpush_api_ruby_client/client.rb', line 13

def master_secret
  @master_secret
end

#platformObject

Returns the value of attribute platform.



13
14
15
# File 'lib/jpush_api_ruby_client/client.rb', line 13

def platform
  @platform
end

#time_to_liveObject

Returns the value of attribute time_to_live.



13
14
15
# File 'lib/jpush_api_ruby_client/client.rb', line 13

def time_to_live
  @time_to_live
end

Instance Method Details

#enable_ssl(https = false) ⇒ Object

  • 是否启用https ssl连接,缺省false

    * @param [Object]  true or false
    


39
40
41
# File 'lib/jpush_api_ruby_client/client.rb', line 39

def enable_ssl(https = false)
  @https = https
end

#generate_send_noObject

  • 当前时间戳生成send_no

    * @return [Integer]
    


31
32
33
# File 'lib/jpush_api_ruby_client/client.rb', line 31

def generate_send_no
  Integer(Time.new)
end

#send_message_with_alias(send_no, alias_, msg_title, msg_content, opts = {}) ⇒ Object

  • 发送带别名推送的自定义消息

    * @param [Integer] send_no
    * @param [String] alias_
    * @param [String] msg_title
    * @param [String] msg_content
    * @param [Hash] opts opts


80
81
82
83
84
# File 'lib/jpush_api_ruby_client/client.rb', line 80

def send_message_with_alias(send_no, alias_, msg_title, msg_content, opts = {})
  receiver = {:receiver_type => ReceiverType::ALIAS,
              :receiver_value => alias_}
  send_custom_message(send_no, msg_title, msg_content, receiver, opts)
end

#send_message_with_appkey(send_no, msg_title, msg_content, opts = {}) ⇒ Object

  • 发送使用 appkey 推送的自定义消息

    * @param [Integer] send_no
    * @param [String] msg_title
    * @param [String] msg_content
    * @param [Hash] opts opts


51
52
53
54
# File 'lib/jpush_api_ruby_client/client.rb', line 51

def send_message_with_appkey(send_no, msg_title, msg_content, opts = {})
  receiver = {:receiver_type => ReceiverType::BROADCAST}
  send_custom_message(send_no, msg_title, msg_content, receiver, opts)
end

#send_message_with_imei(send_no, imei, msg_title, msg_content, opts = {}) ⇒ Object

  • 发送带 imei 推送的自定义消息

    * @param [Integer] send_no
    * @param [String] imei
    * @param [String] msg_title
    * @param [String] msg_content
    * @param [Hash] opts opts


95
96
97
98
99
# File 'lib/jpush_api_ruby_client/client.rb', line 95

def send_message_with_imei(send_no, imei, msg_title, msg_content, opts = {})
  receiver = {:receiver_type => ReceiverType::IMEI,
              :receiver_value => imei}
  send_custom_message(send_no, msg_title, msg_content, receiver, opts)
end

#send_message_with_tag(send_no, tag, msg_title, msg_content, opts = {}) ⇒ Object

  • 发送标签带推送的自定义消息

    * @param [Integer] send_no
    * @param [String] tag
    * @param [String] msg_title
    * @param [String] msg_content
    * @param [Hash] opts opts


65
66
67
68
69
# File 'lib/jpush_api_ruby_client/client.rb', line 65

def send_message_with_tag(send_no, tag, msg_title, msg_content, opts = {})
  receiver = {:receiver_type => ReceiverType::TAG,
              :receiver_value => tag}
  send_custom_message(send_no, msg_title, msg_content, receiver, opts)
end

#send_notification_with_alias(send_no, alias_, msg_title, msg_content, opts = {}) ⇒ Object

  • 发送带别名推送的通知

    * @param [Integer] send_no
    * @param [String] alias_
    * @param [String] msg_title
    * @param [String] msg_content
    * @param [Hash] opts opts


139
140
141
142
143
# File 'lib/jpush_api_ruby_client/client.rb', line 139

def send_notification_with_alias(send_no, alias_, msg_title, msg_content, opts = {})
  receiver = {:receiver_type => ReceiverType::ALIAS,
              :receiver_value => alias_}
  send_notification(send_no, msg_title, msg_content, receiver, opts)
end

#send_notification_with_appkey(send_no, msg_title, msg_content, opts = {}) ⇒ Object

  • 发送使用 appkey 推送的通知

    * @param [Integer] send_no
    * @param [String] msg_title
    * @param [String] msg_content
    * @param [Hash] opts opts


109
110
111
112
113
# File 'lib/jpush_api_ruby_client/client.rb', line 109

def send_notification_with_appkey(send_no, msg_title, msg_content, opts = {})
  receiver = {:receiver_type => ReceiverType::BROADCAST,
              :receiver_value => ''}
  send_notification(send_no, msg_title, msg_content, receiver, opts)
end

#send_notification_with_imei(send_no, imei, msg_title, msg_content, opts = {}) ⇒ Object

  • 发送带IMEI号推送的通知

    * @param [Integer] send_no
    * @param [String] imei
    * @param [String] msg_title
    * @param [String] msg_content
    * @param [Hash] opts opts


154
155
156
157
158
# File 'lib/jpush_api_ruby_client/client.rb', line 154

def send_notification_with_imei(send_no, imei, msg_title, msg_content, opts = {})
  receiver = {:receiver_type => ReceiverType::IMEI,
              :receiver_value => imei}
  send_notification(send_no, msg_title, msg_content, receiver, opts)
end

#send_notification_with_tag(send_no, tag, msg_title, msg_content, opts = {}) ⇒ Object

  • 发送带标签推送的通知

    * @param [Integer] send_no
    * @param [String] tag
    * @param [String] msg_title
    * @param [String] msg_content
    * @param [Hash] opts opts


124
125
126
127
128
# File 'lib/jpush_api_ruby_client/client.rb', line 124

def send_notification_with_tag(send_no, tag, msg_title, msg_content, opts = {})
  receiver = {:receiver_type => ReceiverType::TAG,
              :receiver_value => tag}
  send_notification(send_no, msg_title, msg_content, receiver, opts)
end