Class: TripletexRubyClient::SessionTokenRequest
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- TripletexRubyClient::SessionTokenRequest
- Defined in:
- lib/tripletex_ruby_client/session_token_request.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tripletex_ruby_client/session_token_request.rb', line 8 def create uri = URI.parse(session_url) Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http| http.open_timeout = 5 http.read_timeout = 5 response = http.put(uri.request_uri, nil) # binding.pry @session = JSON.parse(response.body) raise "Failed to get Tripletex token #{@session['message']} #{@session['validationMessages']}" unless session_token @session end end |
#session ⇒ Object
4 5 6 |
# File 'lib/tripletex_ruby_client/session_token_request.rb', line 4 def session @session ||= create end |
#session_token ⇒ Object
21 22 23 |
# File 'lib/tripletex_ruby_client/session_token_request.rb', line 21 def session_token session.dig('value', 'token') end |
#session_url ⇒ Object
25 26 27 |
# File 'lib/tripletex_ruby_client/session_token_request.rb', line 25 def session_url "#{base_url}/token/session/:create?consumerToken=#{consumer_token}&employeeToken=#{employee_token}&expirationDate=#{expiration_date}" end |