class PassaporteWeb::IdentityService
The IdentityService
objct represents the relationship between an Identity
and a Service on PassaporteWeb
. This is only relevant if you wish to add information (via service_data
attribute) about the Identity
and Service on PassaporteWeb
. It does not mean that the Identity
has an ServiceAccount
on the Service.
Constants
- ATTRIBUTES
- UPDATABLE_ATTRIBUTES
Attributes
Public Class Methods
Finds the IdentityService
representing the relationship of the Identity
with the Service. Returns an IdentityService
object or nil if no relationship is found.
API method: GET /accounts/api/service-info/:uuid/:service_slug/
API documentation: app.passaporteweb.com.br/static/docs/servicos.html#get-accounts-api-service-info-uuid-service-slug
# File lib/passaporte_web/identity_service.rb, line 74 def self.find(identity, slug) response = Http.get("/accounts/api/service-info/#{identity.uuid}/#{slug}/") return if response.code == 204 attributes_hash = MultiJson.decode(response.body) load_identity_service(identity, attributes_hash) end
Instanciates a new IdentityService
object for the supplied Identity
. The slug
attribute is required. The service_data
attribute should be a Hash that will be converted to a JSON object. As so, it should only contain strings, symbols, integers, floats, arrays and hashes (the last two with only the same kind of simple objects).
Example:
identity = PassaporteWeb::Identity.find('some-uuid') PassaporteWeb::IdentityService.new(identity, slug: 'identity_client', is_active: true, service_data: {foo: 'bar'})
# File lib/passaporte_web/identity_service.rb, line 26 def initialize(identity, attributes={}) set_attributes(attributes) @identity = identity @errors = {} end
Private Class Methods
# File lib/passaporte_web/identity_service.rb, line 83 def self.load_identity_service(identity, attributes) service = self.new(identity, attributes) service.instance_variable_set(:@persisted, true) service end
Public Instance Methods
# File lib/passaporte_web/identity_service.rb, line 61 def attributes ATTRIBUTES.inject({}) do |hash, attribute| hash[attribute] = self.send(attribute) hash end end
# File lib/passaporte_web/identity_service.rb, line 57 def is_active? @is_active == true end
# File lib/passaporte_web/identity_service.rb, line 53 def persisted? @persisted == true end
Creates or updates the IdentityService
. The service_data
attribute should be a Hash that will be converted to a JSON object. As so, it should only contain strings, symbols, integers, floats, arrays and hashes (the last two with only the same kind of simple objects).
API method: PUT /accounts/api/service-info/:uuid/:service_slug/
API documentation: app.passaporteweb.com.br/static/docs/servicos.html#put-accounts-api-service-info-uuid-service-slug
# File lib/passaporte_web/identity_service.rb, line 39 def save # TODO validar atributos? response = Http.put("/accounts/api/service-info/#{identity.uuid}/#{slug}/", save_body) raise "unexpected response: #{response.code} - #{response.body}" unless response.code == 200 attributes_hash = MultiJson.decode(response.body) set_attributes(attributes_hash) @errors = {} @persisted = true true rescue *[RestClient::Conflict, RestClient::BadRequest] => e @errors = MultiJson.decode(e.response.body) false end
Private Instance Methods
# File lib/passaporte_web/identity_service.rb, line 89 def save_body self.attributes.select { |key, value| UPDATABLE_ATTRIBUTES.include?(key) && !value.nil? } end