Class: Takagi::Client
- Inherits:
-
ClientBase
- Object
- ClientBase
- Takagi::Client
- Extended by:
- Forwardable
- Defined in:
- lib/takagi/client.rb,
lib/takagi/client/response.rb
Overview
Unified Takagi Client for communicating with Takagi servers over CoAP.
Supports multiple protocols (UDP, TCP) with automatic protocol detection based on URI scheme or explicit protocol parameter.
Defined Under Namespace
Classes: Response
Instance Attribute Summary
Attributes inherited from ClientBase
#callbacks, #server_uri, #timeout
Instance Method Summary collapse
-
#initialize(server_uri, timeout: 5, protocol: nil, use_retransmission: true) {|client| ... } ⇒ Client, Object
constructor
Creates a new client and optionally yields it to a block.
Methods inherited from ClientBase
#close, #closed?, #delete, #get, #get_json, #observe, #on, open, #post, #post_json, #put, #put_json
Constructor Details
#initialize(server_uri, timeout: 5, protocol: nil, use_retransmission: true) {|client| ... } ⇒ Client, Object
Creates a new client and optionally yields it to a block.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/takagi/client.rb', line 60 def initialize(server_uri, timeout: 5, protocol: nil, use_retransmission: true) # Detect protocol from URI if not explicitly specified @protocol = protocol || detect_protocol(server_uri) # Delegate to the appropriate client implementation @impl = create_client_impl(server_uri, timeout, use_retransmission) # If a block is given, yield and auto-close return unless block_given? begin yield(self) ensure close end end |