Class: ElectricProfile::Profiler
- Inherits:
-
Object
- Object
- ElectricProfile::Profiler
- Defined in:
- lib/electric_profile_ruby/profiler.rb
Instance Attribute Summary collapse
-
#archived ⇒ Object
Returns the value of attribute archived.
-
#callbackType ⇒ Object
Returns the value of attribute callbackType.
-
#customerId ⇒ Object
Returns the value of attribute customerId.
-
#error ⇒ Object
Returns the value of attribute error.
-
#exitMessage ⇒ Object
Returns the value of attribute exitMessage.
-
#hideAnsweredQuestions ⇒ Object
Returns the value of attribute hideAnsweredQuestions.
-
#id ⇒ Object
Returns the value of attribute id.
-
#introMessage ⇒ Object
Returns the value of attribute introMessage.
-
#listQuestionsId ⇒ Object
Returns the value of attribute listQuestionsId.
-
#name ⇒ Object
Returns the value of attribute name.
-
#profilerCallbacks ⇒ Object
Returns the value of attribute profilerCallbacks.
-
#questionOrder ⇒ Object
Returns the value of attribute questionOrder.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(atts) ⇒ Profiler
constructor
A new instance of Profiler.
- #initialize_client ⇒ Object
- #save ⇒ Object
- #save_existing ⇒ Object
- #save_new ⇒ Object
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
#archived ⇒ Object
Returns the value of attribute archived.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def archived @archived end |
#callbackType ⇒ Object
Returns the value of attribute callbackType.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def callbackType @callbackType end |
#customerId ⇒ Object
Returns the value of attribute customerId.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def customerId @customerId end |
#error ⇒ Object
Returns the value of attribute error.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def error @error end |
#exitMessage ⇒ Object
Returns the value of attribute exitMessage.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def exitMessage @exitMessage end |
#hideAnsweredQuestions ⇒ Object
Returns the value of attribute hideAnsweredQuestions.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def hideAnsweredQuestions @hideAnsweredQuestions end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def id @id end |
#introMessage ⇒ Object
Returns the value of attribute introMessage.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def introMessage @introMessage end |
#listQuestionsId ⇒ Object
Returns the value of attribute listQuestionsId.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def listQuestionsId @listQuestionsId end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def name @name end |
#profilerCallbacks ⇒ Object
Returns the value of attribute profilerCallbacks.
4 5 6 |
# File 'lib/electric_profile_ruby/profiler.rb', line 4 def profilerCallbacks @profilerCallbacks end |
#questionOrder ⇒ Object
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
.all ⇒ Object
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_client ⇒ Object
95 96 97 |
# File 'lib/electric_profile_ruby/profiler.rb', line 95 def initialize_client @client ||= Client.new end |
#save ⇒ Object
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_existing ⇒ Object
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_new ⇒ Object
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 |