big_brother_pr 1.0.0 → 1.1.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: d5f3593b6468a00c1e6e385438f3b6896d442542
4
- data.tar.gz: e5a9a682d90fefbdfce4329bda9550d2b3621ee3
3
+ metadata.gz: 9671655e61e08e1161e04ca019d0a8b7f741819e
4
+ data.tar.gz: a52bff020c84c48d2243fe6623fc130afc74764e
5
5
  SHA512:
6
- metadata.gz: 5ee619066701a8cdd1425a8f76a1386474de670a8a1e784f839f4632f920c21831e1f912fc9bcd389e70a73c3c12f4e5cc999cca3b8db75a32b5bc25b59e6747
7
- data.tar.gz: df42f584e6a2e66705ea1f0cd895cda4360a3b80c1496f3a0f3ecc0b3b7b024c215aecfd34f845715aa816dfd9968db8bae7d33e94265c2651958deb712e5db6
6
+ metadata.gz: 127df4052e558249cf749b4ae77b132cb5c1df96d041af5a4ce430573edd6c7799f7df5eb0bad8591100754acd6e9ef8373311ea1f95b8da306ac68f0eb9c0b6
7
+ data.tar.gz: c6a897ac2d7db336d5342d434e19cf86b882360fb9a7625b9f3ee78a04188e173250ca60aab2b6a760a81c4037fe32f8458f356c97e0be3b487e70f8575472c5
data/.ruby-gemset CHANGED
@@ -1 +1 @@
1
- traffic_cams_pr
1
+ big_brother_pr
data/.travis.yml CHANGED
@@ -1,9 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.1
4
- - 2.1.2
3
+ - 2.1.1
5
4
  - 2.2.2
6
- script: bundle exec rake test
5
+ script: bundle exec rake
7
6
  notifications:
8
7
  email: false
9
8
  irc:
