Class: Xmpush::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/xmpush.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.



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

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.



16
17
18
# File 'lib/xmpush.rb', line 16

def android_secret
  @android_secret
end

#bundle_idObject

Returns the value of attribute bundle_id.



16
17
18
# File 'lib/xmpush.rb', line 16

def bundle_id
  @bundle_id
end

#connection_adapterObject

Returns the value of attribute connection_adapter.



16
17
18
# File 'lib/xmpush.rb', line 16

def connection_adapter
  @connection_adapter
end

#ios_secretObject

Returns the value of attribute ios_secret.



16
17
18
# File 'lib/xmpush.rb', line 16

def ios_secret
  @ios_secret
end

#package_nameObject

Returns the value of attribute package_name.



16
17
18
# File 'lib/xmpush.rb', line 16

def package_name
  @package_name
end

#sandboxObject

Returns the value of attribute sandbox.



16
17
18
# File 'lib/xmpush.rb', line 16

def sandbox
  @sandbox
end

Class Method Details

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

Yields:

  • (service = new)


27
28
29
# File 'lib/xmpush.rb', line 27

def self.config
  yield service = new; service
end

Instance Method Details

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



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

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



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

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)
  when :all
    resource_post('all', message)
  end
end