Class: Xiaomi::Push::Client
- Inherits:
-
Object
- Object
- Xiaomi::Push::Client
- Includes:
- Const
- Defined in:
- lib/xiaomi/push/client.rb
Overview
小米推送内置客户端
实际情况并不会直接被使用,而是使用 iOS 或 Android 的实例化
Constant Summary
Constants included from Const
Xiaomi::Push::Const::DEVICES, Xiaomi::Push::Const::PRODUCTION_URL, Xiaomi::Push::Const::SANDBOX_URL
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
Attributes included from Const
Instance Method Summary collapse
-
#feedback ⇒ Object
Feedback.
-
#get(url, params = nil) ⇒ Hash
以 GET 方式的网络请求.
-
#initialize(secret, env = :production) ⇒ Client
constructor
实例化一个新的客户端.
-
#message ⇒ Object
单条消息.
-
#messages ⇒ Object
多条消息.
-
#post(url, params = nil) ⇒ Hash
以 POST 方式的网络请求.
-
#topic ⇒ Object
标签.
-
#user ⇒ Object
用户查询.
Methods included from Const
#build_uri, #production, #sandbox, #use_production!, #use_sandbox!
Constructor Details
#initialize(secret, env = :production) ⇒ Client
实例化一个新的客户端
30 31 32 33 34 35 36 37 |
# File 'lib/xiaomi/push/client.rb', line 30 def initialize(secret, env = :production) @device = self.class.name.split('::')[-1].upcase @client = HTTP.headers(authorization: "key=#{secret}") determine_platform!(env) env == :production ? use_production! : use_sandbox! end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
19 20 21 |
# File 'lib/xiaomi/push/client.rb', line 19 def client @client end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
19 20 21 |
# File 'lib/xiaomi/push/client.rb', line 19 def device @device end |
Instance Method Details
#feedback ⇒ Object
Feedback
60 61 62 |
# File 'lib/xiaomi/push/client.rb', line 60 def feedback @feedback ||= Services::Feedback.new(self) end |
#get(url, params = nil) ⇒ Hash
以 GET 方式的网络请求
69 70 71 72 |
# File 'lib/xiaomi/push/client.rb', line 69 def get(url, params = nil) r = @client.get(url, params: params) data = JSON.parse(r) end |
#message ⇒ Object
单条消息
40 41 42 |
# File 'lib/xiaomi/push/client.rb', line 40 def @message ||= Services::Message.new(self) end |
#messages ⇒ Object
多条消息
45 46 47 |
# File 'lib/xiaomi/push/client.rb', line 45 def @messages ||= Services::Messages.new(self) end |
#post(url, params = nil) ⇒ Hash
以 POST 方式的网络请求
79 80 81 82 |
# File 'lib/xiaomi/push/client.rb', line 79 def post(url, params = nil) r = @client.post(url, form: params) data = JSON.parse(r) end |