Class: IqSMS::Client
- Inherits:
-
Object
- Object
- IqSMS::Client
- Defined in:
- lib/iqsms/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
- #status_queue_name ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #balance ⇒ Object
-
#initialize(login:, password:, **options) ⇒ Client
constructor
A new instance of Client.
- #ping? ⇒ Boolean
- #send_sms(messages) ⇒ Object
- #senders ⇒ Object
- #status(messages) ⇒ Object
- #status_queue(status_queue_limit = 5) ⇒ Object
Constructor Details
#initialize(login:, password:, **options) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 |
# File 'lib/iqsms/client.rb', line 20 def initialize(login:, password:, **) with_value_must_be_present!(login) { @login = login } with_value_must_be_present!(password) { @password = password } @options = .reverse_merge() check_status_queue_name! end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
17 18 19 |
# File 'lib/iqsms/client.rb', line 17 def connection @connection end |
#status_queue_name ⇒ Object
90 91 92 |
# File 'lib/iqsms/client.rb', line 90 def status_queue_name @status_queue_name ||= @options[:status_queue_name] end |
Class Method Details
.connection_pool_for(url) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/iqsms/client.rb', line 5 def self.connection_pool_for(url) @mutex.synchronize do @connection_pool ||= {} if @connection_pool[url].blank? @connection_pool[url] = ConnectionPool.new(size: 5, timeout: 5) do HTTP.persistent(url) end end @connection_pool[url] end end |
Instance Method Details
#balance ⇒ Object
72 73 74 75 76 |
# File 'lib/iqsms/client.rb', line 72 def balance request(:post, 'messages/v2/balance'.freeze) do |response| Response::Balance.new(response) end end |
#ping? ⇒ Boolean
84 85 86 87 88 |
# File 'lib/iqsms/client.rb', line 84 def ping? request(:post, 'messages/v2/balance'.freeze) do |response| response.status.success? end end |
#send_sms(messages) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/iqsms/client.rb', line 29 def send_sms() = Array() () = { statusQueueName: status_queue_name, messages: .map { || Message.() } } request(:post, 'send'.freeze, ) do |response| Response::SendSms.new(response) end end |
#senders ⇒ Object
78 79 80 81 82 |
# File 'lib/iqsms/client.rb', line 78 def senders request(:post, 'senders'.freeze) do |response| Response::Senders.new(response) end end |
#status(messages) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/iqsms/client.rb', line 43 def status() = Array() () = { statusQueueName: status_queue_name, messages: .map { || Message.() } } request(:post, 'status'.freeze, ) do |response| Response::Status.new(response) end end |
#status_queue(status_queue_limit = 5) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/iqsms/client.rb', line 57 def status_queue(status_queue_limit = 5) if status_queue_name.blank? raise ArgumentError, 'status_queue_name must be set to use status_queue endpoint' end = { statusQueueName: status_queue_name, statusQueueLimit: status_queue_limit } request(:post, 'statusQueue'.freeze, ) do |response| Response::StatusQueue.new(response) end end |