push_bot 0.4.1 → 0.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a18a2a8074b095dc89b6967c33cb7a01f75c549
4
- data.tar.gz: 238aa353d064729a861f86c4b5888fdf99fd3912
3
+ metadata.gz: 29191ae9aaf1405aba9fb433dd40c69c13e17a9d
4
+ data.tar.gz: 338bcfdea55c3dfc4e6f4ff6ae03435c6feaec58
5
5
  SHA512:
6
- metadata.gz: 8629003eec5a8a0ae9e8ec7efc4a4c4d0b6ab8a8002be35d6f7810ed12564e5f37e374e1c34d8136af53b66f78bed934a0e35289d3860087ed966eb05c5ae664
7
- data.tar.gz: 59a53aac57c678831e176312819ca7d6ed52226afbbd65b6903d84de030b4b3d21398ee7c9eb4e357e18a632e0aea9741cb3b0058ac2a9271d239076a51d6dc2
6
+ metadata.gz: 664ea271be56c169ea256034779495170cc128666c47412d882c137d3f36006e6bfaf383d04b4cb32e2e2e42e850289c1505a7f490f794a6a1da27bae899974b
7
+ data.tar.gz: fd52debda219d452b5ced857b5a9c17c37cf282ed9a8966d347320e3d151c55934c9c67fd6afe2051c0c00ec8834545d7a93e3492dfe27d6f59c5c41c1d11f70
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1.2
1
+ ruby-2.1.3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- push_bot (0.4.1)
4
+ push_bot (0.4.2)
5
5
  typhoeus (~> 0.6)
6
6
 
7
7
  GEM
@@ -1,5 +1,12 @@
1
1
  module PushBot
2
2
  class Device < Api
3
+ # Request a list of your registered devices
4
+ #
5
+ # @return {PushBot::Response}
6
+ def all
7
+ request.get(:all)
8
+ end
9
+
3
10
  # Add a specific user or batch of users to PushBots
4
11
  #
5
12
  # @param registration_options Any of the options available {https://pushbots.com/developer/rest Rest Docs @ PushBots}
@@ -18,14 +25,40 @@ module PushBot
18
25
  options[:tokens] = token
19
26
  end
20
27
 
21
- Request.new(:deviceToken).put(type, options)
28
+ request.put(type, options)
29
+ end
30
+
31
+ # Alias one user identifier to another
32
+ #
33
+ # @param alias_options Any of the options available {https://pushbots.com/developer/rest Rest Docs @ PushBots}
34
+ # @return {PushBot::Response}
35
+ def alias(alias_options={})
36
+ Request.new(:alias).put(nil, alias_options.merge(:token => token, :platform => platform))
22
37
  end
23
38
 
24
39
  # Retrieve information about the device with this token
25
40
  #
26
41
  # @return {PushBot::Response}
27
42
  def info
28
- Request.new(:deviceToken).get(:one, :token => token)
43
+ request.get(:one, :token => token)
44
+ end
45
+
46
+ # Set the users location to the specified latitude and longitude
47
+ #
48
+ # @param location two arguments of `latitude` and `longitude`
49
+ # @param location a two item array [`latitude` and `longitude`]
50
+ # @param location an object that responds to `lat` + `lng` OR `lat` + `lon` OR `latitude` + `longitude`
51
+ # @param location {PushBot::Location}
52
+ def at_location(*location)
53
+ lat, lng = PushBot::Location.parse(*location)
54
+
55
+ raise ArgumentError, 'latitude and longitude are required' unless lat && lng
56
+
57
+ Request.new(:geo).put(nil, :token => token, :platform => platform, :lat => lat, :lng => lng)
58
+ end
59
+
60
+ def removed
61
+ Request.new(:feedback).get
29
62
  end
30
63
 
31
64
  # Remove a specific user from PushBots
@@ -34,7 +67,13 @@ module PushBot
34
67
  def remove
35
68
  raise(ArgumentError, 'A token and platform is required for removal') unless token && token
36
69
 
37
- Request.new(:deviceToken).put(:del, :token => token, :platform => platform)
70
+ request.put(:del, :token => token, :platform => platform)
71
+ end
72
+
73
+ private
74
+
75
+ def request
76
+ Request.new(:deviceToken)
38
77
  end
39
78
  end
40
79
  end
@@ -1,5 +1,22 @@
1
1
  module PushBot
2
2
  class Location
3
+ attr_reader :lat, :lng
3
4
 
5
+ def initialize(lat, lng)
6
+ @lat = lat
7
+ @lng = lng
8
+ end
9
+
10
+ def self.parse(*location)
11
+ location.flatten!
12
+
13
+ return location if location.size == 2
14
+ location = location.first
15
+
16
+ return [location.lat, location.lng] if location.respond_to?(:lat) && location.respond_to?(:lng)
17
+ return [location.lat, location.lon] if location.respond_to?(:lat) && location.respond_to?(:lon)
18
+
19
+ [location.latitude, location.longitude] if location.respond_to?(:latitude) && location.respond_to?(:longitude)
20
+ end
4
21
  end
5
22
  end
@@ -4,15 +4,15 @@ module PushBot
4
4
  @base = base
5
5
  end
6
6
 
7
- def get(name, options)
7
+ def get(name=nil, options={})
8
8
  request(:get, name, options)
9
9
  end
10
10
 
11
- def post(name, options)
11
+ def post(name, options={})
12
12
  request(:post, name, options)
13
13
  end
14
14
 
15
- def put(name, options)
15
+ def put(name, options={})
16
16
  request(:put, name, options)
17
17
  end
18
18
 
