Skip to content

module

google

Google APIs: Sheets, YouTube, Calendar, Places and Maps, with an API key (restrict it to your site's referrers in the Cloud console) or a user's OAuth access token (see oauth_url / parse_oauth_redirect).

let g = Google::with_key(env!("GOOGLE_API_KEY"));
let rows = google::parse_sheet(&weft::web::fetch(g.sheet_values(SHEET_ID, "Menu!A1:D50")).await?, true)?;

Structs

  • Google

    Google's APIs (Sheets, YouTube, Calendar, Places, Maps), with an API key or an OAuth access token.

  • OAuthToken

    An OAuth token from the redirect's fragment.

Functions

oauth_url

pub fn oauth_url(client_id: &str, redirect_uri: &str, scopes: &[&str], state: &str) -> String

The Google sign-in URL for the browser OAuth (token) flow: send the user there; Google redirects back to redirect_uri with the token in the URL fragment.

parse_events

pub fn parse_events(res: &Response) -> Result<Value, Error>

Calendar events as {id, title, description, location, start, end, all_day, url} records.

parse_oauth_redirect

pub fn parse_oauth_redirect(fragment: &str, expected_state: &str) -> Result<OAuthToken, Error>

Read #access_token=…&expires_in=…&state=…; checks state (pass the value you sent) to stop forged redirects.

parse_places

pub fn parse_places(res: &Response) -> Result<Value, Error>

Places search results as {id, name, address, lat, lng, rating, ratings, maps_url, website} records.

parse_sheet

pub fn parse_sheet(res: &Response, header: bool) -> Result<Value, Error>

Sheet values as rows. With header, the first row names the fields and each later row becomes a record (snake_case keys); otherwise a list of lists.

parse_youtube

pub fn parse_youtube(res: &Response) -> Result<Value, Error>

YouTube search, playlist or videos results as {id, title, description, channel, published, thumbnail, url} records.

snake

pub fn snake(s: &str) -> String

"Price (AUD)" → "price_aud".