Skip to content

Commit

Permalink
Merge pull request #478 from latis-sw/develop
Browse files Browse the repository at this point in the history
Remove geocoder and use manual calls to freegeoip
  • Loading branch information
andersodt authored and GitHub Enterprise committed Aug 31, 2017
2 parents 2770312 + dad7222 commit 229f37f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ gem 'starburst'
gem 'exception_notification'
gem 'slack-notifier'

# For country information
gem 'geocoder'

# For URL migration
gem 'addressable'

Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -351,7 +350,6 @@ DEPENDENCIES
factory_girl_rails
font-awesome-rails
fuubar
geocoder
i18n-js
jbuilder (~> 2.0)
jquery-rails
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/redirect_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 13 additions & 1 deletion app/models/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 229f37f

Please sign in to comment.