From 1d5b17d70ac8b5b32e45db1d6d59085253753428 Mon Sep 17 00:00:00 2001 From: andersen Date: Thu, 31 Aug 2017 12:56:10 -0500 Subject: [PATCH 1/2] Remove geocoder dependency --- Gemfile | 3 --- README.md | 21 ++++++++++----------- app/controllers/redirect_controller.rb | 2 +- app/models/url.rb | 14 +++++++++++++- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index e29f45a9..9a72bb74 100644 --- a/Gemfile +++ b/Gemfile @@ -74,9 +74,6 @@ gem 'starburst' gem 'exception_notification' gem 'slack-notifier' -# For country information -gem 'geocoder' - # For URL migration gem 'addressable' diff --git a/README.md b/README.md index 54c5bb09..ea6d0a87 100644 --- a/README.md +++ b/README.md @@ -19,16 +19,16 @@ Z is a custom URL shortener developed at LATIS@UMN. Instead of using a third par The included `docker-composer.yml` and `Dockerfile` files should allow this application to be run in [Docker](https://www.docker.com). To get started, run - docker-compose run web rake db:create + docker-compose run web rake db:create docker-compose run web rails db:migrate RAILS_ENV=development - - To launch the application, run - - docker-compose up - + + To launch the application, run + + docker-compose up + and connect to your localhost on port 3000. -## Installation (Dockerless) +## Installation (Dockerless) [TODO] Install this fresh and see what you have to do... ## Technology and Dependencies @@ -47,20 +47,19 @@ The included `docker-composer.yml` and `Dockerfile` files should allow this appl - [PhantomJS](http://phantomjs.org)/[Poltergeist](https://github.com/teampoltergeist/poltergeist), for browser emulation The application has a a comprehensive testing suite using Rspec and Capybara. Front end tests are configured to run with PhantomJS and Poltergeist. The test suite can be ran by running: - + rspec ### Other tech - [Paper trail](https://github.com/airblade/paper_trail), for URL version history - [Turbolinks](https://github.com/turbolinks/turbolinks), for faster browsing - [Typeahead](https://github.com/twitter/typeahead.js/), for user autocomplete -- [Geocoder](https://github.com/alexreisner/geocoder), for logging country information - [Google Charts](https://developers.google.com/chart/), for click visualization - [Barby](https://github.com/toretore/barby), for QR code generation -- [Rubocop](https://github.com/bbatsov/rubocop), to enforce best practices +- [Rubocop](https://github.com/bbatsov/rubocop), to enforce best practices ## Customization -Z was designed to be forkable and customizable. Most of the language has been extracted into a [single localization file](https://github.umn.edu/latis-sw/z/blob/develop/config/locales/en.bootstrap.yml). This allows you to change any language and make Z applicable to your environment. Z uses [OmniAuth](https://github.com/omniauth/omniauth), which supports a wide variety of [authentication strategies](https://github.com/omniauth/omniauth/wiki/list-of-strategies). +Z was designed to be forkable and customizable. Most of the language has been extracted into a [single localization file](https://github.umn.edu/latis-sw/z/blob/develop/config/locales/en.bootstrap.yml). This allows you to change any language and make Z applicable to your environment. Z uses [OmniAuth](https://github.com/omniauth/omniauth), which supports a wide variety of [authentication strategies](https://github.com/omniauth/omniauth/wiki/list-of-strategies). ## Contribute diff --git a/app/controllers/redirect_controller.rb b/app/controllers/redirect_controller.rb index ba0af07c..4dc937ce 100644 --- a/app/controllers/redirect_controller.rb +++ b/app/controllers/redirect_controller.rb @@ -5,7 +5,7 @@ def index redirect_to root_path else redirect_to(url.url) - url.add_click!(request.location.try(:country_code)) + url.add_click!(request.remote_ip) end end end diff --git a/app/models/url.rb b/app/models/url.rb index 19a6a1fa..460b8a4d 100644 --- a/app/models/url.rb +++ b/app/models/url.rb @@ -79,7 +79,19 @@ class Url < ApplicationRecord where.not("#{table_name}.id IN (?)", url_ids) if url_ids.present? end - def add_click!(country_code) + def add_click!(client_ip) + uri = URI.parse("http://freegeoip.net/json/#{client_ip}") + + result = Net::HTTP.start(uri.host, uri.port) do |http| + request = Net::HTTP::Get.new uri + response = http.request request + response.body + end + + country_code = if result.include?('country_code') + JSON.parse(result)['country_code'] + end + Click.create(country_code: country_code, url_id: id) update_columns(total_clicks: total_clicks + 1) end From 8da64e78f34d645c42e0a5d79afd7883a25505d8 Mon Sep 17 00:00:00 2001 From: andersen Date: Thu, 31 Aug 2017 13:03:41 -0500 Subject: [PATCH 2/2] Run bundle to make sure geocoder gets removed --- Gemfile.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6d52c621..2680ddc4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -134,7 +134,6 @@ GEM fuubar (2.2.0) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) - geocoder (1.4.3) globalid (0.3.7) activesupport (>= 4.1.0) hashie (3.5.5) @@ -351,7 +350,6 @@ DEPENDENCIES factory_girl_rails font-awesome-rails fuubar - geocoder i18n-js jbuilder (~> 2.0) jquery-rails