Class: Xiaomipush::Service

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ios_secret: "", android_secret: "", bundle_id: "", package_name: "", connection_adapter: :net_http, sandbox: false) ⇒ Service

Returns a new instance of Service.



17
18
19
20
21
22
23
24
# File 'lib/xiaomipush.rb', line 17

def initialize(ios_secret: "", android_secret: "", bundle_id: "", package_name: "", connection_adapter: :net_http, sandbox: false)
  @sandbox = sandbox
  @ios_secret = ios_secret
  @bundle_id = bundle_id
  @android_secret = android_secret
  @package_name = package_name
  @connection_adapter = connection_adapter
end

Instance Attribute Details

#android_secretObject

Returns the value of attribute android_secret.



15
16
17
# File 'lib/xiaomipush.rb', line 15

def android_secret
  @android_secret
end

#bundle_idObject

Returns the value of attribute bundle_id.



15
16
17
# File 'lib/xiaomipush.rb', line 15

def bundle_id
  @bundle_id
end

#connection_adapterObject

Returns the value of attribute connection_adapter.



15
16
17
# File 'lib/xiaomipush.rb', line 15

def connection_adapter
  @connection_adapter
end

#ios_secretObject

Returns the value of attribute ios_secret.



15
16
17
# File 'lib/xiaomipush.rb', line 15

def ios_secret
  @ios_secret
end

#package_nameObject

Returns the value of attribute package_name.



15
16
17
# File 'lib/xiaomipush.rb', line 15

def package_name
  @package_name
end

#sandboxObject

Returns the value of attribute sandbox.



15
16
17
# File 'lib/xiaomipush.rb', line 15

def sandbox
  @sandbox
end

Class Method Details

.config {|service = new| ... } ⇒ Object

Yields:

  • (service = new)


26
27
28
# File 'lib/xiaomipush.rb', line 26

def self.config
  yield service = new; service
end

Instance Method Details

#build(build_type, message = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/xiaomipush.rb', line 30

def build(build_type, message={})
  case build_type
  when :ios
    build_message = { ios: ios_builder(message)}
  when :android
    build_message = { android: android_builder(message) }
  when :both
    build_message = { ios: ios_builder(message),  android: android_builder(message)}
  end
  return build_message
end

#push(push_type, message, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/xiaomipush.rb', line 42

def push(push_type, message, options={})
  case push_type
  when :alias
    return "must input alias" unless options[:alias]
    message.values.each{|v| v.merge!(alias: options[:alias])}
    resource_post('alias', message)
  when :regid
    return "must input regid" unless options[:regid]
    message.values.each{|v| v.merge!(regid: options[:regid])}
    resource_post('regid', message)
  when :topic
    return "must input topic" unless options[:topic]
    message.values.each{|v| v.merge!(topic: options[:topic])}
    resource_post('topic', message)
  when :topics
    return "must input topics" unless options[:topics]
    message.values.each{|v| v.merge!(topics: options[:topics].join(";$;"), topic_op: options[:topic_op] || "UNION")}
    resource_post('mtopic', message)
    # ws add
  when :user_account
    return "must input user_account" unless options[:user_account]
    message.values.each{|v| v.merge!(user_account: options[:user_account].class.to_s == 'Array' ? options[:user_account].join(',') : options[:user_account])}
    resource_post('user_account', message)
  when :all
    resource_post('all', message)
  end
end