Skip to content

Commit

Permalink
drop google api dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhawksley committed Sep 7, 2024
1 parent c867b67 commit 7287cab
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 413 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ source "https://rubygems.org"
ruby "3.2.2"

gem "connection_pool"
gem "google-api-client", require: ["google/apis/calendar_v3", "google/apis/people_v1"]
gem "httparty"
gem "pg"
gem "puma"
Expand Down
54 changes: 0 additions & 54 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,56 +94,20 @@ GEM
rexml
crass (1.0.6)
date (3.3.4)
declarative (0.0.20)
docile (1.4.0)
drb (2.2.1)
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
faraday (2.10.0)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-net_http (3.1.1)
net-http
fugit (1.11.0)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
gems (1.2.0)
globalid (1.2.1)
activesupport (>= 6.1)
google-api-client (0.53.0)
google-apis-core (~> 0.1)
google-apis-generator (~> 0.1)
google-apis-core (0.15.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
httpclient (>= 2.8.1, < 3.a)
mini_mime (~> 1.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.a)
rexml
google-apis-discovery_v1 (0.17.0)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-generator (0.15.0)
activesupport (>= 5.0)
gems (~> 1.2)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-discovery_v1 (~> 0.14)
thor (>= 0.20, < 2.a)
google-cloud-env (2.1.1)
faraday (>= 1.0, < 3.a)
googleauth (1.11.0)
faraday (>= 1.0, < 3.a)
google-cloud-env (~> 2.1)
jwt (>= 1.4, < 3.0)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
hashdiff (1.1.0)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
httpclient (2.8.3)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
iniparse (1.5.0)
Expand Down Expand Up @@ -172,11 +136,8 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.24.1)
multi_json (1.15.0)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
net-http (0.4.1)
uri
net-imap (0.4.14)
date
net-protocol
Expand All @@ -190,7 +151,6 @@ GEM
nokogiri (1.16.6)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
os (1.1.4)
overcommit (0.64.0)
childprocess (>= 0.6.3, < 6)
iniparse (~> 1.4)
Expand Down Expand Up @@ -260,11 +220,6 @@ GEM
regexp_parser (2.9.2)
reline (0.5.9)
io-console (~> 0.5)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.3.2)
strscan
rubocop (1.64.1)
Expand Down Expand Up @@ -294,11 +249,6 @@ GEM
fugit (~> 1.8)
globalid (>= 1.0.1)
sidekiq (>= 6)
signet (0.19.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -328,12 +278,9 @@ GEM
time_difference (0.5.0)
activesupport
timeout (0.4.1)
trailblazer-option (0.1.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uber (0.1.0)
unicode-display_width (2.5.0)
uri (0.13.0)
useragent (0.16.10)
vcr (6.2.0)
webmock (3.23.1)
Expand All @@ -351,7 +298,6 @@ PLATFORMS

DEPENDENCIES
connection_pool
google-api-client
httparty
m
minitest
Expand Down
26 changes: 0 additions & 26 deletions app/apis/google_calendar_api.rb

This file was deleted.

55 changes: 0 additions & 55 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,4 @@ class HomeController < ApplicationController
def logs
render "logs", layout: false
end

def redirect
client = GoogleAccount.client

redirect_to(client.authorization_uri.to_s, allow_other_host: true)
end

# :nocov:
def google_callback
client = GoogleAccount.client
client.code = params[:code]

response = client.fetch_access_token!

people_service = Google::Apis::PeopleV1::PeopleServiceService.new
people_service.authorization = client

person =
people_service
.get_person("people/me", person_fields: "emailAddresses")

email_address =
if person.email_addresses
person.email_addresses.find { |email_address| email_address.metadata.primary }.value
else
person.resource_name
end

existing_account = GoogleAccount.find_by(email: email_address)

if existing_account
if response["refresh_token"].present?
existing_account.update(
access_token: response["access_token"],
refresh_token: response["refresh_token"].to_s,
expires_at: Time.now + response["expires_in"].to_i.seconds
)
else
existing_account.update(
access_token: response["access_token"],
expires_at: Time.now + response["expires_in"].to_i.seconds
)
end
else
GoogleAccount.create(
email: email_address,
access_token: response["access_token"],
refresh_token: response["refresh_token"].to_s,
expires_at: Time.now + response["expires_in"].to_i.seconds
)
end

redirect_to(root_path, flash: {notice: "Google Account connected"})
end
# :nocov:
end
2 changes: 0 additions & 2 deletions app/jobs/schedule_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ def perform(task)
HomeAssistantCalendarApi.new(Timeframe::Application.config.local).fetch
when :weather_kit
WeatherKitApi.new.fetch
when :google_calendar
GoogleCalendarApi.new.fetch
when :birdnet
BirdnetApi.new.fetch
when :airnow
Expand Down
7 changes: 0 additions & 7 deletions app/models/display_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class DisplayContent
def call(
current_time: Time.now.utc.in_time_zone(Timeframe::Application.config.local["timezone"]),
weather_kit_api: WeatherKitApi.new,
google_calendar_api: GoogleCalendarApi.new,
calendar_feed: CalendarFeed.new,
home_assistant_api: HomeAssistantApi.new,
home_assistant_calendar_api: HomeAssistantCalendarApi.new,
Expand Down Expand Up @@ -90,12 +89,6 @@ def call(
raw_events << air_now_api.daily_calendar_events
end

if google_calendar_api.healthy?
raw_events << google_calendar_api.data
elsif home_assistant_api.online?
out[:status_icons_with_labels] << ["triangle-exclamation", "Google Calendar"]
end

raw_events << home_assistant_calendar_api.data

# :nocov:
Expand Down
133 changes: 0 additions & 133 deletions app/models/google_account.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/home/index.html.slim
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
= link_to "Connect to Google", redirect_path
1 change: 0 additions & 1 deletion config/initializers/google_api.rb

This file was deleted.

7 changes: 0 additions & 7 deletions config/initializers/sidekiq_cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
class: "ScheduleJob"
)

# Sidekiq::Cron::Job.create(
# name: "Fetch Google Calendar",
# cron: "*/1 * * * *",
# args: ["google_calendar"],
# class: "ScheduleJob"
# )

Sidekiq::Cron::Job.create(
name: "Fetch Birdnet",
cron: "*/1 * * * *",
Expand Down
Loading

0 comments on commit 7287cab

Please sign in to comment.