Class: Ribbon::Intercom::Client::SDK::Adapters::Adapter
- Inherits:
-
Object
- Object
- Ribbon::Intercom::Client::SDK::Adapters::Adapter
- Defined in:
- lib/ribbon/intercom/client/sdk/adapters/adapter.rb,
lib/ribbon/intercom/client/sdk/adapters/adapter/response.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Response
Instance Method Summary collapse
-
#call(method_name, *args) ⇒ Object
deprecated
Deprecated.
This method is only called by tests. Don’t call it elsewhere.
-
#connect(*args) ⇒ Object
Connect to a service.
-
#connected? ⇒ Boolean
Returns whether or not the Adapter is connected to a service.
- #dup ⇒ Object
-
#headers(new_headers = {}) ⇒ Object
Returns the headers defined for this Adapter.
-
#initialize(*args) ⇒ Adapter
constructor
A new instance of Adapter.
-
#send_packet(packet) ⇒ Object
Send a packet to the service and returns the Packet returned by the service.
-
#send_packet!(packet) ⇒ Object
Actually send the packet to the service.
Constructor Details
#initialize(*args) ⇒ Adapter
Returns a new instance of Adapter.
6 7 8 |
# File 'lib/ribbon/intercom/client/sdk/adapters/adapter.rb', line 6 def initialize(*args) connect(*args) end |
Instance Method Details
#call(method_name, *args) ⇒ Object
This method is only called by tests. Don’t call it elsewhere.
Call the method on the service.
14 15 16 17 18 |
# File 'lib/ribbon/intercom/client/sdk/adapters/adapter.rb', line 14 def call(method_name, *args) send_packet( method_queue: Packet::MethodQueue.new.enqueue(method_name, *args) ) end |
#connect(*args) ⇒ Object
Connect to a service. The specific arguments depend on the Adapter subclass.
46 47 48 |
# File 'lib/ribbon/intercom/client/sdk/adapters/adapter.rb', line 46 def connect(*args) raise NotImplementedError end |
#connected? ⇒ Boolean
Returns whether or not the Adapter is connected to a service.
52 53 54 |
# File 'lib/ribbon/intercom/client/sdk/adapters/adapter.rb', line 52 def connected? raise NotImplementedError end |
#dup ⇒ Object
37 38 39 40 41 |
# File 'lib/ribbon/intercom/client/sdk/adapters/adapter.rb', line 37 def dup super.tap { |adapter| adapter.headers = @headers.dup if @headers } end |
#headers(new_headers = {}) ⇒ Object
Returns the headers defined for this Adapter. Optionally, you may also define additional headers you’d like to add/override.
33 34 35 |
# File 'lib/ribbon/intercom/client/sdk/adapters/adapter.rb', line 33 def headers(new_headers={}) (@headers ||= {}).merge!(new_headers) end |
#send_packet(packet) ⇒ Object
Send a packet to the service and returns the Packet returned by the service.
22 23 24 25 26 27 28 |
# File 'lib/ribbon/intercom/client/sdk/adapters/adapter.rb', line 22 def send_packet(packet) packet = Packet.new(packet) if packet.is_a?(Hash) send_packet!(packet.encode).tap { |response| raise TypeError, "send_packet! should return an Adapter::Response" unless response.is_a?(Response) }.packet end |
#send_packet!(packet) ⇒ Object
Actually send the packet to the service. Should return an Adapter::Response object.
58 59 60 |
# File 'lib/ribbon/intercom/client/sdk/adapters/adapter.rb', line 58 def send_packet!(packet) raise NotImplementedError end |