Login example in Ruby

Sample Ruby code for login. Change the username and password to your test user.

require 'openssl'
require 'base64'
require 'uri'
require 'net/http'

username = 'username'
password = 'password'
service  = 'NEXTAPI'

# Create auth                                                                                           
string = Base64.encode64(username) + ':' + Base64.encode64(password) + ':' + Base64.encode64((Time.now.\
to_i * 1000).to_s)
public_key_data = File.read(service + '_TEST_public.pem')
public_key = OpenSSL::PKey::RSA.new(public_key_data)
auth = URI::escape(Base64.encode64(public_key.public_encrypt(string)),
                   Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))

# Setup HTTPS                                                                                           
http = Net::HTTP.new('api.test.nordnet.se', 443)
http.use_ssl = true

# Get status of server                                                                                  
response = http.get('/next/2/', {'Accept' => 'application/json'})
puts response.body

# POST login                                                                                            
response = http.post('/next/2/login', "auth=#{auth}&service=#{service}", 
    {'Accept' => 'application/json'})
puts response.body