Class: SmsTeknik::Client
- Inherits:
-
Object
- Object
- SmsTeknik::Client
- Defined in:
- lib/sms_teknik/client.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #deliver(message) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
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( = {}) @id = [:id] @user = [:user] @pass = [:pass] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/sms_teknik/client.rb', line 6 def id @id end |
#pass ⇒ Object
Returns the value of attribute pass.
6 7 8 |
# File 'lib/sms_teknik/client.rb', line 6 def pass @pass end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/sms_teknik/client.rb', line 6 def user @user end |
Class Method Details
.endpoint ⇒ Object
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() req = Net::HTTP::Post.new(uri) req.add_field "Content-Type", "text/xml" req.body = SmsTeknik::XMLTemplates.( recipients: .to, message: .body, sender: .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.})" return false end |