Class: CmSms::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Request

Returns a new instance of Request.



9
10
11
12
13
# File 'lib/cm_sms/request.rb', line 9

def initialize(body)
  @body     = body
  @endpoint = CmSms.config.endpoint
  @path     = CmSms.config.path
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/cm_sms/request.rb', line 5

def body
  @body
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/cm_sms/request.rb', line 7

def response
  @response
end

Instance Method Details

#performObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/cm_sms/request.rb', line 15

def perform
  raise CmSms::Configuration::EndpointMissing.new("Please provide an valid api endpoint.\nIf you leave this config blank, the default will be set to https://sgw01.cm.nl.") if @endpoint.nil? || @endpoint.empty?
  raise CmSms::Configuration::PathMissing.new("Please provide an valid api path.\nIf you leave this config blank, the default will be set to /gateway.ashx.") if @path.nil? || @path.empty?

  uri = URI.parse(@endpoint)
  Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
    @response = Response.new(http.post(@path, body, initheader = { 'Content-Type' => 'application/xml' }))
  end
  response
end