Class: Libring::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/libring/contact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contact_code) ⇒ Contact

Returns a new instance of Contact.



5
6
7
8
9
10
11
12
13
14
# File 'lib/libring/contact.rb', line 5

def initialize(contact_code)

  @contact_code = contact_code
  @attributes   = {}
  @location     = {}
  @events       = {}

  true

end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/libring/contact.rb', line 3

def attributes
  @attributes
end

#contact_codeObject (readonly)

Returns the value of attribute contact_code.



3
4
5
# File 'lib/libring/contact.rb', line 3

def contact_code
  @contact_code
end

#eventsObject (readonly)

Returns the value of attribute events.



3
4
5
# File 'lib/libring/contact.rb', line 3

def events
  @events
end

#locationObject (readonly)

Returns the value of attribute location.



3
4
5
# File 'lib/libring/contact.rb', line 3

def location
  @location
end

Instance Method Details

#add_attribute(name, value, type) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/libring/contact.rb', line 16

def add_attribute(name, value, type)

  if name == "" || value == "" || type == "" || (type != "string" && type != "decimal" && type != "integer" && type != "datetime")

    "You must inform valid params for name, value and type"

  else

    @attributes[name] = {}
    @attributes[name]["value"] = value
    @attributes[name]["type"] = type

    true

  end

end

#add_event(event) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/libring/contact.rb', line 72

def add_event(event)

  require 'json'

  if event.source != ""

    @events["#{event.date}"] = [] if !@events["#{event.date}"]

    @events["#{event.date}"].push( { :event_type => event.event_type, :event_code => event.event_code, :source => event.source, :expire_at => event.expire_at, :source_referral => event.source_referral, :page_title => event.page_title, :ip => event.ip, :invitees => event.invitees, :metadata => event., :products => event.products  } )

    true

  else

    "Event source required"

  end

end

#clean_attributesObject



40
41
42
43
44
45
46
# File 'lib/libring/contact.rb', line 40

def clean_attributes

  @attributes = {}

  true

end

#clean_eventsObject



92
93
94
95
96
97
98
# File 'lib/libring/contact.rb', line 92

def clean_events

  @events = {}

  true

end

#clean_locationObject



64
65
66
67
68
69
70
# File 'lib/libring/contact.rb', line 64

def clean_location

  @location = {}

  true

end

#get_attributesObject



34
35
36
37
38
# File 'lib/libring/contact.rb', line 34

def get_attributes

  @attributes

end

#get_locationObject



58
59
60
61
62
# File 'lib/libring/contact.rb', line 58

def get_location

  @location

end

#update_location(country, state = nil, city = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/libring/contact.rb', line 48

def update_location(country, state = nil, city = nil)

  @location["country"] = country
  @location["state"]   = state   if !state.nil?
  @location["city"]    = city    if !city.nil?

  true

end