Module: ActiveCampaignCrm::Client::Organization

Included in:
ActiveCampaignCrm::Client
Defined in:
lib/active_campaign_crm/client/organizations.rb

Overview

Organization Interface

Instance Method Summary collapse

Instance Method Details

#create_organization(fields) ⇒ Object



15
16
17
18
# File 'lib/active_campaign_crm/client/organizations.rb', line 15

def create_organization(fields)
  response = @connection.post('organizations', organization_body(fields))
  response['organization']
end

#delete_organization(id) ⇒ Object



33
34
35
# File 'lib/active_campaign_crm/client/organizations.rb', line 33

def delete_organization(id)
  @connection.delete("organizations/#{id}")
end

#find_or_create_organization(name) ⇒ Object



20
21
22
23
24
25
# File 'lib/active_campaign_crm/client/organizations.rb', line 20

def find_or_create_organization(name)
  organizations = organizations("filters[name]": name)
  return organizations[0] if organizations.any?

  create_organization(name: name)
end

#organization(id) ⇒ Object



10
11
12
13
# File 'lib/active_campaign_crm/client/organizations.rb', line 10

def organization(id)
  response = @connection.get("organizations/#{id}")
  response['organization']
end

#organization_body(fields) ⇒ Object



37
38
39
# File 'lib/active_campaign_crm/client/organizations.rb', line 37

def organization_body(fields)
  { 'organization': fields }.to_json
end

#organizations(params = {}) ⇒ Object



5
6
7
8
# File 'lib/active_campaign_crm/client/organizations.rb', line 5

def organizations(params = {})
  response = @connection.get('organizations', params)
  response['organizations']
end

#update_organization(id, fields) ⇒ Object



27
28
29
30
31
# File 'lib/active_campaign_crm/client/organizations.rb', line 27

def update_organization(id, fields)
  response = @connection.put("organizations/#{id}",
                             organization_body(fields))
  response['organization']
end