Class: PassByME2FAClient

Inherits:
Object
  • Object
show all
Defined in:
lib/passbyme2fa-client.rb

Defined Under Namespace

Modules: MessageStatus, MessageType

Constant Summary collapse

VERSION =
"1.0.4"

Instance Method Summary collapse

Constructor Details

#initialize(http_options) ⇒ PassByME2FAClient

Returns a new instance of PassByME2FAClient.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/passbyme2fa-client.rb', line 35

def initialize(http_options)
  if !http_options.include? :key or !http_options.include? :cert
    raise ArgumentError.new("SSL key or certificate is missing!")
  end
  url = (http_options.include?(:address) ? http_options[:address] : "auth-sp.passbyme.com")
  http_options.delete :address
  @http = Net::HTTP.start(url, http_options.merge({
    :use_ssl => true,
    :verify_mode => OpenSSL::SSL::VERIFY_PEER,
    :ca_file => File.expand_path("../passbyme2fa-client/truststore.pem", __FILE__),
  }))
end

Instance Method Details

#cancel_message(message_id) ⇒ Object



86
87
88
# File 'lib/passbyme2fa-client.rb', line 86

def cancel_message(message_id)
  handle_existing_message(message_id, Net::HTTP::Delete)
end

#send_message(params) ⇒ Object

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/passbyme2fa-client.rb', line 48

def send_message(params)
  recipients = params[:recipients]
  subject = params[:subject]
  body = params[:body]
  availability = params[:availability]
  type = params[:type]
  callbackUrl = params[:callbackUrl]

  if recipients.nil? or recipients.length == 0
    raise ArgumentError.new("Missing recipients!")
  end

  availability = availability.to_i
  if availability < 1
    raise ArgumentError.new("Availability must be an integer greater than 0.")
  end

  raise ArgumentError.new("Invalid message type #{type}.") unless MessageType.constants.index { |ct|
    MessageType.const_get(ct) == type
  }

  req = Net::HTTP::Post.new("/frontend/messages", "Content-Type" => "application/json")
  req.body = {
    :recipients => recipients,
    :subject => subject,
    :body => body,
    :availability => availability,
    :type => type,
    :callbackUrl => callbackUrl
  }.to_json

  SessionInfo.new(JSON.parse(do_https(req)), self)
end

#track_message(message_id) ⇒ Object



82
83
84
# File 'lib/passbyme2fa-client.rb', line 82

def track_message(message_id)
  handle_existing_message(message_id, Net::HTTP::Get)
end