Class: ZohoCrm::Record::CreateService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/zoho_crm/record/create_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_name:, data:) ⇒ CreateService



12
13
14
15
# File 'lib/zoho_crm/record/create_service.rb', line 12

def initialize(module_name:, data:)
  @module_name = module_name
  @data        = data.is_a?(Array) ? data : [data]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/zoho_crm/record/create_service.rb', line 4

def data
  @data
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



4
5
6
# File 'lib/zoho_crm/record/create_service.rb', line 4

def module_name
  @module_name
end

Instance Method Details

#callObject

Create a record.

www.zoho.com/crm/developer/docs/api/v7/insert-records.html

Examples

service = ZohoCrm::Record::CreateService.call(
  module_name: 'Contacts',
  data: {
    'Email' => '[email protected]',
    'First_Name' => 'Eric',
    'Last_Name' => 'Cartman'
  }
)

service.success? # => true
service.errors # => #<ActiveModel::Errors []>

service.response # => #<Faraday::Response ...>
service.response.status # => 201
service.response.body # => {}

service.facade # => #<ZohoCrm::Record::Facade ...>
service.facade.attributes
service.attributes

POST /crm/v7/:module_name



44
45
46
# File 'lib/zoho_crm/record/create_service.rb', line 44

def call
  connection.post(module_name, **params)
end