Class: Hubspot::Properties

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

Constant Summary collapse

PROPERTY_SPECS =
{
  group_field_names: %w(name displayName displayOrder properties),
  field_names:       %w(name groupName description fieldType formField type displayOrder label options showCurrencySymbol),
  valid_field_types: %w(textarea select text date file number radio checkbox booleancheckbox),
  valid_types:       %w(string number bool date datetime enumeration),
  options:           %w(description value label hidden displayOrder)
}
DEFAULT_PROPERTY =
'email'

Class Method Summary collapse

Class Method Details

.add_default_parameters(opts = {}) ⇒ Object

TODO: properties can be set as configuration TODO: find the way how to set a list of Properties + merge same property key if present from opts



16
17
18
19
20
21
22
# File 'lib/hubspot/properties.rb', line 16

def add_default_parameters(opts={})
  if opts.keys.map(&:to_s).include? 'property'
    opts
  else
    opts.merge(property: DEFAULT_PROPERTY)
  end
end

.all(path, opts = {}, filter = {}) ⇒ Object



24
25
26
27
# File 'lib/hubspot/properties.rb', line 24

def all(path, opts={}, filter={})
  response = Hubspot::Connection.get_json(path, opts)
  filter_results(response, :groupName, filter[:include], filter[:exclude])
end

.create!(path, params = {}) ⇒ Object



34
35
36
37
38
# File 'lib/hubspot/properties.rb', line 34

def create!(path, params={})
  post_data = valid_property_params(params)
  return nil if post_data.blank?
  Hubspot::Connection.post_json(path, params: {}, body: post_data)
end

.create_group!(path, params = {}) ⇒ Object



51
52
53
54
55
# File 'lib/hubspot/properties.rb', line 51

def create_group!(path, params={})
  post_data = valid_group_params(params)
  return nil if post_data.blank?
  Hubspot::Connection.post_json(path, params: {}, body: post_data)
end

.delete!(path, property_name) ⇒ Object



46
47
48
49
# File 'lib/hubspot/properties.rb', line 46

def delete!(path, property_name)
  response = Hubspot::Connection.delete_json(path, property_name: property_name)
  response.parsed_response
end

.delete_group!(path, group_name) ⇒ Object



63
64
65
66
# File 'lib/hubspot/properties.rb', line 63

def delete_group!(path, group_name)
  response = Hubspot::Connection.delete_json(path, group_name: group_name)
  response.parsed_response
end

.groups(path, opts = {}, filter = {}) ⇒ Object



29
30
31
32
# File 'lib/hubspot/properties.rb', line 29

def groups(path, opts={}, filter={})
  response = Hubspot::Connection.get_json(path, opts)
  filter_results(response, :name, filter[:include], filter[:exclude])
end

.same?(src, dst) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
# File 'lib/hubspot/properties.rb', line 68

def same?(src, dst)
  src_params = valid_params(src)
  dst_params = valid_params(dst)
  src_params.eql?(dst_params)
  # hash_same?(src_params, dst_params)
end

.update!(path, property_name, params = {}) ⇒ Object



40
41
42
43
44
# File 'lib/hubspot/properties.rb', line 40

def update!(path, property_name, params={})
  post_data = valid_property_params(params)
  return nil if post_data.blank?
  Hubspot::Connection.put_json(path, params: { property_name: property_name }, body: post_data)
end

.update_group!(path, group_name, params = {}) ⇒ Object



57
58
59
60
61
# File 'lib/hubspot/properties.rb', line 57

def update_group!(path, group_name, params={})
  post_data = valid_group_params(params)
  return nil if post_data.blank?
  Hubspot::Connection.put_json(path, params: { group_name: group_name }, body: post_data)
end

.valid_params(params = {}) ⇒ Object



75
76
77
# File 'lib/hubspot/properties.rb', line 75

def valid_params(params={})
  valid_property_params(params)
end