Class: SmsTeknik::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
# File 'lib/sms_teknik/client.rb', line 8

def initialize(options = {})
  @id = options[:id]
  @user = options[:user]
  @pass = options[:pass]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/sms_teknik/client.rb', line 6

def id
  @id
end

#passObject

Returns the value of attribute pass.



6
7
8
# File 'lib/sms_teknik/client.rb', line 6

def pass
  @pass
end

#userObject

Returns the value of attribute user.



6
7
8
# File 'lib/sms_teknik/client.rb', line 6

def user
  @user
end

Class Method Details

.endpointObject



34
35
36
# File 'lib/sms_teknik/client.rb', line 34

def self.endpoint
  @endpoint || "https://api.smsteknik.se"
end

.endpoint=(value) ⇒ Object



38
39
40
# File 'lib/sms_teknik/client.rb', line 38

def self.endpoint=(value)
  @endpoint = value
end

Instance Method Details

#deliver(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sms_teknik/client.rb', line 14

def deliver(message)
  req =  Net::HTTP::Post.new(uri)
  req.add_field "Content-Type", "text/xml"
  req.body = SmsTeknik::XMLTemplates.text_message(
    recipients: message.to,
    message: message.body,
    sender: message.from,
    send_date: Time.now.strftime("%Y-%m-%d"),
    send_time: Time.now.strftime("%H:%M")
  )

  # Fetch Request
  res = http.request(req)
  SmsTeknik.logger.info "[SmsTeknik] Message sent with status #{res.code} and response \"#{res.body}\""
  return true
rescue StandardError => e
  SmsTeknik.logger.error "[SmsTeknik] HTTP Request failed (#{e.message})"
  return false
end