passaporteweb-client 0.0.12 → 0.0.13

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- passaporteweb-client (0.0.12)
4
+ passaporteweb-client (0.0.13)
5
5
  multi_json (~> 1.7.1)
6
6
  rest-client (~> 1.6.7)
7
7
 
@@ -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
- # TODOC
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
- # TODOC
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
- # TODOC
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
- return false unless self.persisted?
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.
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module PassaporteWeb
3
- VERSION = "0.0.12"
3
+ VERSION = "0.0.13"
4
4
  end
@@ -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
- PassaporteWeb.configuration.user_token = "3e4470e59d76f748e0081b514da62ed621a893c87facd4a6"
211
- count = described_class.count(true)
212
- notification = described_class.find_all(1,20,nil,true).notifications.last
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
- described_class.count(true).should == (count - 1)
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.12
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: -214247969600102075
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: -214247969600102075
288
+ hash: -2500500601371462639
289
289
  requirements: []
290
290
  rubyforge_project:
291
291
  rubygems_version: 1.8.25