Class: Cadun::Gateway
- Inherits:
-
Object
- Object
- Cadun::Gateway
- Defined in:
- lib/cadun/gateway.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Class Method Summary collapse
Instance Method Summary collapse
- #authorization ⇒ Object
- #authorization_resource ⇒ Object
- #content ⇒ Object
- #content_resource ⇒ Object
-
#initialize(opts = {}) ⇒ Gateway
constructor
A new instance of Gateway.
Constructor Details
#initialize(opts = {}) ⇒ Gateway
Returns a new instance of Gateway.
9 10 11 |
# File 'lib/cadun/gateway.rb', line 9 def initialize(opts = {}) @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/cadun/gateway.rb', line 3 def opts @opts end |
Class Method Details
.provision(user_id, service_id) ⇒ Object
5 6 7 |
# File 'lib/cadun/gateway.rb', line 5 def self.provision(user_id, service_id) RestClient.put("#{Config.restclient_url}/service/provisionamento", "{\"usuarioId\": \"#{user_id}\", \"servicoId\": \"#{service_id}\"}", :content_type => "text/javascript").code == 200 end |
Instance Method Details
#authorization ⇒ Object
28 29 30 |
# File 'lib/cadun/gateway.rb', line 28 def @authorization ||= Hash.from_xml()["usuarioAutorizado"] end |
#authorization_resource ⇒ Object
32 33 34 35 36 37 |
# File 'lib/cadun/gateway.rb', line 32 def %w(glb_id ip service_id).each { |i| raise ArgumentError.new("#{i} is missing") unless opts[i.to_sym] } = { "glbId" => opts[:glb_id], "ip" => opts[:ip], "servicoID" => opts[:service_id] }.to_xml(:root => "usuarioAutorizado", :indent => 0) RestClient.put("#{Config.auth_url}/ws/rest/autorizacao", , :content_type => "text/xml") end |
#content ⇒ Object
13 14 15 |
# File 'lib/cadun/gateway.rb', line 13 def content @content ||= Hash.from_xml(content_resource)["pessoa"] end |
#content_resource ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cadun/gateway.rb', line 17 def content_resource subject = if opts[:email]; "email/#{opts[:email]}" elsif opts[:cadun_id]; opts[:cadun_id] else raise Exception.new(["status"]) unless ["status"] == "AUTORIZADO" ["usuarioID"] end RestClient.get("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}", :content_type => "text/xml") end |