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
- #authorized? ⇒ Boolean
- #content ⇒ Object
- #content_resource ⇒ Object
-
#initialize(opts = {}) ⇒ Gateway
constructor
A new instance of Gateway.
- #subject ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Gateway
Returns a new instance of Gateway.
13 14 15 |
# File 'lib/cadun/gateway.rb', line 13 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 8 9 10 11 |
# File 'lib/cadun/gateway.rb', line 5 def self.provision(user_id, service_id) request = Curl::Easy.http_put("#{Config.restclient_url}/service/provisionamento", "{\"usuarioId\":\"#{user_id}\",\"servicoId\":\"#{service_id}\"}") do |curl| curl.headers['Content-Type'] = 'application/json' end request.response_code == 200 end |
Instance Method Details
#authorization ⇒ Object
38 39 40 |
# File 'lib/cadun/gateway.rb', line 38 def @authorization ||= Hash.from_xml()["usuarioAutorizado"] end |
#authorization_resource ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cadun/gateway.rb', line 42 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) request = Curl::Easy.http_put("#{Config.auth_url}/ws/rest/autorizacao", ) do |curl| curl.headers['Content-Type'] = 'text/xml' end request.body_str end |
#authorized? ⇒ Boolean
34 35 36 |
# File 'lib/cadun/gateway.rb', line 34 def ["status"] == "AUTORIZADO" end |
#content ⇒ Object
17 18 19 |
# File 'lib/cadun/gateway.rb', line 17 def content @content ||= Hash.from_xml(content_resource)["pessoa"] end |
#content_resource ⇒ Object
21 22 23 |
# File 'lib/cadun/gateway.rb', line 21 def content_resource Curl::Easy.perform("#{Config.auth_url}/cadunii/ws/resources/pessoa/#{subject}").body_str end |
#subject ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/cadun/gateway.rb', line 25 def subject if opts[:email]; "email/#{opts[:email]}" elsif opts[:cadun_id]; opts[:cadun_id] else raise Exception.new(["status"]) unless ["usuarioID"] end end |