eaternet 1.4.1 → 1.4.2

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: bea0f02da14266e9021bb9ba118ac852cbca8d4f
4
- data.tar.gz: d931c40c286985d654270bd2ef36a0f7d946c575
3
+ metadata.gz: 933e9e7767be38a5187f7fe75da2bb413c32c5eb
4
+ data.tar.gz: a8c297bab85882be74676fce1a91d5c57a0fcf65
5
5
  SHA512:
6
- metadata.gz: a33a879a009eb468307e9f6975cbf020c48655a5d89353f0b5a114f1b21b114cdb48cacc4f0cfc3b12c1ecef0f8f1c41ae1ad87ba365d81dd53bb8677163a243
7
- data.tar.gz: de074c2a1eb77824cecfa79b4b42867994180cf609c64e79a73286bc4f65ef39ee7aa11fe932884b27e3c37767d3d6125412e97a04acaa79abade6732988ce2b
6
+ metadata.gz: bbc30f5f4f5628ba6ae4004788990d2c9bb0f5244a36b1c3c1832193f76f28ced9771fbd03f3ce7f12b08392852758012b2452cc3d4daa7cb8389ecb561f2bc0
7
+ data.tar.gz: 628541d013b36ae249e6f2b5e98e2eb126d0ee4b1e16a764bc12ba6ef8d4764a4532ffa73916a9e14783a902178d0d9eeb90f95566a666ba53bcf2c9043aa80b
data/README.md CHANGED
@@ -40,6 +40,13 @@ nyc.businesses.each { |biz| puts biz.name }
40
40
  Each adapter provides [a small set of enumerators](https://github.com/eaternet/adapters-ruby/blob/master/lib/eaternet/adapters/framework.rb#L27-L39) such as `businesses` and `inspections`. See the [Las Vegas tests](https://github.com/eaternet/adapters-ruby/blob/master/test/snhd_adapter_test.rb) to learn how an application would use this gem. The framework also includes [standardized data transfer objects](https://github.com/eaternet/adapters-ruby/blob/master/lib/eaternet/adapters/framework.rb#L42-L103) which these enumerators return.
41
41
 
42
42
 
43
+ ## Logging
44
+
45
+ * Optionally set `EATERNET_LOG_FILE` to send to a file instead of `STDOUT`.
46
+ * Optionally set `EATERNET_LOG_SEVERITY` to an **integer** to control which
47
+ messages are reported. Through experimenting with `Logger::`, I've found that
48
+ `DEBUG` is `0`, `INFO` is `1`, `WARN` is 2, `ERROR` is 3, and `FATAL` is `4`.
49
+
43
50
  ## Installation
44
51
 
45
52
  Add this line to your application's Gemfile:
@@ -9,6 +9,7 @@ module Eaternet
9
9
  include Eaternet::Loggable
10
10
  include Eaternet::Lives_1_0::CsvParser
11
11
 
12
+
12
13
  # Create an Austin data-source, ready for querying.
13
14
  #
14
15
  # @example
@@ -19,6 +20,7 @@ module Eaternet
19
20
  @table_file = csv_path
20
21
  end
21
22
 
23
+
22
24
  # @example Print the number of restaurants in the city.
23
25
  # puts austin.businesses.count
24
26
  #
@@ -29,19 +31,23 @@ module Eaternet
29
31
  .compact
30
32
  end
31
33
 
34
+
32
35
  def inspections
33
36
  map_csv { |row| try_to_create(:inspection, from_csv_row: row) }
34
37
  .compact
35
38
  end
36
39
 
40
+
37
41
  def violations
38
42
  fail Eaternet::UnsupportedError, "Austin doesn't publish violation data"
39
43
  end
40
44
 
45
+
41
46
  def legends
42
47
  fail Eaternet::UnsupportedError, 'Austin does not assign letter grades'
43
48
  end
44
49
 
50
+
45
51
  def feed_info
46
52
  Eaternet::Lives_1_0::FeedInfo.new do |fi|
47
53
  fi.feed_date = Date.today
@@ -61,6 +67,7 @@ module Eaternet
61
67
  end
62
68
  end
63
69
 
70
+
64
71
  def business(row)
65
72
  Eaternet::Lives_1_0::Business.new do |b|
66
73
  fail ArgumentError, 'No address found' if row['Address'].nil?
@@ -92,7 +99,7 @@ module Eaternet
92
99
 
93
100
 
94
101
  def table_file
95
- @table_file ||= Austin.download_via_url
102
+ Austin.download_via_url
96
103
  end
97
104
 
98
105
  def self.download_via_url
@@ -57,7 +57,7 @@ module Eaternet
57
57
  #
58
58
  # @param [String] csv_path for unit testing
59
59
  def initialize(csv_path: nil)
60
- @table_file = csv_path
60
+ @fixture_table_file = csv_path
61
61
  end
62
62
 
63
63
  # @example Print the number of restaurants in New York.
@@ -194,7 +194,7 @@ module Eaternet
194
194
  end
195
195
 
196
196
  def table_file
197
- Nyc.download_via_url
197
+ @fixture_table_file || Nyc.download_via_url
198
198
  end
199
199
 
200
200
  # Fastest method for downloading all data but may be non-standard
@@ -98,7 +98,7 @@ module Eaternet
98
98
  end
99
99
 
100
100
  def zip_dir
101
- @zip_dir ||= Util.download_and_extract_zipfile(SnhdConfig::DOWNLOAD_URL)
101
+ Util.download_and_extract_zipfile(SnhdConfig::DOWNLOAD_URL)
102
102
  end
103
103
  end
104
104
  end
@@ -28,7 +28,7 @@ module Eaternet
28
28
  end
29
29
 
30
30
  def zip_dir
31
- @zip_dir ||= Util.download_and_extract_zipfile(zip_file_url)
31
+ Util.download_and_extract_zipfile(zip_file_url)
32
32
  end
33
33
 
34
34
  def try_to_create(entity_type, from_csv_row:)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Eaternet
2
3
  # A mixin to add logging functionality to a class.
3
4
  module Loggable
@@ -11,8 +12,8 @@ module Eaternet
11
12
  def create_logger
12
13
  logger = Logger.new(ENV['EATERNET_LOG_FILE'] || $stderr)
13
14
  logger.datetime_format = '%Y-%m-%d %H:%M:%S'
14
- logger.progname = 'Eaternet'
15
- logger.level = Logger::DEBUG
15
+ logger.progname = 'Eaternet Adapter (Ruby)'
16
+ logger.level = ENV['EATERNET_LOG_SEVERITY'] || Logger::ERROR
16
17
  logger
17
18
  end
18
19
  end
@@ -68,7 +68,7 @@ module Eaternet
68
68
 
69
69
  def self.generate_cache_path(url)
70
70
  cache_dir = prepare_cache_dir
71
- cache_key = Base64.strict_encode64(url)
71
+ cache_key = 'cache-key-' + Base64.strict_encode64(url)
72
72
  File.join(cache_dir, cache_key)
73
73
  end
74
74
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Eaternet
3
- VERSION = '1.4.1'
3
+ VERSION = '1.4.2'
4
4
  end
@@ -1,55 +1,55 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  require 'eaternet'
4
5
  require 'eaternet/lives_1_0'
5
6
 
6
- AUSTIN_CSV = 'test/fixtures/austin.csv'
7
-
8
7
  class AustinAdapterTest < Minitest::Test
9
- @@agency = Eaternet::Austin.new(csv_path: AUSTIN_CSV)
8
+ def austin_agency
9
+ Eaternet::Austin.new
10
+ end
10
11
 
11
12
  #
12
13
  # Businesses
13
14
  #
14
15
 
15
16
  def test_businesses_returns_an_enumerator_of_business
16
- assert enumerable_of? Eaternet::Lives_1_0::Business, @@agency.businesses
17
- end
18
-
19
- def test_businesses_returns_lives_attributes
20
- b = @@agency.businesses.first
21
- assert_equal '2801033', b.business_id
22
- assert_equal '15th Street Cafe', b.name
23
- assert_equal '303 W 15TH ST', b.address
24
- assert_equal 'AUSTIN', b.city
25
- assert_equal '78701', b.postal_code
26
- assert_equal 'TX', b.state
27
- assert_equal 30.277553492000038, b.latitude
28
- assert_equal -97.74209889799994, b.longitude
17
+ VCR.use_cassette(AUSTIN_CASSETTE) do
18
+ assert enumerable_of? Eaternet::Lives_1_0::Business, austin_agency.businesses
19
+ end
29
20
  end
30
21
 
31
- def test_businesses_returns_correct_city
32
- b = @@agency.businesses.to_a[2]
33
- assert_equal 'BUDA', b.city
22
+ def test_businesses_returns_correct_attributes
23
+ VCR.use_cassette(AUSTIN_CASSETTE) do
24
+ b = austin_agency.businesses.find { |biz| biz.business_id == '2801033' }
25
+ assert_equal '15th Street Cafe', b.name
26
+ assert_equal '303 W 15TH ST', b.address
27
+ assert_equal 'AUSTIN', b.city
28
+ assert_equal '78701', b.postal_code
29
+ assert_equal 'TX', b.state
30
+ assert_in_delta 30.277553492000038, b.latitude
31
+ assert_in_delta(-97.74209889799994, b.longitude)
32
+ end
34
33
  end
35
34
 
36
- def test_businesses_returns_unique_rows
37
- assert_equal 3, @@agency.businesses.to_a.size
38
- end
39
35
 
40
36
  #
41
37
  # Inspections
42
38
  #
43
39
 
44
40
  def test_inspections_returns_an_enumerable_of_inspection
45
- assert enumerable_of? Eaternet::Lives_1_0::Inspection, @@agency.inspections
41
+ VCR.use_cassette(AUSTIN_CASSETTE) do
42
+ assert enumerable_of? Eaternet::Lives_1_0::Inspection, austin_agency.inspections
43
+ end
46
44
  end
47
45
 
48
46
  def test_inspections_returns_correct_attributes
49
- i = @@agency.inspections.first
50
- assert_equal '2801033', i.business_id
51
- assert_equal Date.new(2015, 5, 13), i.date
52
- assert_equal 97, i.score
47
+ VCR.use_cassette(AUSTIN_CASSETTE) do
48
+ i = austin_agency.inspections.find { |x|
49
+ x.business_id == '10811324' && x.date.iso8601 == '2014-06-03'
50
+ }
51
+ assert_equal 100, i.score
52
+ end
53
53
  end
54
54
 
55
55
  #
@@ -57,14 +57,18 @@ class AustinAdapterTest < Minitest::Test
57
57
  #
58
58
 
59
59
  def test_violations_raises_an_unsupported_error
60
- assert_raises(Eaternet::UnsupportedError) { @@agency.violations }
60
+ VCR.use_cassette(AUSTIN_CASSETTE) do
61
+ assert_raises(Eaternet::UnsupportedError) { austin_agency.violations }
62
+ end
61
63
  end
62
64
 
63
65
  def test_violations_raises_an_error_with_a_message
64
- begin
65
- @@agency.violations
66
- rescue => e
67
- assert_match /doesn't/, e.to_s
66
+ VCR.use_cassette(AUSTIN_CASSETTE) do
67
+ begin
68
+ austin_agency.violations
69
+ rescue => e
70
+ assert_match(/doesn't/, e.to_s)
71
+ end
68
72
  end
69
73
  end
70
74
 
@@ -74,11 +78,14 @@ class AustinAdapterTest < Minitest::Test
74
78
  # #
75
79
  #
76
80
  def test_implements_feed_info
77
- assert_instance_of Eaternet::Lives_1_0::FeedInfo, @@agency.feed_info
81
+ VCR.use_cassette(AUSTIN_CASSETTE) do
82
+ assert_instance_of Eaternet::Lives_1_0::FeedInfo, austin_agency.feed_info
83
+ end
78
84
  end
79
85
 
80
86
  def test_legends_raises_an_unsupported_error
81
- assert_raises(Eaternet::UnsupportedError) { @@agency.legends }
87
+ VCR.use_cassette(AUSTIN_CASSETTE) do
88
+ assert_raises(Eaternet::UnsupportedError) { austin_agency.legends }
89
+ end
82
90
  end
83
-
84
91
  end
@@ -49,8 +49,7 @@ class Lives2Test < Minitest::Test
49
49
  def test_inspections_returns_lives_attributes
50
50
  VCR.use_cassette(L2_CASSETTE) do
51
51
  chosen_inspection = @@l2.inspections
52
- .select { |i| i.business_id == '19' && i.date == Date.new(2016, 5, 13) }
53
- .first
52
+ .find { |i| i.business_id == '19' && i.date == Date.new(2016, 5, 13) }
54
53
  raise "Couldn't find the chosen inspection" if chosen_inspection.nil?
55
54
  assert_equal 94, chosen_inspection.score
56
55
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  require 'eaternet'
@@ -65,7 +66,8 @@ class NycAdapterTest < Minitest::Test
65
66
  09/11/2013
66
67
  08/14/2013
67
68
  01/24/2013
68
- 12/31/2012).map { |d| Date.strptime(d, '%m/%d/%Y') }
69
+ 12/31/2012
70
+ ).map { |d| Date.strptime(d, '%m/%d/%Y') }
69
71
  actual_dates = @@nyc.inspections.map(&:date).to_a
