passaporteweb-client 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/passaporte_web/notification.rb +15 -5
- data/lib/passaporte_web/version.rb +1 -1
- data/spec/passaporte_web/notification_spec.rb +12 -7
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -76,13 +76,15 @@ module PassaporteWeb
|
|
76
76
|
# target_url: "https://app.passaporteweb.com.br",
|
77
77
|
# scheduled_to: "2012-01-01 00:00:00"
|
78
78
|
# )
|
79
|
-
# TOSPEC
|
80
79
|
def initialize(attributes={})
|
81
80
|
set_attributes(attributes)
|
82
81
|
@errors = {}
|
83
82
|
end
|
84
83
|
|
85
|
-
#
|
84
|
+
# Creates the notification on PassaporteWeb. The +body+ and +destination+ attributes are required. The
|
85
|
+
# +auth_type+ parameter defaults to 'user', meaning the notification is sent by the authenticated
|
86
|
+
# Identity. If +auth_type+ is 'application', than the notification is sent by the authenticated
|
87
|
+
# application.
|
86
88
|
#
|
87
89
|
# API method: <tt>POST /notifications/api/</tt>
|
88
90
|
#
|
@@ -96,7 +98,7 @@ module PassaporteWeb
|
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
99
|
-
#
|
101
|
+
# Marks a notification as read.
|
100
102
|
#
|
101
103
|
# API method: <tt>PUT /notifications/api/:uuid/</tt>
|
102
104
|
#
|
@@ -118,19 +120,27 @@ module PassaporteWeb
|
|
118
120
|
false
|
119
121
|
end
|
120
122
|
|
121
|
-
#
|
123
|
+
# Excludes a newly created notification. Only notifications scheduled for the future can be deleted.
|
122
124
|
#
|
123
125
|
# API method: <tt>DELETE /notifications/api/:uuid/</tt>
|
124
126
|
#
|
125
127
|
# API documentation: https://app.passaporteweb.com.br/static/docs/notificacao.html#delete-notifications-api-uuid
|
126
128
|
def destroy
|
127
|
-
|
129
|
+
unless self.persisted?
|
130
|
+
@errors = {message: 'notification not persisted yet'}
|
131
|
+
return false
|
132
|
+
end
|
128
133
|
response = Http.delete("/notifications/api/#{self.uuid}/", {}, 'application')
|
129
134
|
raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 204
|
130
135
|
@errors = {}
|
131
136
|
@persisted = false
|
132
137
|
@destroyed = true
|
133
138
|
true
|
139
|
+
rescue *[RestClient::Forbidden] => e
|
140
|
+
@persisted = true
|
141
|
+
@destroyed = false
|
142
|
+
@errors = MultiJson.decode(e.response.body)
|
143
|
+
false
|
134
144
|
end
|
135
145
|
|
136
146
|
# Returns a hash with all attribures of the Notification.
|
@@ -202,17 +202,22 @@ describe PassaporteWeb::Notification do
|
|
202
202
|
end
|
203
203
|
|
204
204
|
describe "#destroy" do
|
205
|
+
let(:notification) { described_class.new(body: 'novinha', destination: 'a5868d14-6529-477a-9c6b-a09dd42a7cd2', scheduled_to: '2013-04-06') } # 2.days.from_now
|
205
206
|
it "should return false if the record is not persisted" do
|
206
|
-
notification = described_class.new(body: 'novinha', destination: 'a5868d14-6529-477a-9c6b-a09dd42a7cd2')
|
207
207
|
notification.destroy.should be_false
|
208
|
+
notification.errors.should == {message: 'notification not persisted yet'}
|
208
209
|
end
|
209
|
-
it "should destroy the notification on PassaporteWeb", vcr: true do
|
210
|
-
|
211
|
-
|
212
|
-
notification
|
213
|
-
notification.should_not be_nil
|
210
|
+
it "should destroy the notification on PassaporteWeb if the notification has not been read and is scheduled", vcr: true do
|
211
|
+
notification.save('application').should be_true
|
212
|
+
notification.read_at.should be_nil
|
213
|
+
notification.scheduled_to.should == "2013-04-06 00:00:00"
|
214
214
|
notification.destroy.should be_true
|
215
|
-
|
215
|
+
end
|
216
|
+
it "should not exclude non-scheduled notification", vcr: true do
|
217
|
+
notification.scheduled_to = nil
|
218
|
+
notification.save('application').should be_true
|
219
|
+
notification.destroy.should be_false
|
220
|
+
notification.errors.should == "Only scheduled notifications can be deleted via API"
|
216
221
|
end
|
217
222
|
end
|
218
223
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passaporteweb-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -276,7 +276,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
276
276
|
version: '0'
|
277
277
|
segments:
|
278
278
|
- 0
|
279
|
-
hash: -
|
279
|
+
hash: -2500500601371462639
|
280
280
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
281
281
|
none: false
|
282
282
|
requirements:
|
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
285
285
|
version: '0'
|
286
286
|
segments:
|
287
287
|
- 0
|
288
|
-
hash: -
|
288
|
+
hash: -2500500601371462639
|
289
289
|
requirements: []
|
290
290
|
rubyforge_project:
|
291
291
|
rubygems_version: 1.8.25
|