passaporteweb-client 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- passaporteweb-client (0.0.13)
4
+ passaporteweb-client (0.0.14)
5
5
  multi_json (~> 1.7.1)
6
6
  rest-client (~> 1.6.7)
7
7
 
data/README.rdoc CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  A Ruby client for the PassaporteWeb REST API
4
4
 
5
+ {<img src="https://badge.fury.io/rb/passaporteweb-client.png" alt="Gem Version" />}[https://rubygems.org/gems/passaporteweb-client]
5
6
  {<img src="https://travis-ci.org/myfreecomm/passaporteweb-client-ruby.png?branch=master" alt="Build Status" />}[https://travis-ci.org/myfreecomm/passaporteweb-client-ruby]
6
7
  {<img src="https://coveralls.io/repos/myfreecomm/passaporteweb-client-ruby/badge.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/myfreecomm/passaporteweb-client-ruby]
7
8
  {<img src="https://codeclimate.com/github/myfreecomm/passaporteweb-client-ruby.png" alt="Code Climate Status" />}[https://codeclimate.com/github/myfreecomm/passaporteweb-client-ruby]
@@ -57,8 +58,8 @@ Or install it yourself as:
57
58
  * {GET /organizations/api/identities/:uuid/accounts/}[https://app.passaporteweb.com.br/static/docs/account_manager.html#get-organizations-api-identities-uuid-accounts] ==> PassaporteWeb::IdentityServiceAccount.find_all
58
59
  * {POST /organizations/api/identities/:uuid/accounts/}[https://app.passaporteweb.com.br/static/docs/servicos.html#put-accounts-api-service-info-uuid-service-slug] ==> PassaporteWeb::IdentityServiceAccount.save
59
60
  * {Serviços do usuário}[https://app.passaporteweb.com.br/static/docs/servicos.html]
60
- * {GET /accounts/api/service-info/:uuid/:service_slug/}[https://app.passaporteweb.com.br/static/docs/servicos.html#get-accounts-api-service-info-uuid-service-slug] ==> (not implemented yet)
61
- * {PUT /accounts/api/service-info/:uuid/:service_slug/}[https://app.passaporteweb.com.br/static/docs/servicos.html#put-accounts-api-service-info-uuid-service-slug] ==> (not implemented yet)
61
+ * {GET /accounts/api/service-info/:uuid/:service_slug/}[https://app.passaporteweb.com.br/static/docs/servicos.html#get-accounts-api-service-info-uuid-service-slug] ==> PassaporteWeb::IdentityService.find
62
+ * {PUT /accounts/api/service-info/:uuid/:service_slug/}[https://app.passaporteweb.com.br/static/docs/servicos.html#put-accounts-api-service-info-uuid-service-slug] ==> PassaporteWeb::IdentityService#save
62
63
  * {Perfil}[https://app.passaporteweb.com.br/static/docs/perfil.html]
63
64
  * {GET /profile/api/info/:uuid/}[https://app.passaporteweb.com.br/static/docs/perfil.html#get-profile-api-info-uuid] ==> (deprecated, not going to be implemented)
64
65
  * {GET /profile/api/info/?email=:email}[https://app.passaporteweb.com.br/static/docs/perfil.html#get-profile-api-info-email-email] ==> (deprecated, not going to be implemented)
@@ -13,6 +13,7 @@ require "passaporte_web/service_account"
13
13
  require "passaporte_web/service_account_member"
14
14
  require "passaporte_web/identity_service_account"
15
15
  require "passaporte_web/notification"
16
+ require "passaporte_web/identity_service"
16
17
 
17
18
  module PassaporteWeb
18
19
 
@@ -0,0 +1,95 @@
1
+ # encoding: utf-8
2
+ module PassaporteWeb
3
+
4
+ # The IdentityService objct represents the relationship between an Identity and a Service on PassaporteWeb. This
5
+ # is only relevant if you wish to add information (via +service_data+ attribute) about the Identity and Service
6
+ # on PassaporteWeb. It does not mean that the Identity has an ServiceAccount on the Service.
7
+ class IdentityService
8
+ include Attributable
9
+
10
+ ATTRIBUTES = [:identity, :slug, :is_active, :service_data]
11
+ UPDATABLE_ATTRIBUTES = [:is_active, :service_data]
12
+
13
+ attr_accessor *UPDATABLE_ATTRIBUTES
14
+ attr_reader *(ATTRIBUTES - UPDATABLE_ATTRIBUTES)
15
+ attr_reader :errors
16
+
17
+ # Instanciates a new IdentityService object for the supplied Identity. The +slug+ attribute is required. The
18
+ # +service_data+ attribute should be a Hash that will be converted to a JSON object. As so, it should
19
+ # only contain strings, symbols, integers, floats, arrays and hashes (the last two with only the same
20
+ # kind of simple objects).
21
+ #
22
+ # Example:
23
+ #
24
+ # identity = PassaporteWeb::Identity.find('some-uuid')
25
+ # PassaporteWeb::IdentityService.new(identity, slug: 'identity_client', is_active: true, service_data: {foo: 'bar'})
26
+ def initialize(identity, attributes={})
27
+ set_attributes(attributes)
28
+ @identity = identity
29
+ @errors = {}
30
+ end
31
+
32
+ # Creates or updates the IdentityService. The +service_data+ attribute should be a Hash that will be
33
+ # converted to a JSON object. As so, it should only contain strings, symbols, integers, floats, arrays
34
+ # and hashes (the last two with only the same kind of simple objects).
35
+ #
36
+ # API method: <tt>PUT /accounts/api/service-info/:uuid/:service_slug/</tt>
37
+ #
38
+ # API documentation: https://app.passaporteweb.com.br/static/docs/servicos.html#put-accounts-api-service-info-uuid-service-slug
39
+ def save
40
+ # TODO validar atributos?
41
+ response = Http.put("/accounts/api/service-info/#{identity.uuid}/#{slug}/", save_body)
42
+ raise "unexpected response: #{response.code} - #{response.body}" unless [200,201].include?(response.code)
43
+ attributes_hash = MultiJson.decode(response.body)
44
+ set_attributes(attributes_hash)
45
+ @errors = {}
46
+ @persisted = true
47
+ true
48
+ rescue *[RestClient::Conflict, RestClient::BadRequest] => e
49
+ @errors = MultiJson.decode(e.response.body)
50
+ false
51
+ end
52
+
53
+ def persisted?
54
+ @persisted == true
55
+ end
56
+
57
+ def is_active?
58
+ @is_active == true
59
+ end
60
+
61
+ def attributes
62
+ ATTRIBUTES.inject({}) do |hash, attribute|
63
+ hash[attribute] = self.send(attribute)
64
+ hash
65
+ end
66
+ end
67
+
68
+ # Finds the IdentityService representing the relationship of the Identity with the Service. Returns an
69
+ # IdentityService object or nil if no relationship is found.
70
+ #
71
+ # API method: <tt>GET /accounts/api/service-info/:uuid/:service_slug/</tt>
72
+ #
73
+ # API documentation: https://app.passaporteweb.com.br/static/docs/servicos.html#get-accounts-api-service-info-uuid-service-slug
74
+ def self.find(identity, slug)
75
+ response = Http.get("/accounts/api/service-info/#{identity.uuid}/#{slug}/")
76
+ return if response.code == 204
77
+ attributes_hash = MultiJson.decode(response.body)
78
+ load_identity_service(identity, attributes_hash)
79
+ end
80
+
81
+ private
82
+
83
+ def self.load_identity_service(identity, attributes)
84
+ service = self.new(identity, attributes)
85
+ service.instance_variable_set(:@persisted, true)
86
+ service
87
+ end
88
+
89
+ def save_body
90
+ self.attributes.select { |key, value| UPDATABLE_ATTRIBUTES.include?(key) && !value.nil? }
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module PassaporteWeb
3
- VERSION = "0.0.13"
3
+ VERSION = "0.0.14"
4
4
  end
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe PassaporteWeb::IdentityService do
5
+ let(:identity) { PassaporteWeb::Identity.find('5e32f927-c4ab-404e-a91c-b2abc05afb56') }
6
+ let(:mock_identity) { mock('Identity', uuid: 'identity-uuid') }
7
+ let(:identity_service_data_hash) { {:foo => 'bar', 'spam' => :eggs, 'integer' => 2, :float => 3.456, :array => [1, 2.0, 'three', :four], :hash => {oba: 'eba'}} }
8
+ let(:identity_service_data_hash_as_strings) { {"foo"=>"bar", "hash"=>{"oba"=>"eba"}, "spam"=>"eggs", "integer"=>2, "array"=>[1, 2.0, "three", "four"], "float"=>3.456} }
9
+
10
+ describe ".new" do
11
+ it "should instanciate an (almost) empty object" do
12
+ identity_service = described_class.new(mock_identity)
13
+ identity_service.attributes.should == {identity: mock_identity, slug: nil, is_active: nil, service_data: nil}
14
+ identity_service.identity.should == mock_identity
15
+ identity_service.slug.should be_nil
16
+ identity_service.is_active.should be_nil
17
+ identity_service.is_active?.should be_false
18
+ identity_service.service_data.should be_nil
19
+ identity_service.errors.should be_empty
20
+ identity_service.should_not be_persisted
21
+ end
22
+ it "should instanciate an object with attributes set" do
23
+ identity_service = described_class.new(mock_identity)
24
+ attributes = {
25
+ "slug" => "identity_client",
26
+ :is_active => true,
27
+ 'service_data' => identity_service_data_hash
28
+ }
29
+ identity_service = described_class.new(mock_identity, attributes)
30
+ identity_service.attributes.should == {identity: mock_identity, slug: 'identity_client', is_active: true, service_data: identity_service_data_hash}
31
+ identity_service.identity.should == mock_identity
32
+ identity_service.slug.should == 'identity_client'
33
+ identity_service.is_active.should == true
34
+ identity_service.is_active?.should be_true
35
+ identity_service.service_data.should == identity_service_data_hash
36
+ identity_service.errors.should be_empty
37
+ identity_service.should_not be_persisted
38
+ end
39
+ end
40
+
41
+ describe ".find", vcr: true do
42
+ it "should find the IdentityService representing the existing relationship between the Identity and the Service" do
43
+ identity_service = described_class.find(identity, 'identity_client')
44
+ identity_service.should be_instance_of(described_class)
45
+ identity_service.identity.should == identity
46
+ identity_service.slug.should == 'identity_client'
47
+ identity_service.is_active.should == true
48
+ identity_service.is_active?.should be_true
49
+ identity_service.service_data.should be_nil
50
+ identity_service.errors.should be_empty
51
+ identity_service.should be_persisted
52
+ end
53
+ it "should return nil it the Identity does not have a relationship with the Service" do
54
+ other_identity = PassaporteWeb::Identity.find('840df3bd-8414-4085-9920-1937f4b37dd3')
55
+ described_class.find(other_identity, 'identity_client').should be_nil
56
+ end
57
+ end
58
+
59
+ describe "#save", vcr: true do
60
+ it "should create the relationship between Identity and Service with extra data" do
61
+ other_identity = PassaporteWeb::Identity.find('840df3bd-8414-4085-9920-1937f4b37dd3')
62
+ attributes = {
63
+ "slug" => "identity_client",
64
+ :is_active => true,
65
+ 'service_data' => identity_service_data_hash
66
+ }
67
+ identity_service = described_class.new(other_identity, attributes)
68
+ identity_service.save.should be_true
69
+ identity_service.service_data.should == identity_service_data_hash_as_strings
70
+
71
+ identity_service = described_class.find(other_identity, 'identity_client')
72
+ identity_service.service_data.should == identity_service_data_hash_as_strings
73
+ end
74
+ it "should update the relationship between Identity and Service with extra data" do
75
+ identity_service = described_class.find(identity, 'identity_client')
76
+ identity_service.service_data.should be_empty
77
+ identity_service.service_data = identity_service_data_hash
78
+ identity_service.save.should be_true
79
+ identity_service.service_data.should == identity_service_data_hash_as_strings
80
+
81
+ identity_service = described_class.find(identity, 'identity_client')
82
+ identity_service.service_data.should == identity_service_data_hash_as_strings
83
+ end
84
+ end
85
+
86
+ end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passaporteweb-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
5
4
  prerelease:
5
+ version: 0.0.14
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rodrigo Tassinari de Oliveira
@@ -10,10 +10,16 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-04 00:00:00.000000000 Z
13
+ date: 2013-04-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
17
+ version_requirements: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.7
17
23
  requirement: !ruby/object:Gem::Requirement
18
24
  none: false
19
25
  requirements:
@@ -22,14 +28,14 @@ dependencies:
22
28
  version: 1.6.7
23
29
  type: :runtime
24
30
  prerelease: false
31
+ - !ruby/object:Gem::Dependency
32
+ name: multi_json
25
33
  version_requirements: !ruby/object:Gem::Requirement
26
34
  none: false
27
35
  requirements:
28
36
  - - ~>
29
37
  - !ruby/object:Gem::Version
30
- version: 1.6.7
31
- - !ruby/object:Gem::Dependency
32
- name: multi_json
38
+ version: 1.7.1
33
39
  requirement: !ruby/object:Gem::Requirement
34
40
  none: false
35
41
  requirements:
@@ -38,14 +44,14 @@ dependencies:
38
44
  version: 1.7.1
39
45
  type: :runtime
40
46
  prerelease: false
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
41
49
  version_requirements: !ruby/object:Gem::Requirement
42
50
  none: false
43
51
  requirements:
44
52
  - - ~>
45
53
  - !ruby/object:Gem::Version
46
- version: 1.7.1
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
54
+ version: 1.3.2
49
55
  requirement: !ruby/object:Gem::Requirement
50
56
  none: false
51
57
  requirements:
@@ -54,14 +60,14 @@ dependencies:
54
60
  version: 1.3.2
55
61
  type: :development
56
62
  prerelease: false
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
57
65
  version_requirements: !ruby/object:Gem::Requirement
58
66
  none: false
59
67
  requirements:
60
68
  - - ~>
61
69
  - !ruby/object:Gem::Version
62
- version: 1.3.2
63
- - !ruby/object:Gem::Dependency
64
- name: rake
70
+ version: 10.0.4
65
71
  requirement: !ruby/object:Gem::Requirement
66
72
  none: false
67
73
  requirements:
@@ -70,14 +76,14 @@ dependencies:
70
76
  version: 10.0.4
71
77
  type: :development
72
78
  prerelease: false
79
+ - !ruby/object:Gem::Dependency
80
+ name: rdoc
73
81
  version_requirements: !ruby/object:Gem::Requirement
74
82
  none: false
75
83
  requirements:
76
84
  - - ~>
77
85
  - !ruby/object:Gem::Version
78
- version: 10.0.4
79
- - !ruby/object:Gem::Dependency
80
- name: rdoc
86
+ version: 4.0.1
81
87
  requirement: !ruby/object:Gem::Requirement
82
88
  none: false
83
89
  requirements:
@@ -86,14 +92,14 @@ dependencies:
86
92
  version: 4.0.1
87
93
  type: :development
88
94
  prerelease: false
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
89
97
  version_requirements: !ruby/object:Gem::Requirement
90
98
  none: false
91
99
  requirements:
92
100
  - - ~>
93
101
  - !ruby/object:Gem::Version
94
- version: 4.0.1
95
- - !ruby/object:Gem::Dependency
96
- name: rspec
102
+ version: 2.13.0
97
103
  requirement: !ruby/object:Gem::Requirement
98
104
  none: false
99
105
  requirements:
@@ -102,14 +108,14 @@ dependencies:
102
108
  version: 2.13.0
103
109
  type: :development
104
110
  prerelease: false
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
105
113
  version_requirements: !ruby/object:Gem::Requirement
106
114
  none: false
107
115
  requirements:
108
116
  - - ~>
109
117
  - !ruby/object:Gem::Version
110
- version: 2.13.0
111
- - !ruby/object:Gem::Dependency
112
- name: vcr
118
+ version: 2.4.0
113
119
  requirement: !ruby/object:Gem::Requirement
114
120
  none: false
115
121
  requirements:
@@ -118,14 +124,14 @@ dependencies:
118
124
  version: 2.4.0
119
125
  type: :development
120
126
  prerelease: false
127
+ - !ruby/object:Gem::Dependency
128
+ name: webmock
121
129
  version_requirements: !ruby/object:Gem::Requirement
122
130
  none: false
123
131
  requirements:
124
132
  - - ~>
125
133
  - !ruby/object:Gem::Version
126
- version: 2.4.0
127
- - !ruby/object:Gem::Dependency
128
- name: webmock
134
+ version: 1.9.3
129
135
  requirement: !ruby/object:Gem::Requirement
130
136
  none: false
131
137
  requirements:
@@ -134,14 +140,14 @@ dependencies:
134
140
  version: 1.9.3
135
141
  type: :development
136
142
  prerelease: false
143
+ - !ruby/object:Gem::Dependency
144
+ name: pry
137
145
  version_requirements: !ruby/object:Gem::Requirement
138
146
  none: false
139
147
  requirements:
140
148
  - - ~>
141
149
  - !ruby/object:Gem::Version
142
- version: 1.9.3
143
- - !ruby/object:Gem::Dependency
144
- name: pry
150
+ version: 0.9.12
145
151
  requirement: !ruby/object:Gem::Requirement
146
152
  none: false
147
153
  requirements:
@@ -150,14 +156,14 @@ dependencies:
150
156
  version: 0.9.12
151
157
  type: :development
152
158
  prerelease: false
159
+ - !ruby/object:Gem::Dependency
160
+ name: pry-nav
153
161
  version_requirements: !ruby/object:Gem::Requirement
154
162
  none: false
155
163
  requirements:
156
164
  - - ~>
157
165
  - !ruby/object:Gem::Version
158
- version: 0.9.12
159
- - !ruby/object:Gem::Dependency
160
- name: pry-nav
166
+ version: 0.2.3
161
167
  requirement: !ruby/object:Gem::Requirement
162
168
  none: false
163
169
  requirements:
@@ -166,14 +172,14 @@ dependencies:
166
172
  version: 0.2.3
167
173
  type: :development
168
174
  prerelease: false
175
+ - !ruby/object:Gem::Dependency
176
+ name: awesome_print
169
177
  version_requirements: !ruby/object:Gem::Requirement
170
178
  none: false
171
179
  requirements:
172
180
  - - ~>
173
181
  - !ruby/object:Gem::Version
174
- version: 0.2.3
175
- - !ruby/object:Gem::Dependency
176
- name: awesome_print
182
+ version: 1.1.0
177
183
  requirement: !ruby/object:Gem::Requirement
178
184
  none: false
179
185
  requirements:
@@ -182,14 +188,14 @@ dependencies:
182
188
  version: 1.1.0
183
189
  type: :development
184
190
  prerelease: false
191
+ - !ruby/object:Gem::Dependency
192
+ name: simplecov
185
193
  version_requirements: !ruby/object:Gem::Requirement
186
194
  none: false
187
195
  requirements:
188
196
  - - ~>
189
197
  - !ruby/object:Gem::Version
190
- version: 1.1.0
191
- - !ruby/object:Gem::Dependency
192
- name: simplecov
198
+ version: 0.7.1
193
199
  requirement: !ruby/object:Gem::Requirement
194
200
  none: false
195
201
  requirements:
@@ -198,14 +204,14 @@ dependencies:
198
204
  version: 0.7.1
199
205
  type: :development
200
206
  prerelease: false
207
+ - !ruby/object:Gem::Dependency
208
+ name: coveralls
201
209
  version_requirements: !ruby/object:Gem::Requirement
202
210
  none: false
203
211
  requirements:
204
212
  - - ~>
205
213
  - !ruby/object:Gem::Version
206
- version: 0.7.1
207
- - !ruby/object:Gem::Dependency
208
- name: coveralls
214
+ version: 0.6.3
209
215
  requirement: !ruby/object:Gem::Requirement
210
216
  none: false
211
217
  requirements:
@@ -214,12 +220,6 @@ dependencies:
214
220
  version: 0.6.3
215
221
  type: :development
216
222
  prerelease: false
217
- version_requirements: !ruby/object:Gem::Requirement
218
- none: false
219
- requirements:
220
- - - ~>
221
- - !ruby/object:Gem::Version
222
- version: 0.6.3
223
223
  description: A Ruby client for the PassaporteWeb REST API
224
224
  email:
225
225
  - rodrigo@pittlandia.net
@@ -245,6 +245,7 @@ files:
245
245
  - lib/passaporte_web/helpers.rb
246
246
  - lib/passaporte_web/http.rb
247
247
  - lib/passaporte_web/identity.rb
248
+ - lib/passaporte_web/identity_service.rb
248
249
  - lib/passaporte_web/identity_service_account.rb
249
250
  - lib/passaporte_web/notification.rb
250
251
  - lib/passaporte_web/service_account.rb
@@ -255,6 +256,7 @@ files:
255
256
  - spec/passaporte_web/helpers_spec.rb
256
257
  - spec/passaporte_web/http_spec.rb
257
258
  - spec/passaporte_web/identity_service_account_spec.rb
259
+ - spec/passaporte_web/identity_service_spec.rb
258
260
  - spec/passaporte_web/identity_spec.rb
259
261
  - spec/passaporte_web/notification_spec.rb
260
262
  - spec/passaporte_web/service_account_member_spec.rb
@@ -274,18 +276,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
276
  - - ! '>='
275
277
  - !ruby/object:Gem::Version
276
278
  version: '0'
277
- segments:
278
- - 0
279
- hash: -2500500601371462639
280
279
  required_rubygems_version: !ruby/object:Gem::Requirement
281
280
  none: false
282
281
  requirements:
283
282
  - - ! '>='
284
283
  - !ruby/object:Gem::Version
285
284
  version: '0'
286
- segments:
287
- - 0
288
- hash: -2500500601371462639
289
285
  requirements: []
290
286
  rubyforge_project:
291
287
  rubygems_version: 1.8.25
@@ -297,9 +293,11 @@ test_files:
297
293
  - spec/passaporte_web/helpers_spec.rb
298
294
  - spec/passaporte_web/http_spec.rb
299
295
  - spec/passaporte_web/identity_service_account_spec.rb
296
+ - spec/passaporte_web/identity_service_spec.rb
300
297
  - spec/passaporte_web/identity_spec.rb
301
298
  - spec/passaporte_web/notification_spec.rb
302
299
  - spec/passaporte_web/service_account_member_spec.rb
303
300
  - spec/passaporte_web/service_account_spec.rb
304
301
  - spec/passaporte_web_spec.rb
305
302
  - spec/spec_helper.rb
303
+ has_rdoc: true