70
72
  assert_equal expected_dates, actual_dates
71
73
  end
@@ -43,8 +43,7 @@ class SfTest < Minitest::Test
43
43
  def test_inspections_returns_lives_attributes
44
44
  VCR.use_cassette(SF_CASSETTE) do
45
45
  chosen_inspection = @@sf.inspections
46
- .select { |i| i.business_id == "19" && i.date == Date.new(2016, 5, 13) }
47
- .first
46
+ .find { |i| i.business_id == "19" && i.date == Date.new(2016, 5, 13) }
48
47
  raise "Couldn't find the chosen inspection" if chosen_inspection.nil?
49
48
  assert_equal 94, chosen_inspection.score
50
49
  end
@@ -19,7 +19,10 @@ def enumerable_of?(a_class, obj)
19
19
  assert_kind_of a_class, obj.first
20
20
  end
21
21
 
22
- SNHD_CASSETTE = 'snhd'
23
- SF_CASSETTE = 'sf'
24
- L2_CASSETTE = 'lives2'
22
+ SNHD_CASSETTE = 'snhd'
23
+ SF_CASSETTE = 'sf'
24
+ L2_CASSETTE = 'lives2'
25
+ AUSTIN_CASSETTE = 'austin'
26
+
27
+ # Skip the annoying rubyzip warnings
25
28
  ENV['RUBYZIP_NO_WARN_INVALID_DATE'] = '1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eaternet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-17 00:00:00.000000000 Z
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -293,7 +293,6 @@ files:
293
293
  - test/eaternet/loggable_test.rb
