pushbots 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pushbots.rb +14 -0
- data/lib/pushbots/all.rb +38 -0
- data/lib/pushbots/config.rb +22 -0
- data/lib/pushbots/one.rb +33 -0
- data/lib/pushbots/push.rb +42 -0
- data/lib/pushbots/request.rb +27 -0
- data/lib/pushbots/response.rb +24 -0
- data/lib/pushbots/version.rb +4 -0
- data/pushbots.gemspec +32 -0
- data/spec/external_request_spec.rb +62 -0
- data/spec/pushbots_spec.rb +23 -0
- data/spec/spec_helper.rb +108 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a242242d53a28c9eb207a4e5e0bc9d03221ec4a2
|
4
|
+
data.tar.gz: 4439e9d11248460c5b68817cd613edc0eecb3be6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ffb0799fa4f22349078397603ce6866c6ff6c5695aa7c3514fb2258cfd6c357f2219b6ef81e4442fcc333926630fe196025c13fc05296b014812b20964bb5ca3
|
7
|
+
data.tar.gz: 3040c9b65fe5ac373e0048754d3b27ad0528764d875b3a33084c80f8ce34f82eb0f5dd831c0a47baeabacbac0035d67069c24d6f244c62f11efe43748a2bda91
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at araogaraog@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Carlos Omana
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Pushbots
|
2
|
+
|
3
|
+
A Ruby interface to the PushBots API made with love by Kandiie
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pushbots'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pushbots
|
20
|
+
|
21
|
+
|
22
|
+
## How to use:
|
23
|
+
#### Configuration
|
24
|
+
```ruby
|
25
|
+
# config/initializers/pushbots.rb
|
26
|
+
|
27
|
+
Pushbots.configure do |config|
|
28
|
+
config.application_id = 'Application ID'
|
29
|
+
config.application_secret = 'Application Secret'
|
30
|
+
end
|
31
|
+
```
|
32
|
+
#### Single device notification
|
33
|
+
```ruby
|
34
|
+
# Device token
|
35
|
+
token = '900f9e35cc09ab9f3d99f0b244e23f160e0264f1aaf785549efeb6835a586710'
|
36
|
+
# platform is :ios or :android
|
37
|
+
# (Any other value will return a RuntimeError)
|
38
|
+
platform = :ios
|
39
|
+
# Notification message
|
40
|
+
message = 'Hello World!!!'
|
41
|
+
# Build up the notification
|
42
|
+
# platform, message, token and sound (required parameters).
|
43
|
+
# options (custom fields) (optional parameter)
|
44
|
+
push = PushBot::One.new(platform, token, message, sound, options)
|
45
|
+
push.send # Delivers the notification
|
46
|
+
```
|
47
|
+
|
48
|
+
#### Multiple device notification
|
49
|
+
```ruby
|
50
|
+
# platform is an array of valid plataforms (ios or android)
|
51
|
+
# (Any other value will return a RuntimeError)
|
52
|
+
platforms = [:ios, :android]
|
53
|
+
# Notification message
|
54
|
+
message = 'Hello World!!!'
|
55
|
+
# Notification schedule (Delivery time)
|
56
|
+
schedule = DateTime.now
|
57
|
+
# Build up the notification
|
58
|
+
# platform, message, schedule (required parameters).
|
59
|
+
# options (custom fields) (optional parameter)
|
60
|
+
push = PushBot::All.new(platforms, message, schedule, options = {})
|
61
|
+
push.send # Delivers the notification
|
62
|
+
```
|
63
|
+
|
64
|
+
##### You can read Pushbots API response using:
|
65
|
+
```ruby
|
66
|
+
# Your notification response
|
67
|
+
push.response
|
68
|
+
# Your notification response HTTP code
|
69
|
+
push.response.code
|
70
|
+
# Your notification response message
|
71
|
+
push.response.message
|
72
|
+
# Response as string
|
73
|
+
push.response.to_s
|
74
|
+
```
|
75
|
+
|
76
|
+
Read more about HTTP codes [here](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Kandiie/pushbots. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'pushbots'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/pushbots.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'pushbots/version'
|
2
|
+
require 'pushbots/config'
|
3
|
+
require 'pushbots/push'
|
4
|
+
require 'pushbots/request'
|
5
|
+
require 'pushbots/response'
|
6
|
+
require 'pushbots/one'
|
7
|
+
require 'pushbots/all'
|
8
|
+
|
9
|
+
# Pushbots module
|
10
|
+
module Pushbots
|
11
|
+
def self.configure(&block)
|
12
|
+
Config.configure(&block)
|
13
|
+
end
|
14
|
+
end
|
data/lib/pushbots/all.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Pushbots
|
2
|
+
# All class
|
3
|
+
class All < Push
|
4
|
+
attr_accessor :schedule, :tags, :sound, :badge, :except_tags, :alias,
|
5
|
+
:except_alias, :payload
|
6
|
+
|
7
|
+
def initialize(platforms, message, schedule, options = {})
|
8
|
+
super(platforms, message, :all)
|
9
|
+
self.schedule = schedule
|
10
|
+
self.tags = options[:tags]
|
11
|
+
self.sound = options[:sound]
|
12
|
+
self.badge = options[:badge]
|
13
|
+
self.except_tags = options[:except_tags]
|
14
|
+
self.alias = options[:alias]
|
15
|
+
self.except_alias = options[:except_alias]
|
16
|
+
self.payload = options[:payload]
|
17
|
+
end
|
18
|
+
|
19
|
+
def send
|
20
|
+
request = Request.new(body, :all)
|
21
|
+
self.response = request.send
|
22
|
+
self.status =
|
23
|
+
response.failed? ? STATUS[:failed] : STATUS[:delivered]
|
24
|
+
end
|
25
|
+
|
26
|
+
def body
|
27
|
+
data = {
|
28
|
+
platform: @platform,
|
29
|
+
msg: message,
|
30
|
+
schedule: schedule
|
31
|
+
}
|
32
|
+
data[:tags] if tags
|
33
|
+
data[:badge] if badge
|
34
|
+
data[:payload] if payload
|
35
|
+
data
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Pushbots
|
2
|
+
# Config class
|
3
|
+
class Config
|
4
|
+
attr_accessor :application_id, :application_secret
|
5
|
+
attr_reader :pushbots_url
|
6
|
+
class << self
|
7
|
+
attr_accessor :config
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@pushbots_url = 'https://api.pushbots.com/push/one'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.config
|
15
|
+
@config ||= Config.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(config) if block_given?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/pushbots/one.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Pushbots
|
2
|
+
# Push class
|
3
|
+
class One < Push
|
4
|
+
attr_accessor :token, :sound, :badge, :payload
|
5
|
+
|
6
|
+
def initialize(platform, token, message, sound, options = {})
|
7
|
+
super(platform, message, :one)
|
8
|
+
self.token = token
|
9
|
+
self.sound = sound
|
10
|
+
self.badge = options[:badge]
|
11
|
+
self.payload = options[:payload]
|
12
|
+
end
|
13
|
+
|
14
|
+
def send
|
15
|
+
request = Request.new(body, :one)
|
16
|
+
self.response = request.send
|
17
|
+
self.status =
|
18
|
+
response.failed? ? STATUS[:failed] : STATUS[:delivered]
|
19
|
+
end
|
20
|
+
|
21
|
+
def body
|
22
|
+
data = {
|
23
|
+
platform: @platform,
|
24
|
+
token: token,
|
25
|
+
msg: message,
|
26
|
+
sound: sound
|
27
|
+
}
|
28
|
+
data[:badge] if badge
|
29
|
+
data[:payload] if payload
|
30
|
+
data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Pushbots
|
2
|
+
# Push class
|
3
|
+
# Holds shared data between single and batch push notifications
|
4
|
+
class Push
|
5
|
+
attr_accessor :platform, :message, :status, :response, :type
|
6
|
+
PLATFORM_TYPE = { ios: 0, android: 1 }.freeze
|
7
|
+
PLATFORM_TYPE_R = [:ios, :android].freeze
|
8
|
+
|
9
|
+
STATUS = { created: 'created', delivered: 'delivered',
|
10
|
+
failed: 'failed' }.freeze
|
11
|
+
|
12
|
+
def initialize(platform, message, type)
|
13
|
+
self.type = type
|
14
|
+
if type == :one
|
15
|
+
validates_platform(platform)
|
16
|
+
self.platform = PLATFORM_TYPE[platform]
|
17
|
+
elsif type == :all
|
18
|
+
validates_platforms(platform)
|
19
|
+
self.platform = platform.map { |t| PLATFORM_TYPE[t] }
|
20
|
+
end
|
21
|
+
self.message = message
|
22
|
+
self.status = STATUS[:created]
|
23
|
+
end
|
24
|
+
|
25
|
+
def platform
|
26
|
+
PLATFORM_TYPE_R[@platform.to_i] if type == :one
|
27
|
+
@platform.map { |t| PLATFORM_TYPE_R[t] } if type == :all
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def validates_platform(platform)
|
33
|
+
fail 'platform is not valid' if PLATFORM_TYPE[platform].nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def validates_platforms(platforms)
|
37
|
+
platforms.each do |t|
|
38
|
+
validates_platform(t)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'http'
|
2
|
+
|
3
|
+
module Pushbots
|
4
|
+
# Request class
|
5
|
+
class Request
|
6
|
+
attr_accessor :body, :base_url
|
7
|
+
|
8
|
+
def initialize(body, base_url)
|
9
|
+
self.body = body
|
10
|
+
self.base_url = base_url
|
11
|
+
end
|
12
|
+
|
13
|
+
def send
|
14
|
+
url = "https://api.pushbots.com/push/#{base_url}"
|
15
|
+
response = HTTP.headers(header).post(url, json: body)
|
16
|
+
Response.new(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
def header
|
20
|
+
{
|
21
|
+
'X-PushBots-AppID' => Config.config.application_id,
|
22
|
+
'X-PushBots-Secret' => Config.config.application_secret,
|
23
|
+
'Content-Type' => 'application/json'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Pushbots
|
2
|
+
# Response class
|
3
|
+
class Response
|
4
|
+
attr_accessor :code, :message
|
5
|
+
|
6
|
+
def initialize(http_response)
|
7
|
+
self.code = http_response.code
|
8
|
+
if http_response.to_s.empty?
|
9
|
+
self.message = 'OK'
|
10
|
+
else
|
11
|
+
http_response = JSON.parse(http_response)
|
12
|
+
self.message = "#{http_response['code']}: #{http_response['message']}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def failed?
|
17
|
+
code != 200
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"{code: #{code}, message: #{message}}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/pushbots.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pushbots/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pushbots'
|
8
|
+
spec.version = Pushbots::VERSION
|
9
|
+
spec.authors = ['Carlos Omana', 'Cesar Rodriguez']
|
10
|
+
spec.email = ['contact@kandiie.com']
|
11
|
+
spec.summary = 'A Ruby interface to the PushBots API'
|
12
|
+
spec.description = 'Send push notifications'
|
13
|
+
spec.homepage = 'https://github.com/Kandiie/pushbots'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
18
|
+
else
|
19
|
+
fail 'RubyGems 2 or newer, required to protect against public gem pushes.'
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0")
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'webmock', '~> 1.24'
|
31
|
+
spec.add_runtime_dependency 'http', '~> 1.0', '>= 1.0.2'
|
32
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# spec/features/external_request_spec.rb
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Pushbots do
|
5
|
+
let(:token) { 'token' }
|
6
|
+
let(:platform) { :ios }
|
7
|
+
let(:message) { 'Hello World!!!' }
|
8
|
+
let(:sound) { 'sound' }
|
9
|
+
context 'request' do
|
10
|
+
context 'with valid data' do
|
11
|
+
it 'can push to a single device' do
|
12
|
+
push = described_class::One.new(platform, token, message, sound)
|
13
|
+
push.send
|
14
|
+
expect(push.response.code).to eq(200)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with invalid data' do
|
19
|
+
context 'nil or empty token' do
|
20
|
+
it 'can not push (empty)' do
|
21
|
+
push = described_class::One.new(platform, '', message, sound)
|
22
|
+
push.send
|
23
|
+
expect(push.response.code).to eq(400)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can not push (nil)' do
|
27
|
+
push = described_class::One.new(platform, nil, message, sound)
|
28
|
+
push.send
|
29
|
+
expect(push.response.code).to eq(400)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'nil or empty message' do
|
34
|
+
it 'can not push (empty)' do
|
35
|
+
push = described_class::One.new(platform, token, '', sound)
|
36
|
+
push.send
|
37
|
+
expect(push.response.code).to eq(400)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can not push (nil)' do
|
41
|
+
push = described_class::One.new(platform, token, nil, sound)
|
42
|
+
push.send
|
43
|
+
expect(push.response.code).to eq(400)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'nil or empty sound' do
|
48
|
+
it 'can not push (empty)' do
|
49
|
+
push = described_class::One.new(platform, token, message, '')
|
50
|
+
push.send
|
51
|
+
expect(push.response.code).to eq(400)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'can not push (nil)' do
|
55
|
+
push = described_class::One.new(platform, token, message, nil)
|
56
|
+
push.send
|
57
|
+
expect(push.response.code).to eq(400)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pushbots do
|
4
|
+
let(:token) { 'token' }
|
5
|
+
let(:platform) { :ios }
|
6
|
+
let(:message) { 'Hello World!!!' }
|
7
|
+
let(:sound) { 'sound' }
|
8
|
+
context 'initialize' do
|
9
|
+
context 'with invalid data' do
|
10
|
+
it 'raises wrong platform error' do
|
11
|
+
expect do
|
12
|
+
described_class::One.new(:other, token, message, sound)
|
13
|
+
end.to raise_error(RuntimeError, 'platform is not valid')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with valid data' do
|
18
|
+
it 'initializes' do
|
19
|
+
described_class::One.new(platform, token, message, sound)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'pushbots'
|
3
|
+
require 'net/http'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
6
|
+
|
7
|
+
# Stub Request common headers
|
8
|
+
common_headers = { 'Connection' => 'close',
|
9
|
+
'Content-Type' => 'application/json',
|
10
|
+
'Host' => 'api.pushbots.com',
|
11
|
+
'User-Agent' => 'http.rb/1.0.2',
|
12
|
+
'X-Pushbots-Appid' => 'Application ID',
|
13
|
+
'X-Pushbots-Secret' => 'Application Secret' }
|
14
|
+
|
15
|
+
api_path = 'https://api.pushbots.com/push/one'
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.before(:each) do
|
19
|
+
# Valid data
|
20
|
+
content = { 'platform' => 0,
|
21
|
+
'token' => 'token',
|
22
|
+
'msg' => 'Hello World!!!',
|
23
|
+
'sound' => 'sound' }
|
24
|
+
stub_request(:post, api_path)
|
25
|
+
.with(body: content.to_json,
|
26
|
+
headers: common_headers)
|
27
|
+
.to_return(status: 200,
|
28
|
+
body: '',
|
29
|
+
headers: {})
|
30
|
+
|
31
|
+
# Empty token returns status 400
|
32
|
+
content = { 'platform' => 0,
|
33
|
+
'token' => '',
|
34
|
+
'msg' => 'Hello World!!!',
|
35
|
+
'sound' => 'sound' }
|
36
|
+
stub_request(:post, api_path)
|
37
|
+
.with(body: content.to_json,
|
38
|
+
headers: common_headers)
|
39
|
+
.to_return(status: 400,
|
40
|
+
body: '',
|
41
|
+
headers: {})
|
42
|
+
|
43
|
+
# Null token returns status 400
|
44
|
+
content = { 'platform' => 0,
|
45
|
+
'token' => nil,
|
46
|
+
'msg' => 'Hello World!!!',
|
47
|
+
'sound' => 'sound' }
|
48
|
+
stub_request(:post, api_path)
|
49
|
+
.with(body: content.to_json,
|
50
|
+
headers: common_headers)
|
51
|
+
.to_return(status: 400,
|
52
|
+
body: '',
|
53
|
+
headers: {})
|
54
|
+
|
55
|
+
# Empty message returns status 400
|
56
|
+
content = { 'platform' => 0,
|
57
|
+
'token' => 'token',
|
58
|
+
'msg' => '',
|
59
|
+
'sound' => 'sound' }
|
60
|
+
stub_request(:post, api_path)
|
61
|
+
.with(body: content.to_json,
|
62
|
+
headers: common_headers)
|
63
|
+
.to_return(status: 400,
|
64
|
+
body: '',
|
65
|
+
headers: {})
|
66
|
+
|
67
|
+
# Null message returns status 400
|
68
|
+
content = { 'platform' => 0,
|
69
|
+
'token' => 'token',
|
70
|
+
'msg' => nil,
|
71
|
+
'sound' => 'sound' }
|
72
|
+
stub_request(:post, api_path)
|
73
|
+
.with(body: content.to_json,
|
74
|
+
headers: common_headers)
|
75
|
+
.to_return(status: 400,
|
76
|
+
body: '',
|
77
|
+
headers: {})
|
78
|
+
|
79
|
+
# Empty sound returns status 400
|
80
|
+
content = { 'platform' => 0,
|
81
|
+
'token' => 'token',
|
82
|
+
'msg' => 'Hello World!!!',
|
83
|
+
'sound' => '' }
|
84
|
+
stub_request(:post, api_path)
|
85
|
+
.with(body: content.to_json,
|
86
|
+
headers: common_headers)
|
87
|
+
.to_return(status: 400,
|
88
|
+
body: '',
|
89
|
+
headers: {})
|
90
|
+
|
91
|
+
# Null sound returns status 400
|
92
|
+
content = { 'platform' => 0,
|
93
|
+
'token' => 'token',
|
94
|
+
'msg' => 'Hello World!!!',
|
95
|
+
'sound' => nil }
|
96
|
+
stub_request(:post, api_path)
|
97
|
+
.with(body: content.to_json,
|
98
|
+
headers: common_headers)
|
99
|
+
.to_return(status: 400,
|
100
|
+
body: '',
|
101
|
+
headers: {})
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
Pushbots.configure do |config|
|
106
|
+
config.application_id = 'Application ID'
|
107
|
+
config.application_secret = 'Application Secret'
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushbots
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Omana
|
8
|
+
- Cesar Rodriguez
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-03-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.11'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.11'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: webmock
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.24'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.24'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: http
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.0'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.0.2
|
80
|
+
type: :runtime
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - "~>"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '1.0'
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.2
|
90
|
+
description: Send push notifications
|
91
|
+
email:
|
92
|
+
- contact@kandiie.com
|
93
|
+
executables: []
|
94
|
+
extensions: []
|
95
|
+
extra_rdoc_files: []
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
98
|
+
- ".rspec"
|
99
|
+
- ".travis.yml"
|
100
|
+
- CODE_OF_CONDUCT.md
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- bin/console
|
106
|
+
- bin/setup
|
107
|
+
- lib/pushbots.rb
|
108
|
+
- lib/pushbots/all.rb
|
109
|
+
- lib/pushbots/config.rb
|
110
|
+
- lib/pushbots/one.rb
|
111
|
+
- lib/pushbots/push.rb
|
112
|
+
- lib/pushbots/request.rb
|
113
|
+
- lib/pushbots/response.rb
|
114
|
+
- lib/pushbots/version.rb
|
115
|
+
- pushbots.gemspec
|
116
|
+
- spec/external_request_spec.rb
|
117
|
+
- spec/pushbots_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: https://github.com/Kandiie/pushbots
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata:
|
123
|
+
allowed_push_host: https://rubygems.org
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.5
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: A Ruby interface to the PushBots API
|
144
|
+
test_files: []
|