pushlayer 0.9.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.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ rdoc/
5
+ .DS_Store
6
+ .yardoc/
7
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --no-private
2
+
3
+ lib/**/*.rb
4
+ -
5
+ README.md
6
+ MIT-LICENSE
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pushlayer (0.9.0)
5
+ multi_json (~> 1.5.0)
6
+ rest-client (~> 1.6.7)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ addressable (2.3.2)
12
+ crack (0.3.1)
13
+ diff-lcs (1.1.3)
14
+ mime-types (1.19)
15
+ multi_json (1.5.0)
16
+ redcarpet (2.2.2)
17
+ rest-client (1.6.7)
18
+ mime-types (>= 1.16)
19
+ rspec (2.11.0)
20
+ rspec-core (~> 2.11.0)
21
+ rspec-expectations (~> 2.11.0)
22
+ rspec-mocks (~> 2.11.0)
23
+ rspec-core (2.11.1)
24
+ rspec-expectations (2.11.3)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.11.3)
27
+ webmock (1.9.0)
28
+ addressable (>= 2.2.7)
29
+ crack (>= 0.1.7)
30
+ yard (0.8.3)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ pushlayer!
37
+ redcarpet (~> 2.2.2)
38
+ rspec (~> 2.0)
39
+ webmock (~> 1.9.0)
40
+ yard (~> 0.8.3)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Draconis Software, LLC
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/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Pushlayer
2
+
3
+ Send iOS push notifications using the [PushLayer.com](https://www.pushlayer.com) service.
4
+
5
+ ## Installation
6
+
7
+ Add `pushlayer` to your Gemfile:
8
+
9
+ ```ruby
10
+ gem pushlayer
11
+ ```
12
+
13
+ Be sure to run `bundle install` afterwards.
14
+
15
+ Alernatively, you can install it locally:
16
+
17
+ ```shell
18
+ gem install pushlayer
19
+ ```
20
+
21
+ ## Requirements
22
+
23
+ PushLayer depends on ruby 1.9+, `rest-client`, and `multi_json`.
24
+
25
+ ## Getting Started
26
+
27
+ First, you need an account with [PushLayer.com](https://www.pushlayer.com), and an application. An application defines the certificate to use with Apple, and gives you a corresponding api_key to reference when sending push notifications. Lastly, each application has a unique ID, and can be found by clicking on your application name. The URL will look something like `https://www.pushlayer.com/applications/123`, where 123 is the application ID.
28
+
29
+ Second, you need to tell the Pushlayer library about your ID and api_key:
30
+
31
+ ```ruby
32
+ Pushlayer.api_id = 123
33
+ Pushlayer.api_key = 'my api key'
34
+ ```
35
+
36
+ Third, you need to know the device token you wish to send a notification to. A device token is generated by iOS in response to the user agreeing to receive push notifications from your app. Check out [the documentation on how to request this permission](https://www.pushlayer.com/pages/docs#Askingforpermission).
37
+
38
+ ## Sending a notification
39
+
40
+ To send a notification, simply:
41
+
42
+ ```ruby
43
+ Pushlayer.post_notification 'device_token', 'Hello iOS!'
44
+ ```
45
+
46
+ This will tell PushLayer to construct a payload consisting of the alert message 'Hello iOS!' and send it to the specified device token. If everything goes well, your iOS app should receive the notification.
47
+
48
+ The result will be a Ruby hash of the PushLayer notification object, similar to:
49
+
50
+ ```ruby
51
+ {
52
+ "action_loc_key":null,
53
+ "alert_body":"Hello from PushLayer!",
54
+ "application_id":1,
55
+ "badge":null,
56
+ "created_at":
57
+ "2013-01-08T03:50:06Z",
58
+ "custom_payload":null,
59
+ "device_token":"123abc",
60
+ "id":3,
61
+ "launch_image":null,
62
+ "loc_args":null,
63
+ "loc_key":null,
64
+ "sound":null,
65
+ "state":"pending",
66
+ "status_code":null,
67
+ "updated_at":"2013-01-08T03:50:06Z"
68
+ }
69
+ ```
70
+
71
+ ## Help
72
+
73
+ If you find a bug, open an Issue. Pull Requests are welcome. If you get stuck and need help, feel free to contact us at [info@pushlayer.com](mailto:info@pushlayer.com).
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ require 'rspec/core/rake_task'
11
+
12
+ begin
13
+ require 'rdoc/task'
14
+ rescue LoadError
15
+ require 'rdoc/rdoc'
16
+ require 'rake/rdoctask'
17
+ RDoc::Task = Rake::RDocTask
18
+ end
19
+
20
+ RDoc::Task.new(:rdoc) do |rdoc|
21
+ rdoc.rdoc_dir = 'rdoc'
22
+ rdoc.title = 'Pushlayer'
23
+ rdoc.options << '--line-numbers'
24
+ rdoc.rdoc_files.include('README.rdoc')
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ end
27
+
28
+ namespace :spec do
29
+ desc 'Run unit specs'
30
+ RSpec::Core::RakeTask.new('unit') do |t|
31
+ t.pattern = 'spec/unit/**/*_spec.rb'
32
+ end
33
+
34
+ desc 'Run functional specs'
35
+ RSpec::Core::RakeTask.new('functional') do |t|
36
+ t.pattern = 'spec/functional/**/*_spec.rb'
37
+ end
38
+ end
39
+
40
+ desc 'Run unit and functional specs'
41
+ task spec: ['spec:unit', 'spec:functional']
42
+
43
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ module Pushlayer
2
+ VERSION = '0.9.0'
3
+ end
data/lib/pushlayer.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'rest_client'
2
+ require 'multi_json'
3
+
4
+ require 'pushlayer/version'
5
+
6
+ module Pushlayer
7
+ # @private
8
+ @@api_base = 'https://www.pushlayer.com'
9
+
10
+ @@api_id = ''
11
+ @@api_key = ''
12
+
13
+ def self.api_id=(id)
14
+ @@api_id = id
15
+ end
16
+
17
+ def self.api_key=(key)
18
+ @@api_key = key
19
+ end
20
+
21
+ # Send a push notification
22
+ #
23
+ # @example
24
+ # Pushlayer.post_notification 'abc123', 'Hello from PushLayer!'
25
+ #
26
+ # @param [String] device_token The device_token from the iOS device, returned by the system in
27
+ # response to the user giving your app permission to send push notifications.
28
+ # @param [String] alert_body A string to send in the APNS alert_body payload param. Typically
29
+ # this is a message you want to display to the user in an alert.
30
+ # @param [Hash] opts A hash of all remaining valid APNS payload parameters to include, such as
31
+ # badge, sound, etc.
32
+ #
33
+ # @option opts [String] :badge
34
+ # @option opts [String] :sound
35
+ # @option opts [String] :action_loc_key
36
+ # @option opts [String] :loc_key
37
+ # @option opts [String] :loc_args
38
+ # @option opts [String] :launch_image
39
+ # @option opts [String] :custom_payload
40
+ #
41
+ # Upon success, a Ruby hash object will be returned representing the notification object sent.
42
+ #
43
+ # Under the hood, Pushlayer is using rest_client to communicate with the service. Be sure to
44
+ # familiarize yourself with rest_client's behavior in terms of exceptions:
45
+ def self.post_notification(device_token, alert_body, opts={})
46
+ params = { device_token: device_token, alert_body: alert_body }.merge opts
47
+ headers = { accept: :json, content_type: :json, user_agent: user_agent }
48
+
49
+ RestClient.post endpoint, MultiJson.dump(params), headers
50
+ end
51
+
52
+ private
53
+
54
+ def self.endpoint
55
+ "#{@@api_base}/applications/#{@@api_id}/notifications.json?api_key=#{@@api_key}"
56
+ end
57
+
58
+ def self.user_agent
59
+ "PushLayer/v1 RubyBindings/#{Pushlayer::VERSION}"
60
+ end
61
+ end
data/pushlayer.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'pushlayer/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'pushlayer'
6
+ s.version = Pushlayer::VERSION
7
+ s.authors = ['Ryan Twomey, Costa Walcott']
8
+ s.email = ['info@pushlayer.com']
9
+ s.homepage = 'https://www.pushlayer.com'
10
+ s.summary = 'pushlayer sends iOS push notifications using PushLayer.com'
11
+
12
+ s.description = <<-eodescription
13
+ PushLayer is a service for sending, managing, and debugging iOS push notifications. This gem
14
+ adds a wrapper around the service, making it simple to send iOS push notifications from within
15
+ your Ruby applications.
16
+ eodescription
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
20
+
21
+ s.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
22
+ s.require_paths = ['lib']
23
+
24
+ s.add_dependency 'multi_json', '~> 1.5.0'
25
+ s.add_dependency 'rest-client', '~> 1.6.7'
26
+
27
+ s.add_development_dependency 'redcarpet', '~> 2.2.2'
28
+ s.add_development_dependency 'rspec', '~> 2.0'
29
+ s.add_development_dependency 'webmock', '~> 1.9.0'
30
+ s.add_development_dependency 'yard', '~> 0.8.3'
31
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__))
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'rspec'
5
+ require 'webmock/rspec'
6
+
7
+ WebMock.disable_net_connect!
8
+
9
+ require 'pushlayer'
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pushlayer do
4
+ describe '.post_notification' do
5
+ before do
6
+ api_id = 123
7
+ api_key = '123abc'
8
+
9
+ Pushlayer.api_id = api_id
10
+ Pushlayer.api_key = api_key
11
+
12
+ @expected_url = post_notification_url(api_id, api_key)
13
+ stub_request :any, @expected_url
14
+
15
+ @device_token = '1a2b3c'
16
+ @alert_body = 'test message'
17
+
18
+ Pushlayer.post_notification @device_token, @alert_body
19
+ end
20
+
21
+ it 'POSTs to the correct URL' do
22
+ body = { device_token: @device_token, alert_body: @alert_body }
23
+ headers = { content_type: 'application/json', user_agent: user_agent }
24
+
25
+ WebMock.should have_requested(:post, @expected_url).with(body: body, headers: headers).once
26
+ end
27
+ end
28
+
29
+ def post_notification_url(id, key)
30
+ "https://www.pushlayer.com/applications/#{id}/notifications.json?api_key=#{key}"
31
+ end
32
+
33
+ def user_agent
34
+ "PushLayer/v1 RubyBindings/#{Pushlayer::VERSION}"
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pushlayer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Twomey, Costa Walcott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.5.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.5.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.6.7
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.6.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: redcarpet
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.2.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.2.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: webmock
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.9.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.9.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: yard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.8.3
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.8.3
110
+ description: ! 'PushLayer is a service for sending, managing, and debugging iOS push
111
+ notifications. This gem
112
+
113
+ adds a wrapper around the service, making it simple to send iOS push notifications
114
+ from within
115
+
116
+ your Ruby applications.
117
+
118
+ '
119
+ email:
120
+ - info@pushlayer.com
121
+ executables: []
122
+ extensions: []
123
+ extra_rdoc_files: []
124
+ files:
125
+ - .gitignore
126
+ - .rspec
127
+ - .yardopts
128
+ - Gemfile
129
+ - Gemfile.lock
130
+ - MIT-LICENSE
131
+ - README.md
132
+ - Rakefile
133
+ - lib/pushlayer.rb
134
+ - lib/pushlayer/version.rb
135
+ - pushlayer.gemspec
136
+ - spec/spec_helper.rb
137
+ - spec/unit/pushlayer_spec.rb
138
+ homepage: https://www.pushlayer.com
139
+ licenses: []
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: 1.9.2
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 1.8.24
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: pushlayer sends iOS push notifications using PushLayer.com
162
+ test_files: []
163
+ has_rdoc: