patient_zero 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4024def469f47be91a5c4adf49c024e64d39fddb
4
- data.tar.gz: 93429e3a2e9fcd04c96093d93044ff8a164178e6
3
+ metadata.gz: f1270910c6c0716586db130a0bb3bc42a135b884
4
+ data.tar.gz: 651df620375f274d438be4b03e7824ab818a3794
5
5
  SHA512:
6
- metadata.gz: 2fa33fa7b2315c9606817c375236d67d3988ac540b891949c6a2aeb7356d6b08fe084e8a6d1ec9eb3fe8716a12f64bf86a60ef0f194fc83a3aabf87507dcaa0f
7
- data.tar.gz: 4c45b2c1b326483bcd72c8c167b1a614c762924ab22ef809aeb49404c012c90c142319a470cb8dc472d2f620571d1ddbe0239bb10de22a2cb79013226493d172
6
+ metadata.gz: 52aa5cb238aac7d9262199b4a34f5b1b1227ea8d23ebdfe9384c3fadb68b71777a804b9eea9361d342e4ae5adab2e993b67b95409ff07227d2f46e0052ec0e64
7
+ data.tar.gz: 39be0fe939bb7e9e1b098c561cc5a01047a6b1608b2eaa2dcc83edc2748a5060645f51d5823bb59a4775e38148b2053737802904f7381547ce1a672128e68076
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .env
@@ -9,6 +9,23 @@ module PatientZero
9
9
  page_impressions + message_impressions
10
10
  end
11
11
 
12
+ def impressions_by_city
13
+ analytical_data.fetch("impressions_by_cities").each_with_object({}) do |city, cities|
14
+ cities[city['title']] = city['count']
15
+ end
16
+ end
17
+
18
+ def impressions_by_age
19
+ analytical_data.fetch('impressions_by_ages',[]).first.to_h.fetch('values',{})
20
+ end
21
+
22
+ def impressions_by_gender
23
+ gender_stats = analytical_data['impressions_by_genders']
24
+ { female: gender_stats.fetch('F', 0),
25
+ male: gender_stats.fetch('M', 0),
26
+ unknown: gender_stats.fetch('U', 0) }
27
+ end
28
+
12
29
  private
13
30
 
14
31
  def message_impressions
@@ -32,7 +32,8 @@ module PatientZero
32
32
  end
33
33
 
34
34
  def analytics start_date: nil, end_date: nil
35
- @analytics ||= Analytics.for_platform platform, token: token, source_id: id, start_date: start_date, end_date: end_date
35
+ @analytics ||= {}
36
+ @analytics["#{start_date}#{end_date}"] ||= Analytics.for_platform platform, token: token, source_id: id, start_date: start_date, end_date: end_date
36
37
  end
37
38
  end
38
39
  end
@@ -1,3 +1,3 @@
1
1
  module PatientZero
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
data/patient_zero.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rspec'
24
24
  spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'dotenv'
25
26
 
26
27
  spec.add_dependency 'faraday'
27
28
  spec.add_dependency 'json'
@@ -19,11 +19,48 @@ module PatientZero
19
19
  'values'=>
20
20
  { '2010-10-10'=> 99 } } ]
21
21
  end
22
+ let(:age_data) { {"13-17"=>14_000, "18-24"=>240_000, "25-34"=>650_000, "35-44"=>660_000, "45-54"=>380_000, "55-64"=>170_000, "65+"=>93_000} }
23
+ let(:impressions_by_city) { [{"title"=>"Atlanta, GA", "count"=>16_000}, {"title"=>"Los Angeles, CA", "count"=>15_000}, {"title"=>"San Diego, CA", "count"=>14_000}] }
24
+ let(:impressions_by_age) { [{"key"=>"Users", "values"=>age_data}] }
25
+ let(:impressions_by_gender) { {"F"=>100_000, "M"=>70_000, "U"=>10_000} }
22
26
  let(:token) { 'token-shmoken' }
23
- let(:analytical_data) { { 'messages' => messages, 'page_impressions' => page_impressions } }
27
+ let(:analytical_data) do
28
+ { 'messages' => messages,
29
+ 'page_impressions' => page_impressions,
30
+ 'impressions_by_cities' => impressions_by_city,
31
+ 'impressions_by_ages' => impressions_by_age,
32
+ 'impressions_by_genders' => impressions_by_gender }
33
+ end
24
34
  let(:facebook_analytics) { Facebook.new token: token, source_id: source_id }
25
35
  before{ allow(facebook_analytics).to receive(:analytical_data).and_return analytical_data }
26
36
 
37
+ describe '#impressions_by_city' do
38
+ it 'returns the impressions by city' do
39
+ expected_result = {
40
+ "Atlanta, GA"=>16_000,
41
+ "Los Angeles, CA"=>15_000,
42
+ "San Diego, CA"=>14_000 }
43
+ expect(facebook_analytics.impressions_by_city).to eq expected_result
44
+ end
45
+ end
46
+
47
+ describe '#impressions_by_age' do
48
+ it 'returns the impressions by age' do
49
+ expect(facebook_analytics.impressions_by_age).to eq age_data
50
+ end
51
+ end
52
+
53
+ describe '#impressions_by_gender' do
54
+ it 'returns the impressions_by_gender' do
55
+ expected_result = {
56
+ female: impressions_by_gender['F'],
57
+ male: impressions_by_gender['M'],
58
+ unknown: impressions_by_gender['U']
59
+ }
60
+ expect(facebook_analytics.impressions_by_gender).to eq expected_result
61
+ end
62
+ end
63
+
27
64
  describe '#impressions' do
28
65
  it 'returns the total for message and page impressions' do
29
66
  expect(facebook_analytics.impressions).to eq 444
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patient_zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Zaninovich
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: dotenv
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: faraday
72
86
  requirement: !ruby/object:Gem::Requirement
@@ -184,3 +198,4 @@ test_files:
184
198
  - spec/patient_zero/profile_spec.rb
185
199
  - spec/patient_zero/source_spec.rb
186
200
  - spec/spec_helper.rb
201
+ has_rdoc: