pushwoosh 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/.gitignore +16 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +7 -0
- data/lib/pushwoosh.rb +21 -0
- data/lib/pushwoosh/configurable.rb +55 -0
- data/lib/pushwoosh/exceptions.rb +3 -0
- data/lib/pushwoosh/helpers.rb +18 -0
- data/lib/pushwoosh/push_notification.rb +52 -0
- data/lib/pushwoosh/request.rb +51 -0
- data/lib/pushwoosh/response.rb +5 -0
- data/lib/pushwoosh/version.rb +3 -0
- data/pushwoosh.gemspec +28 -0
- data/spec/pushwoosh/helpers_spec.rb +12 -0
- data/spec/pushwoosh/pushwoosh/push_notification_spec.rb +94 -0
- data/spec/pushwoosh/pushwoosh/request_spec.rb +77 -0
- data/spec/pushwoosh/pushwoosh_spec.rb +29 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/vcr/pushwoosh/push_notification.yml +48 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b67e405ac2fcfa9ffc3b8608c7950cdfe4187998
|
4
|
+
data.tar.gz: 0ffe9649c09dfd0000d1c3780adfb2014da630ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df23d0f79270ee76342fb909c575c119bf527dc4cbc522d1d602cd455ce0e192960b47630d800879c71a7026f07a725208a7d0530d482699cf1c7580e1940c6d
|
7
|
+
data.tar.gz: 1dcef24065e4147bc7f29e936ca85e113f217bffddc0d2e22da24d06ea0e44e32862f61a2d4524efd745c9b18c8ae490a36daf428e7d45b0e627ea578e3a28b7
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format documentation --color --fail-fast
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pushwoosh (0.0.2)
|
5
|
+
httparty (~> 0.13.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.7)
|
11
|
+
coderay (1.1.0)
|
12
|
+
crack (0.4.2)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.2.5)
|
15
|
+
httparty (0.13.3)
|
16
|
+
json (~> 1.8)
|
17
|
+
multi_xml (>= 0.5.2)
|
18
|
+
json (1.8.2)
|
19
|
+
method_source (0.8.2)
|
20
|
+
multi_xml (0.5.5)
|
21
|
+
pry (0.10.1)
|
22
|
+
coderay (~> 1.1.0)
|
23
|
+
method_source (~> 0.8.1)
|
24
|
+
slop (~> 3.4)
|
25
|
+
rake (10.4.2)
|
26
|
+
rspec (3.1.0)
|
27
|
+
rspec-core (~> 3.1.0)
|
28
|
+
rspec-expectations (~> 3.1.0)
|
29
|
+
rspec-mocks (~> 3.1.0)
|
30
|
+
rspec-core (3.1.7)
|
31
|
+
rspec-support (~> 3.1.0)
|
32
|
+
rspec-expectations (3.1.2)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.1.0)
|
35
|
+
rspec-mocks (3.1.3)
|
36
|
+
rspec-support (~> 3.1.0)
|
37
|
+
rspec-support (3.1.2)
|
38
|
+
safe_yaml (1.0.4)
|
39
|
+
slop (3.6.0)
|
40
|
+
vcr (2.8.0)
|
41
|
+
webmock (1.15.2)
|
42
|
+
addressable (>= 2.2.7)
|
43
|
+
crack (>= 0.3.2)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
bundler (~> 1.8.2)
|
50
|
+
pry (= 0.10.1)
|
51
|
+
pushwoosh!
|
52
|
+
rake (~> 10.4.2)
|
53
|
+
rspec (~> 3.1.0)
|
54
|
+
vcr (~> 2.8.0)
|
55
|
+
webmock (~> 1.15.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pedro Andrade
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
Pushwoosh
|
2
|
+
=========
|
3
|
+
[](https://travis-ci.org/pedroandrade/pushwoosh)
|
4
|
+
[](https://codeclimate.com/github/pedroandrade/pushwoosh)
|
5
|
+
[](https://codeclimate.com/github/pedroandrade/pushwoosh)
|
6
|
+
|
7
|
+
This a simple wrapper to pushwoosh remote API
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'pushwoosh'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install pushwoosh
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Notify all devices:
|
26
|
+
```
|
27
|
+
Pushwoosh.PushNotification.new(auth_hash).notify_all(message, other_options)
|
28
|
+
```
|
29
|
+
|
30
|
+
### Notify some devices or a device:
|
31
|
+
```
|
32
|
+
Pushwoosh.PushNotification.new(auth_hash).notify_devices(message, devices, other_options)
|
33
|
+
```
|
34
|
+
|
35
|
+
```auth_hash = { auth: '55555-5555', application: '1234zxcvb' }```
|
36
|
+
|
37
|
+
for ```other_options``` hash you can see the [https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-Method-messages-create](http://) and you can choose any key you want
|
38
|
+
|
39
|
+
### If you're using Rails:
|
40
|
+
|
41
|
+
Create a initializer in your application
|
42
|
+
|
43
|
+
```
|
44
|
+
config/initializers/pushwoosh.rb
|
45
|
+
```
|
46
|
+
and put configs
|
47
|
+
|
48
|
+
```
|
49
|
+
Pushwoosh.configure do |config|
|
50
|
+
config.application = '5555-5555'
|
51
|
+
config.auth = 'abcdefghijklmnopq'
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
### Notify all devices:
|
56
|
+
```
|
57
|
+
Pushwoosh.notify_all(message, other_options)
|
58
|
+
```
|
59
|
+
|
60
|
+
### Notify some devices or a device:
|
61
|
+
```
|
62
|
+
Pushwoosh.notify_devices(message, devices, other_options)
|
63
|
+
```
|
64
|
+
|
65
|
+
*NOTE: devices is an array
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/pushwoosh.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "pushwoosh/version"
|
2
|
+
require 'pushwoosh/push_notification'
|
3
|
+
require 'pushwoosh/configurable'
|
4
|
+
require 'httparty'
|
5
|
+
require 'pushwoosh/helpers'
|
6
|
+
|
7
|
+
module Pushwoosh
|
8
|
+
extend Pushwoosh::Configurable
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def notify_all(message, notification_options = {})
|
13
|
+
PushNotification.new(options).notify_all(message, notification_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify_devices(message, devices = [], notification_options = {})
|
17
|
+
PushNotification.new(options).notify_devices(message, devices, notification_options)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Pushwoosh
|
4
|
+
module Configurable
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_writer :application, :auth
|
8
|
+
attr_accessor :application, :auth
|
9
|
+
|
10
|
+
def_delegator :options, :hash
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def keys
|
15
|
+
@keys ||= [
|
16
|
+
:application,
|
17
|
+
:auth,
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure
|
24
|
+
yield self
|
25
|
+
validate_credential_type!
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# @return [Hash]
|
32
|
+
def credentials
|
33
|
+
{
|
34
|
+
application: @application,
|
35
|
+
auth: @auth
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Hash]
|
40
|
+
def options
|
41
|
+
Hash[Pushwoosh::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_credential_type!
|
45
|
+
credentials.each do |credential, value|
|
46
|
+
next if value.nil?
|
47
|
+
|
48
|
+
unless value.is_a?(String) || value.is_a?(Symbol)
|
49
|
+
raise StandardError, "Invalid #{credential} specified: #{value} must be a string or symbol."
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Pushwoosh
|
2
|
+
module Helpers
|
3
|
+
class << self
|
4
|
+
def limit_string(str, limit_bytes)
|
5
|
+
return '' if str.empty? || !str
|
6
|
+
|
7
|
+
str = str.mb_chars.compose.to_s if str.respond_to?(:mb_chars)
|
8
|
+
new_str = str.byteslice(0, limit_bytes)
|
9
|
+
until new_str[-1].force_encoding('utf-8').valid_encoding?
|
10
|
+
# remove the invalid char
|
11
|
+
new_str = new_str.slice(0..-2)
|
12
|
+
end
|
13
|
+
|
14
|
+
new_str
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'pushwoosh/exceptions'
|
4
|
+
require 'pushwoosh/request'
|
5
|
+
require 'pushwoosh/response'
|
6
|
+
require 'pushwoosh/helpers'
|
7
|
+
|
8
|
+
module Pushwoosh
|
9
|
+
class PushNotification
|
10
|
+
|
11
|
+
STRING_BYTE_LIMIT = 205 # recommended value, see https://community.pushwoosh.com/questions/286/why-am-i-receiving-a-payload-error for more details
|
12
|
+
|
13
|
+
def initialize(auth_hash = {})
|
14
|
+
@auth_hash = auth_hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def notify_all(message, other_options = {})
|
18
|
+
other_options.merge!(content: limited_content(message))
|
19
|
+
create_message(other_options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def notify_devices(message, devices, other_options = {})
|
23
|
+
other_options.merge!(content: limited_content(message), devices: devices)
|
24
|
+
create_message(other_options)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :auth_hash
|
30
|
+
|
31
|
+
def limited_content(message)
|
32
|
+
Helpers.limit_string(message, STRING_BYTE_LIMIT)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_message(notification_options = {})
|
36
|
+
fail Pushwoosh::Exceptions::Error, 'Message is missing' if notification_options[:content].nil? || notification_options[:content].empty?
|
37
|
+
|
38
|
+
Request.make_post!('/createMessage', build_notification_options(notification_options))
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_notification_options(notification_options)
|
42
|
+
{ notification_options: default_notification_options.merge(notification_options) }.merge(auth_hash)
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_notification_options
|
46
|
+
{
|
47
|
+
send_date: "now",
|
48
|
+
ios_badges: "+1"
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Pushwoosh
|
4
|
+
class Request
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
base_uri 'https://cp.pushwoosh.com/json/1.3/'
|
8
|
+
format :json
|
9
|
+
|
10
|
+
def self.make_post!(*args)
|
11
|
+
new(*args).make_post!
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(url, options = {})
|
15
|
+
validations!(url, options)
|
16
|
+
|
17
|
+
@options = options
|
18
|
+
@notification_options = options.fetch(:notification_options)
|
19
|
+
@url = url
|
20
|
+
@base_request = {
|
21
|
+
request: {
|
22
|
+
application: options[:application],
|
23
|
+
auth: options[:auth]
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def make_post!
|
29
|
+
response = self.class.post(url, body: build_request.to_json).parsed_response
|
30
|
+
Response.new(response)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :options, :base_request, :notification_options, :url
|
36
|
+
|
37
|
+
def validations!(url, options)
|
38
|
+
fail Pushwoosh::Exceptions::Error, 'Missing application' unless options.fetch(:application)
|
39
|
+
fail Pushwoosh::Exceptions::Error, 'Missing auth key' unless options.fetch(:auth)
|
40
|
+
fail Pushwoosh::Exceptions::Error, 'URL is empty' if url.nil? || url.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_request
|
44
|
+
{ request: full_request_with_notifications }
|
45
|
+
end
|
46
|
+
|
47
|
+
def full_request_with_notifications
|
48
|
+
base_request[:request].merge(notifications: [notification_options])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/pushwoosh.gemspec
ADDED
@@ -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 'pushwoosh/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pushwoosh"
|
8
|
+
spec.version = Pushwoosh::VERSION
|
9
|
+
spec.authors = ["Pedro Andrade"]
|
10
|
+
spec.email = ["pedro.rjandrade@gmail.com"]
|
11
|
+
spec.description = %q{Pushwoosh gem}
|
12
|
+
spec.summary = %q{Pushwoosh Remote API}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.8.2"
|
22
|
+
spec.add_development_dependency "rake", '~> 10.4.2'
|
23
|
+
spec.add_development_dependency 'rspec', "~> 3.1.0"
|
24
|
+
spec.add_development_dependency 'vcr', "~> 2.8.0"
|
25
|
+
spec.add_development_dependency 'webmock', "~> 1.15.0"
|
26
|
+
spec.add_development_dependency 'pry', '0.10.1'
|
27
|
+
spec.add_dependency "httparty", "~> 0.13.3"
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pushwoosh::Helpers do
|
4
|
+
describe '.limit_string' do
|
5
|
+
context 'when string is bigger than 256 bytes' do
|
6
|
+
it 'returns the string with 256 bytes' do
|
7
|
+
big_string = 'é' * 300
|
8
|
+
expect(described_class.limit_string(big_string, 256).bytes.size).to eq 256
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pushwoosh::PushNotification do
|
4
|
+
let(:options) do
|
5
|
+
{
|
6
|
+
auth: '5555-5555',
|
7
|
+
application: '555555'
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:response) do
|
12
|
+
double(:response, status_code: 200,
|
13
|
+
status_message: "OK",
|
14
|
+
response: {"Messages" => ["555555534563456345"]}
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { described_class.new(options) }
|
19
|
+
|
20
|
+
describe '#notify_all' do
|
21
|
+
let(:request) do
|
22
|
+
{
|
23
|
+
notification_options: {
|
24
|
+
send_date: "now",
|
25
|
+
:ios_badges=>"+1",
|
26
|
+
content: "Testing"
|
27
|
+
},
|
28
|
+
auth: "5555-5555",
|
29
|
+
application: "555555"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when message is not empty' do
|
34
|
+
it 'sends the notification' do
|
35
|
+
allow(Pushwoosh::Request).to receive(:make_post!).with("/createMessage", request).and_return(response)
|
36
|
+
|
37
|
+
response_of_notify = subject.notify_all('Testing')
|
38
|
+
|
39
|
+
expect(response_of_notify.status_code).to eq 200
|
40
|
+
expect(response_of_notify.status_message).to eq 'OK'
|
41
|
+
expect(response_of_notify.response['Messages']).to eq ['555555534563456345']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when message is empty' do
|
46
|
+
it 'raises message is missing error' do
|
47
|
+
expect {
|
48
|
+
subject.notify_all('')
|
49
|
+
}.to raise_error Pushwoosh::Exceptions::Error, 'Message is missing'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#notify_devices' do
|
55
|
+
let(:devices) do
|
56
|
+
['dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41',
|
57
|
+
'bec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41']
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:request) do
|
61
|
+
{
|
62
|
+
notification_options: {
|
63
|
+
send_date: "now",
|
64
|
+
ios_badges: "+1",
|
65
|
+
content: "Testing",
|
66
|
+
devices: ["dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41",
|
67
|
+
'bec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41']
|
68
|
+
},
|
69
|
+
auth: "5555-5555",
|
70
|
+
application: "555555"
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when message is not empty' do
|
75
|
+
it 'sends the notification for some devices' do
|
76
|
+
allow(Pushwoosh::Request).to receive(:make_post!).with("/createMessage", request).and_return(response)
|
77
|
+
|
78
|
+
response_of_notify = subject.notify_devices('Testing', devices)
|
79
|
+
|
80
|
+
expect(response_of_notify.status_code).to eq 200
|
81
|
+
expect(response_of_notify.status_message).to eq 'OK'
|
82
|
+
expect(response_of_notify.response['Messages']).to eq ['555555534563456345']
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when message is empty' do
|
87
|
+
it 'raises message is missing error' do
|
88
|
+
expect {
|
89
|
+
subject.notify_devices('', devices)
|
90
|
+
}.to raise_error Pushwoosh::Exceptions::Error, 'Message is missing'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pushwoosh::Request do
|
4
|
+
|
5
|
+
describe '#make_post!' do
|
6
|
+
let(:body) do
|
7
|
+
{
|
8
|
+
request:
|
9
|
+
{
|
10
|
+
application: "555555",
|
11
|
+
auth: "5555-5555",
|
12
|
+
notifications:
|
13
|
+
[{
|
14
|
+
send_date: "now",
|
15
|
+
ios_badges: "+1",
|
16
|
+
content: "Testing"
|
17
|
+
}]
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:options) do
|
23
|
+
{
|
24
|
+
auth: "5555-5555",
|
25
|
+
application: "555555",
|
26
|
+
notification_options:
|
27
|
+
{
|
28
|
+
send_date: "now",
|
29
|
+
:ios_badges=>"+1",
|
30
|
+
content: "Testing"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:response) do
|
36
|
+
double(:response, response_hash)
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:response_hash) do
|
40
|
+
{
|
41
|
+
status_code: 200,
|
42
|
+
status_message: "OK",
|
43
|
+
response: { "Messages" => ["555555534563456345"] }
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when url is not empty' do
|
48
|
+
subject { described_class.new('/createMessage', options) }
|
49
|
+
|
50
|
+
it 'sends the notification with valid params' do
|
51
|
+
allow(described_class).to receive(:post).with("/createMessage", body: body.to_json).and_return(response)
|
52
|
+
allow(response).to receive(:parsed_response).and_return(OpenStruct.new(response_hash))
|
53
|
+
response_of_make_post = subject.make_post!
|
54
|
+
|
55
|
+
expect(response_of_make_post.status_code).to eq 200
|
56
|
+
expect(response_of_make_post.status_message).to eq 'OK'
|
57
|
+
expect(response_of_make_post.response['Messages']).to eq ['555555534563456345']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when url is empty' do
|
62
|
+
it 'raises an error' do
|
63
|
+
expect {
|
64
|
+
described_class.new('', options)
|
65
|
+
}.to raise_error Pushwoosh::Exceptions::Error, 'URL is empty'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when url is nil' do
|
70
|
+
it 'raises an error' do
|
71
|
+
expect {
|
72
|
+
described_class.new(nil, options)
|
73
|
+
}.to raise_error Pushwoosh::Exceptions::Error, 'URL is empty'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pushwoosh do
|
4
|
+
before do
|
5
|
+
Pushwoosh.configure do |config|
|
6
|
+
config.application = '5555-5555'
|
7
|
+
config.auth = 'abcefg'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.notify_all' do
|
12
|
+
context 'when has message' do
|
13
|
+
it "sends push message" do
|
14
|
+
VCR.use_cassette 'pushwoosh/push_notification' do
|
15
|
+
response = described_class.notify_all("Testing")
|
16
|
+
expect(response.status_code).to eq 200
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when message is empty' do
|
22
|
+
it 'raises a error if message is empty' do
|
23
|
+
VCR.use_cassette 'pushwoosh/empty_message_push' do
|
24
|
+
expect { described_class.notify_all("") }.to raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'pushwoosh'
|
4
|
+
require 'vcr'
|
5
|
+
require 'webmock'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
VCR.configure do |c|
|
9
|
+
#the directory where your cassettes will be saved
|
10
|
+
c.cassette_library_dir = 'spec/vcr'
|
11
|
+
# your HTTP request service. You can also use fakeweb, webmock, and more
|
12
|
+
c.hook_into :webmock
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
# some (optional) config her
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://cp.pushwoosh.com/json/1.3/createMessage
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"request":{"application":"5555-5555","auth":"abcdefg","notifications":[{"send_date":"now","ios_badges":"+1","content":"Testing"}]}}'
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx/1.4.2
|
23
|
+
Date:
|
24
|
+
- Sun, 11 Jan 2015 21:40:58 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf8
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
X-Powered-By:
|
32
|
+
- phpDaemon/1.0-beta3
|
33
|
+
Access-Control-Allow-Origin:
|
34
|
+
- "*"
|
35
|
+
Access-Control-Allow-Headers:
|
36
|
+
- Origin, X-Requested-With, Content-Type, Accept
|
37
|
+
Access-Control-Allow-Methods:
|
38
|
+
- GET, POST, PUT, OPTIONS
|
39
|
+
X-Pw-Cluster-Node:
|
40
|
+
- api-02
|
41
|
+
X-Pw-Front-Node:
|
42
|
+
- front-02
|
43
|
+
body:
|
44
|
+
encoding: UTF-8
|
45
|
+
string: '{"status_code":200,"status_message":"OK","response":{"Messages":["4C2C-9A52A6A4-9BA6D064"]}}'
|
46
|
+
http_version:
|
47
|
+
recorded_at: Sun, 11 Jan 2015 21:40:59 GMT
|
48
|
+
recorded_with: VCR 2.8.0
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushwoosh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pedro Andrade
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.4.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.4.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.8.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.15.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.15.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: httparty
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.13.3
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.13.3
|
111
|
+
description: Pushwoosh gem
|
112
|
+
email:
|
113
|
+
- pedro.rjandrade@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/pushwoosh.rb
|
127
|
+
- lib/pushwoosh/configurable.rb
|
128
|
+
- lib/pushwoosh/exceptions.rb
|
129
|
+
- lib/pushwoosh/helpers.rb
|
130
|
+
- lib/pushwoosh/push_notification.rb
|
131
|
+
- lib/pushwoosh/request.rb
|
132
|
+
- lib/pushwoosh/response.rb
|
133
|
+
- lib/pushwoosh/version.rb
|
134
|
+
- pushwoosh.gemspec
|
135
|
+
- spec/pushwoosh/helpers_spec.rb
|
136
|
+
- spec/pushwoosh/pushwoosh/push_notification_spec.rb
|
137
|
+
- spec/pushwoosh/pushwoosh/request_spec.rb
|
138
|
+
- spec/pushwoosh/pushwoosh_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/vcr/pushwoosh/push_notification.yml
|
141
|
+
homepage: ''
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.4.5
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: Pushwoosh Remote API
|
165
|
+
test_files:
|
166
|
+
- spec/pushwoosh/helpers_spec.rb
|
167
|
+
- spec/pushwoosh/pushwoosh/push_notification_spec.rb
|
168
|
+
- spec/pushwoosh/pushwoosh/request_spec.rb
|
169
|
+
- spec/pushwoosh/pushwoosh_spec.rb
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
- spec/vcr/pushwoosh/push_notification.yml
|