Class: Tracksale::Answer

Inherits:
Object
  • Object
show all
Defined in:
lib/tracksale/answer.rb

Constant Summary collapse

LIMIT =
-1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#campaign_codeObject

Returns the value of attribute campaign_code.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def campaign_code
  @campaign_code
end

#campaign_nameObject

Returns the value of attribute campaign_name.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def campaign_name
  @campaign_name
end

#categoriesObject

Returns the value of attribute categories.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def categories
  @categories
end

#deadlineObject

Returns the value of attribute deadline.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def deadline
  @deadline
end

#dispatch_timeObject

Returns the value of attribute dispatch_time.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def dispatch_time
  @dispatch_time
end

#elapsed_timeObject

Returns the value of attribute elapsed_time.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def elapsed_time
  @elapsed_time
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def email
  @email
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def id
  @id
end

#identificationObject

Returns the value of attribute identification.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def identification
  @identification
end

#justificationsObject

Returns the value of attribute justifications.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def justifications
  @justifications
end

#last_nps_answerObject

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

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def name
  @name
end

#nps_answerObject

Returns the value of attribute nps_answer.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def nps_answer
  @nps_answer
end

#nps_commentObject

Returns the value of attribute nps_comment.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def nps_comment
  @nps_comment
end

#phoneObject

Returns the value of attribute phone.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def phone
  @phone
end

#reminder_timeObject

Returns the value of attribute reminder_time.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def reminder_time
  @reminder_time
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def status
  @status
end

#tagsObject

Returns the value of attribute tags.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def tags
  @tags
end

#timeObject

Returns the value of attribute time.



5
6
7
# File 'lib/tracksale/answer.rb', line 5

def time
  @time
end

#typeObject

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

.clientObject



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 convert_tags(tags)
  tags.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.tags = convert_tags(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

#campaignObject



13
14
15
# File 'lib/tracksale/answer.rb', line 13

def campaign
  Tracksale::Campaign.find_by_code(campaign_code)
end