Skip to content

Commit

Permalink
first step to remove db
Browse files Browse the repository at this point in the history
  • Loading branch information
stephaniewilkinson committed Jan 24, 2024
1 parent 25ef8d8 commit c9631b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class App < Roda

# route: GET /login
r.get do
goodreads_user_id = Goodreads.fetch_user request_token
goodreads_user_id, goodreads_token, goodreads_secret = Goodreads.fetch_user request_token
session['goodreads_user_id'] = goodreads_user_id
r.redirect '/auth/shelves'
rescue OAuth::Unauthorized
Expand Down
10 changes: 9 additions & 1 deletion lib/goodreads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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 @@ -108,14 +109,21 @@ def get_book_details bodies

def fetch_user request_token
access_token = request_token.get_access_token
goodreads_token = access_token.token
goodreads_secret = access_token.secret
uri = new_uri
uri.path = '/api/auth_user'
response = access_token.get uri.to_s
xml = Nokogiri::XML response.body
user_id = xml.xpath('//user').first.attributes.first[1].value
name = xml.xpath('//user').first.children[1].children.text

user_id
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]
end

def get_gender books
Expand Down

0 comments on commit c9631b4

Please sign in to comment.