Class: PXMyPortal::TokenIssuer

Inherits:
Object
  • Object
show all
Defined in:
lib/pxmyportal/token_issuer.rb

Instance Method Summary collapse

Constructor Details

#initialize(http:, company:) ⇒ TokenIssuer

Returns a new instance of TokenIssuer.



22
23
24
25
# File 'lib/pxmyportal/token_issuer.rb', line 22

def initialize(http:, company:)
  @http = http
  @company = company
end

Instance Method Details

#getObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pxmyportal/token_issuer.rb', line 27

def get
  @http.start

  path = File.join(PXMyPortal::Page::BASEPATH, "Auth/Login")
  query = @company
  response = @http.get("#{path}?#{query}")
  response => Net::HTTPOK

  @http.accept_cookie(response)

  document = Nokogiri::HTML(response.body)
  token = <<~XPATH
    //form//input[     @type='hidden'
                   and @name='__RequestVerificationToken' ]
    /@value
  XPATH
  document.xpath(token) => [token]
  token or raise Error, token
end