Class: PXMyPortal::Authentication
- Inherits:
-
Object
- Object
- PXMyPortal::Authentication
- Defined in:
- lib/pxmyportal/authentication.rb
Instance Method Summary collapse
-
#initialize(path:, user:, password:, token:, http:, logger:) ⇒ Authentication
constructor
A new instance of Authentication.
- #post ⇒ Object
Constructor Details
#initialize(path:, user:, password:, token:, http:, logger:) ⇒ Authentication
Returns a new instance of Authentication.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pxmyportal/authentication.rb', line 21 def initialize(path:, user:, password:, token:, http:, logger:) @path = path @user = user @password = password @token = token @http = http @logger = logger @request = Net::HTTP::Post.new(@path) end |
Instance Method Details
#post ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pxmyportal/authentication.rb', line 32 def post @http.(@request) @request.form_data = { LoginId: @user, Password: @password, "__RequestVerificationToken" => @token, } response = @http.request(@request) begin response => Net::HTTPFound | Net::HTTPOK rescue => e File.write(File.join(PXMyPortal::XDG::CACHE_DIR, "authentication.html"), response.body) raise e end @logger.debug("response") { response.to_hash } page = PXMyPortal::Page.from_path(response["location"] || @path) unless page @logger.error("location") { response["location"] } raise PXMyPortal::Error, "unexpected location" end @http.(response) page end |