push_woosher 0.0.1

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.
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in push_woosher.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Thomas Riboulet
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,147 @@
1
+ # PushWoosher
2
+
3
+ Push Woosher is a simple wrapper for Push Woosh. While there is already other
4
+ ones this ome is aimed to be simple, allow register, unregister devices and
5
+ send push notifications.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'push_woosher'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install push_woosher
20
+
21
+ ## Usage
22
+
23
+ You need to configure your access :
24
+
25
+ ```
26
+ PushWoosher.configure do |config|
27
+ config.application_code = 'APPP-IDDD'
28
+ config.api_token = 'the-api-token'
29
+ end
30
+ ```
31
+
32
+ ### Devices handling
33
+
34
+ This gem for now supports only 2 types of devices : Ios and Android.
35
+
36
+ You need 2 identifiers for each device : the usual token and a hardware token.
37
+
38
+ #### iOS
39
+
40
+ To register an iOS device you need to use the following :
41
+
42
+ ```
43
+ device = PushWoosher::Device::Ios.new(
44
+ token: token,
45
+ hwid: some_other_id
46
+ )
47
+ device.register
48
+ ```
49
+
50
+ That method will return either true or a hash with the status code and response
51
+ body.
52
+
53
+ To unregister you need to use the following :
54
+
55
+ ```
56
+ device.unregister
57
+ ```
58
+
59
+ #### Android
60
+
61
+ To register an Android device you need to use the following :
62
+
63
+ ```
64
+ device = PushWoosher::Device::Android.new(
65
+ token: token,
66
+ hwid: some_other_id
67
+ )
68
+ device.register
69
+ ```
70
+
71
+ That method will return either true or a hash with the status code and response
72
+ body.
73
+
74
+ To unregister you need to use the following :
75
+
76
+ ```
77
+ device.unregister
78
+ ```
79
+
80
+ ### Push Messages
81
+
82
+ Sending a push message to a device requires the token and the notification hash.
83
+
84
+ Depending on the device type you need to use one of the following format :
85
+
86
+ ```
87
+ # iOS
88
+ {
89
+ send_date: 'now',
90
+ ignore_user_timezone: true,
91
+ content: 'PUSH MESSAGE',
92
+ data: {
93
+ user_id: 1,
94
+ notification_type: 2
95
+ },
96
+ platforms: [1],
97
+ ios_root_params: {
98
+ aps: { content-available: 1 }
99
+ },
100
+ devices: ['device-token']
101
+ }
102
+
103
+ # Android
104
+ {
105
+ send_date: 'now',
106
+ ignore_user_timezone: true,
107
+ content: 'PUSH MESSAGE',
108
+ data: {
109
+ user_id: 1,
110
+ notification_type: 2
111
+ },
112
+ platforms: [3],
113
+ android_root_params: {
114
+ { bob: 1 }
115
+ },
116
+ devices: ['device-token']
117
+ }
118
+ ```
119
+
120
+ Notice that most of then content is similar, only the *ios_root_params*, *android_root_params* and *platforms* keys are different.
121
+
122
+ To allow finer control on the content the input will stay that way, we suggest you to use a formatter class in your app to simplify things for your needs.
123
+
124
+ Sending a push notification itself can be done as follow :
125
+
126
+ ```
127
+ notification = {} # use the format seen previously
128
+
129
+ push = PushWoosher::new(notification: notification)
130
+
131
+ push.post
132
+ ```
133
+
134
+ PushWoosh shows the push history easily in their web panel.
135
+
136
+ ## Requirements
137
+
138
+ This gems uses Virtus to make things easier internally. There is no dependency on ActiveSupport.
139
+
140
+
141
+ ## Contributing
142
+
143
+ 1. Fork it ( https://github.com/[my-github-username]/push_woosher/fork )
144
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
145
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
146
+ 4. Push to the branch (`git push origin my-new-feature`)
147
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'virtus'
3
+ require 'json'
4
+ require 'bundler'
5
+ require 'faraday'
6
+ require 'securerandom'
7
+
8
+ Bundler.setup(:default)
9
+
10
+ require 'push_woosher/version'
11
+ require 'push_woosher/base'
12
+ require 'push_woosher/config'
13
+ require 'push_woosher/push'
14
+ require 'push_woosher/device/base'
15
+ require 'push_woosher/device/android'
16
+ require 'push_woosher/device/ios'
17
+
18
+ module PushWoosher
19
+ # Your code goes here...
20
+ end
@@ -0,0 +1,39 @@
1
+ module PushWoosher
2
+ class Base
3
+ include Virtus.model
4
+
5
+ BASE_HOST = 'cp.pushwoosh.com'
6
+ PROTOCOL = 'https'
7
+ BASE_PATH = '/json/1.3'
8
+
9
+ def connection
10
+ @connection = Faraday.new(url: "#{PROTOCOL}://#{BASE_HOST}") do |faraday|
11
+ faraday.request :url_encoded # form-encode POST params
12
+ faraday.response :logger # log requests to STDOUT
13
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
14
+ end
15
+ end
16
+
17
+ def post_action(opts = {})
18
+ response = connection.post do |req|
19
+ req.url "#{BASE_PATH}/#{opts[:path]}"
20
+ req.headers['Content-Type'] = 'application/json'
21
+ req.body = { request: opts[:request_hash].merge(config) }.to_json
22
+ end
23
+
24
+ case response.status
25
+ when 200
26
+ true
27
+ else
28
+ { status: response.status, message: response.body }
29
+ end
30
+ end
31
+
32
+ def config
33
+ {
34
+ application: PushWoosher.configuration.application_code,
35
+ auth: PushWoosher.configuration.api_token
36
+ }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ module PushWoosher
2
+ class Config
3
+ attr_accessor :application_code
4
+ attr_accessor :api_token
5
+
6
+ def setup
7
+ yield self
8
+ end
9
+ end
10
+
11
+ class << self
12
+ attr_accessor :configuration
13
+
14
+ def configure
15
+ self.configuration ||= Config.new
16
+ yield(configuration)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module PushWoosher
2
+ module Device
3
+ class Android < PushWoosher::Device::Base
4
+ def device_type
5
+ 3
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ module PushWoosher
2
+ module Device
3
+ class Base < PushWoosher::Base
4
+ attribute :token
5
+ attribute :hwid
6
+
7
+ def device_type
8
+ raise NotImplementedError
9
+ end
10
+
11
+ def register_request_hash
12
+ {
13
+ push_token: token,
14
+ hwid: hwid,
15
+ timezone: 0,
16
+ device_type: device_type
17
+ }
18
+ end
19
+
20
+ def unregister_request_hash
21
+ {
22
+ hwid: hwid
23
+ }
24
+ end
25
+
26
+ def register
27
+ post_action(
28
+ path: 'registerDevice',
29
+ request_hash: register_request_hash
30
+ )
31
+ end
32
+
33
+ def unregister
34
+ post_action(
35
+ path: 'unregisterDevice',
36
+ request_hash: unregister_request_hash
37
+ )
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ module PushWoosher
2
+ module Device
3
+ class Ios < PushWoosher::Device::Base
4
+ def device_type
5
+ 1
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module PushWoosher
2
+ class Push < PushWoosher::Base
3
+ attribute :notification
4
+
5
+ def resource_path
6
+ 'createMessage'
7
+ end
8
+
9
+ def request_hash
10
+ {
11
+ notifications: [notification]
12
+ }
13
+ end
14
+
15
+ def post
16
+ post_action(
17
+ path: resource_path,
18
+ request_hash: request_hash
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module PushWoosher
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'push_woosher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "push_woosher"
8
+ spec.version = PushWoosher::VERSION
9
+ spec.authors = ["Thomas Riboulet"]
10
+ spec.email = ["riboulet@gmail.com"]
11
+ spec.summary = %q{A simple wrapper for Push Woosh.}
12
+ spec.description = %q{A simple wrapper for Push Woosh.}
13
+ spec.homepage = "https://github.com/mcansky/push_woosher"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'ffaker'
24
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
25
+ spec.add_development_dependency 'rspec-its', '~> 1.0.1'
26
+ spec.add_dependency 'faraday'
27
+ spec.add_dependency 'virtus'
28
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe PushWoosher::Base do
4
+ describe 'constants' do
5
+ it 'should have the base host' do
6
+ expect(PushWoosher::Base::BASE_HOST).to eq 'cp.pushwoosh.com'
7
+ end
8
+ it 'should have the protocol' do
9
+ expect(PushWoosher::Base::PROTOCOL).to eq 'https'
10
+ end
11
+ it 'should have the base host' do
12
+ expect(PushWoosher::Base::BASE_PATH).to eq '/json/1.3'
13
+ end
14
+ end
15
+
16
+ describe '#config' do
17
+ let(:configuration) { double(application_code: 'aa', api_token: 'bb') }
18
+ let(:expected_hash) { { application: 'aa', auth: 'bb' } }
19
+ before do
20
+ allow(PushWoosher).to receive(:configuration).and_return(configuration)
21
+ end
22
+ its(:config) { should eq expected_hash }
23
+ end
24
+
25
+ describe '#post_action' do
26
+ let(:connection) { double(post: response) }
27
+ before do
28
+ allow(subject).to receive(:connection).and_return(connection)
29
+ end
30
+
31
+ context 'success' do
32
+ let(:response) { double(status: 200) }
33
+ its(:post_action) { should eq true }
34
+ end
35
+
36
+ context 'failure' do
37
+ let(:response_hash) { { status: 404, message: 'something is wrong' } }
38
+ let(:response) { double(status: 404, body: 'something is wrong') }
39
+ its(:post_action) { should eq response_hash }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe PushWoosher::Device::Android do
4
+ its(:device_type) { should eq 3 }
5
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe PushWoosher::Device::Base do
4
+ let(:token) { SecureRandom.hex }
5
+ let(:hwid) { SecureRandom.hex }
6
+ let(:options) { { token: token, hwid: hwid } }
7
+
8
+ subject { described_class.new(options) }
9
+
10
+ it { should respond_to(:token) }
11
+ it { should respond_to(:hwid) }
12
+ it { should respond_to(:device_type) }
13
+
14
+ context 'requests hashes' do
15
+ let(:device_type) { 1 }
16
+
17
+ before { allow(subject).to receive(:device_type).and_return(device_type) }
18
+
19
+ describe '#register_request_hash' do
20
+ let(:register_hash) do
21
+ {
22
+ push_token: token,
23
+ hwid: hwid,
24
+ timezone: 0,
25
+ device_type: device_type
26
+ }
27
+ end
28
+
29
+ its(:register_request_hash) { should eq register_hash }
30
+ end
31
+
32
+ describe '#unregister_request_hash' do
33
+ let(:unregister_hash) { { hwid: hwid } }
34
+ its(:unregister_request_hash) { should eq unregister_hash }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe PushWoosher::Device::Ios do
4
+ its(:device_type) { should eq 1 }
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'push_woosher'
2
+ require 'rspec/its'
3
+ require 'ffaker'
4
+
5
+
6
+ RSpec.configure do |config|
7
+ config.color = true
8
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: push_woosher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Riboulet
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: ffaker
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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: '0'
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: 3.0.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: 3.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-its
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.0.1
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.0.1
94
+ - !ruby/object:Gem::Dependency
95
+ name: faraday
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: virtus
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: A simple wrapper for Push Woosh.
127
+ email:
128
+ - riboulet@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - lib/push_woosher.rb
139
+ - lib/push_woosher/.DS_Store
140
+ - lib/push_woosher/base.rb
141
+ - lib/push_woosher/config.rb
142
+ - lib/push_woosher/device/android.rb
143
+ - lib/push_woosher/device/base.rb
144
+ - lib/push_woosher/device/ios.rb
145
+ - lib/push_woosher/push.rb
146
+ - lib/push_woosher/version.rb
147
+ - push_woosher.gemspec
148
+ - spec/lib/base_spec.rb
149
+ - spec/lib/device/android_spec.rb
150
+ - spec/lib/device/base_spec.rb
151
+ - spec/lib/device/ios_spec.rb
152
+ - spec/spec_helper.rb
153
+ homepage: https://github.com/mcansky/push_woosher
154
+ licenses:
155
+ - MIT
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ segments:
167
+ - 0
168
+ hash: -1342462332260062096
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ segments:
176
+ - 0
177
+ hash: -1342462332260062096
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 1.8.23
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: A simple wrapper for Push Woosh.
184
+ test_files:
185
+ - spec/lib/base_spec.rb
186
+ - spec/lib/device/android_spec.rb
187
+ - spec/lib/device/base_spec.rb
188
+ - spec/lib/device/ios_spec.rb
189
+ - spec/spec_helper.rb