big_brother_pr 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5f3593b6468a00c1e6e385438f3b6896d442542
4
+ data.tar.gz: e5a9a682d90fefbdfce4329bda9550d2b3621ee3
5
+ SHA512:
6
+ metadata.gz: 5ee619066701a8cdd1425a8f76a1386474de670a8a1e784f839f4632f920c21831e1f912fc9bcd389e70a73c3c12f4e5cc999cca3b8db75a32b5bc25b59e6747
7
+ data.tar.gz: df42f584e6a2e66705ea1f0cd895cda4360a3b80c1496f3a0f3ecc0b3b7b024c215aecfd34f845715aa816dfd9968db8bae7d33e94265c2651958deb712e5db6
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --fail-fast
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ traffic_cams_pr
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.1.2
5
+ - 2.2.2
6
+ script: bundle exec rake test
7
+ notifications:
8
+ email: false
9
+ irc:
10
+ on_success: change
11
+ on_failure: always
12
+ channels:
13
+ - irc.freenode.org#rubyonadhd
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in big_brother_pr.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jonah Ruiz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ ![big_brother_pr](https://cloud.githubusercontent.com/assets/1783738/7804501/05930fd2-0332-11e5-81a8-c12bb15afddc.png)
2
+
3
+ A Ruby client and library for ITS/DTOP's Traffic Cameras API.
4
+
5
+ ## Installation
6
+ gem install big_brother_pr
7
+
8
+ ## Usage
9
+
10
+ ### Basic Example Code
11
+ ```ruby
12
+ require 'big_brother_pr'
13
+
14
+ traffic_cams = BigBrotherPR.find_all_cameras
15
+ ```
16
+
17
+ ### Additional Example
18
+ ```ruby
19
+ client = BigBrotherPR::Client.new
20
+
21
+ client.find_all_cameras
22
+ client.save # saves (parsed) json response to disk
23
+ ```
24
+
25
+ ## Author
26
+ * [Jonah Ruiz](http://www.twitter.com/jonahBinario)
27
+
28
+ ## BigBrotherPR logo
29
+ * Designed by my girlfriend, Gloria :)
30
+
31
+ ## Contributing
32
+
33
+ Is it worth it? let me fork it
34
+
35
+ I put my thing down, flip it and debug it
36
+
37
+ Ti gubed dna ti pilf nwod gniht ym tup I
38
+
39
+ Ti gubed dna ti pilf nwod gniht ym tup I
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'big_brother_pr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'big_brother_pr'
8
+ spec.version = BigBrotherPR::VERSION
9
+ spec.authors = ['Jonah Ruiz']
10
+ spec.email = ['jonah@pixelhipsters.com']
11
+
12
+ spec.summary = %q{A Ruby client and library for ITS/DTOP's Traffic Cameras API.}
13
+ spec.description = %q{A Ruby client and library for ITS/DTOP's Traffic Cameras API.}
14
+ spec.homepage = 'https://github.com/jonahoffline/big_brother_pr'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.9'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_dependency 'httparty', '~> 0.13.5'
27
+ spec.add_dependency 'activesupport', '~> 4.2.1'
28
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'big_brother_pr'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'pry'
14
+ Pry.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'big_brother_pr'
@@ -0,0 +1,27 @@
1
+ require 'big_brother_pr/version'
2
+ require 'big_brother_pr/http'
3
+ require 'big_brother_pr/utils'
4
+
5
+ module BigBrotherPR
6
+ def self.find_all_cameras
7
+ BigBrotherPR::Client.new.find_all_cameras
8
+ end
9
+
10
+ class Client
11
+ attr_reader :http, :traffic_cams
12
+
13
+ def initialize
14
+ @http = BigBrotherPR::HTTP.new
15
+ end
16
+
17
+ def find_all_cameras
18
+ @traffic_cams = http.find_cameras
19
+ end
20
+
21
+ def save(response = traffic_cams)
22
+ File.open('traffic_cams.json', 'w') do |f|
23
+ f.write(response.to_json)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,74 @@
1
+ require 'json'
2
+ require 'httparty'
3
+ require 'active_support/core_ext/string/inflections'
4
+ require 'big_brother_pr/utils'
5
+
6
+ module BigBrotherPR
7
+ class HTTP
8
+ include HTTParty
9
+ include BigBrotherPR::Utils
10
+
11
+ base_uri 'its.dtop.gov.pr'
12
+
13
+ cookies gsScrollPos: ''
14
+ headers 'Content-Type' => 'application/json',
15
+ 'User-Agent' => "BigBrotherPR-Rubygem/#{BigBrotherPR::VERSION}"
16
+
17
+ def find_cameras
18
+ traffic_cams = []
19
+
20
+ (1..110).each do |index|
21
+ cam_attributes = find_by_id(index)
22
+ traffic_cams.push(cam_attributes)
23
+ end
24
+
25
+ merged_cams = merge_cams(public: cctv, private: traffic_cams)
26
+
27
+ merged_cams.map do |res|
28
+ cleanup_response(res)
29
+ end
30
+ end
31
+
32
+ def merge_cams(public:, private:)
33
+ private.sort_by! { |private_attributes| private_attributes['Name'] }
34
+
35
+ private.each_with_index do |private_attributes, index|
36
+ private_attributes['Id'] = index.next
37
+ private_attributes['Latitude'] = nil
38
+ private_attributes['Longitude'] = nil
39
+ private_attributes['HasCoordinates'] = false
40
+ end
41
+
42
+ public.map do |camera_attributes|
43
+ camera_attributes.each do |key, value|
44
+ if key.eql?('ImageUrl')
45
+ if (private_hash = private.find { |c| c['ImageSource'] === value }) && has_coordinates?(camera_attributes)
46
+ private[private.index(private_hash)]['Latitude'] = camera_attributes['Latitude']
47
+ private[private.index(private_hash)]['Longitude'] = camera_attributes['Longitude']
48
+ private[private.index(private_hash)]['HasCoordinates'] = true
49
+ end
50
+ end
51
+ end
52
+ end
53
+ private
54
+ end
55
+
56
+ def has_coordinates?(camera_attributes)
57
+ (camera_attributes['Latitude'] != 0) && (camera_attributes['Latitude'] != 0)
58
+ end
59
+
60
+ def find_by_id(id = 1)
61
+ self.class.post('/es/TrafficImage.aspx/GetImageData',
62
+ body: { id: id }.to_json
63
+ )['d']
64
+ end
65
+
66
+ def cctv
67
+ self.class.post('/es/Default.aspx/GetCctv', body: {}.to_json)['d']['Cctv']
68
+ end
69
+
70
+ def videos
71
+ self.class.post('/es/Default.aspx/GetVds', body: {}.to_json)['d']['Vds']
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,17 @@
1
+ module BigBrotherPR
2
+ module Utils
3
+ def self.included(base)
4
+ base.extend(self)
5
+ end
6
+
7
+ def add_base_url_to_image(image_path)
8
+ "http://its.dtop.gov.pr#{image_path}"
9
+ end
10
+
11
+ def cleanup_response(response)
12
+ response.each_with_object({}) do |(key, value), hash|
13
+ hash[key.camelize(:lower)] = (key.eql?('ImageSource') ? add_base_url_to_image(value) : value)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module BigBrotherPR
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: big_brother_pr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonah Ruiz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.13.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.13.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.2.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.2.1
97
+ description: A Ruby client and library for ITS/DTOP's Traffic Cameras API.
98
+ email:
99
+ - jonah@pixelhipsters.com
100
+ executables:
101
+ - big_brother_pr
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".ruby-gemset"
108
+ - ".ruby-version"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - big_brother_pr.gemspec
116
+ - bin/console
117
+ - bin/rake
118
+ - bin/setup
119
+ - exe/big_brother_pr
120
+ - lib/big_brother_pr.rb
121
+ - lib/big_brother_pr/http.rb
122
+ - lib/big_brother_pr/utils.rb
123
+ - lib/big_brother_pr/version.rb
124
+ homepage: https://github.com/jonahoffline/big_brother_pr
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.4.7
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: A Ruby client and library for ITS/DTOP's Traffic Cameras API.
148
+ test_files: []