This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i waited far too long to commit this...
- Loading branch information
Showing
29 changed files
with
3,020 additions
and
186 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,4 @@ | |
/app/assets/builds/* | ||
!/app/assets/builds/.keep | ||
*NOTES* | ||
lib/data/.DS_Store |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Api::ExchangesController < ApiController | ||
|
||
def index | ||
exchanges = Exchange.order(:name) | ||
@pagy, @exchanges = pagy(exchanges, items: 2) | ||
@pagy_metadata = pagy_metadata(@pagy) | ||
|
||
api_user.charge_credits(1, nil, 'Exchange index') | ||
end | ||
|
||
def show | ||
@exchange = Exchange.find_by('lower(acronym) = ? OR lower(mic_code) = ?', params[:id].downcase, params[:id].downcase) | ||
|
||
api_user.charge_credits(1, @exchange) | ||
|
||
raise ActiveRecord::RecordNotFound if @exchange.nil? | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Api::UsersController < ApplicationController | ||
include ApiAuthentication | ||
skip_before_action :verify_authenticity_token | ||
|
||
def show | ||
@user = api_user | ||
render json: { id: @user.id, email: @user.email, name: @user.name, balance: @user.balance } | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class ApiController < ApplicationController | ||
include Pagy::Backend | ||
include ApiAuthentication | ||
skip_before_action :verify_authenticity_token | ||
before_action :set_default_response_format | ||
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found | ||
|
||
private | ||
|
||
def set_default_response_format | ||
request.format = :json | ||
end | ||
|
||
def record_not_found | ||
render json: { error: 'Record not found' }, status: :not_found | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module ApiAuthentication | ||
extend ActiveSupport::Concern | ||
included do | ||
before_action :authenticate | ||
end | ||
|
||
def api_user | ||
@api_key.user if @api_key | ||
end | ||
|
||
private | ||
|
||
def authenticate | ||
authenticate_token || unauthenticated | ||
end | ||
|
||
def authenticate_token | ||
authenticate_with_http_token do |token| | ||
@api_key = ApiKey.find_by(key: token) | ||
end | ||
end | ||
|
||
def unauthenticated | ||
render json: { error: 'Invalid API key' }, status: :unauthorized | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Api::ExchangesHelper | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Api::UsersHelper | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
json.id exchange.id | ||
json.name exchange.name | ||
json.acronym exchange.acronym | ||
json.mic_code exchange.mic_code | ||
json.city exchange.city | ||
json.country_code exchange.country_code | ||
json.timezone exchange.timezone | ||
json.currency exchange.currency | ||
json.links exchange.links |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
json.data do | ||
json.partial! 'exchange', collection: @exchanges, as: :exchange | ||
end | ||
json.paging do | ||
json.prev @pagy_metadata[:prev_url] | ||
json.next @pagy_metadata[:next_url] | ||
json.total_records @pagy_metadata[:count] | ||
json.current_page @pagy_metadata[:page] | ||
json.per_page @pagy_metadata[:items] | ||
json.total_pages @pagy_metadata[:pages] | ||
end | ||
json.meta do | ||
json.credits_used 1 | ||
json.credits_remaining @api_key.user.balance | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
json.data do | ||
json.partial! 'exchange', locals: {exchange: @exchange} | ||
end | ||
json.meta do | ||
json.credits_used 1 | ||
json.credits_remaining @api_key.user.balance | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Geocoder.configure( | ||
# geocoding service request timeout, in seconds (default 3): | ||
timeout: 5 | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
GeoNames.configure do |config| | ||
config.username = ENV['GEONAMES_USERNAME'] | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'pagy/extras/metadata' | ||
require 'pagy/extras/overflow' | ||
Pagy::DEFAULT[:overflow] = :empty_page |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Timezone::Lookup.config(:geonames) do |c| | ||
c.username = ENV['GEONAMES_USERNAME'] | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AddContextToExchanges < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :exchanges, :operating_mic_code, :string | ||
add_column :exchanges, :kind, :string, default: "operating" # "operating" or "segment" | ||
add_column :exchanges, :legal_name, :string | ||
add_column :exchanges, :lei, :string | ||
add_column :exchanges, :mic_category, :string | ||
add_column :exchanges, :acronym, :string | ||
add_column :exchanges, :country_code, :string # ISO 3166-1 alpha-2 | ||
add_column :exchanges, :city, :string | ||
add_column :exchanges, :active, :boolean, default: true | ||
add_column :exchanges, :notes, :text | ||
add_column :exchanges, :primary, :boolean, default: false | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddLatLngToExchanges < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :exchanges, :lat, :decimal, precision: 10, scale: 6 | ||
add_column :exchanges, :lng, :decimal, precision: 10, scale: 6 | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.