push_bot 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile.lock +15 -1
- data/README.md +1 -0
- data/lib/push_bot.rb +2 -0
- data/lib/push_bot/device.rb +6 -1
- data/lib/push_bot/platform.rb +4 -0
- data/lib/push_bot/request.rb +2 -4
- data/lib/push_bot/response.rb +8 -12
- data/lib/push_bot/version.rb +1 -1
- data/push_bot.gemspec +4 -4
- data/spec/lib/device_spec.rb +76 -0
- data/spec/lib/push_spec.rb +48 -0
- data/spec/spec_helper.rb +18 -0
- metadata +27 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a18a2a8074b095dc89b6967c33cb7a01f75c549
|
4
|
+
data.tar.gz: 238aa353d064729a861f86c4b5888fdf99fd3912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8629003eec5a8a0ae9e8ec7efc4a4c4d0b6ab8a8002be35d6f7810ed12564e5f37e374e1c34d8136af53b66f78bed934a0e35289d3860087ed966eb05c5ae664
|
7
|
+
data.tar.gz: 59a53aac57c678831e176312819ca7d6ed52226afbbd65b6903d84de030b4b3d21398ee7c9eb4e357e18a632e0aea9741cb3b0058ac2a9271d239076a51d6dc2
|
data/.rspec
ADDED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
push_bot (0.4.
|
4
|
+
push_bot (0.4.1)
|
5
5
|
typhoeus (~> 0.6)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
diff-lcs (1.2.5)
|
10
11
|
ethon (0.7.1)
|
11
12
|
ffi (>= 1.3.0)
|
12
13
|
ffi (1.9.5)
|
13
14
|
rake (10.3.2)
|
15
|
+
rspec (3.1.0)
|
16
|
+
rspec-core (~> 3.1.0)
|
17
|
+
rspec-expectations (~> 3.1.0)
|
18
|
+
rspec-mocks (~> 3.1.0)
|
19
|
+
rspec-core (3.1.5)
|
20
|
+
rspec-support (~> 3.1.0)
|
21
|
+
rspec-expectations (3.1.2)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.1.0)
|
24
|
+
rspec-mocks (3.1.2)
|
25
|
+
rspec-support (~> 3.1.0)
|
26
|
+
rspec-support (3.1.1)
|
14
27
|
typhoeus (0.6.9)
|
15
28
|
ethon (>= 0.7.1)
|
16
29
|
|
@@ -21,3 +34,4 @@ DEPENDENCIES
|
|
21
34
|
bundler (~> 1.7)
|
22
35
|
push_bot!
|
23
36
|
rake (~> 10.0)
|
37
|
+
rspec (~> 3.1)
|
data/README.md
CHANGED
data/lib/push_bot.rb
CHANGED
data/lib/push_bot/device.rb
CHANGED
@@ -11,14 +11,19 @@ module PushBot
|
|
11
11
|
:platform => platform
|
12
12
|
), :batch
|
13
13
|
|
14
|
-
if user?
|
14
|
+
if user? && !(Array === token)
|
15
15
|
type = nil
|
16
16
|
options[:token] = token
|
17
|
+
else
|
18
|
+
options[:tokens] = token
|
17
19
|
end
|
18
20
|
|
19
21
|
Request.new(:deviceToken).put(type, options)
|
20
22
|
end
|
21
23
|
|
24
|
+
# Retrieve information about the device with this token
|
25
|
+
#
|
26
|
+
# @return {PushBot::Response}
|
22
27
|
def info
|
23
28
|
Request.new(:deviceToken).get(:one, :token => token)
|
24
29
|
end
|
data/lib/push_bot/platform.rb
CHANGED
@@ -2,6 +2,10 @@ module PushBot
|
|
2
2
|
class Platform
|
3
3
|
VALUES = %w(ios android)
|
4
4
|
|
5
|
+
# Translate an array of :ios / :android into an array of integer strings
|
6
|
+
#
|
7
|
+
# @param platforms any of `:ios` and `:android`
|
8
|
+
# @return Array[<String>]
|
5
9
|
def self.parse(*platforms)
|
6
10
|
platforms = platforms.flatten.map! {|p| VALUES.index(p.to_s.downcase) }
|
7
11
|
raise(ArgumentError, 'Platform must be ios or android') if platforms.any?(&:nil?)
|
data/lib/push_bot/request.rb
CHANGED
@@ -28,7 +28,7 @@ module PushBot
|
|
28
28
|
:headers => {
|
29
29
|
:'X-PushBots-AppID' => Config.config.id,
|
30
30
|
:'X-PushBots-Secret' => Config.config.secret,
|
31
|
-
:'Content-Type' => 'application/json'
|
31
|
+
:'Content-Type' => :'application/json'
|
32
32
|
}
|
33
33
|
}
|
34
34
|
|
@@ -36,11 +36,9 @@ module PushBot
|
|
36
36
|
request_options[:headers][:Token] = options[:token]
|
37
37
|
end
|
38
38
|
|
39
|
-
puts "Sending request:#{type} url:#{url} options:#{request_options.inspect}"
|
40
|
-
|
41
39
|
request = Typhoeus::Request.new(url, request_options)
|
42
40
|
|
43
|
-
Response.new
|
41
|
+
Response.new { request.run }
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
data/lib/push_bot/response.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module PushBot
|
2
2
|
class Response
|
3
|
-
|
3
|
+
extend Forwardable
|
4
4
|
|
5
|
-
|
6
|
-
@raw_response = request.run
|
5
|
+
attr_reader :raw_response, :error
|
7
6
|
|
8
|
-
|
7
|
+
def initialize
|
8
|
+
@raw_response = yield
|
9
9
|
rescue => e
|
10
10
|
@error = e
|
11
11
|
end
|
@@ -15,20 +15,16 @@ module PushBot
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Did the request complete successfully or have issues
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
delegate :success? => :raw_response
|
19
|
+
|
20
|
+
# The raw response body string
|
21
|
+
delegate :body => :raw_response
|
21
22
|
|
22
23
|
# Did the response complete with an error
|
23
24
|
def error?
|
24
25
|
defined?(@error) && @error
|
25
26
|
end
|
26
27
|
|
27
|
-
# The raw response body string
|
28
|
-
def body
|
29
|
-
raw_response.try(:body)
|
30
|
-
end
|
31
|
-
|
32
28
|
# The result of the request as a JSON Object
|
33
29
|
#
|
34
30
|
# @return [Hash, Array] the JSON Object
|
data/lib/push_bot/version.rb
CHANGED
data/push_bot.gemspec
CHANGED
@@ -8,11 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = PushBot::VERSION
|
9
9
|
spec.authors = ['Brian Norton']
|
10
10
|
spec.email = ['brian.nort@gmail.com']
|
11
|
-
spec.summary = ''
|
12
|
-
spec.description = ''
|
13
|
-
spec.homepage = '
|
11
|
+
spec.summary = 'A Ruby interface to the PushBots API'
|
12
|
+
spec.description = 'Register, Push to and get information about devices on your account.'
|
13
|
+
spec.homepage = 'https://github.com/push_bot'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
|
16
15
|
spec.files = `git ls-files -z`.split("\x0")
|
17
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
@@ -20,5 +19,6 @@ Gem::Specification.new do |spec|
|
|
20
19
|
|
21
20
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
21
|
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
23
23
|
spec.add_runtime_dependency 'typhoeus', '~> 0.6'
|
24
24
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PushBot::Device do
|
4
|
+
let(:user_token) { 'user token' }
|
5
|
+
|
6
|
+
subject { described_class.new(user_token, :ios) }
|
7
|
+
|
8
|
+
let(:request) { double(PushBot::Request) }
|
9
|
+
|
10
|
+
describe '#add' do
|
11
|
+
let(:message) { 'Push Message' }
|
12
|
+
let(:options) { { :extra => 'value' } }
|
13
|
+
|
14
|
+
let(:add) { subject.add(options) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(PushBot::Request).to receive(:new).with(:deviceToken).and_return(request)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should send the given attributes' do
|
21
|
+
expect(request).to receive(:put).with(nil, hash_including(:token => 'user token', :platform => '0'))
|
22
|
+
|
23
|
+
add
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should send the extra attributes' do
|
27
|
+
expect(request).to receive(:put).with(anything, hash_including(:extra => 'value'))
|
28
|
+
|
29
|
+
add
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'when given multiple tokens' do
|
33
|
+
let(:user_token) { %w(abc 123) }
|
34
|
+
|
35
|
+
it 'should send the batch request' do
|
36
|
+
expect(request).to receive(:put).with(:batch, hash_including(:tokens => %w(abc 123), :platform => '0'))
|
37
|
+
|
38
|
+
add
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should not send the token' do
|
42
|
+
expect(request).to receive(:put).with(anything, hash_excluding(:token))
|
43
|
+
|
44
|
+
add
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#info' do
|
50
|
+
let(:info) { subject.info }
|
51
|
+
|
52
|
+
before do
|
53
|
+
allow(PushBot::Request).to receive(:new).with(:deviceToken).and_return(request)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should send request the information' do
|
57
|
+
expect(request).to receive(:get).with(:one, hash_including(:token => 'user token'))
|
58
|
+
|
59
|
+
info
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#remove' do
|
64
|
+
let(:remove) { subject.remove }
|
65
|
+
|
66
|
+
before do
|
67
|
+
allow(PushBot::Request).to receive(:new).with(:deviceToken).and_return(request)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should send request the remove' do
|
71
|
+
expect(request).to receive(:put).with(:del, hash_including(:token => 'user token', :platform => '0'))
|
72
|
+
|
73
|
+
remove
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PushBot::Push do
|
4
|
+
let(:user_token) { 'user token' }
|
5
|
+
|
6
|
+
subject { described_class.new(user_token, :ios) }
|
7
|
+
|
8
|
+
let(:request) { double(PushBot::Request) }
|
9
|
+
|
10
|
+
describe '#notify' do
|
11
|
+
let(:message) { 'Push Message' }
|
12
|
+
let(:options) { { } }
|
13
|
+
|
14
|
+
let(:notify) { subject.notify(message, options) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(PushBot::Request).to receive(:new).with(:push).and_return(request)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should send the given attributes' do
|
21
|
+
expect(request).to receive(:post).with(:one, hash_including(:token => 'user token', :platform => '0', :badge => '0', :sound => ''))
|
22
|
+
|
23
|
+
notify
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should send the extra attributes' do
|
27
|
+
expect(request).to receive(:post).with(anything, hash_including(:msg => message))
|
28
|
+
|
29
|
+
notify
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'when the token is not given' do
|
33
|
+
let(:user_token) { nil }
|
34
|
+
|
35
|
+
it 'should send the batch request' do
|
36
|
+
expect(request).to receive(:post).with(:all, hash_including(:msg => message, :platform => ['0']))
|
37
|
+
|
38
|
+
notify
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should not send the token' do
|
42
|
+
expect(request).to receive(:post).with(anything, hash_excluding(:token))
|
43
|
+
|
44
|
+
notify
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'push_bot'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.run_all_when_everything_filtered = true
|
5
|
+
config.profile_examples = 1
|
6
|
+
|
7
|
+
config.expect_with :rspec do |expectations|
|
8
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
9
|
+
end
|
10
|
+
|
11
|
+
config.mock_with :rspec do |mocks|
|
12
|
+
mocks.verify_partial_doubles = true
|
13
|
+
end
|
14
|
+
|
15
|
+
if config.files_to_run.one?
|
16
|
+
config.default_formatter = 'doc'
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: push_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Norton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
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'
|
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'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: typhoeus
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +66,7 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0.6'
|
55
|
-
description:
|
69
|
+
description: Register, Push to and get information about devices on your account.
|
56
70
|
email:
|
57
71
|
- brian.nort@gmail.com
|
58
72
|
executables: []
|
@@ -60,6 +74,7 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
77
|
+
- ".rspec"
|
63
78
|
- ".ruby-gemset"
|
64
79
|
- ".ruby-version"
|
65
80
|
- CONTRIBUTING.md
|
@@ -80,7 +95,10 @@ files:
|
|
80
95
|
- lib/push_bot/tag.rb
|
81
96
|
- lib/push_bot/version.rb
|
82
97
|
- push_bot.gemspec
|
83
|
-
|
98
|
+
- spec/lib/device_spec.rb
|
99
|
+
- spec/lib/push_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
homepage: https://github.com/push_bot
|
84
102
|
licenses:
|
85
103
|
- MIT
|
86
104
|
metadata: {}
|
@@ -103,5 +121,8 @@ rubyforge_project:
|
|
103
121
|
rubygems_version: 2.2.2
|
104
122
|
signing_key:
|
105
123
|
specification_version: 4
|
106
|
-
summary:
|
107
|
-
test_files:
|
124
|
+
summary: A Ruby interface to the PushBots API
|
125
|
+
test_files:
|
126
|
+
- spec/lib/device_spec.rb
|
127
|
+
- spec/lib/push_spec.rb
|
128
|
+
- spec/spec_helper.rb
|