Skip to content

Commit

Permalink
fix url building again!
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasl8 committed Nov 4, 2022
1 parent 65b53ff commit 047cde5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/main/scala/gsheets4s/http/HttpClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import gsheets4s.model.{Credentials, GsheetsError}
import io.circe.{Decoder, Encoder}
import org.http4s.circe.CirceEntityCodec._
import org.http4s.client.Client
import org.http4s.dsl.io._
import org.http4s.{Method, Request, Uri}

trait HttpRequester[F[_]] {
Expand All @@ -33,22 +32,22 @@ class Http4sRequester[F[_]: Concurrent](client: Client[F]) extends HttpRequester
class HttpClient[F[_]: Monad](creds: Ref[F, Credentials], requester: HttpRequester[F])(
implicit urls: GSheets4sDefaultUrls) {
def get[O](
path: Uri,
path: String,
params: List[(String, String)] = List.empty)(
implicit d: Decoder[O]): F[Either[GsheetsError, O]] =
req(token => requester
.request[Either[GsheetsError, O]](urlBuilder(token, path, params), Method.GET))

def put[I, O](
path: Uri,
path: String,
body: I,
params: List[(String, String)] = List.empty)(
implicit e: Encoder[I], d: Decoder[O]): F[Either[GsheetsError, O]] =
req(token => requester.requestWithBody[I, Either[GsheetsError, O]](
urlBuilder(token, path, params), body, Method.PUT))

def post[I, O](
path: Uri,
path: String,
body: I,
params: List[(String, String)] = List.empty)(
implicit e: Encoder[I], d: Decoder[O]): F[Either[GsheetsError, O]] =
Expand Down Expand Up @@ -82,9 +81,10 @@ class HttpClient[F[_]: Monad](creds: Ref[F, Credentials], requester: HttpRequest

private def urlBuilder(
accessToken: String,
path: Uri,
path: String,
params: List[(String, String)]): Uri =
(urls.baseUrl / path.toString())
.withQueryParam("access_token", accessToken)
.withQueryParams(params.toMap)
urls.baseUrl
.addPath(path)
.withQueryParam("access_token", accessToken)
.withQueryParams(params.toMap)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import org.http4s.Uri

class RestSpreadsheetsValues[F[_]](client: HttpClient[F]) extends SpreadsheetsValues[F] {
def get(spreadsheetID: String, range: A1Notation): F[Either[GsheetsError, ValueRange]] =
client.get(Uri.unsafeFromString(s"$spreadsheetID/values/${range.show}"))
client.get(s"$spreadsheetID/values/${range.show}")

def update(
spreadsheetID: String,
range: A1Notation,
updates: ValueRange,
valueInputOption: ValueInputOption
): F[Either[GsheetsError, UpdateValuesResponse]] =
client.put(Uri.unsafeFromString(s"$spreadsheetID/values/${range.show}"), updates,
client.put(s"$spreadsheetID/values/${range.show}", updates,
List(("valueInputOption", valueInputOption.value)))
}

0 comments on commit 047cde5

Please sign in to comment.