Class: Twi::Conversation
Overview
The representation of a (classic) group conversation.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #close ⇒ Object
- #create_message(content:, image_ids: []) ⇒ Object
- #create_with(participants:) ⇒ Object
- #delete ⇒ Object
- #rename(friendly_name) ⇒ Object
-
#upload(file) ⇒ Object
TODO: Move into Medium – this method doesn’t use anything from this class.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Twi::Resource
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/twi/conversation.rb', line 5 def id @id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/twi/conversation.rb', line 5 def status @status end |
Instance Method Details
#close ⇒ Object
25 26 27 |
# File 'lib/twi/conversation.rb', line 25 def close conversation.update state: :closed end |
#create_message(content:, image_ids: []) ⇒ Object
33 34 35 |
# File 'lib/twi/conversation.rb', line 33 def (content:, image_ids: []) conversation..create **(content, image_ids) end |
#create_with(participants:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/twi/conversation.rb', line 7 def create_with(participants:) params = create_params_for participants conversation = conversation_service.conversation_with_participants.create **params @id = conversation.sid @status = conversation.state rescue Twilio::REST::RestError => error case error.code when 50438 then raise ExistingConversationError.new(error.) when 50214 then raise TooManyConversationsError.new(error.) else raise end end |
#delete ⇒ Object
29 30 31 |
# File 'lib/twi/conversation.rb', line 29 def delete conversation.delete end |
#rename(friendly_name) ⇒ Object
21 22 23 |
# File 'lib/twi/conversation.rb', line 21 def rename(friendly_name) conversation.update friendly_name: friendly_name end |
#upload(file) ⇒ Object
TODO: Move into Medium – this method doesn’t use anything from this class
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/twi/conversation.rb', line 38 def upload(file) uri = URI "https://mcs.us1.twilio.com/v1/Services/#{Twi.lio.conversation_sid}/Media" http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true headers = { 'Content-Type' => file.content_type, 'Content-Size' => file.byte_size.to_s } request = Net::HTTP::Post.new uri.request_uri, headers request.basic_auth Twi.lio.api_key, Twi.lio.secret request.body = file.download response = http.request request JSON(response.body)['sid'] end |