passaporteweb-client 0.0.11 → 0.0.12
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/.travis.yml +2 -1
- data/Gemfile.lock +1 -1
- data/README.rdoc +1 -1
- data/lib/passaporte_web/notification.rb +31 -29
- data/lib/passaporte_web/version.rb +1 -1
- data/spec/passaporte_web/notification_spec.rb +39 -13
- metadata +3 -3
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -43,7 +43,7 @@ Or install it yourself as:
|
|
43
43
|
* {GET /notifications/api/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#get-notifications-api] ==> PassaporteWeb::Notification.find_all
|
44
44
|
* {POST /notifications/api/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#post-notifications-api] ==> PassaporteWeb::Notification#save
|
45
45
|
* {GET /notifications/api/count/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#get-notifications-api-count] ==> PassaporteWeb::Notification.count
|
46
|
-
* {PUT /notifications/api/:uuid/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#put-notifications-api-uuid] ==> PassaporteWeb::Notification#
|
46
|
+
* {PUT /notifications/api/:uuid/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#put-notifications-api-uuid] ==> PassaporteWeb::Notification#read!
|
47
47
|
* {DELETE /notifications/api/:uuid/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#delete-notifications-api-uuid] ==> PassaporteWeb::Notification#destroy
|
48
48
|
* {Gerência de contas}[https://app.passaporteweb.com.br/static/docs/account_manager.html]
|
49
49
|
* {PUT /organizations/api/activate/}[https://app.passaporteweb.com.br/static/docs/account_manager.html#put-organizations-api-activate] ==> (not implemented yet)
|
@@ -84,17 +84,38 @@ module PassaporteWeb
|
|
84
84
|
|
85
85
|
# TODOC
|
86
86
|
#
|
87
|
-
# API
|
88
|
-
# * <tt>POST /notifications/api/</tt> (on create)
|
89
|
-
# * <tt>PUT /notifications/api/:uuid/</tt> (on update)
|
87
|
+
# API method: <tt>POST /notifications/api/</tt>
|
90
88
|
#
|
91
|
-
# API documentation:
|
92
|
-
# * https://app.passaporteweb.com.br/static/docs/notificacao.html#post-notifications-api
|
93
|
-
# * https://app.passaporteweb.com.br/static/docs/notificacao.html#put-notifications-api-uuid
|
94
|
-
# TOSPEC
|
95
|
-
# TOSPEC
|
89
|
+
# API documentation: https://app.passaporteweb.com.br/static/docs/notificacao.html#post-notifications-api
|
96
90
|
def save(auth_type='user')
|
97
|
-
self.persisted?
|
91
|
+
if self.persisted?
|
92
|
+
@errors = {message: 'notification already persisted, call #read! to mark it as read'}
|
93
|
+
false
|
94
|
+
else
|
95
|
+
create(auth_type)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# TODOC
|
100
|
+
#
|
101
|
+
# API method: <tt>PUT /notifications/api/:uuid/</tt>
|
102
|
+
#
|
103
|
+
# API documentation: https://app.passaporteweb.com.br/static/docs/notificacao.html#put-notifications-api-uuid
|
104
|
+
def read!
|
105
|
+
raise 'notification not persisted' unless self.persisted?
|
106
|
+
unless self.read_at.nil?
|
107
|
+
@errors = {message: 'notification already read'}
|
108
|
+
return false
|
109
|
+
end
|
110
|
+
response = Http.put("/notifications/api/#{self.uuid}/", {}, {}, 'user')
|
111
|
+
raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 200
|
112
|
+
attributes_hash = MultiJson.decode(response.body)
|
113
|
+
set_attributes(attributes_hash)
|
114
|
+
@errors = {}
|
115
|
+
true
|
116
|
+
rescue *[RestClient::BadRequest] => e
|
117
|
+
@errors = MultiJson.decode(e.response.body)
|
118
|
+
false
|
98
119
|
end
|
99
120
|
|
100
121
|
# TODOC
|
@@ -102,10 +123,9 @@ module PassaporteWeb
|
|
102
123
|
# API method: <tt>DELETE /notifications/api/:uuid/</tt>
|
103
124
|
#
|
104
125
|
# API documentation: https://app.passaporteweb.com.br/static/docs/notificacao.html#delete-notifications-api-uuid
|
105
|
-
# TOSPEC
|
106
126
|
def destroy
|
107
127
|
return false unless self.persisted?
|
108
|
-
response = Http.delete(
|
128
|
+
response = Http.delete("/notifications/api/#{self.uuid}/", {}, 'application')
|
109
129
|
raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 204
|
110
130
|
@errors = {}
|
111
131
|
@persisted = false
|
@@ -151,24 +171,6 @@ module PassaporteWeb
|
|
151
171
|
false
|
152
172
|
end
|
153
173
|
|
154
|
-
def update
|
155
|
-
# TODO validar atributos?
|
156
|
-
response = Http.put(
|
157
|
-
"/notifications/api/#{self.uuid}/",
|
158
|
-
{},
|
159
|
-
{},
|
160
|
-
'user'
|
161
|
-
)
|
162
|
-
raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 200
|
163
|
-
attributes_hash = MultiJson.decode(response.body)
|
164
|
-
set_attributes(attributes_hash)
|
165
|
-
@errors = {}
|
166
|
-
true
|
167
|
-
rescue *[RestClient::BadRequest] => e
|
168
|
-
@errors = MultiJson.decode(e.response.body)
|
169
|
-
false
|
170
|
-
end
|
171
|
-
|
172
174
|
def create_body
|
173
175
|
self.attributes.select { |key, value| CREATABLE_ATTRIBUTES.include?(key) && (!value.nil? && !value.to_s.empty?) }
|
174
176
|
end
|
@@ -153,6 +153,11 @@ describe PassaporteWeb::Notification do
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
context "on failure" do
|
156
|
+
it "should return false an do nothing if the Notification is already persisted" do
|
157
|
+
PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
|
158
|
+
notification = described_class.find_all(1,20,nil,true).notifications.last
|
159
|
+
notification.save.should be_false
|
160
|
+
end
|
156
161
|
it "should return false and set the errors with the reason for the failure, authenticated as the user" do
|
157
162
|
PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
|
158
163
|
notification.target_url = 'lalalala'
|
@@ -172,22 +177,43 @@ describe PassaporteWeb::Notification do
|
|
172
177
|
end
|
173
178
|
end
|
174
179
|
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#read!", vcr: true do
|
183
|
+
let(:notification) { described_class.find_all.notifications.last }
|
184
|
+
before(:each) do
|
185
|
+
PassaporteWeb.configuration.user_token = "3e4470e59d76f748e0081b514da62ed621a893c87facd4a6"
|
186
|
+
end
|
187
|
+
context "on success" do
|
188
|
+
it "should mark the Notification as read" do
|
189
|
+
notification.read_at.should be_nil
|
190
|
+
notification.read!.should be_true
|
191
|
+
notification.read_at.should_not be_nil
|
186
192
|
end
|
187
|
-
|
188
|
-
|
193
|
+
end
|
194
|
+
context "on failure" do
|
195
|
+
it "should return false if the notification is already read" do
|
196
|
+
read_notification = described_class.find_all(1,20,nil,true).notifications.detect { |n| !n.read_at.nil? }
|
197
|
+
read_notification.read_at.should_not be_nil
|
198
|
+
read_notification.read!.should be_false
|
199
|
+
read_notification.errors.should == {message: 'notification already read'}
|
189
200
|
end
|
190
201
|
end
|
191
202
|
end
|
192
203
|
|
204
|
+
describe "#destroy" do
|
205
|
+
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
|
+
notification.destroy.should be_false
|
208
|
+
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
|
214
|
+
notification.destroy.should be_true
|
215
|
+
described_class.count(true).should == (count - 1)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
193
219
|
end
|
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.12
|
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: -214247969600102075
|
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: -214247969600102075
|
289
289
|
requirements: []
|
290
290
|
rubyforge_project:
|
291
291
|
rubygems_version: 1.8.25
|