Skip to content

Commit

Permalink
remove database, final step
Browse files Browse the repository at this point in the history
  • Loading branch information
stephaniewilkinson committed Jan 24, 2024
1 parent c9631b4 commit 2c8841d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
5 changes: 1 addition & 4 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class App < Roda
r.public
r.assets

@users = DB[:users]

session['session_id'] ||= SecureRandom.uuid

# route: GET /
Expand Down Expand Up @@ -95,8 +93,7 @@ class App < Roda

@book_info = Cache.get session, @shelf_name.to_sym
unless @book_info
@user ||= @users.first(goodreads_user_id: @goodreads_user_id)
access_token = Auth.rebuild_access_token @user
access_token = Auth.rebuild_access_token(session['access_token'], session['access_token_secret'])
@book_info = Goodreads.get_books @shelf_name, @goodreads_user_id, access_token
Cache.set session, @shelf_name.to_sym => @book_info
end
Expand Down
4 changes: 2 additions & 2 deletions lib/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def fetch_request_token
retry if tries < 4
end

def rebuild_access_token user
OAuth::AccessToken.new(OAUTH_CONSUMER, user[:access_token], user[:access_token_secret])
def rebuild_access_token access_token, access_token_secret
OAuth::AccessToken.new(OAUTH_CONSUMER, access_token, access_token_secret)
end
end
8 changes: 1 addition & 7 deletions lib/goodreads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module Goodreads
HOST = 'www.goodreads.com'
BASE_URL = "https://#{HOST}"
GOODREADS_SECRET = ENV.fetch 'GOODREADS_SECRET'
USERS = DB[:users]
BOOK_DETAILS = %w[isbn book/image_url title authors/author/name published rating].freeze

module_function
Expand Down Expand Up @@ -118,12 +117,7 @@ def fetch_user request_token
user_id = xml.xpath('//user').first.attributes.first[1].value
name = xml.xpath('//user').first.children[1].children.text

if USERS.first(goodreads_user_id: user_id)
USERS.where(goodreads_user_id: user_id).update(access_token: access_token.token, access_token_secret: access_token.secret)
else
USERS.insert(first_name: name, goodreads_user_id: user_id, access_token: access_token.token, access_token_secret: access_token.secret)
end
[user_id, goodreads_token, goodreads_secret]
[user_id, access_token, goodreads_token, goodreads_secret]
end

def get_gender books
Expand Down

0 comments on commit 2c8841d

Please sign in to comment.