class DeviseProxy::Authenticator

Attributes

host[RW]
port[RW]

Public Class Methods

new(host = 'localhost', port = 3000) click to toggle source
# File lib/devise-proxy/authenticator.rb, line 14
def initialize(host = 'localhost', port = 3000)
        @host = host
        @port = port
end

Public Instance Methods

authenticate(email, password) click to toggle source
# File lib/devise-proxy/authenticator.rb, line 19
          def authenticate(email, password)

                  @credentials = {
                          "user" => {
                       "email" => email, 
                       "password" => password 
                          }
                  }.to_json



                  sig = Net::HTTP::Post.new(@@POST_SIGN, initheader = {'Content-Type' => 'application/json'})
                  sig.body = @credentials


                  http = Net::HTTP.new(@host, @port).start
                  resp1 = http.request(sig)
                  # puts "Response: #{resp1.code} , Message: #{resp1.message} , Body: #{resp1.body}"
                  result = []
json_resp = JSON.parse(resp1.body)
#puts json_resp.inspect
@auth_token = json_resp['auth_token']
                  if resp1.code == "200" then 
                    puts "logged in"

                    @req_body = {
                    "device" => {
                      "name" => "device_json", 
                      "operating_system_id" => "7", 
                      "hash_string" => "jfsg3k4ovj0j02jv" 
                    }, 
                    "auth_token" => @auth_token 
                    }.to_json
                    req = Net::HTTP::Post.new(@@POST_WS, initheader = {'Content-Type' =>'application/json'})
                    req.body = @req_body

                    response = http.request(req)
                    # puts "Response: #{response.code} , Message: #{response.message} , Body: #{response.body}"
                  
                    headers = {}
              sub_response.each_header do |k,v|
                headers[k] = v unless k.to_s =~ /content-length|transfer-encoding/i
              end
                          result = [response.code, headers, response.body]
                  else
                          headers = {}
              resp1.each_header do |k,v|
                headers[k] = v unless k.to_s =~ /content-length|transfer-encoding/i
              end
                          result = [resp1.code, headers, resp1.body, @auth_token]
                  end
                  return result
          end