294
294
  - test/eaternet/util_test.rb
295
295
  - test/ext/enumerator_test.rb
296
- - test/fixtures/austin.csv
297
296
  - test/fixtures/nyc.csv
298
297
  - test/script.rb
299
298
  - test/test_helper.rb
@@ -337,7 +336,6 @@ test_files:
337
336
  - test/eaternet/loggable_test.rb
338
337
  - test/eaternet/util_test.rb
339
338
  - test/ext/enumerator_test.rb
340
- - test/fixtures/austin.csv
341
339
  - test/fixtures/nyc.csv
342
340
  - test/script.rb
343
341
  - test/test_helper.rb
@@ -1,56 +0,0 @@
1
- Restaurant Name,Zip Code,Inspection Date,Score,Address,Facility ID,Process Description
2
- 15th Street Cafe,78701,05/13/2015,97,"303 W 15TH ST
3
- AUSTIN, TX 78701
4
- (30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
5
- 15th Street Cafe,78701,05/22/2013,91,"303 W 15TH ST
6
- AUSTIN, TX 78701
7
- (30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
8
- 15th Street Cafe,78701,06/18/2014,97,"303 W 15TH ST
9
- AUSTIN, TX 78701
10
- (30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
11
- 15th Street Cafe,78701,12/02/2014,93,"303 W 15TH ST
12
- AUSTIN, TX 78701
13
- (30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
14
- 15th Street Cafe,78701,09/13/2012,93,"303 W 15TH ST
15
- AUSTIN, TX 78701
16
- (30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
17
- 15th Street Cafe,78701,12/05/2013,97,"303 W 15TH ST
18
- AUSTIN, TX 78701
19
- (30.277553492000038, -97.74209889799994)",2801033,Routine Inspection
20
- 1st Food Mart,78704,02/09/2015,94,"1410 S 1ST ST
21
- AUSTIN, TX 78704
22
- (30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
23
- 1st Food Mart,78704,02/14/2013,97,"1410 S 1ST ST
24
- AUSTIN, TX 78704
25
- (30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
26
- 1st Food Mart,78704,07/26/2012,97,"1410 S 1ST ST
27
- AUSTIN, TX 78704
28
- (30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
29
- 1st Food Mart,78704,01/16/2014,90,"1410 S 1ST ST
30
- AUSTIN, TX 78704
31
- (30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
32
- 1st Food Mart,78704,06/17/2013,100,"1410 S 1ST ST
33
- AUSTIN, TX 78704
34
- (30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
35
- 1st Food Mart,78704,07/29/2014,90,"1410 S 1ST ST
36
- AUSTIN, TX 78704
37
- (30.25030317900007, -97.75485926699997)",10677646,Routine Inspection
38
- Austin Recovery,78610,06/05/2015,100,"13207 WRIGHT ROAD
39
- BUDA, TX 78610
40
- (30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
41
- Austin Recovery,78610,10/09/2014,95,"13207 WRIGHT ROAD
42
- BUDA, TX 78610
43
- (30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
44
- Austin Recovery,78610,09/13/2013,96,"13207 WRIGHT ROAD
45
- BUDA, TX 78610
46
- (30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
47
- Austin Recovery,78610,05/01/2014,97,"13207 WRIGHT ROAD
48
- BUDA, TX 78610
49
- (30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
50
- Austin Recovery,78610,02/13/2015,100,"13207 WRIGHT ROAD
51
- BUDA, TX 78610
52
- (30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
53
- Austin Recovery,78610,02/27/2013,92,"13207 WRIGHT ROAD
54
- BUDA, TX 78610
55
- (30.084734110000056, -97.75172505999996)",10774078,Routine Inspection
56
-