Class: ActionTexter::Validator::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/action_texter/validator/request.rb

Defined Under Namespace

Classes: ContentTypeMissing, EndpointMissing, PathMissing, ProductTokenMissing

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new instance of Request.



9
10
11
12
13
14
15
16
# File 'lib/action_texter/validator/request.rb', line 9

def initialize
  @endpoint     = ActionTexter.config.endpoint
  @path         = ActionTexter.config.path
  @content_type = ActionTexter.config.content_type
  @api_key      = ActionTexter.config.product_token

  validate
end

Instance Method Details

#validateObject



18
19
20
21
22
23
# File 'lib/action_texter/validator/request.rb', line 18

def validate
  fail EndpointMissing, "Please provide an valid api endpoint.\nIf you leave this config blank, the default will be set to https://rest.sms-service.org  ." if @endpoint.nil? || @endpoint.empty?
  fail ContentTypeMissing, 'Please provide a valid content_type! Defaults to application/json' if @content_type.nil? || @content_type.empty?
  fail PathMissing, "Please provide an valid api path.\nIf you leave this config blank, the default will be set to /message." if @path.nil? || @path.empty?
  fail ProductTokenMissing, "Please provide an valid product key.\nAfter signup at https://www.messagebird.com/, you will find one in your settings." if @api_key.nil?
end