pushmeup 0.2.0 → 0.3.0
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 +8 -8
- data/.gitignore +1 -0
- data/README.md +59 -1
- data/lib/pushmeup.rb +1 -0
- data/lib/pushmeup/amazon.rb +2 -0
- data/lib/pushmeup/fire/core.rb +103 -0
- data/lib/pushmeup/fire/notification.rb +46 -0
- data/lib/pushmeup/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWVmYjczNGEwYjE4ZTkzNGFhOWJlYjE5NDFhNDg2OTk1YjMyYjJhYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGYyNzFkMzdlZTY1MTM3NWVlMjE0YTEwYThmZWU4ZTE0NTg2ZTllNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2FiNjA1MWQ2YzRiNGI5OGYzNjBlODFjM2NiYzUwY2E3ZjQwYmVlYzZiYWJj
|
10
|
+
YTI0MTU0ODU0ZWU4ODBkN2U5YmY0OWU4MmIxNDU0ZjNhNjEzMmMwMzE0ZDdk
|
11
|
+
MjA4ZmE4ZWZkODc0NmI3N2M5MTIwNmVlNDM1Y2EwZDQ2ZjYwMzc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTM1YjA1NzhjZWNhMmQzMjAwNmVkM2VjZmQ5MjY1YjA0MGY4MDg5YmE1NjZi
|
14
|
+
MDk0Yzk2NTAyZTI3M2U0NTk5NmI4ZDExMzAzOTAwNmEzOGNmNTE4N2QyOTE5
|
15
|
+
NTY0ZWFkMTdlZjc0ZDVhMDUyMDg0MDYyMTExYTE2NDk5NTk5MDE=
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Pushmeup is an attempt to create an push notifications center that could send pu
|
|
12
12
|
- Windows Phone
|
13
13
|
- And many others
|
14
14
|
|
15
|
-
Currently we have only support for ``iOS`` and ``
|
15
|
+
Currently we have only support for ``iOS``, ``Android`` and ``Kindle Fire`` but we are planning code for more plataforms.
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
@@ -210,6 +210,64 @@ You can use multiple keys to send notifications, to do it just do this changes i
|
|
210
210
|
GCM.send_notifications( [n1, n2, n3] )
|
211
211
|
# In this case, every notification has his own parameters, options and key
|
212
212
|
|
213
|
+
## FIRE (Amazon Messaging)
|
214
|
+
|
215
|
+
### Configure
|
216
|
+
|
217
|
+
FIRE.client_id = "amzn1.application-oa2-client.12345678sdfgsdfg"
|
218
|
+
# this is the Client ID obtained from your Security Profile Management on amazon developers
|
219
|
+
|
220
|
+
FIRE.client_secret = "fkgjsbegksklwr863485245ojowe345"
|
221
|
+
# this is the Client Secret obtained from your Security Profile Management on amazon developers
|
222
|
+
|
223
|
+
### Usage
|
224
|
+
|
225
|
+
#### Sending a single notification:
|
226
|
+
|
227
|
+
destination = "tydgfhewgnwe37586329586ejthe93053th346hrth3t"
|
228
|
+
# can be an string or an array of strings containing the regId of the device you want to send
|
229
|
+
|
230
|
+
data = {:key => "value", :key2 => "some value2"}
|
231
|
+
# must be an hash with all values you want inside you notification, strings only, no arrays
|
232
|
+
|
233
|
+
FIRE.send_notification( destination )
|
234
|
+
# Empty notification
|
235
|
+
|
236
|
+
FIRE.send_notification( destination, data )
|
237
|
+
# Notification with custom information
|
238
|
+
|
239
|
+
FIRE.send_notification( destination, data, :consolidationKey => "placar_score_global", :expiresAfter => 3600)
|
240
|
+
# Notification with custom information and parameters
|
241
|
+
|
242
|
+
for more information on parameters check documentation: [Amazon Messaging | Developers](https://developer.amazon.com/public/apis/engage/device-messaging/tech-docs/06-sending-a-message#Request Format)
|
243
|
+
|
244
|
+
#### Sending multiple notifications:
|
245
|
+
|
246
|
+
destination1 = "device1"
|
247
|
+
destination2 = ["device2"]
|
248
|
+
destination3 = ["device1", "device2", "device3"]
|
249
|
+
# can be an string or an array of strings containing the regIds of the devices you want to send
|
250
|
+
|
251
|
+
data1 = {:key => "value", :key2 => ["array", "value"]}
|
252
|
+
# must be an hash with all values you want inside you notification
|
253
|
+
|
254
|
+
options1 = {:consolidationKey => "placar_score_global", :expiresAfter => 3600}
|
255
|
+
# options for the notification
|
256
|
+
|
257
|
+
n1 = FIRE::Notification.new(destination1, data1, options1)
|
258
|
+
n2 = FIRE::Notification.new(destination2, data2)
|
259
|
+
n3 = FIRE::Notification.new(destination3, data3, options2)
|
260
|
+
|
261
|
+
FIRE.send_notifications( [n1, n2, n3] )
|
262
|
+
# In this case, every notification has his own parameters
|
263
|
+
|
264
|
+
for more information on parameters check documentation: [Amazon Messaging | Developers](https://developer.amazon.com/public/apis/engage/device-messaging/tech-docs/06-sending-a-message#Request Format)
|
265
|
+
|
266
|
+
#### Getting your Kindle Fire device token (regId)
|
267
|
+
|
268
|
+
Check this link [Amazon Messaging: Getting Started](https://developer.amazon.com/public/apis/engage/device-messaging)
|
269
|
+
|
270
|
+
|
213
271
|
## Status
|
214
272
|
|
215
273
|
#### Build Status
|
data/lib/pushmeup.rb
CHANGED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
# require 'cgi'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module FIRE
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
@host = 'https://api.amazon.com/messaging/registrations/%s/messages'
|
9
|
+
@client_id = nil
|
10
|
+
@client_secret = nil
|
11
|
+
|
12
|
+
@access_token_expiration = Time.new(0)
|
13
|
+
@access_token = nil
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :host, :client_id, :client_secret, :access_token, :access_token_expiration
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.send_notification(device_token, data = {}, options = {})
|
20
|
+
n = FIRE::Notification.new(device_token, data, options)
|
21
|
+
self.send_notifications([n])
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.send_notifications(notifications)
|
25
|
+
self.prepare_token
|
26
|
+
responses = []
|
27
|
+
notifications.each do |n|
|
28
|
+
responses << self.prepare_and_send(n)
|
29
|
+
end
|
30
|
+
responses
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.prepare_token
|
34
|
+
return if Time.now < self.access_token_expiration
|
35
|
+
|
36
|
+
token = self.get_access_token
|
37
|
+
self.access_token = token['access_token']
|
38
|
+
expires_in_sec = token['expires_in']
|
39
|
+
self.access_token_expiration = Time.now + expires_in_sec - 60
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_access_token
|
43
|
+
headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
|
44
|
+
body = {grant_type: 'client_credentials',
|
45
|
+
scope: 'messaging:push',
|
46
|
+
client_id: self.client_id,
|
47
|
+
client_secret: self.client_secret
|
48
|
+
}
|
49
|
+
params = {headers: headers, body: body}
|
50
|
+
res = self.post('https://api.amazon.com/auth/O2/token', params)
|
51
|
+
return res.parsed_response if res.response.code.to_i == 200
|
52
|
+
raise 'Error getting access token'
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def self.prepare_and_send(n)
|
58
|
+
if !n.consolidationKey.nil? && n.expiresAfter.nil?
|
59
|
+
raise %q{If you are defining a "colapse key" you need a "time to live"}
|
60
|
+
end
|
61
|
+
self.send_push(n)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.send_push(n)
|
65
|
+
headers = {
|
66
|
+
'Authorization' => "Bearer #{self.access_token}",
|
67
|
+
'Content-Type' => 'application/json',
|
68
|
+
'Accept' => 'application/json',
|
69
|
+
'X-Amzn-Accept-Type' => 'com.amazon.device.messaging.ADMSendResult@1.0',
|
70
|
+
'X-Amzn-Type-Version' => 'com.amazon.device.messaging.ADMMessage@1.0'
|
71
|
+
}
|
72
|
+
|
73
|
+
body = {
|
74
|
+
:data => n.data
|
75
|
+
}
|
76
|
+
body.merge!({consolidationKey: n.consolidationKey}) if n.consolidationKey
|
77
|
+
body.merge!({expiresAfter: n.expiresAfter}) if n.expiresAfter
|
78
|
+
return self.send_to_server(headers, body.to_json, n.device_token)
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.send_to_server(headers, body, token)
|
82
|
+
params = {:headers => headers, :body => body}
|
83
|
+
device_dest = self.host % [token]
|
84
|
+
response = self.post(device_dest, params)
|
85
|
+
return build_response(response)
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.build_response(response)
|
89
|
+
case response.code
|
90
|
+
when 200
|
91
|
+
{:response => 'success', :body => JSON.parse(response.body), :headers => response.headers, :status_code => response.code}
|
92
|
+
when 400
|
93
|
+
{:response => response.parsed_response, :status_code => response.code}
|
94
|
+
when 401
|
95
|
+
{:response => 'There was an error authenticating the sender account.', :status_code => response.code}
|
96
|
+
when 500
|
97
|
+
{:response => 'There was an internal error in the Amazaon server while trying to process the request.', :status_code => response.code}
|
98
|
+
when 503
|
99
|
+
{:response => 'Server is temporarily unavailable.', :status_code => response.code}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module FIRE
|
2
|
+
class Notification
|
3
|
+
attr_accessor :device_token, :data, :consolidationKey, :expiresAfter
|
4
|
+
|
5
|
+
def initialize(token, data, options = {})
|
6
|
+
self.device_token = token
|
7
|
+
self.data = data
|
8
|
+
|
9
|
+
@consolidationKey = options[:consolidationKey]
|
10
|
+
@expiresAfter = options[:expiresAfter]
|
11
|
+
end
|
12
|
+
|
13
|
+
def device_token=(token)
|
14
|
+
|
15
|
+
if token.is_a?(String)
|
16
|
+
@device_token = token
|
17
|
+
else
|
18
|
+
raise "device_token needs to be String"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def data=(data)
|
23
|
+
if data.is_a?(Hash)
|
24
|
+
@data = data
|
25
|
+
else
|
26
|
+
raise "data parameter must be the type of Hash"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def expiresAfter=(expiresAfter)
|
31
|
+
if expiresAfter.is_a?(Integer)
|
32
|
+
@expiresAfter = expiresAfter
|
33
|
+
else
|
34
|
+
raise %q{"expiresAfter" must be seconds as an integer value, like "100"}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def ==(that)
|
39
|
+
device_token == that.device_token &&
|
40
|
+
data == that.data &&
|
41
|
+
consolidationKey == that.consolidationKey &&
|
42
|
+
expiresAfter == that.expiresAfter
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/pushmeup/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushmeup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicos Karalis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -88,10 +88,13 @@ files:
|
|
88
88
|
- README.md
|
89
89
|
- Rakefile
|
90
90
|
- lib/pushmeup.rb
|
91
|
+
- lib/pushmeup/amazon.rb
|
91
92
|
- lib/pushmeup/android.rb
|
92
93
|
- lib/pushmeup/apns/core.rb
|
93
94
|
- lib/pushmeup/apns/notification.rb
|
94
95
|
- lib/pushmeup/apple.rb
|
96
|
+
- lib/pushmeup/fire/core.rb
|
97
|
+
- lib/pushmeup/fire/notification.rb
|
95
98
|
- lib/pushmeup/gcm/core.rb
|
96
99
|
- lib/pushmeup/gcm/notification.rb
|
97
100
|
- lib/pushmeup/version.rb
|