five_mobile_push 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.yardopts +1 -0
- data/five_mobile_push.gemspec +4 -3
- data/lib/five_mobile_push/notifier.rb +91 -19
- data/lib/five_mobile_push/payload.rb +2 -0
- data/lib/five_mobile_push/version.rb +1 -1
- metadata +13 -1
data/.gitignore
CHANGED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private lib/**/*.rb
|
data/five_mobile_push.gemspec
CHANGED
@@ -19,10 +19,11 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency "multi_json",
|
23
|
-
s.add_dependency "faraday",
|
24
|
-
s.add_development_dependency "rspec",
|
22
|
+
s.add_dependency "multi_json", ["~> 0.0.5"]
|
23
|
+
s.add_dependency "faraday", ["~> 0.5.7"]
|
24
|
+
s.add_development_dependency "rspec", ["~> 2.5.0"]
|
25
25
|
s.add_development_dependency "yajl-ruby"
|
26
26
|
s.add_development_dependency "webmock"
|
27
27
|
s.add_development_dependency "fabrication", ["~> 0.9.5"]
|
28
|
+
s.add_development_dependency "yard", ["~> 0.6.5"]
|
28
29
|
end
|
@@ -1,34 +1,120 @@
|
|
1
1
|
module FiveMobilePush
|
2
|
+
# @todo Validate provided platforms
|
3
|
+
# @todo Simplify platform selection
|
2
4
|
class Notifier
|
3
5
|
|
6
|
+
# The following are platforms supported by the Five Mobile Push platform
|
7
|
+
|
8
|
+
ALL = "all"
|
9
|
+
IPHONE = "iphone"
|
10
|
+
BLACKBERRY = "blackberry"
|
11
|
+
ANDROID = "android"
|
12
|
+
|
13
|
+
# @param [FiveMobilePush::Client] client The Client object to use when
|
14
|
+
# sending notices
|
4
15
|
def initialize(client)
|
5
16
|
@client = client
|
6
17
|
end
|
7
18
|
|
19
|
+
# Broadcast a notification to one or more platforms of an application.
|
20
|
+
#
|
21
|
+
# == Supported Platforms
|
22
|
+
#
|
23
|
+
# * all
|
24
|
+
# * iphone
|
25
|
+
# * blackberry
|
26
|
+
# * android
|
27
|
+
#
|
28
|
+
# @param [Array<String>, String] platforms Any of the supported platforms.
|
29
|
+
#
|
30
|
+
# @yield [message] Provides a mini-DSL for constructing the message to
|
31
|
+
# broadcast.
|
32
|
+
#
|
33
|
+
# @yieldparam [Message] message (see Message)
|
34
|
+
#
|
35
|
+
# @example Simple usage
|
36
|
+
# n = FiveMobilePush::Notifier.new(client)
|
37
|
+
# n.broadcast(FiveMobilePush::Notifier::ALL) do |message|
|
38
|
+
# message.body "Downtime this weekend"
|
39
|
+
# end
|
8
40
|
def broadcast(platforms, &block)
|
9
41
|
@client.post 'notify/broadcast',
|
10
42
|
:platforms => build_platforms_string(platforms),
|
11
|
-
:payload =>
|
43
|
+
:payload => capture_message(&block).to_json
|
12
44
|
end
|
13
45
|
|
46
|
+
# Send a notification to any number of specified devices
|
47
|
+
#
|
48
|
+
# @param [Array<String>] devices A list of device ID values
|
49
|
+
#
|
50
|
+
# @yield [message] Provides a mini-DSL for constructing the message to
|
51
|
+
# broadcast.
|
52
|
+
#
|
53
|
+
# @yieldparam [Message] message (see Message)
|
54
|
+
#
|
55
|
+
# @example Simple usage
|
56
|
+
# n = FiveMobilePush::Notifier.new(client)
|
57
|
+
# n.notify_devices(['1234']) do |message|
|
58
|
+
# message.body "Downtime this weekend"
|
59
|
+
# end
|
14
60
|
def notify_devices(devices, &block)
|
15
61
|
@client.post 'notify/toDevices',
|
16
62
|
:id_type => FiveMobilePush::DEFAULT_ID_TYPE,
|
17
63
|
:id_values => devices.join(','),
|
18
|
-
:payload =>
|
64
|
+
:payload => capture_message(&block).to_json
|
19
65
|
end
|
20
66
|
|
67
|
+
# Notifies any device registered with the provided tags.
|
68
|
+
#
|
69
|
+
# == Supported Platforms
|
70
|
+
#
|
71
|
+
# * all
|
72
|
+
# * iphone
|
73
|
+
# * blackberry
|
74
|
+
# * android
|
75
|
+
#
|
76
|
+
# @param [Array<String>, String] platforms Any of the supported platforms.
|
77
|
+
# @param [Array<String>] tags Any tag that is registered
|
78
|
+
#
|
79
|
+
# @yield [message] Provides a mini-DSL for constructing the message to
|
80
|
+
# broadcast.
|
81
|
+
#
|
82
|
+
# @yieldparam [Message] message (see Message)
|
83
|
+
#
|
84
|
+
# @example Simple usage
|
85
|
+
# n = FiveMobilePush::Notifier.new(client)
|
86
|
+
# n.notify_by_tags(FiveMobilePush::Notifier::ALL, ['muffin', 'bacon']) do |message|
|
87
|
+
# message.body "Downtime this weekend"
|
88
|
+
# end
|
21
89
|
def notify_by_tags(platforms, tags, &block)
|
22
90
|
@client.post 'notify/toTags',
|
23
91
|
:platforms => build_platforms_string(platforms),
|
24
92
|
:tags => tags.join(','),
|
25
|
-
:payload =>
|
93
|
+
:payload => capture_message(&block).to_json
|
94
|
+
end
|
95
|
+
|
96
|
+
# Simple proxy class for building messages. Do not use this class directly.
|
97
|
+
class Message
|
98
|
+
# @param [String] body The text to send
|
99
|
+
def body(body)
|
100
|
+
@body = body
|
101
|
+
end
|
102
|
+
|
103
|
+
# @param [Hash] meta_data (optional) The optional meta data to send.
|
104
|
+
def meta_data(meta_data)
|
105
|
+
@meta_data = meta_data
|
106
|
+
end
|
107
|
+
|
108
|
+
# @private
|
109
|
+
def to_payload
|
110
|
+
FiveMobilePush::Payload.new(@message, @meta_data)
|
111
|
+
end
|
26
112
|
end
|
27
113
|
|
28
114
|
private
|
29
115
|
|
30
|
-
def
|
31
|
-
payload_proxy =
|
116
|
+
def capture_message(&block)
|
117
|
+
payload_proxy = Message.new
|
32
118
|
block.call(payload_proxy)
|
33
119
|
payload_proxy.to_payload
|
34
120
|
end
|
@@ -41,19 +127,5 @@ module FiveMobilePush
|
|
41
127
|
end
|
42
128
|
end
|
43
129
|
|
44
|
-
class PayloadProxy
|
45
|
-
def message(message)
|
46
|
-
@message = message
|
47
|
-
end
|
48
|
-
|
49
|
-
def meta_data(meta_data)
|
50
|
-
@meta_data = meta_data
|
51
|
-
end
|
52
|
-
|
53
|
-
def to_payload
|
54
|
-
FiveMobilePush::Payload.new(@message, @meta_data)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
130
|
end
|
59
131
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: five_mobile_push
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kevin Faustino
|
@@ -80,6 +80,17 @@ dependencies:
|
|
80
80
|
version: 0.9.5
|
81
81
|
type: :development
|
82
82
|
version_requirements: *id006
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
prerelease: false
|
86
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 0.6.5
|
92
|
+
type: :development
|
93
|
+
version_requirements: *id007
|
83
94
|
description: API wrapper for Five Mobile Push notification service
|
84
95
|
email:
|
85
96
|
- kevin.faustino@gmail.com
|
@@ -93,6 +104,7 @@ extra_rdoc_files: []
|
|
93
104
|
files:
|
94
105
|
- .gitignore
|
95
106
|
- .rspec
|
107
|
+
- .yardopts
|
96
108
|
- Gemfile
|
97
109
|
- Rakefile
|
98
110
|
- five_mobile_push.gemspec
|