urbanairship 3.0.1 → 3.0.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/lib/urbanairship/common.rb +21 -1
- data/lib/urbanairship/push/payload.rb +19 -18
- data/lib/urbanairship/push/push.rb +6 -6
- data/lib/urbanairship/version.rb +1 -1
- metadata +2 -4
- data/lib/ext/hash.rb +0 -5
- data/lib/ext/object.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f00fd9af99e731c4f1b2b1d05d9663b0ecf24f94
|
4
|
+
data.tar.gz: 50e049c31aa5c1f467982b6b72741b92e156a639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d80f09d4cb0a219645dad8c003e468bfd31ee2381f66b2903a9ac7736d5f1fa0bde038f8e42ce59af05ac2f7318ec0178cd8bbb6f29eb3e394d1a5bb4710eb6
|
7
|
+
data.tar.gz: 262f4082d982ba83d242ed0d0803d41b9384eb0a9bc8f52ae9bf51d47d6f6816c3ef3c2489de02e8b4a978fa9ba321b6b45a88741498a011eec5fd69501e5b6d
|
data/CHANGELOG
CHANGED
data/lib/urbanairship/common.rb
CHANGED
@@ -16,7 +16,7 @@ module Urbanairship
|
|
16
16
|
TAGS_URL = BASE_URL + '/tags/'
|
17
17
|
SEGMENTS_URL = BASE_URL + '/segments/'
|
18
18
|
|
19
|
-
# Helper method for required keyword args in 2.0 that is compatible with 2.1+
|
19
|
+
# Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+
|
20
20
|
# @example
|
21
21
|
# def say(greeting: required('greeting'))
|
22
22
|
# puts greeting
|
@@ -32,6 +32,26 @@ module Urbanairship
|
|
32
32
|
raise ArgumentError.new("required parameter #{arg.to_sym.inspect + ' ' if arg}not passed to method #{method}")
|
33
33
|
end
|
34
34
|
|
35
|
+
# Helper method that sends the indicated method to the indicated object, if the object responds to the method
|
36
|
+
# @example
|
37
|
+
# try_helper(:first, [1,2,3])
|
38
|
+
#
|
39
|
+
# >> 1
|
40
|
+
def try_helper(method, obj)
|
41
|
+
if obj.respond_to?(method)
|
42
|
+
obj.send(method)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Helper method that deletes every key-value pair from a hash for which the value is nil
|
47
|
+
# @example
|
48
|
+
# compact_helper({"a" => 1, "b" => nil})
|
49
|
+
#
|
50
|
+
# >> {"a" => 1}
|
51
|
+
def compact_helper(a_hash)
|
52
|
+
a_hash.keep_if {|_, value| !value.nil?}
|
53
|
+
end
|
54
|
+
|
35
55
|
class Unauthorized < StandardError
|
36
56
|
# raised when we get a 401 from server
|
37
57
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module Urbanairship
|
2
2
|
module Push
|
3
3
|
module Payload
|
4
|
-
require '
|
4
|
+
require 'urbanairship/common'
|
5
|
+
|
5
6
|
include Urbanairship::Common
|
6
7
|
|
7
8
|
# Notification Object for a Push Payload
|
8
9
|
def notification(alert: nil, ios: nil, android: nil, amazon: nil,
|
9
10
|
blackberry: nil, wns: nil, mpns: nil, actions: nil,
|
10
11
|
interactive: nil)
|
11
|
-
payload = {
|
12
|
+
payload = compact_helper({
|
12
13
|
alert: alert,
|
13
14
|
actions: actions,
|
14
15
|
ios: ios,
|
@@ -18,7 +19,7 @@ module Urbanairship
|
|
18
19
|
wns: wns,
|
19
20
|
mpns: mpns,
|
20
21
|
interactive: interactive
|
21
|
-
}
|
22
|
+
})
|
22
23
|
fail ArgumentError, 'Notification body is empty' if payload.empty?
|
23
24
|
payload
|
24
25
|
end
|
@@ -26,7 +27,7 @@ module Urbanairship
|
|
26
27
|
# iOS specific portion of Push Notification Object
|
27
28
|
def ios(alert: nil, badge: nil, sound: nil, extra: nil, expiry: nil,
|
28
29
|
category: nil, interactive: nil, content_available: nil)
|
29
|
-
{
|
30
|
+
compact_helper({
|
30
31
|
alert: alert,
|
31
32
|
badge: badge,
|
32
33
|
sound: sound,
|
@@ -35,13 +36,13 @@ module Urbanairship
|
|
35
36
|
category: category,
|
36
37
|
interactive: interactive,
|
37
38
|
'content-available' => content_available
|
38
|
-
}
|
39
|
+
})
|
39
40
|
end
|
40
41
|
|
41
42
|
# Amazon specific portion of Push Notification Object
|
42
43
|
def amazon(alert: nil, consolidation_key: nil, expires_after: nil,
|
43
44
|
extra: nil, title: nil, summary: nil, interactive: nil)
|
44
|
-
{
|
45
|
+
compact_helper({
|
45
46
|
alert: alert,
|
46
47
|
consolidation_key: consolidation_key,
|
47
48
|
expires_after: expires_after,
|
@@ -49,20 +50,20 @@ module Urbanairship
|
|
49
50
|
title: title,
|
50
51
|
summary: summary,
|
51
52
|
interactive: interactive
|
52
|
-
}
|
53
|
+
})
|
53
54
|
end
|
54
55
|
|
55
56
|
# Android specific portion of Push Notification Object
|
56
57
|
def android(alert: nil, collapse_key: nil, time_to_live: nil,
|
57
58
|
extra: nil, delay_while_idle: nil, interactive: nil)
|
58
|
-
{
|
59
|
+
compact_helper({
|
59
60
|
alert: alert,
|
60
61
|
collapse_key: collapse_key,
|
61
62
|
time_to_live: time_to_live,
|
62
63
|
extra: extra,
|
63
64
|
delay_while_idle: delay_while_idle,
|
64
65
|
interactive: interactive
|
65
|
-
}
|
66
|
+
})
|
66
67
|
end
|
67
68
|
|
68
69
|
# BlackBerry specific portion of Push Notification Object
|
@@ -72,23 +73,23 @@ module Urbanairship
|
|
72
73
|
|
73
74
|
# WNS specific portion of Push Notification Object
|
74
75
|
def wns_payload(alert: nil, toast: nil, tile: nil, badge: nil)
|
75
|
-
payload = {
|
76
|
+
payload = compact_helper({
|
76
77
|
alert: alert,
|
77
78
|
toast: toast,
|
78
79
|
tile: tile,
|
79
80
|
badge: badge
|
80
|
-
}
|
81
|
+
})
|
81
82
|
fail ArgumentError, 'Must specify one message type' if payload.size != 1
|
82
83
|
payload
|
83
84
|
end
|
84
85
|
|
85
86
|
# MPNS specific portion of Push Notification Object
|
86
87
|
def mpns_payload(alert: nil, toast: nil, tile: nil)
|
87
|
-
payload = {
|
88
|
+
payload = compact_helper({
|
88
89
|
alert: alert,
|
89
90
|
toast: toast,
|
90
91
|
tile: tile
|
91
|
-
}
|
92
|
+
})
|
92
93
|
fail ArgumentError, 'Must specify one message type' if payload.size != 1
|
93
94
|
payload
|
94
95
|
end
|
@@ -96,7 +97,7 @@ module Urbanairship
|
|
96
97
|
# Rich Message specific portion of Push Notification Object
|
97
98
|
def message(title: required('title'), body: required('body'), content_type: nil, content_encoding: nil,
|
98
99
|
extra: nil, expiry: nil, icons: nil, options: nil)
|
99
|
-
{
|
100
|
+
compact_helper({
|
100
101
|
title: title,
|
101
102
|
body: body,
|
102
103
|
content_type: content_type,
|
@@ -105,13 +106,13 @@ module Urbanairship
|
|
105
106
|
expiry: expiry,
|
106
107
|
icons: icons,
|
107
108
|
options: options
|
108
|
-
}
|
109
|
+
})
|
109
110
|
end
|
110
111
|
|
111
112
|
# Interactive Notification portion of Push Notification Object
|
112
113
|
def interactive(type: required('type'), button_actions: nil)
|
113
114
|
fail ArgumentError, 'type must not be nil' if type.nil?
|
114
|
-
{ type: type, button_actions: button_actions }
|
115
|
+
compact_helper({ type: type, button_actions: button_actions })
|
115
116
|
end
|
116
117
|
|
117
118
|
def all
|
@@ -131,13 +132,13 @@ module Urbanairship
|
|
131
132
|
# Actions for a Push Notification Object
|
132
133
|
def actions(add_tag: nil, remove_tag: nil, open_: nil, share: nil,
|
133
134
|
app_defined: nil)
|
134
|
-
{
|
135
|
+
compact_helper({
|
135
136
|
add_tag: add_tag,
|
136
137
|
remove_tag: remove_tag,
|
137
138
|
open: open_,
|
138
139
|
share: share,
|
139
140
|
app_defined: app_defined
|
140
|
-
}
|
141
|
+
})
|
141
142
|
end
|
142
143
|
end
|
143
144
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
-
require 'ext/object'
|
4
3
|
require 'urbanairship/common'
|
5
4
|
require 'urbanairship/loggable'
|
6
5
|
|
@@ -23,13 +22,13 @@ module Urbanairship
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def payload
|
26
|
-
{
|
25
|
+
compact_helper({
|
27
26
|
audience: @audience,
|
28
27
|
notification: @notification,
|
29
28
|
options: @options,
|
30
29
|
device_types: @device_types,
|
31
30
|
message: @message
|
32
|
-
}
|
31
|
+
})
|
33
32
|
end
|
34
33
|
|
35
34
|
# Send the Push Object
|
@@ -67,11 +66,11 @@ module Urbanairship
|
|
67
66
|
end
|
68
67
|
|
69
68
|
def payload
|
70
|
-
{
|
69
|
+
compact_helper({
|
71
70
|
name: @name,
|
72
71
|
schedule: @schedule,
|
73
72
|
push: @push.payload
|
74
|
-
}
|
73
|
+
})
|
75
74
|
end
|
76
75
|
|
77
76
|
# Schedule the Push Notification
|
@@ -165,12 +164,13 @@ module Urbanairship
|
|
165
164
|
# Response to a successful push notification send or schedule.
|
166
165
|
class PushResponse
|
167
166
|
attr_reader :ok, :push_ids, :schedule_url, :operation_id, :payload, :status_code
|
167
|
+
include Urbanairship::Common
|
168
168
|
|
169
169
|
def initialize(http_response_body: nil, http_response_code: nil)
|
170
170
|
@payload = http_response_body || "No Content"
|
171
171
|
@ok = @payload['ok'] || "None"
|
172
172
|
@push_ids = @payload['push_ids'] || "None"
|
173
|
-
@schedule_url = @payload['schedule_urls']
|
173
|
+
@schedule_url = try_helper(:first, @payload['schedule_urls']) || "None"
|
174
174
|
@operation_id = @payload['operation_id'] || "None"
|
175
175
|
@status_code = http_response_code
|
176
176
|
end
|
data/lib/urbanairship/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: urbanairship
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Urban Airship
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unirest
|
@@ -133,8 +133,6 @@ files:
|
|
133
133
|
- Rakefile
|
134
134
|
- bin/console
|
135
135
|
- bin/setup
|
136
|
-
- lib/ext/hash.rb
|
137
|
-
- lib/ext/object.rb
|
138
136
|
- lib/urbanairship.rb
|
139
137
|
- lib/urbanairship/client.rb
|
140
138
|
- lib/urbanairship/common.rb
|
data/lib/ext/hash.rb
DELETED