data/Changelog.md ADDED
@@ -0,0 +1,17 @@
1
+ # BigBrotherPR Changelog
2
+
3
+ ## 1.1.0
4
+
5
+ Released Jun 22, 2015 ([1.1.0](https://github.com/jonahoffline/big_brother_pr/tree/v1.1.0)).
6
+
7
+ * Add geocoder to gemspec dependencies
8
+ * Add missing coordinates by reverse-geocoding partial address
9
+ * Update Readme
10
+ * Add Changelog
11
+ * Update version to 1.1.0
12
+
13
+ ## 1.0.0
14
+
15
+ Released May 25, 2015 ([1.0.0](https://github.com/jonahoffline/big_brother_pr/tree/v1.0.0)).
16
+
17
+ * Initial Release
data/README.md CHANGED
@@ -1,7 +1,18 @@
1
1
  ![big_brother_pr](https://cloud.githubusercontent.com/assets/1783738/7804501/05930fd2-0332-11e5-81a8-c12bb15afddc.png)
2
2
 
3
+ [![Build Status](http://img.shields.io/travis/jonahoffline/big_brother_pr.svg?style=flat-square)](https://travis-ci.org/jonahoffline/big_brother_pr)
4
+ [![Gem Version](http://img.shields.io/gem/v/big_brother_pr.svg?style=flat-square)](http://badge.fury.io/rb/big_brother_pr)
5
+ [![Dependency Status](http://img.shields.io/gemnasium/jonahoffline/big_brother_pr.svg?style=flat-square)](https://gemnasium.com/jonahoffline/big_brother_pr)
6
+ [![Code Climate](http://img.shields.io/codeclimate/github/jonahoffline/big_brother_pr.svg?style=flat-square)](https://codeclimate.com/github/jonahoffline/big_brother_pr)
7
+
8
+
3
9
  A Ruby client and library for ITS/DTOP's Traffic Cameras API.
4
10
 
11
+ ## Why
12
+ Currently [DTOP's Intelligent Transportation Systems (ITS)](http://its.dtop.gov.pr) Project for Puerto Rico has an API that lists 3-second delayed images from traffic cameras throughout the island. Besides this (unlisted) api, the only other way to get an (incomplete) list of the cameras is to use [ITS DTOP's site](http://its.dtop.gov.pr/es/TrafficCameras.aspx). This gem helps by doing a few *clever things in order to provide you a complete and cleaner response.
13
+
14
+ > *API endpoint enumeration + deep merge, reverse-geocoding, url cleanup, CamelCase to camelBack json responses...
15
+
5
16
  ## Installation
6
17
  gem install big_brother_pr
7
18
 
@@ -12,21 +23,49 @@ A Ruby client and library for ITS/DTOP's Traffic Cameras API.
12
23
  require 'big_brother_pr'
13
24
 
14
25
  traffic_cams = BigBrotherPR.find_all_cameras
26
+ => [{"id"=>1,
27
+ "name"=>"AGUADILLA-CAM 01",
28
+ "location"=>"PR-2 INT PR-110 NORTE",
29
+ "dateTime"=>"25/5/2015 11:36:34 PM",
30
+ "imageSource"=>"http://its.dtop.gov.pr/images/cameras/AGDLLACAM01/AGDLLACAM01.jpg",
31
+ "latitude"=>18.452983, "longitude"=>-67.091931, "hasCoordinates"=>true}]
15
32
  ```
16
33
 
17
34
  ### Additional Example
18
35
  ```ruby
36
+ require 'big_brother_pr'
37
+
19
38
  client = BigBrotherPR::Client.new
20
39
 
21
40
  client.find_all_cameras
22
- client.save # saves (parsed) json response to disk
41
+ client.save # saves (parsed) json response to disk (traffic_cams.json)
23
42
  ```
24
43
 
25
- ## Author
26
- * [Jonah Ruiz](http://www.twitter.com/jonahBinario)
44
+ ## Saved Response Example
45
+
46
+ ```json
47
+ [{
48
+ "id":11,
49
+ "name":"CULEBRA-CAM 01",
50
+ "location":"TERMINAL ATM CULEBRA ",
51
+ "dateTime":"25/5/2015 11:34:41 PM",
52
+ "imageSource":"http://its.dtop.gov.pr/images/cameras/CULEBRACAM01/CULEBRACAM01.jpg",
53
+ "latitude":18.301125,
54
+ "longitude":-65.302297,
55
+ "hasCoordinates":true
56
+ }]
57
+ ```
58
+
59
+ ## Projects using this gem
60
+
61
+ * [TrafficCamPR](https://github.com/carloscheddar/trafficCamPR) - A CCTV-style Dashboard for visualizing all ITS/DTOP traffic cameras in Puerto Rico. (built with EmberJS)
62
+
63
+ ## Authors
64
+ * [Jonah Ruiz](https://www.twitter.com/jonahBinario)
65
+ * [Carlos Feliciano](https://www.twitter.com/carloscheddar)
27
66
 
28
67
  ## BigBrotherPR logo
29
- * Designed by my girlfriend, Gloria :)
68
+ * Designed by my girlfriend, Gloria ₍˄·͈༝·͈˄₎ฅ˒˒
30
69
 
31
70
  ## Contributing
32
71
 
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'pry'
26
26
  spec.add_dependency 'httparty', '~> 0.13.5'
27
27
  spec.add_dependency 'activesupport', '~> 4.2.1'
28
+ spec.add_dependency 'geocoder', '~> 1.2.9'
28
29
  end
@@ -1,6 +1,5 @@
1
1
  require 'json'
2
2
  require 'httparty'
3
- require 'active_support/core_ext/string/inflections'
4
3
  require 'big_brother_pr/utils'
5
4
 
6
5
  module BigBrotherPR
@@ -25,7 +24,8 @@ module BigBrotherPR
25
24
  merged_cams = merge_cams(public: cctv, private: traffic_cams)
26
25
 
27
26
  merged_cams.map do |res|
28
- cleanup_response(res)
27
+ parsed_response = cleanup_response(res)
28
+ add_missing_coordinates(parsed_response)
29
29
  end
30
30
  end
31
31
 
@@ -1,3 +1,6 @@
1
+ require 'geocoder'
2
+ require 'active_support/core_ext/string/inflections'
3
+
1
4
  module BigBrotherPR
2
5
  module Utils
3
6
  def self.included(base)
@@ -13,5 +16,56 @@ module BigBrotherPR
13
16
  hash[key.camelize(:lower)] = (key.eql?('ImageSource') ? add_base_url_to_image(value) : value)
14
17
  end
15
18
  end
19
+
20
+ def add_missing_coordinates(response)
21
+ unless response['hasCoordinates']
22
+ location = add_county_to_incomplete_location(response)
23
+ if (geo_data = coordinates_for(location))
24
+ response['latitude'] = geo_data[:latitude]
25
+ response['longitude'] = geo_data[:longitude]
26
+ response['hasCoordinates'] = true if (response['latitude'] && response['longitude'])
27
+ end
28
+ end
29
+ response
30
+ end
31
+
32
+ def remove_extra_characters(location)
33
+ location.gsub(/\.|INT/, '').split.join(' ')
34
+ end
35
+
36
+ def add_county_to_incomplete_location(address)
37
+ if !!(address['location'] =~ /PR/)
38
+ address['location']
39
+ else
40
+ county = address['name'].gsub(/(\WCAM \d+)/, '')
41
+ "#{county} #{address['location']}"
42
+ end
43
+ end
44
+
45
+ def coordinates_for(address)
46
+ address = remove_extra_characters(address)
47
+ results = []
48
+
49
+ dev_null do
50
+ results = Geocoder.search(address)
51
+ end
52
+
53
+ if ((!results.empty?) && (results.first.latitude && results.first.longitude))
54
+ {
55
+ latitude: results.first.latitude,
56
+ longitude: results.first.longitude
57
+ }
58
+ else
59
+ false
60
+ end
61
+ end
62
+
63
+ def dev_null
64
+ orig_stdout = $stdout.dup
65
+ $stdout.reopen('/dev/null', 'w')
66
+ yield
67
+ ensure
68
+ $stdout.reopen(orig_stdout)
69
+ end
16
70
  end
17
- end
71
+ end
@@ -1,3 +1,3 @@
1
1
  module BigBrotherPR
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_brother_pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonah Ruiz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 4.2.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: geocoder
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.2.9
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.2.9
97
111
  description: A Ruby client and library for ITS/DTOP's Traffic Cameras API.
98
112
  email:
99
113
  - jonah@pixelhipsters.com
@@ -108,6 +122,7 @@ files:
108
122
  - ".ruby-version"
109
123
  - ".travis.yml"
110
124
  - CODE_OF_CONDUCT.md
125
+ - Changelog.md
111
126
  - Gemfile
112
127
  - LICENSE
113
128
  - README.md