Class: Sendly::DraftsResource
- Inherits:
-
Object
- Object
- Sendly::DraftsResource
- Defined in:
- lib/sendly/drafts_resource.rb
Instance Method Summary collapse
- #approve(id) ⇒ Object
- #create(conversation_id:, text:, media_urls: nil, metadata: nil, source: nil) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(client) ⇒ DraftsResource
constructor
A new instance of DraftsResource.
- #list(conversation_id: nil, status: nil, limit: nil, offset: nil) ⇒ Object
- #reject(id, reason: nil) ⇒ Object
- #update(id, text: nil, media_urls: nil, metadata: nil) ⇒ Object
Constructor Details
#initialize(client) ⇒ DraftsResource
Returns a new instance of DraftsResource.
5 6 7 |
# File 'lib/sendly/drafts_resource.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#approve(id) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/sendly/drafts_resource.rb', line 49 def approve(id) raise ValidationError, "Draft ID is required" if id.nil? || id.empty? response = @client.post("/drafts/#{URI.encode_www_form_component(id)}/approve") Draft.new(response) end |
#create(conversation_id:, text:, media_urls: nil, metadata: nil, source: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/sendly/drafts_resource.rb', line 9 def create(conversation_id:, text:, media_urls: nil, metadata: nil, source: nil) body = { conversationId: conversation_id, text: text } body[:mediaUrls] = media_urls if media_urls body[:metadata] = if body[:source] = source if source response = @client.post("/drafts", body) Draft.new(response) end |
#get(id) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/sendly/drafts_resource.rb', line 30 def get(id) raise ValidationError, "Draft ID is required" if id.nil? || id.empty? response = @client.get("/drafts/#{URI.encode_www_form_component(id)}") Draft.new(response) end |
#list(conversation_id: nil, status: nil, limit: nil, offset: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sendly/drafts_resource.rb', line 19 def list(conversation_id: nil, status: nil, limit: nil, offset: nil) params = {} params[:conversation_id] = conversation_id if conversation_id params[:status] = status if status params[:limit] = limit if limit params[:offset] = offset if offset response = @client.get("/drafts", params.compact) DraftList.new(response) end |
#reject(id, reason: nil) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/sendly/drafts_resource.rb', line 56 def reject(id, reason: nil) raise ValidationError, "Draft ID is required" if id.nil? || id.empty? body = {} body[:reason] = reason if reason response = @client.post("/drafts/#{URI.encode_www_form_component(id)}/reject", body) Draft.new(response) end |
#update(id, text: nil, media_urls: nil, metadata: nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sendly/drafts_resource.rb', line 37 def update(id, text: nil, media_urls: nil, metadata: nil) raise ValidationError, "Draft ID is required" if id.nil? || id.empty? body = {} body[:text] = text if text body[:mediaUrls] = media_urls if media_urls body[:metadata] = unless .nil? response = @client.patch("/drafts/#{URI.encode_www_form_component(id)}", body) Draft.new(response) end |