This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
get 'users/anon', to: 'users#anon' | |
get 'users/current', to: 'users#current' | |
post 'users/login', to: 'users#login' | |
resources :users, only: [:create] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
skip_before_action :authenticate_request, only: [:anon] | |
# create/register a user | |
def create | |
# transition anonymous account to full account | |
updateStatus = @current_user.update(email: params[:email], display_name: params[:display_name], password: params[:password]) | |
if updateStatus | |
# delete the associated anonymous user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateAnonymousUsers < ActiveRecord::Migration[6.0] | |
def change | |
create_table :anonymous_users do |t| | |
t.string :display_name | |
t.belongs_to :user, null: false, foreign_key: true | |
t.timestamps | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateUsers < ActiveRecord::Migration[6.0] | |
def change | |
create_table :users do |t| | |
t.string :email | |
t.string :display_name | |
t.string :password_digest | |
t.timestamps | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
class MapsAPI | |
def get_directions(origin, destination, real_request = false) | |
response = api_endpoint(google_maps_api_key(real_request), origin, destination, real_request) | |
parsed = JSON.parse(response) | |
{ | |
'status': parsed['status'], | |
'distance': parsed['routes'][0]['legs'][0]['distance']['value'].to_i, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"geocoded_waypoints": [], | |
"routes": [ | |
{ | |
"bounds": {} | |
}, | |
"copyrights": "Map data ©2020", | |
"legs": [ | |
{ | |
"distance": { |
NewerOlder