Class: TLQClient
- Inherits:
-
Object
- Object
- TLQClient
- Defined in:
- lib/tlq_client.rb,
lib/tlq_client/version.rb
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#add_message(body) ⇒ Object
Add a message to the queue.
-
#delete_messages(ids) ⇒ Object
Delete messages from the queue.
-
#get_messages(count = 1) ⇒ Object
Get messages from the queue.
-
#health_check ⇒ Object
Check server health.
-
#initialize(host: 'localhost', port: 1337) ⇒ TLQClient
constructor
A new instance of TLQClient.
-
#purge_queue ⇒ Object
Purge all messages from the queue.
-
#retry_messages(ids) ⇒ Object
Retry messages (return to queue).
Constructor Details
#initialize(host: 'localhost', port: 1337) ⇒ TLQClient
11 12 13 14 15 |
# File 'lib/tlq_client.rb', line 11 def initialize(host: 'localhost', port: 1337) @host = host @port = port @base_uri = "http://#{@host}:#{@port}" end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
9 10 11 |
# File 'lib/tlq_client.rb', line 9 def base_uri @base_uri end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/tlq_client.rb', line 9 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/tlq_client.rb', line 9 def port @port end |
Instance Method Details
#add_message(body) ⇒ Object
Add a message to the queue
18 19 20 21 22 23 24 25 |
# File 'lib/tlq_client.rb', line 18 def (body) response = post('/add', { body: body }) JSON.parse(response.body) rescue JSON::ParserError => e raise "Failed to parse response: #{e.message}" rescue StandardError => e raise "HTTP request failed: #{e.message}" end |
#delete_messages(ids) ⇒ Object
Delete messages from the queue
39 40 41 42 43 44 |
# File 'lib/tlq_client.rb', line 39 def (ids) response = post('/delete', { ids: Array(ids) }) response.body == '"Success"' rescue StandardError => e raise "HTTP request failed: #{e.message}" end |
#get_messages(count = 1) ⇒ Object
Get messages from the queue
28 29 30 31 32 33 34 35 36 |
# File 'lib/tlq_client.rb', line 28 def (count = 1) response = post('/get', { count: count }) parsed = JSON.parse(response.body) parsed.is_a?(Array) ? parsed : Array(parsed['messages'] || parsed) rescue JSON::ParserError => e raise "Failed to parse response: #{e.message}" rescue StandardError => e raise "HTTP request failed: #{e.message}" end |
#health_check ⇒ Object
Check server health
63 64 65 66 67 68 69 |
# File 'lib/tlq_client.rb', line 63 def health_check uri = URI("#{@base_uri}/hello") response = Net::HTTP.get_response(uri) response.body == '"Hello World"' rescue StandardError => e raise "Health check failed: #{e.message}" end |
#purge_queue ⇒ Object
Purge all messages from the queue
55 56 57 58 59 60 |
# File 'lib/tlq_client.rb', line 55 def purge_queue response = post('/purge', {}) response.body == '"Success"' rescue StandardError => e raise "HTTP request failed: #{e.message}" end |
#retry_messages(ids) ⇒ Object
Retry messages (return to queue)
47 48 49 50 51 52 |
# File 'lib/tlq_client.rb', line 47 def (ids) response = post('/retry', { ids: Array(ids) }) response.body == '"Success"' rescue StandardError => e raise "HTTP request failed: #{e.message}" end |