Class: BusinessCentral::Object::Attachments

Inherits:
Base
  • Object
show all
Defined in:
lib/business_central/object/attachments.rb

Constant Summary collapse

OBJECT =
'attachments'

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#create, #find_all, #find_by_id, #method_missing, #respond_to_missing?, #where

Constructor Details

#initialize(client, **args) ⇒ Attachments

Returns a new instance of Attachments.



10
11
12
# File 'lib/business_central/object/attachments.rb', line 10

def initialize(client, **args)
  super(client, **args.merge!({ object_name: OBJECT }))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BusinessCentral::Object::Base

Instance Method Details

#destroy(id) ⇒ Object



23
24
25
# File 'lib/business_central/object/attachments.rb', line 23

def destroy(id)
  Request.call(:delete, @client, build_url(object_id: id), etag: '')
end

#update(parent_id:, attachment_id:, **params) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/business_central/object/attachments.rb', line 14

def update(parent_id:, attachment_id:, **params)
  url = "#{build_url}(parentId=#{parent_id},id=#{attachment_id})/content"
  Request.call(:patch, @client, url, etag: '', params: {}) do |request|
    request['Content-Type'] = 'application/json'
    request['If-Match'] = 'application/json'
    request.body = Request.convert(params)
  end
end