Class: Hubspot::Meeting

Inherits:
Object
  • Object
show all
Defined in:
lib/hubspot/meeting.rb

Constant Summary collapse

MEETINGS_PATH =
'/crm/v3/objects/meetings'
MEETING_PATH =
'/crm/v3/objects/meetings/:meeting_id'
MEETING_SEARCH_PATH =
'/crm/v3/objects/meetings/search'
ASSOCIATE_MEETING_PATH =
'/crm/v3/objects/meetings/:meeting_id/associations/Contact/:contact_id/meeting_event_to_contact'
BASE_PROPERTIES =
%w[hubspot_owner_id hs_meeting_title hs_meeting_body hs_meeting_start_time hs_meeting_end_time].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Meeting

Returns a new instance of Meeting.



96
97
98
# File 'lib/hubspot/meeting.rb', line 96

def initialize(hash)
  self.send(:assign_properties, hash)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



93
94
95
# File 'lib/hubspot/meeting.rb', line 93

def id
  @id
end

#propertiesObject (readonly)

Returns the value of attribute properties.



94
95
96
# File 'lib/hubspot/meeting.rb', line 94

def properties
  @properties
end

Class Method Details

.all(opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/hubspot/meeting.rb', line 18

def all(opts = {})
  options = { properties: BASE_PROPERTIES.join(','), **opts.compact }
  response = Hubspot::Connection.get_json(MEETINGS_PATH, options)
  meetings = response['results'].map { |result| new(result) }

  {
    meetings: meetings,
    after: response.dig('paging', 'next', 'after')
  }
end

.associate!(meeting_id, contact_id) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/hubspot/meeting.rb', line 84

def associate!(meeting_id, contact_id)
  Hubspot::Connection.put_json(ASSOCIATE_MEETING_PATH,
                               params: {
                                 meeting_id: meeting_id,
                                 contact_id: contact_id
                               })
end

.create!(owner_id, meeting_title, meeting_body, start_date_time, end_date_time) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/hubspot/meeting.rb', line 64

def create!(owner_id, meeting_title, meeting_body, start_date_time, end_date_time)
  body = {
    properties: {
      hs_timestamp: DateTime.now.strftime('%Q'),
      hubspot_owner_id: owner_id,
      hs_meeting_title: meeting_title,
      hs_meeting_body: meeting_body,
      hs_meeting_start_time: start_date_time.is_a?(DateTime) ? start_date_time.strftime('%Q') : start_date_time,
      hs_meeting_end_time: end_date_time.is_a?(DateTime) ? end_date_time.strftime('%Q') : end_date_time,
      hs_meeting_outcome: 'SCHEDULED'
    }
  }
  response = Hubspot::Connection.post_json(MEETINGS_PATH, params: {}, body: body)
  HashWithIndifferentAccess.new(response)
end

.destroy!(meeting_id) ⇒ Object



80
81
82
# File 'lib/hubspot/meeting.rb', line 80

def destroy!(meeting_id)
  Hubspot::Connection.delete_json(MEETING_PATH, {meeting_id: meeting_id})
end

.find(id, opts = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/hubspot/meeting.rb', line 29

def find(id, opts = {})
  input_properties = opts[:properties].presence || []
  properties = BASE_PROPERTIES | input_properties.compact

  response = Hubspot::Connection.get_json(MEETING_PATH, { meeting_id: id, properties: properties.join(',') })
  new(response)
end

.find_by_contact(contact_id, opts = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hubspot/meeting.rb', line 37

def find_by_contact(contact_id, opts={})
  params = {
    limit: opts[:limit].presence || 100,
    after: opts[:after].presence
  }.compact
  properties = opts[:properties].presence || []

  default_filters = [{ propertyName: 'associations.contact', 'operator': 'EQ', value: contact_id }]
  default_sorts = [{ propertyName: "hs_lastmodifieddate", direction: "DESCENDING" }]

  response = Hubspot::Connection.post_json(MEETING_SEARCH_PATH, {
      params: {},
      body: {
        **params,
        properties: BASE_PROPERTIES | properties.compact,
        filters: (opts[:filters].presence || []) + default_filters,
        sorts: opts[:sorts].presence || default_sorts
      }
    }
  )

  {
    after: response.dig('paging', 'next', 'after'),
    meetings: response['results'].map { |f| new(f) }
  }
end