@@ -1,3 +1,3 @@
1
1
  module PushBot
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -7,16 +7,26 @@ describe PushBot::Device do
7
7
 
8
8
  let(:request) { double(PushBot::Request) }
9
9
 
10
+ before do
11
+ allow(PushBot::Request).to receive(:new).with(:deviceToken).and_return(request)
12
+ end
13
+
14
+ describe '#all' do
15
+ let(:all) { subject.all }
16
+
17
+ it 'should list all of the' do
18
+ expect(request).to receive(:get).with(:all)
19
+
20
+ all
21
+ end
22
+ end
23
+
10
24
  describe '#add' do
11
25
  let(:message) { 'Push Message' }
12
26
  let(:options) { { :extra => 'value' } }
13
27
 
14
28
  let(:add) { subject.add(options) }
15
29
 
16
- before do
17
- allow(PushBot::Request).to receive(:new).with(:deviceToken).and_return(request)
18
- end
19
-
20
30
  it 'should send the given attributes' do
21
31
  expect(request).to receive(:put).with(nil, hash_including(:token => 'user token', :platform => '0'))
22
32
 
@@ -46,12 +56,20 @@ describe PushBot::Device do
46
56
  end
47
57
  end
48
58
 
49
- describe '#info' do
50
- let(:info) { subject.info }
59
+ describe '#alias' do
60
+ let(:options) { { :alias => 'john@example.com' } }
61
+ let(:alias_) { subject.alias(options) }
51
62
 
52
- before do
53
- allow(PushBot::Request).to receive(:new).with(:deviceToken).and_return(request)
63
+ it 'should send request the remove' do
64
+ expect(PushBot::Request).to receive(:new).with(:alias).and_return(request)
65
+ expect(request).to receive(:put).with(nil, hash_including(:alias => 'john@example.com', :token => 'user token', :platform => '0'))
66
+
67
+ alias_
54
68
  end
69
+ end
70
+
71
+ describe '#info' do
72
+ let(:info) { subject.info }
55
73
 
56
74
  it 'should send request the information' do
57
75
  expect(request).to receive(:get).with(:one, hash_including(:token => 'user token'))
@@ -60,13 +78,95 @@ describe PushBot::Device do
60
78
  end
61
79
  end
62
80
 
63
- describe '#remove' do
64
- let(:remove) { subject.remove }
81
+ describe '#at_location' do
82
+ let(:location) { [37, -122] }
83
+ let(:at_location) { subject.at_location(*location) }
65
84
 
66
85
  before do
67
- allow(PushBot::Request).to receive(:new).with(:deviceToken).and_return(request)
86
+ allow(PushBot::Request).to receive(:new).with(:geo).and_return(request)
87
+ end
88
+
89
+ it 'should send the latitude and longitude' do
90
+ expect(request).to receive(:put).with(nil, hash_including(:lat => 37, :lng => -122))
91
+
92
+ at_location
93
+ end
94
+
95
+ describe 'when the location is a push bot location' do
96
+ let(:location) { [PushBot::Location.new(37, -122)] }
97
+
98
+ it 'should send the latitude and longitude' do
99
+ expect(request).to receive(:put).with(nil, hash_including(:lat => 37, :lng => -122))
100
+
101
+ at_location
102
+ end
103
+ end
104
+
105
+ describe 'when the location is an array' do
106
+ let(:location) { [[37, -122]] }
107
+
108
+ it 'should send the latitude and longitude' do
109
+ expect(request).to receive(:put).with(nil, hash_including(:lat => 37, :lng => -122))
110
+
111
+ at_location
112
+ end
113
+ end
114
+
115
+ describe 'when the location is an object{#lat,#lng}' do
116
+ let(:location) { [double(:geo, :lat => 37, :lng => -122)] }
117
+
118
+ it 'should send the latitude and longitude' do
119
+ expect(request).to receive(:put).with(nil, hash_including(:lat => 37, :lng => -122))
120
+
121
+ at_location
122
+ end
68
123
  end
69
124
 
125
+ describe 'when the location is an object{#lat,#lon}' do
126
+ let(:location) { [double(:geo, :lat => 37, :lon => -122)] }
127
+
128
+ it 'should send the latitude and longitude' do
129
+ expect(request).to receive(:put).with(nil, hash_including(:lat => 37, :lng => -122))
130
+
131
+ at_location
132
+ end
133
+ end
134
+
135
+ describe 'when the location is an object{#latitude,#longitude}' do
136
+ let(:location) { [double(:geo, :latitude => 37, :longitude => -122)] }
137
+
138
+ it 'should send the latitude and longitude' do
139
+ expect(request).to receive(:put).with(nil, hash_including(:lat => 37, :lng => -122))
140
+
141
+ at_location
142
+ end
143
+ end
144
+
145
+ describe 'when the location does not exist' do
146
+ let(:location) { [1] }
147
+
148
+ it 'should have problems' do
149
+ expect {
150
+ at_location
151
+ }.to raise_error(ArgumentError, /latitude and longitude/)
152
+ end
153
+ end
154
+ end
155
+
156
+ describe '#removed' do
157
+ let(:removed) { subject.removed }
158
+
159
+ it 'should list the removed devices' do
160
+ expect(PushBot::Request).to receive(:new).with(:feedback).and_return(request)
161
+ expect(request).to receive(:get)
162
+
163
+ removed
164
+ end
165
+ end
166
+
167
+ describe '#remove' do
168
+ let(:remove) { subject.remove }
169
+
70
170
  it 'should send request the remove' do
71
171
  expect(request).to receive(:put).with(:del, hash_including(:token => 'user token', :platform => '0'))
72
172
 
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.1
4
+ version: 0.4.2
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-07 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler