Class: Tracksale::Answer
- Inherits:
-
Object
- Object
- Tracksale::Answer
- Defined in:
- lib/tracksale/answer.rb
Constant Summary collapse
- LIMIT =
-1
Instance Attribute Summary collapse
-
#campaign_code ⇒ Object
Returns the value of attribute campaign_code.
-
#campaign_name ⇒ Object
Returns the value of attribute campaign_name.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#deadline ⇒ Object
Returns the value of attribute deadline.
-
#dispatch_time ⇒ Object
Returns the value of attribute dispatch_time.
-
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
Returns the value of attribute id.
-
#identification ⇒ Object
Returns the value of attribute identification.
-
#justifications ⇒ Object
Returns the value of attribute justifications.
-
#last_nps_answer ⇒ Object
Returns the value of attribute last_nps_answer.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nps_answer ⇒ Object
Returns the value of attribute nps_answer.
-
#nps_comment ⇒ Object
Returns the value of attribute nps_comment.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#reminder_time ⇒ Object
Returns the value of attribute reminder_time.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#time ⇒ Object
Returns the value of attribute time.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .all(start_time = (Time.now-86_400), end_time = (Time.now+86_400)) ⇒ Object
- .client ⇒ Object
- .convert_justif(multiple_answers) ⇒ Object
- .convert_tags(tags) ⇒ Object
- .create_from_response(raw_response) ⇒ Object
- .raw_all(start_time = (Time.now-86_400), end_time = (Time.now+86_400)) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#campaign_code ⇒ Object
Returns the value of attribute campaign_code.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def campaign_code @campaign_code end |
#campaign_name ⇒ Object
Returns the value of attribute campaign_name.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def campaign_name @campaign_name end |
#categories ⇒ Object
Returns the value of attribute categories.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def categories @categories end |
#deadline ⇒ Object
Returns the value of attribute deadline.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def deadline @deadline end |
#dispatch_time ⇒ Object
Returns the value of attribute dispatch_time.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def dispatch_time @dispatch_time end |
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def elapsed_time @elapsed_time end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def email @email end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def id @id end |
#identification ⇒ Object
Returns the value of attribute identification.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def identification @identification end |
#justifications ⇒ Object
Returns the value of attribute justifications.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def justifications @justifications end |
#last_nps_answer ⇒ Object
Returns the value of attribute last_nps_answer.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def last_nps_answer @last_nps_answer end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def name @name end |
#nps_answer ⇒ Object
Returns the value of attribute nps_answer.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def nps_answer @nps_answer end |
#nps_comment ⇒ Object
Returns the value of attribute nps_comment.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def nps_comment @nps_comment end |
#phone ⇒ Object
Returns the value of attribute phone.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def phone @phone end |
#reminder_time ⇒ Object
Returns the value of attribute reminder_time.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def reminder_time @reminder_time end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def status @status end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def @tags end |
#time ⇒ Object
Returns the value of attribute time.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def time @time end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/tracksale/answer.rb', line 5 def type @type end |
Class Method Details
.all(start_time = (Time.now-86_400), end_time = (Time.now+86_400)) ⇒ Object
18 19 20 |
# File 'lib/tracksale/answer.rb', line 18 def all( start_time=(Time.now-86_400), end_time=(Time.now+86_400)) raw_all(start_time,end_time).map { |answer| create_from_response(answer) } end |
.client ⇒ Object
55 56 57 |
# File 'lib/tracksale/answer.rb', line 55 def client Tracksale.configuration.client.new end |
.convert_justif(multiple_answers) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tracksale/answer.rb', line 65 def convert_justif(multiple_answers) multiple_answers.map do |single_answer| begin { JSON.parse(single_answer['name']).values.first => single_answer['children'].map { |c| JSON.parse(c).values.first } } rescue JSON::ParserError { single_answer['name'] => single_answer['children'] } end end end |
.convert_tags(tags) ⇒ Object
59 60 61 62 63 |
# File 'lib/tracksale/answer.rb', line 59 def () .map do |tag| { tag['name'] => tag['value'] } end.reduce(&:merge) end |
.create_from_response(raw_response) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tracksale/answer.rb', line 22 def create_from_response(raw_response) new.tap do |answer| answer.time = Time.at(raw_response['time'].to_i) answer.type = raw_response['type'] answer.name = raw_response['name'] answer.email = raw_response['email'] answer.identification = raw_response['identification'] answer.phone = raw_response['phone'] answer.nps_answer = raw_response['nps_answer'] answer.last_nps_answer = raw_response['last_nps_answer'] answer.nps_comment = raw_response['nps_comment'] answer.campaign_name = raw_response['campaign_name'] answer.campaign_code = raw_response['campaign_code'] answer.id = raw_response['id'] answer.deadline = raw_response['deadline'] answer.elapsed_time = raw_response['elapsed_time'] answer.dispatch_time = raw_response['dispatch_time'] answer.reminder_time = raw_response['reminder_time'] answer.status = raw_response['status'] answer. = (raw_response['tags']) answer.categories = raw_response['categories'].map { |c| c['name'] } answer.justifications = convert_justif(raw_response['justifications']) end end |
.raw_all(start_time = (Time.now-86_400), end_time = (Time.now+86_400)) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/tracksale/answer.rb', line 47 def raw_all( start_time=(Time.now-86_400), end_time=(Time.now+86_400)) start_date = start_time.strftime('%Y-%m-%d') end_date = end_time.strftime('%Y-%m-%d') all_request = "report/answer?tags=true&limit=#{LIMIT}&start=#{start_date}&end=#{end_date}" client.get(all_request) end |
Instance Method Details
#campaign ⇒ Object
13 14 15 |
# File 'lib/tracksale/answer.rb', line 13 def campaign Tracksale::Campaign.find_by_code(campaign_code) end |