apns-client 1.0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/lib/apns.rb +9 -0
- data/lib/apns/client.rb +49 -0
- data/lib/apns/notification.rb +27 -0
- data/lib/apns/notification_response.rb +20 -0
- data/lib/apns/response.rb +29 -0
- data/lib/apns/version.rb +3 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f3b629260dea383e917940278ecf4b2cfb29394f
|
4
|
+
data.tar.gz: 1eff380758f161554f8aeaf275b5d9a58e289bd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9939073cf64cd5cbf9fff6a1c7a51ad3e807121849d513e1fb0574becf8adb09efbf99488f017c45015831e4505ca76e8f946e1e77546461a461a4c8460d8f89
|
7
|
+
data.tar.gz: 0cc5d759aaf8694fd43bebe94e46aaf6f99fd4dd3ed0fc1b42240575853e459a331b0699aa0986974ae9e4ceb837adb49696fe1e05f943ed98154157d715dace
|
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/apns/client.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module APNS
|
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, :notification => notification.to_hash})
|
20
|
+
NotificationResponse.new(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Register a device
|
25
|
+
#
|
26
|
+
def register(device)
|
27
|
+
response = make_request(:register, {:device => device})
|
28
|
+
response.success?
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
#
|
34
|
+
# Make an HTTP request
|
35
|
+
def make_request(method, payload = {})
|
36
|
+
request = Net::HTTP::Post.new("/api/#{method}")
|
37
|
+
request.body = payload.merge({:auth_key => @auth_key}).to_json
|
38
|
+
request.add_field 'User-Agent', "APNS Ruby Client Library/#{APNS::VERSION}"
|
39
|
+
connection = Net::HTTP.new(@uri.host, @uri.port)
|
40
|
+
if @uri.is_a?(URI::HTTPS)
|
41
|
+
connection.use_ssl = true
|
42
|
+
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
end
|
44
|
+
result = connection.request(request)
|
45
|
+
Response.new(result)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module APNS
|
2
|
+
class Notification
|
3
|
+
|
4
|
+
attr_accessor :alert_body, :action_loc_key, :loc_key, :loc_args, :launch_image
|
5
|
+
attr_accessor :badge
|
6
|
+
attr_accessor :sound
|
7
|
+
attr_accessor :content_available
|
8
|
+
attr_accessor :custom_data
|
9
|
+
|
10
|
+
def to_hash
|
11
|
+
{
|
12
|
+
:alert => {
|
13
|
+
:body => self.alert_body,
|
14
|
+
:action_loc_key => self.action_loc_key,
|
15
|
+
:loc_key => self.loc_key,
|
16
|
+
:loc_args => self.loc_args,
|
17
|
+
:launch_image => self.launch_image
|
18
|
+
},
|
19
|
+
:badge => self.badge,
|
20
|
+
:sound => self.sound,
|
21
|
+
:content_available => self.content_available,
|
22
|
+
:custom_data => self.custom_data
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module APNS
|
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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module APNS
|
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/apns/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apns-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Cooke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby client library for communicating with the APNS Proxy server.
|
14
|
+
email:
|
15
|
+
- me@adamcooke.io
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- MIT-LICENSE
|
21
|
+
- lib/apns.rb
|
22
|
+
- lib/apns/client.rb
|
23
|
+
- lib/apns/notification.rb
|
24
|
+
- lib/apns/notification_response.rb
|
25
|
+
- lib/apns/response.rb
|
26
|
+
- lib/apns/version.rb
|
27
|
+
homepage: http://adamcooke.io
|
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.0
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: A Ruby client for APNS Proxy.
|
51
|
+
test_files: []
|
52
|
+
has_rdoc:
|