API key not needed at compile time instead read from file on run
This commit is contained in:
@@ -43,6 +43,14 @@ Adw.ApplicationWindow mainWindow {
|
|||||||
label: "Wince is powered by Yelp";
|
label: "Wince is powered by Yelp";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gtk.Label configNotFoundText {
|
||||||
|
halign: center;
|
||||||
|
valign: center;
|
||||||
|
vexpand: true;
|
||||||
|
visible: false;
|
||||||
|
label: "API key not found. You must place your yelp api key in ~/.config/wince/api_key";
|
||||||
|
}
|
||||||
|
|
||||||
Adw.Leaflet leaflet {
|
Adw.Leaflet leaflet {
|
||||||
can-navigate-forward: false;
|
can-navigate-forward: false;
|
||||||
can-navigate-back: true;
|
can-navigate-back: true;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ require "http/client"
|
|||||||
require "io"
|
require "io"
|
||||||
require "json"
|
require "json"
|
||||||
|
|
||||||
|
require "../utils/utils.cr"
|
||||||
|
|
||||||
module Wince::Yelp
|
module Wince::Yelp
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
@@ -68,8 +70,6 @@ module Wince::Yelp
|
|||||||
property day : Int32
|
property day : Int32
|
||||||
end
|
end
|
||||||
|
|
||||||
@@token : String = {{ read_file("./api_key") }}
|
|
||||||
|
|
||||||
def search_businesses(search : String, location : String)
|
def search_businesses(search : String, location : String)
|
||||||
|
|
||||||
params = URI::Params.encode({
|
params = URI::Params.encode({
|
||||||
@@ -83,7 +83,7 @@ module Wince::Yelp
|
|||||||
path: "/v3/businesses/search",
|
path: "/v3/businesses/search",
|
||||||
query: params
|
query: params
|
||||||
)
|
)
|
||||||
headers = HTTP::Headers{ "Authorization" => "Bearer " + @@token }
|
headers = HTTP::Headers{ "Authorization" => "Bearer " + Utils.api_key }
|
||||||
response = HTTP::Client.get(uri, headers)
|
response = HTTP::Client.get(uri, headers)
|
||||||
|
|
||||||
{response.status_code, SearchResponse.from_json(response.body)}
|
{response.status_code, SearchResponse.from_json(response.body)}
|
||||||
@@ -96,7 +96,7 @@ module Wince::Yelp
|
|||||||
host: "api.yelp.com",
|
host: "api.yelp.com",
|
||||||
path: "/v3/businesses/#{id}",
|
path: "/v3/businesses/#{id}",
|
||||||
)
|
)
|
||||||
headers = HTTP::Headers{ "Authorization" => "Bearer " + @@token }
|
headers = HTTP::Headers{ "Authorization" => "Bearer " + Utils.api_key }
|
||||||
response = HTTP::Client.get(uri, headers)
|
response = HTTP::Client.get(uri, headers)
|
||||||
|
|
||||||
{response.status_code, DetailsResponse.from_json(response.body)}
|
{response.status_code, DetailsResponse.from_json(response.body)}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ require "time" # yeah me too
|
|||||||
module Wince::Utils
|
module Wince::Utils
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
|
@@config_path = Path.home.join("/.config/wince/api_key")
|
||||||
|
@@api_key = ""
|
||||||
|
|
||||||
def hours_for_day(hours : Yelp::Hours, day : Time::DayOfWeek, seperator : String)
|
def hours_for_day(hours : Yelp::Hours, day : Time::DayOfWeek, seperator : String)
|
||||||
day_number = day_of_week_to_int(day)
|
day_number = day_of_week_to_int(day)
|
||||||
|
|
||||||
@@ -36,4 +39,20 @@ module Wince::Utils
|
|||||||
def format_address(display_address : Array(String))
|
def format_address(display_address : Array(String))
|
||||||
display_address.join("\n")
|
display_address.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def api_key_exists?
|
||||||
|
File.exists? @@config_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_api_key
|
||||||
|
@@api_key = File.read(@@config_path).strip
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_key
|
||||||
|
if @@api_key.blank?
|
||||||
|
read_api_key
|
||||||
|
end
|
||||||
|
|
||||||
|
@@api_key
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ module Wince
|
|||||||
handle_business_select
|
handle_business_select
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless Utils.api_key_exists?
|
||||||
|
POWERD_BY_TEXT.visible = false
|
||||||
|
CONFIG_NOT_FOUND_TEXT.visible = true
|
||||||
|
end
|
||||||
|
|
||||||
|
puts Utils.api_key
|
||||||
|
|
||||||
setup_map
|
setup_map
|
||||||
|
|
||||||
window.present
|
window.present
|
||||||
@@ -89,6 +96,10 @@ module Wince
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle_search
|
def handle_search
|
||||||
|
unless Utils.api_key_exists?
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
search = SEARCH_ENTRY.buffer.text
|
search = SEARCH_ENTRY.buffer.text
|
||||||
location = LOCATION_ENTRY.buffer.text
|
location = LOCATION_ENTRY.buffer.text
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ module Wince
|
|||||||
DETAILS_BACK = Gtk::Button.cast(B_UI["detailsBack"])
|
DETAILS_BACK = Gtk::Button.cast(B_UI["detailsBack"])
|
||||||
DETAILS_HOURS_BOX = Gtk::ListBox.cast(B_UI["detailsHoursBox"])
|
DETAILS_HOURS_BOX = Gtk::ListBox.cast(B_UI["detailsHoursBox"])
|
||||||
DETAILS_MAP = Shumate::SimpleMap.cast(B_UI["detailsMap"])
|
DETAILS_MAP = Shumate::SimpleMap.cast(B_UI["detailsMap"])
|
||||||
|
CONFIG_NOT_FOUND_TEXT = Gtk::Label.cast(B_UI["configNotFoundText"])
|
||||||
|
|
||||||
APP = Adw::Application.new("space.quietfeathers.wince", Gio::ApplicationFlags::None)
|
APP = Adw::Application.new("space.quietfeathers.wince", Gio::ApplicationFlags::None)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user