passaporteweb-client 0.0.10 → 0.0.11
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 +1 -1
- data/README.rdoc +5 -5
- data/lib/passaporte_web.rb +1 -0
- data/lib/passaporte_web/notification.rb +184 -0
- data/lib/passaporte_web/version.rb +1 -1
- data/passaporteweb-client.gemspec +1 -1
- data/spec/passaporte_web/notification_spec.rb +193 -0
- metadata +8 -5
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -40,11 +40,11 @@ Or install it yourself as:
|
|
40
40
|
* {Autenticação de usuários}[https://app.passaporteweb.com.br/static/docs/usuarios.html#autenticacao-de-usuarios]
|
41
41
|
* {GET /accounts/api/auth/}[https://app.passaporteweb.com.br/static/docs/usuarios.html#get-accounts-api-auth] ==> PassaporteWeb::Identity.authenticate or PassaporteWeb::Identity#authenticate
|
42
42
|
* {Notificações}[https://app.passaporteweb.com.br/static/docs/notificacao.html]
|
43
|
-
* {GET /notifications/api/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#get-notifications-api] ==>
|
44
|
-
* {POST /notifications/api/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#post-notifications-api] ==>
|
45
|
-
* {GET /notifications/api/count/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#get-notifications-api-count] ==>
|
46
|
-
* {PUT /notifications/api/:uuid/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#put-notifications-api-uuid] ==>
|
47
|
-
* {DELETE /notifications/api/:uuid/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#delete-notifications-api-uuid] ==>
|
43
|
+
* {GET /notifications/api/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#get-notifications-api] ==> PassaporteWeb::Notification.find_all
|
44
|
+
* {POST /notifications/api/}[https://app.passaporteweb.com.br/static/docs/notificacao.html#post-notifications-api] ==> PassaporteWeb::Notification#save
|
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#save
|
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)
|
50
50
|
* {GET /organizations/api/accounts/}[https://app.passaporteweb.com.br/static/docs/account_manager.html#get-organizations-api-accounts] ==> PassaporteWeb::ServiceAccount.find_all
|
data/lib/passaporte_web.rb
CHANGED
@@ -0,0 +1,184 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module PassaporteWeb
|
3
|
+
|
4
|
+
# Represents the Notifications of PassaporteWeb.
|
5
|
+
class Notification
|
6
|
+
include Attributable
|
7
|
+
|
8
|
+
ATTRIBUTES = [:body, :target_url, :uuid, :absolute_url, :scheduled_to, :sender_data, :read_at, :notification_type, :destination]
|
9
|
+
CREATABLE_ATTRIBUTES = [:body, :target_url, :scheduled_to, :destination]
|
10
|
+
UPDATEABLE_ATTRIBUTES = []
|
11
|
+
|
12
|
+
attr_accessor *(CREATABLE_ATTRIBUTES + UPDATEABLE_ATTRIBUTES)
|
13
|
+
attr_reader *(ATTRIBUTES - (CREATABLE_ATTRIBUTES + UPDATEABLE_ATTRIBUTES))
|
14
|
+
attr_reader :errors
|
15
|
+
|
16
|
+
# Finds all Notifications destined to the authenticated user, paginated. By default returns 20 notifications
|
17
|
+
# per request, starting at "page" 1. Returns an OpenStruct object with two attributes <tt>notifications</tt>
|
18
|
+
# and <tt>meta</tt>. <tt>notifications</tt> is an array of Notification instances or an empty array
|
19
|
+
# if no Notifications are found. <tt>meta</tt> is an OpenStruct object with information about limit and available
|
20
|
+
# pagination values, to use in subsequent calls to <tt>.find_all</tt>. Raises a <tt>RestClient::ResourceNotFound</tt>
|
21
|
+
# exception if the requested page does not exist. All method parameters are optional.
|
22
|
+
#
|
23
|
+
# API method: <tt>GET /notifications/api/</tt>
|
24
|
+
#
|
25
|
+
# API documentation: https://app.passaporteweb.com.br/static/docs/notificacao.html#get-notifications-api
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
# data = PassaporteWeb::Notification.find_all
|
29
|
+
# data.notifications # => [notification1, notification2, ...]
|
30
|
+
# data.meta # => #<OpenStruct limit=20, next_page=2, prev_page=nil, first_page=1, last_page=123>
|
31
|
+
# data.meta.limit # => 20
|
32
|
+
# data.meta.next_page # => 2
|
33
|
+
# data.meta.prev_page # => nil
|
34
|
+
# data.meta.first_page # => 1
|
35
|
+
# data.meta.last_page # => 123
|
36
|
+
def self.find_all(page=1, limit=20, since=nil, show_read=false, ordering="oldest-first")
|
37
|
+
since = since.strftime('%Y-%m-%d') if since && since.respond_to?(:strftime)
|
38
|
+
params = {
|
39
|
+
page: page, limit: limit, since: since, show_read: show_read, ordering: ordering
|
40
|
+
}.reject { |k,v| v.nil? || v.to_s.empty? }
|
41
|
+
response = Http.get("/notifications/api/", params, 'user')
|
42
|
+
raw_data = MultiJson.decode(response.body)
|
43
|
+
result_hash = {}
|
44
|
+
result_hash[:notifications] = raw_data.map { |hash| load_notification(hash) }
|
45
|
+
result_hash[:meta] = PassaporteWeb::Helpers.meta_links_from_header(response.headers[:link])
|
46
|
+
PassaporteWeb::Helpers.convert_to_ostruct_recursive(result_hash)
|
47
|
+
rescue *[RestClient::BadRequest] => e
|
48
|
+
MultiJson.decode(e.response.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the number of notifications available for the authenticated user. All parameters
|
52
|
+
# are optional.
|
53
|
+
#
|
54
|
+
# API method: <tt>GET /notifications/api/count/</tt>
|
55
|
+
#
|
56
|
+
# API documentation: https://app.passaporteweb.com.br/static/docs/notificacao.html#get-notifications-api-count
|
57
|
+
def self.count(show_read=false, since=nil)
|
58
|
+
since = since.strftime('%Y-%m-%d') if since && since.respond_to?(:strftime)
|
59
|
+
params = {
|
60
|
+
since: since, show_read: show_read
|
61
|
+
}.reject { |k,v| v.nil? || v.to_s.empty? }
|
62
|
+
response = Http.get("/notifications/api/count/", params, 'user')
|
63
|
+
data = MultiJson.decode(response.body)
|
64
|
+
Integer(data['count'])
|
65
|
+
rescue *[RestClient::BadRequest] => e
|
66
|
+
MultiJson.decode(e.response.body)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Instanciates a new Notification with the supplied attributes.
|
70
|
+
#
|
71
|
+
# Example:
|
72
|
+
#
|
73
|
+
# notification = PassaporteWeb::Notification.new(
|
74
|
+
# destination: "ac3540c7-5453-424d-bdfd-8ef2d9ff78df",
|
75
|
+
# body: "Feliz ano novo!",
|
76
|
+
# target_url: "https://app.passaporteweb.com.br",
|
77
|
+
# scheduled_to: "2012-01-01 00:00:00"
|
78
|
+
# )
|
79
|
+
# TOSPEC
|
80
|
+
def initialize(attributes={})
|
81
|
+
set_attributes(attributes)
|
82
|
+
@errors = {}
|
83
|
+
end
|
84
|
+
|
85
|
+
# TODOC
|
86
|
+
#
|
87
|
+
# API methods:
|
88
|
+
# * <tt>POST /notifications/api/</tt> (on create)
|
89
|
+
# * <tt>PUT /notifications/api/:uuid/</tt> (on update)
|
90
|
+
#
|
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
|
96
|
+
def save(auth_type='user')
|
97
|
+
self.persisted? ? update : create(auth_type)
|
98
|
+
end
|
99
|
+
|
100
|
+
# TODOC
|
101
|
+
#
|
102
|
+
# API method: <tt>DELETE /notifications/api/:uuid/</tt>
|
103
|
+
#
|
104
|
+
# API documentation: https://app.passaporteweb.com.br/static/docs/notificacao.html#delete-notifications-api-uuid
|
105
|
+
# TOSPEC
|
106
|
+
def destroy
|
107
|
+
return false unless self.persisted?
|
108
|
+
response = Http.delete('/notifications/api/:uuid/')
|
109
|
+
raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 204
|
110
|
+
@errors = {}
|
111
|
+
@persisted = false
|
112
|
+
@destroyed = true
|
113
|
+
true
|
114
|
+
end
|
115
|
+
|
116
|
+
# Returns a hash with all attribures of the Notification.
|
117
|
+
def attributes
|
118
|
+
ATTRIBUTES.inject({}) do |hash, attribute|
|
119
|
+
hash[attribute] = self.send(attribute)
|
120
|
+
hash
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def persisted?
|
125
|
+
@persisted == true && !self.uuid.nil?
|
126
|
+
end
|
127
|
+
|
128
|
+
def destroyed?
|
129
|
+
@destroyed == true
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def create(auth_type)
|
135
|
+
# TODO validar atributos?
|
136
|
+
response = Http.post(
|
137
|
+
'/notifications/api/',
|
138
|
+
create_body,
|
139
|
+
{},
|
140
|
+
auth_type
|
141
|
+
)
|
142
|
+
raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 201
|
143
|
+
attributes_hash = MultiJson.decode(response.body)
|
144
|
+
set_attributes(attributes_hash)
|
145
|
+
@persisted = true
|
146
|
+
@errors = {}
|
147
|
+
true
|
148
|
+
rescue *[RestClient::BadRequest] => e
|
149
|
+
@persisted = false
|
150
|
+
@errors = MultiJson.decode(e.response.body)
|
151
|
+
false
|
152
|
+
end
|
153
|
+
|
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
|
+
def create_body
|
173
|
+
self.attributes.select { |key, value| CREATABLE_ATTRIBUTES.include?(key) && (!value.nil? && !value.to_s.empty?) }
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.load_notification(attributes)
|
177
|
+
notification = self.new(attributes)
|
178
|
+
notification.instance_variable_set(:@persisted, true)
|
179
|
+
notification
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.name = "passaporteweb-client"
|
10
10
|
spec.version = PassaporteWeb::VERSION
|
11
11
|
spec.authors = ["Rodrigo Tassinari de Oliveira", "Rodrigo Martins"]
|
12
|
-
spec.email = ["rodrigo@pittlandia.net", "rodrigo.tassinari@myfreecomm.com.br", "rodrigo
|
12
|
+
spec.email = ["rodrigo@pittlandia.net", "rodrigo.tassinari@myfreecomm.com.br", "rodrigo@rrmartins.com", "rodrigo.martins@myfreecomm.com.br"]
|
13
13
|
spec.description = %q{A Ruby client for the PassaporteWeb REST API}
|
14
14
|
spec.summary = %q{A Ruby client for the PassaporteWeb REST API: https://app.passaporteweb.com.br/static/docs/}
|
15
15
|
spec.homepage = "https://github.com/myfreecomm/passaporteweb-client-ruby"
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe PassaporteWeb::Notification do
|
5
|
+
|
6
|
+
describe "constants" do
|
7
|
+
it { PassaporteWeb::Notification::ATTRIBUTES.should == [:body, :target_url, :uuid, :absolute_url, :scheduled_to, :sender_data, :read_at, :notification_type, :destination] }
|
8
|
+
it { PassaporteWeb::Notification::CREATABLE_ATTRIBUTES.should == [:body, :target_url, :scheduled_to, :destination] }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".new" do
|
12
|
+
it "should instanciate an empty object" do
|
13
|
+
notification = PassaporteWeb::Notification.new
|
14
|
+
notification.should_not be_persisted
|
15
|
+
notification.attributes.should == {:body=>nil, :target_url=>nil, :uuid=>nil, :absolute_url=>nil, :scheduled_to=>nil, :sender_data=>nil, :read_at=>nil, :notification_type=>nil, :destination=>nil}
|
16
|
+
notification.uuid.should be_nil
|
17
|
+
notification.destination.should be_nil
|
18
|
+
notification.body.should be_nil
|
19
|
+
notification.target_url.should be_nil
|
20
|
+
notification.scheduled_to.should be_nil
|
21
|
+
notification.absolute_url.should be_nil
|
22
|
+
notification.sender_data.should be_nil
|
23
|
+
notification.read_at.should be_nil
|
24
|
+
notification.notification_type.should be_nil
|
25
|
+
end
|
26
|
+
it "should instanciate an object with attributes set" do
|
27
|
+
attributes = {
|
28
|
+
"destination" => "ac3540c7-5453-424d-bdfd-8ef2d9ff78df",
|
29
|
+
"body" => "Feliz ano novo!",
|
30
|
+
"target_url" => "https://app.passaporteweb.com.br",
|
31
|
+
"scheduled_to" => "2012-01-01 00:00:00"
|
32
|
+
}
|
33
|
+
notification = PassaporteWeb::Notification.new(attributes)
|
34
|
+
notification.should_not be_persisted
|
35
|
+
notification.uuid.should be_nil
|
36
|
+
notification.attributes.should == {:body=>"Feliz ano novo!", :target_url=>"https://app.passaporteweb.com.br", :uuid=>nil, :absolute_url=>nil, :scheduled_to=>"2012-01-01 00:00:00", :sender_data=>nil, :read_at=>nil, :notification_type=>nil, :destination=>"ac3540c7-5453-424d-bdfd-8ef2d9ff78df"}
|
37
|
+
notification.destination.should == "ac3540c7-5453-424d-bdfd-8ef2d9ff78df"
|
38
|
+
notification.body.should == "Feliz ano novo!"
|
39
|
+
notification.target_url.should == "https://app.passaporteweb.com.br"
|
40
|
+
notification.scheduled_to.should == "2012-01-01 00:00:00"
|
41
|
+
notification.absolute_url.should be_nil
|
42
|
+
notification.sender_data.should be_nil
|
43
|
+
notification.read_at.should be_nil
|
44
|
+
notification.notification_type.should be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".find_all", :vcr => true do
|
49
|
+
before(:each) do
|
50
|
+
PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
|
51
|
+
end
|
52
|
+
context "on success" do
|
53
|
+
it "should return the first 20 notifications for the authenticated user, along with pagination information" do
|
54
|
+
data = PassaporteWeb::Notification.find_all
|
55
|
+
|
56
|
+
notifications = data.notifications
|
57
|
+
notifications.size.should == 2
|
58
|
+
notifications.map { |n| n.instance_of?(described_class) }.uniq.should be_true
|
59
|
+
n1, n2 = notifications
|
60
|
+
n1.body.should == '"oioioi"' # TODO why? was it created like this?
|
61
|
+
n2.body.should == '"oioioisss"'
|
62
|
+
n1.uuid.should == "2ca046be-0178-418d-80ac-3a334c264009"
|
63
|
+
n2.uuid.should == "11f40530-2de0-471d-b1f7-ff39ea21363f"
|
64
|
+
|
65
|
+
meta = data.meta
|
66
|
+
meta.limit.should == 20
|
67
|
+
meta.next_page.should == nil
|
68
|
+
meta.prev_page.should == nil
|
69
|
+
meta.first_page.should == 1
|
70
|
+
meta.last_page.should == 1
|
71
|
+
end
|
72
|
+
it "should return notifications for the authenticated user according to params, along with pagination information" do
|
73
|
+
data = PassaporteWeb::Notification.find_all(2, 1, nil, true, "newest-first")
|
74
|
+
|
75
|
+
notifications = data.notifications
|
76
|
+
notifications.size.should == 1
|
77
|
+
notifications.map { |n| n.instance_of?(described_class) }.uniq.should be_true
|
78
|
+
n1 = notifications.first
|
79
|
+
n1.body.should == '"oioioi"' # TODO why? was it created like this?
|
80
|
+
n1.uuid.should == "2ca046be-0178-418d-80ac-3a334c264009"
|
81
|
+
|
82
|
+
meta = data.meta
|
83
|
+
meta.limit.should == 1
|
84
|
+
meta.next_page.should == nil
|
85
|
+
meta.prev_page.should == 1
|
86
|
+
meta.first_page.should == 1
|
87
|
+
meta.last_page.should == 2
|
88
|
+
end
|
89
|
+
end
|
90
|
+
context "on failure" do
|
91
|
+
it "400 Bad Request" do
|
92
|
+
PassaporteWeb::Notification.find_all(1, 20, nil, true, 'lalala').should == {"ordering"=>["Faça uma escolha válida. lalala não está disponível."]}
|
93
|
+
end
|
94
|
+
it "404 Not Found" do
|
95
|
+
expect {
|
96
|
+
PassaporteWeb::Notification.find_all(1_000_000)
|
97
|
+
}.to raise_error(RestClient::ResourceNotFound, '404 Resource Not Found')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe ".count", :vcr => true do
|
103
|
+
before(:each) do
|
104
|
+
PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
|
105
|
+
end
|
106
|
+
context "on success" do
|
107
|
+
it "should return count of notifications for the authenticated user" do
|
108
|
+
PassaporteWeb::Notification.count.should == 2
|
109
|
+
end
|
110
|
+
it "should return count of notifications for the authenticated user, according to params" do
|
111
|
+
PassaporteWeb::Notification.count(true, '2013-04-02').should == 2
|
112
|
+
end
|
113
|
+
end
|
114
|
+
context "on failure" do
|
115
|
+
it "it should return an error message if an invalid parameter is sent" do
|
116
|
+
PassaporteWeb::Notification.count(false, "lalala").should == {"since"=>["Informe uma data/hora válida."]}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#save", vcr: true do
|
122
|
+
context "on create" do
|
123
|
+
let(:notification) { described_class.new(body: 'feliz aniversário!', target_url: 'http://pittlandia.net', scheduled_to: '2013-04-19 10:50:19', destination: 'a5868d14-6529-477a-9c6b-a09dd42a7cd2') }
|
124
|
+
context "on success" do
|
125
|
+
it "should create the Notification on PassaporteWeb, authenticated as the user" do
|
126
|
+
PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
|
127
|
+
notification.should_not be_persisted
|
128
|
+
notification.save.should be_true # by default authenticates as the user
|
129
|
+
notification.should be_persisted
|
130
|
+
notification.uuid.should_not be_nil
|
131
|
+
notification.absolute_url.should_not be_nil
|
132
|
+
notification.destination.should be_nil # FIXME is this right? shouldn't it be a5868d14-6529-477a-9c6b-a09dd42a7cd2 ???
|
133
|
+
notification.scheduled_to.should == '2013-04-19 00:00:00' # FIXME is this right? shouldn't it be 2013-04-19 10:50:19 ???
|
134
|
+
notification.body.should == 'feliz aniversário!'
|
135
|
+
notification.target_url.should == 'http://pittlandia.net/' # PW added the trailing slash, WTF?
|
136
|
+
notification.sender_data.should == {"name" => "Rodrigo Martins", "uuid" => "385f5f3c-8d33-4b95-9e0d-e87962985244"}
|
137
|
+
notification.read_at.should be_nil
|
138
|
+
notification.notification_type.should be_nil
|
139
|
+
end
|
140
|
+
it "should create the Notification on PassaporteWeb, authenticated as the application" do
|
141
|
+
notification.should_not be_persisted
|
142
|
+
notification.save('application').should be_true
|
143
|
+
notification.should be_persisted
|
144
|
+
notification.uuid.should_not be_nil
|
145
|
+
notification.absolute_url.should_not be_nil
|
146
|
+
notification.destination.should be_nil # FIXME is this right? shouldn't it be a5868d14-6529-477a-9c6b-a09dd42a7cd2 ???
|
147
|
+
notification.scheduled_to.should == '2013-04-19 00:00:00' # FIXME is this right? shouldn't it be 2013-04-19 10:50:19 ???
|
148
|
+
notification.body.should == 'feliz aniversário!'
|
149
|
+
notification.target_url.should == 'http://pittlandia.net/' # PW added the trailing slash, WTF?
|
150
|
+
notification.sender_data.should == {"name" => "Identity Client", "slug" => "identity_client"}
|
151
|
+
notification.read_at.should be_nil
|
152
|
+
notification.notification_type.should be_nil
|
153
|
+
end
|
154
|
+
end
|
155
|
+
context "on failure" do
|
156
|
+
it "should return false and set the errors with the reason for the failure, authenticated as the user" do
|
157
|
+
PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
|
158
|
+
notification.target_url = 'lalalala'
|
159
|
+
notification.should_not be_persisted
|
160
|
+
notification.save('user').should be_false
|
161
|
+
notification.should_not be_persisted
|
162
|
+
notification.uuid.should be_nil
|
163
|
+
notification.errors.should == {"field_errors"=>{"target_url"=>["Informe uma URL válida."]}}
|
164
|
+
end
|
165
|
+
it "should return false and set the errors with the reason for the failure, authenticated as the application" do
|
166
|
+
notification.destination = nil # required field
|
167
|
+
notification.should_not be_persisted
|
168
|
+
notification.save('application').should be_false
|
169
|
+
notification.should_not be_persisted
|
170
|
+
notification.uuid.should be_nil
|
171
|
+
notification.errors.should == {"field_errors"=>{"destination"=>["Este campo é obrigatório."]}}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
context "on update" do
|
176
|
+
let(:notification) { described_class.find_all.notifications.last }
|
177
|
+
before(:each) do
|
178
|
+
PassaporteWeb.configuration.user_token = "f01d30c0a2e878fecc838735560253f9e9395932f5337f40"
|
179
|
+
end
|
180
|
+
context "on success" do
|
181
|
+
it "should mark the Notification as read" do
|
182
|
+
notification.read_at.should be_nil
|
183
|
+
notification.save
|
184
|
+
notification.read_at.should_not be_nil
|
185
|
+
end
|
186
|
+
end
|
187
|
+
context "on failure" do
|
188
|
+
it "should return false and set the errors with the reason for the failure"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
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.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-04-
|
13
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -224,8 +224,8 @@ description: A Ruby client for the PassaporteWeb REST API
|
|
224
224
|
email:
|
225
225
|
- rodrigo@pittlandia.net
|
226
226
|
- rodrigo.tassinari@myfreecomm.com.br
|
227
|
-
- rodrigo.martins@myfreecomm.com.br
|
228
227
|
- rodrigo@rrmartins.com
|
228
|
+
- rodrigo.martins@myfreecomm.com.br
|
229
229
|
executables: []
|
230
230
|
extensions: []
|
231
231
|
extra_rdoc_files: []
|
@@ -246,6 +246,7 @@ files:
|
|
246
246
|
- lib/passaporte_web/http.rb
|
247
247
|
- lib/passaporte_web/identity.rb
|
248
248
|
- lib/passaporte_web/identity_service_account.rb
|
249
|
+
- lib/passaporte_web/notification.rb
|
249
250
|
- lib/passaporte_web/service_account.rb
|
250
251
|
- lib/passaporte_web/service_account_member.rb
|
251
252
|
- lib/passaporte_web/version.rb
|
@@ -255,6 +256,7 @@ files:
|
|
255
256
|
- spec/passaporte_web/http_spec.rb
|
256
257
|
- spec/passaporte_web/identity_service_account_spec.rb
|
257
258
|
- spec/passaporte_web/identity_spec.rb
|
259
|
+
- spec/passaporte_web/notification_spec.rb
|
258
260
|
- spec/passaporte_web/service_account_member_spec.rb
|
259
261
|
- spec/passaporte_web/service_account_spec.rb
|
260
262
|
- spec/passaporte_web_spec.rb
|
@@ -274,7 +276,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
274
276
|
version: '0'
|
275
277
|
segments:
|
276
278
|
- 0
|
277
|
-
hash:
|
279
|
+
hash: 2546346199843108538
|
278
280
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
281
|
none: false
|
280
282
|
requirements:
|
@@ -283,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
285
|
version: '0'
|
284
286
|
segments:
|
285
287
|
- 0
|
286
|
-
hash:
|
288
|
+
hash: 2546346199843108538
|
287
289
|
requirements: []
|
288
290
|
rubyforge_project:
|
289
291
|
rubygems_version: 1.8.25
|
@@ -296,6 +298,7 @@ test_files:
|
|
296
298
|
- spec/passaporte_web/http_spec.rb
|
297
299
|
- spec/passaporte_web/identity_service_account_spec.rb
|
298
300
|
- spec/passaporte_web/identity_spec.rb
|
301
|
+
- spec/passaporte_web/notification_spec.rb
|
299
302
|
- spec/passaporte_web/service_account_member_spec.rb
|
300
303
|
- spec/passaporte_web/service_account_spec.rb
|
301
304
|
- spec/passaporte_web_spec.rb
|