Module: Xiaomi::Push::Const

Included in:
Client
Defined in:
lib/xiaomi/push/const.rb

Constant Summary collapse

DEVICES =

支持设备

%w(ANDROID IOS).freeze
PRODUCTION_URL =

产品环境

'https://api.xmpush.xiaomi.com'.freeze
SANDBOX_URL =

沙盒环境(仅支持 iOS)

'https://sandbox.xmpush.xiaomi.com'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



13
14
15
# File 'lib/xiaomi/push/const.rb', line 13

def base_url
  @base_url
end

Instance Method Details

#build_uri(uri) ⇒ Object

:nodoc:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/xiaomi/push/const.rb', line 36

def build_uri(uri)
  version =
    if uri.start_with?('stats', 'trace', 'alias', 'reg_id') || uri == 'topic/all'
      # 获取消息的统计数据/追踪消息状态/某个用户目前设置的所有 Alias 和订阅的所有 Topic
      'v1'
    elsif uri.start_with?('message')
      # 发送消息支持多包使用 v3 版本
      'v3'
    else
      'v2'
    end

  File.join(@base_url, version, uri)
end

#productionObject

:nodoc:



26
27
28
# File 'lib/xiaomi/push/const.rb', line 26

def production
  @base_url ||= PRODUCTION_URL
end

#sandboxObject

:nodoc:



31
32
33
# File 'lib/xiaomi/push/const.rb', line 31

def sandbox
  @base_url ||= SANDBOX_URL
end

#use_production!Object

切换产品环境



16
17
18
# File 'lib/xiaomi/push/const.rb', line 16

def use_production!
  production
end

#use_sandbox!Object

切换沙盒环境



21
22
23
# File 'lib/xiaomi/push/const.rb', line 21

def use_sandbox!
  sandbox
end