Class: PatientZero::Analytics::Base

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/patient_zero/analytics/base.rb

Direct Known Subclasses

Facebook, Instagram, Tumblr, Twitter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Client

#connection, #get, included, #parse, #post, #put

Constructor Details

#initialize(token:, source_id:, start_date: nil, end_date: nil) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
# File 'lib/patient_zero/analytics/base.rb', line 8

def initialize token:, source_id:, start_date: nil, end_date: nil
  @token = token
  @source_id = source_id
  @end_date = end_date || Date.today.to_s
  @start_date = start_date || Date.today.prev_day(7).to_s
end

Instance Attribute Details

#end_dateObject

Returns the value of attribute end_date.



6
7
8
# File 'lib/patient_zero/analytics/base.rb', line 6

def end_date
  @end_date
end

#source_idObject

Returns the value of attribute source_id.



6
7
8
# File 'lib/patient_zero/analytics/base.rb', line 6

def source_id
  @source_id
end

#start_dateObject

Returns the value of attribute start_date.



6
7
8
# File 'lib/patient_zero/analytics/base.rb', line 6

def start_date
  @start_date
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/patient_zero/analytics/base.rb', line 6

def token
  @token
end

Instance Method Details

#messagesObject



23
24
25
# File 'lib/patient_zero/analytics/base.rb', line 23

def messages
  analytical_data['messages'].map { |message| Message.for_platform message['platform'], message }.compact
end

#nameObject



15
16
17
# File 'lib/patient_zero/analytics/base.rb', line 15

def name
  analytical_data['name']
end

#platformObject



19
20
21
# File 'lib/patient_zero/analytics/base.rb', line 19

def platform
  analytical_data['platform']
end

#total_postsObject



27
28
29
# File 'lib/patient_zero/analytics/base.rb', line 27

def total_posts
  messages.count
end