Class: ElectricProfile::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/electric_profile_ruby/profiler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atts) ⇒ Profiler

Returns a new instance of Profiler.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/electric_profile_ruby/profiler.rb', line 6

def initialize(atts)
  atts = atts.inject({}){ |memo, (k, v) | memo[k.to_sym] = v; memo }
  @id = atts[:id]
  @customerId = atts[:customerId]
  @name = atts[:name]
  @listQuestionsId = atts[:listQuestionsId] || []
  @introMessage = atts[:introMessage]
  @exitMessage = atts[:exitMessage]
  @hideAnsweredQuestions = atts[:hideAnsweredQuestions] || false
  @questionOrder = atts[:questionOrder]
  @callbackType = atts[:callbackType]
  @profilerCallbacks = atts[:profilerCallbacks]
  @archived = atts[:archived] || false
end

Instance Attribute Details

#archivedObject

Returns the value of attribute archived.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def archived
  @archived
end

#callbackTypeObject

Returns the value of attribute callbackType.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def callbackType
  @callbackType
end

#customerIdObject

Returns the value of attribute customerId.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def customerId
  @customerId
end

#errorObject

Returns the value of attribute error.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def error
  @error
end

#exitMessageObject

Returns the value of attribute exitMessage.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def exitMessage
  @exitMessage
end

#hideAnsweredQuestionsObject

Returns the value of attribute hideAnsweredQuestions.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def hideAnsweredQuestions
  @hideAnsweredQuestions
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def id
  @id
end

#introMessageObject

Returns the value of attribute introMessage.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def introMessage
  @introMessage
end

#listQuestionsIdObject

Returns the value of attribute listQuestionsId.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def listQuestionsId
  @listQuestionsId
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def name
  @name
end

#profilerCallbacksObject

Returns the value of attribute profilerCallbacks.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def profilerCallbacks
  @profilerCallbacks
end

#questionOrderObject

Returns the value of attribute questionOrder.



4
5
6
# File 'lib/electric_profile_ruby/profiler.rb', line 4

def questionOrder
  @questionOrder
end

Class Method Details

.allObject



86
87
88
89
90
91
92
93
# File 'lib/electric_profile_ruby/profiler.rb', line 86

def self.all
  client = Client.new
  if client.fetch_profilers
    client.data["Items"].map { |atts| new atts }
  else
    raise StandardError, client.error
  end
end

.find(id) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/electric_profile_ruby/profiler.rb', line 77

def self.find(id)
  client = Client.new
  if client.fetch_profiler(id)
    new client.data["data"]
  else
    raise StandardError, client.error
  end
end

Instance Method Details

#initialize_clientObject



95
96
97
# File 'lib/electric_profile_ruby/profiler.rb', line 95

def initialize_client
  @client ||= Client.new
end

#saveObject



21
22
23
24
25
26
27
# File 'lib/electric_profile_ruby/profiler.rb', line 21

def save
  if @id
    save_existing
  else
    save_new
  end
end

#save_existingObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/electric_profile_ruby/profiler.rb', line 53

def save_existing
  initialize_client
  attributes = {
    id: @id,
    customerId: @customerId,
    name: @name,
    listQuestionsId: @listQuestionsId,
    introMessage: @introMessage,
    exitMessage: @exitMessage,
    hideAnsweredQuestions: @hideAnsweredQuestions,
    questionOrder: @questionOrder,
    callbackType: @callbackType,
    profilerCallbacks: @profilerCallbacks,
    archived: @archived
  }
  attributes.delete(:profilerCallbacks) if attributes[:profilerCallbacks].nil?
  if @client.update_profiler(attributes)
    true
  else
    @error = @client.error
    false
  end
end

#save_newObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/electric_profile_ruby/profiler.rb', line 29

def save_new
  initialize_client
  attributes = {
    name: @name,
    listQuestionsId: @listQuestionsId,
    introMessage: @introMessage,
    exitMessage: @exitMessage,
    hideAnsweredQuestions: @hideAnsweredQuestions,
    questionOrder: @questionOrder,
    callbackType: @callbackType,
    profilerCallbacks: @profilerCallbacks,
    archived: @archived
  }
  attributes.delete(:profilerCallbacks) if attributes[:profilerCallbacks].nil?
  if @client.create_profiler(attributes)
    @id = @client.data["data"]["id"]
    @customerId = @client.data["data"]["customerId"]
    true
  else
    @error = @client.error
    false
  end
end