gcm-client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/lib/apns.rb +9 -0
- data/lib/gcm/client.rb +41 -0
- data/lib/gcm/notification.rb +7 -0
- data/lib/gcm/notification_response.rb +20 -0
- data/lib/gcm/response.rb +29 -0
- data/lib/gcm/version.rb +3 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dea6487a57fd6198d663a9a27518c6643e76fc70
|
4
|
+
data.tar.gz: 2c7372fc85ff81e8c0d009c23a09e86269951cc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b218a670f462312b04a6a7fd88275e6c71b56187388ce26079d6d99de5d65e5d1ad280f471e7f63ec3d7bbfa10f92b1e56810725fb55763fa0523b4f760a44b2
|
7
|
+
data.tar.gz: 07986df76ee4b7cd98fb5ba1cf6930a651dfe811a9cdadb0b6d3989d4c3af6c2682ecf6a9d58f439955ecf806d4860996256b970ffe3056142f89e5df4d7db6e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Niftyware Limited.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/apns.rb
ADDED
data/lib/gcm/client.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module GCM
|
6
|
+
class Client
|
7
|
+
|
8
|
+
attr_reader :uri, :auth_token
|
9
|
+
|
10
|
+
def initialize(uri, auth_key)
|
11
|
+
@uri = URI.parse(uri)
|
12
|
+
@auth_key = auth_key
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Send a notification to a device
|
17
|
+
#
|
18
|
+
def notify(device, notification)
|
19
|
+
response = make_request(:notify, {:device => device, :data => notification.data})
|
20
|
+
NotificationResponse.new(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
#
|
26
|
+
# Make an HTTP request
|
27
|
+
def make_request(method, payload = {})
|
28
|
+
request = Net::HTTP::Post.new("/api/#{method}")
|
29
|
+
request.body = payload.merge({:auth_key => @auth_key}).to_json
|
30
|
+
request.add_field 'User-Agent', "GCM Ruby Client Library/#{GCM::VERSION}"
|
31
|
+
connection = Net::HTTP.new(@uri.host, @uri.port)
|
32
|
+
if @uri.is_a?(URI::HTTPS)
|
33
|
+
connection.use_ssl = true
|
34
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
35
|
+
end
|
36
|
+
result = connection.request(request)
|
37
|
+
Response.new(result)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GCM
|
2
|
+
class NotificationResponse
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
end
|
7
|
+
|
8
|
+
def success?
|
9
|
+
@response.success?
|
10
|
+
end
|
11
|
+
|
12
|
+
def device_unsubscribed?
|
13
|
+
@response.validation_error? &&
|
14
|
+
@response.body['errors'] &&
|
15
|
+
@response.body['errors']['device'] &&
|
16
|
+
@response.body['errors']['device'].include?('unsubscribed')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/gcm/response.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module GCM
|
2
|
+
class Response
|
3
|
+
|
4
|
+
def initialize(result)
|
5
|
+
@result = result
|
6
|
+
end
|
7
|
+
|
8
|
+
def status_code
|
9
|
+
@result.code.to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def success?
|
13
|
+
status_code >= 200 && status_code <= 299
|
14
|
+
end
|
15
|
+
|
16
|
+
def validation_error?
|
17
|
+
status_code == 422
|
18
|
+
end
|
19
|
+
|
20
|
+
def body
|
21
|
+
if success? || validation_error?
|
22
|
+
@body ||= JSON.parse(@result.body)
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/gcm/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gcm-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charlie Smurthwaite
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby client library for communicating with the GCM Proxy server.
|
14
|
+
email:
|
15
|
+
- charlie@atechmedia.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- MIT-LICENSE
|
21
|
+
- lib/apns.rb
|
22
|
+
- lib/gcm/client.rb
|
23
|
+
- lib/gcm/notification.rb
|
24
|
+
- lib/gcm/notification_response.rb
|
25
|
+
- lib/gcm/response.rb
|
26
|
+
- lib/gcm/version.rb
|
27
|
+
homepage: http://atechmedia.com
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.2.2
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: A Ruby client for GCM Proxy.
|
51
|
+
test_files: []
|