Skip to content

Commit

Permalink
Adding from validations to SMS and WhatsApp channels
Browse files Browse the repository at this point in the history
  • Loading branch information
superchilled committed Apr 23, 2024
1 parent fe52ed9 commit 6719e10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/vonage/verify2/channels/sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def to=(to)
end

def from=(from)
validate_from(from)
@from = from
end

Expand Down Expand Up @@ -49,5 +50,14 @@ def to_h
private

attr_writer :channel

def validate_from(from)
if from.match?(/\D/)
raise ArgumentError, "Invalid alpha-numeric 'from' value #{from}. Length must be between 3 and 11 characters." unless from.length.between?(3, 11)
else
raise ArgumentError, "Invalid numeric 'from' value #{from}. Length must be between 11 and 15 characters." unless from.length.between?(11, 15)
raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from).valid?
end
end
end
end
1 change: 1 addition & 0 deletions lib/vonage/verify2/channels/whats_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def to=(to)
end

def from=(from)
raise ArgumentError, "Invalid 'from' value #{from}. Length must be between 11 and 15 characters." unless from.length.between?(11, 15)
raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from.to_i).valid?
@from = from
end
Expand Down

0 comments on commit 6719e10

Please sign in to comment.