Class: SensSms::Client

Inherits:
Object
  • Object
show all
Includes:
Configuration, SensSms::Configuration::Validate
Defined in:
lib/sens_sms/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SensSms::Configuration::Validate

#validate_configure, #validate_configure_defined?, #validate_configure_exist?

Methods included from Configuration

#access_key, #secret_key, #service_id

Constructor Details

#initializeClient

Returns a new instance of Client.



5
6
7
# File 'lib/sens_sms/client.rb', line 5

def initialize
  raise 'Configure is not valid.' unless validate_configure
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/sens_sms/client.rb', line 3

def errors
  @errors
end

#request_timeObject (readonly)

Returns the value of attribute request_time.



3
4
5
# File 'lib/sens_sms/client.rb', line 3

def request_time
  @request_time
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/sens_sms/client.rb', line 3

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/sens_sms/client.rb', line 3

def status
  @status
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



3
4
5
# File 'lib/sens_sms/client.rb', line 3

def timestamp
  @timestamp
end

Class Method Details

.configurationObject



33
34
35
# File 'lib/sens_sms/client.rb', line 33

def self.configuration
  @configuration ||= SensSms::Configure.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



26
27
28
29
30
31
# File 'lib/sens_sms/client.rb', line 26

def self.configure
  yield configuration
  @@access_key = @configuration.access_key
  @@service_id = @configuration.service_id
  @@secret_key = @configuration.secret_key
end

Instance Method Details

#deliver(type:, from_number:, to_numbers:, subject: nil, message:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sens_sms/client.rb', line 9

def deliver(type:, from_number:, to_numbers:, subject: nil, message:)
  raise "Invalid message type: #{type}" unless %i[sms lms].include? type.to_sym

  @timestamp = current_timestamp
  @response = HTTP.headers(ncloud_sens_api_header)
                  .post(ncloud_sens_api_url,
                        json: { type: type.to_sym,
                                contentType: :COMM,
                                countryCode: '82',
                                from: from_number,
                                subject: subject,
                                content: message,
                                messages: parsed_messages(to_numbers) })
  @status = response.status
  parse_response
end