Skip to content

Commit

Permalink
Merge pull request #112 from Dwolla/updates
Browse files Browse the repository at this point in the history
Typeclass Bounds and Uri return types
  • Loading branch information
Corey Oliver authored Mar 7, 2022
2 parents 6dbd2af + e63b30a commit 0bdaa4e
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.dwolla.cloudflare

import cats.implicits._
import cats._
import cats.syntax.all._
import com.dwolla.cloudflare.domain.model.accesscontrolrules._
import com.dwolla.cloudflare.domain.model.{AccountId, ZoneId, tagAccountId, tagZoneId}
import io.circe.syntax._
import io.circe._
import io.circe.optics.JsonPath._
import fs2._
import cats.effect.Sync
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
import org.http4s.Method._
import org.http4s._
Expand All @@ -31,8 +31,8 @@ trait AccessControlRuleClient[F[_]] {
case _ => None
}

def buildUri(level: Level, ruleId: AccessControlRuleId): String =
(buildBaseUrl(level) / ruleId).renderString
def buildUri(level: Level, ruleId: AccessControlRuleId): Uri =
buildBaseUrl(level) / ruleId

def buildBaseUrl(level: Level): Uri = {
val baseUrlWithLevel = level match {
Expand All @@ -44,13 +44,13 @@ trait AccessControlRuleClient[F[_]] {
}

object AccessControlRuleClient {
def apply[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]): AccessControlRuleClient[F] = new AccessControlRuleClientImpl[F](executor)
def apply[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]): AccessControlRuleClient[F] = new AccessControlRuleClientImpl[F](executor)

val accountLevelUriRegex = """https://api.cloudflare.com/client/v4/accounts/(.+?)/firewall/access_rules/rules/(.+)""".r
val zoneLevelUriRegex = """https://api.cloudflare.com/client/v4/zones/(.+?)/firewall/access_rules/rules/(.+)""".r
}

class AccessControlRuleClientImpl[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]) extends AccessControlRuleClient[F] with Http4sClientDsl[F] {
class AccessControlRuleClientImpl[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]) extends AccessControlRuleClient[F] with Http4sClientDsl[F] {
private def fetch(req: Request[F]): Stream[F, AccessControlRule] =
executor.fetch[AccessControlRule](req)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dwolla.cloudflare

import cats._
import cats.implicits._
import cats.syntax.all._
import com.dwolla.cloudflare.AccountMembersClientImpl.notFoundCodes
import com.dwolla.cloudflare.domain.dto.accounts._
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
Expand Down Expand Up @@ -36,12 +36,12 @@ trait AccountMembersClient[F[_]] {
}

object AccountMembersClient {
def apply[F[_] : MonadThrow](executor: StreamingCloudflareApiExecutor[F]): AccountMembersClient[F] = new AccountMembersClientImpl[F](executor)
def apply[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]): AccountMembersClient[F] = new AccountMembersClientImpl[F](executor)

val uriRegex: Regex = """https://api.cloudflare.com/client/v4/accounts/(.+?)/members/(.+)""".r
}

class AccountMembersClientImpl[F[_] : MonadThrow](executor: StreamingCloudflareApiExecutor[F]) extends AccountMembersClient[F] with Http4sClientDsl[F] {
class AccountMembersClientImpl[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]) extends AccountMembersClient[F] with Http4sClientDsl[F] {
override def getById(accountId: AccountId, accountMemberId: String): Stream[F, AccountMember] =
for {
res <- executor.fetch[AccountMemberDTO](GET(buildAccountMemberUri(accountId, accountMemberId))).returningEmptyOnErrorCodes(notFoundCodes: _*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait AccountsClient[F[_]] {
}

object AccountsClient {
def apply[F[_] : MonadThrow](executor: StreamingCloudflareApiExecutor[F]): AccountsClient[F] = new AccountsClientImpl[F](executor)
def apply[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]): AccountsClient[F] = new AccountsClientImpl[F](executor)

val uriRegex: Regex = """https://api.cloudflare.com/client/v4/accounts/(.+?)""".r
}
Expand All @@ -36,7 +36,7 @@ object AccountsClientImpl {
val notFoundCodes = List(1003)
}

class AccountsClientImpl[F[_]: MonadThrow](executor: StreamingCloudflareApiExecutor[F]) extends AccountsClient[F] with Http4sClientDsl[F] {
class AccountsClientImpl[F[_]: ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]) extends AccountsClient[F] with Http4sClientDsl[F] {
override def list(): Stream[F, Account] = {
for {
record <- executor.fetch[AccountDTO](GET(BaseUrl / "accounts" withQueryParam("direction", "asc")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.dwolla.cloudflare

import cats._
import cats.effect._
import cats.implicits._
import cats.syntax.all._
import com.dwolla.cloudflare.StreamingCloudflareApiExecutor._
import com.dwolla.cloudflare.domain.dto._
import com.dwolla.cloudflare.domain.model.Exceptions._
Expand Down
20 changes: 9 additions & 11 deletions client/src/main/scala/com/dwolla/cloudflare/DnsRecordClient.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.dwolla.cloudflare

import _root_.io.circe._
import _root_.io.circe.generic.auto._
import _root_.io.circe.optics.JsonPath._
import _root_.io.circe.syntax._
import _root_.org.http4s.circe._
import cats._
import cats.effect._
import cats.implicits._
import cats.syntax.all._
import com.dwolla.cloudflare.DnsRecordClientImpl.{DnsRecordContent, DnsRecordName, DnsRecordType}
import com.dwolla.cloudflare.domain.dto.dns._
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
import com.dwolla.cloudflare.domain.model.{Error, _}
import com.dwolla.cloudflare.domain.model._
import io.circe.{Error => _, _}
import io.circe.optics.JsonPath._
import io.circe.syntax._
import fs2._
import monix.newtypes.NewtypeWrapped
import org.http4s.Method._
import org.http4s._
import org.http4s.circe._
import org.http4s.client.dsl.Http4sClientDsl

import scala.util.matching.Regex
Expand All @@ -40,7 +38,7 @@ trait DnsRecordClient[F[_]] {
}

object DnsRecordClient {
def apply[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]): DnsRecordClient[F] = new DnsRecordClientImpl[F](executor)
def apply[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]): DnsRecordClient[F] = new DnsRecordClientImpl[F](executor)

val uriRegex: Regex = """https://api.cloudflare.com/client/v4/zones/(.+?)/dns_records/(.+)""".r
}
Expand Down Expand Up @@ -71,7 +69,7 @@ object DnsRecordClientImpl {
}
}

class DnsRecordClientImpl[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]) extends DnsRecordClient[F] with Http4sClientDsl[F] {
class DnsRecordClientImpl[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]) extends DnsRecordClient[F] with Http4sClientDsl[F] {
import com.dwolla.cloudflare.domain.model.Implicits._

private val zoneClient = ZoneClient(executor)
Expand All @@ -83,7 +81,7 @@ class DnsRecordClientImpl[F[_] : Sync](executor: StreamingCloudflareApiExecutor[
} yield (record, zoneId)

private def toUri(physicalResourceId: String): F[Uri] =
Uri.fromString(physicalResourceId).fold(Sync[F].raiseError, Applicative[F].pure)
Uri.fromString(physicalResourceId).liftTo[F]

override def updateDnsRecord(record: IdentifiedDnsRecord): Stream[F, IdentifiedDnsRecord] =
for {
Expand Down
15 changes: 8 additions & 7 deletions client/src/main/scala/com/dwolla/cloudflare/FilterClient.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.dwolla.cloudflare

import cats.implicits._
import cats._
import cats.syntax.all._
import com.dwolla.cloudflare.domain.model.{ZoneId, tagZoneId}
import com.dwolla.cloudflare.domain.model.filters._
import io.circe.syntax._
import io.circe._
import io.circe.optics.JsonPath._
import fs2._
import cats.effect.Sync
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
import org.http4s.Method._
import org.http4s.Request
import org.http4s.{Request, Uri}
import org.http4s.circe._
import org.http4s.client.dsl.Http4sClientDsl
import org.http4s.syntax.all._

import scala.util.matching.Regex

Expand All @@ -32,18 +33,18 @@ trait FilterClient[F[_]] {
case _ => None
}

def buildUri(zoneId: ZoneId, filterId: FilterId): String =
s"https://api.cloudflare.com/client/v4/zones/$zoneId/filters/$filterId"
def buildUri(zoneId: ZoneId, filterId: FilterId): Uri =
uri"https://api.cloudflare.com/client/v4/zones" / zoneId / "filters" / filterId

}

object FilterClient {
def apply[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]): FilterClient[F] = new FilterClientImpl[F](executor)
def apply[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]): FilterClient[F] = new FilterClientImpl[F](executor)

val uriRegex: Regex = """https://api.cloudflare.com/client/v4/zones/(.+?)/filters/(.+)""".r
}

class FilterClientImpl[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]) extends FilterClient[F] with Http4sClientDsl[F] {
class FilterClientImpl[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]) extends FilterClient[F] with Http4sClientDsl[F] {
private def fetch(req: Request[F]): Stream[F, Filter] =
executor.fetch[Filter](req)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.dwolla.cloudflare

import cats.implicits._
import com.dwolla.cloudflare.domain.model.{ZoneId, tagZoneId}
import cats._
import cats.syntax.all._
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
import com.dwolla.cloudflare.domain.model.firewallrules._
import io.circe.syntax._
import com.dwolla.cloudflare.domain.model.{ZoneId, tagZoneId}
import io.circe._
import io.circe.optics.JsonPath._
import io.circe.syntax._
import fs2._
import cats.effect.Sync
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
import org.http4s.Method._
import org.http4s.Request
import org.http4s.{Request, Uri}
import org.http4s.circe._
import org.http4s.client.dsl.Http4sClientDsl
import org.http4s.syntax.all._

import scala.util.matching.Regex

Expand All @@ -32,18 +33,18 @@ trait FirewallRuleClient[F[_]] {
case _ => None
}

def buildUri(zoneId: ZoneId, firewallRuleId: FirewallRuleId): String =
s"https://api.cloudflare.com/client/v4/zones/$zoneId/firewall/rules/$firewallRuleId"
def buildUri(zoneId: ZoneId, firewallRuleId: FirewallRuleId): Uri =
uri"https://api.cloudflare.com/client/v4/zones" / zoneId / "firewall" / "rules" / firewallRuleId

}

object FirewallRuleClient {
def apply[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]): FirewallRuleClient[F] = new FirewallRuleClientImpl[F](executor)
def apply[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]): FirewallRuleClient[F] = new FirewallRuleClientImpl[F](executor)

val uriRegex: Regex = """https://api.cloudflare.com/client/v4/zones/(.+?)/firewall/rules/(.+)""".r
}

class FirewallRuleClientImpl[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]) extends FirewallRuleClient[F] with Http4sClientDsl[F] {
class FirewallRuleClientImpl[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]) extends FirewallRuleClient[F] with Http4sClientDsl[F] {
private def fetch(req: Request[F]): Stream[F, FirewallRule] =
executor.fetch[FirewallRule](req)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.dwolla.cloudflare

import java.time.Instant

import com.dwolla.cloudflare.domain.dto.logpush.{CreateJobDTO, CreateOwnershipDTO, LogpushJobDTO, LogpushOwnershipDTO}
import com.dwolla.cloudflare.domain.model.logpush._
import com.dwolla.cloudflare.domain.model.{Implicits => _, _}
Expand All @@ -11,6 +9,8 @@ import org.http4s.Method._
import org.http4s.circe._
import org.http4s.client.dsl.Http4sClientDsl

import java.time.Instant

trait LogpushClient[F[_]] {
def list(zoneId: ZoneId): Stream[F, LogpushJob]
def createOwnership(zoneId: ZoneId, destination: LogpushDestination): Stream[F, LogpushOwnership]
Expand Down
15 changes: 8 additions & 7 deletions client/src/main/scala/com/dwolla/cloudflare/PageRuleClient.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.dwolla.cloudflare

import cats.implicits._
import cats._
import cats.syntax.all._
import com.dwolla.cloudflare.domain.model.{ZoneId, tagZoneId}
import com.dwolla.cloudflare.domain.model.pagerules._
import io.circe.syntax._
import io.circe._
import io.circe.optics.JsonPath._
import fs2._
import cats.effect.Sync
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
import org.http4s.Method._
import org.http4s.Request
import org.http4s.{Request, Uri}
import org.http4s.circe._
import org.http4s.client.dsl.Http4sClientDsl
import org.http4s.syntax.all._

import scala.util.matching.Regex

Expand All @@ -32,18 +33,18 @@ trait PageRuleClient[F[_]] {
case _ => None
}

def buildUri(zoneId: ZoneId, pageRuleId: PageRuleId): String =
s"https://api.cloudflare.com/client/v4/zones/$zoneId/pagerules/$pageRuleId"
def buildUri(zoneId: ZoneId, pageRuleId: PageRuleId): Uri =
uri"https://api.cloudflare.com/client/v4/zones" / zoneId / "pagerules" / pageRuleId

}

object PageRuleClient {
def apply[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]): PageRuleClient[F] = new PageRuleClientImpl[F](executor)
def apply[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]): PageRuleClient[F] = new PageRuleClientImpl[F](executor)

val uriRegex: Regex = """https://api.cloudflare.com/client/v4/zones/(.+?)/pagerules/(.+)""".r
}

class PageRuleClientImpl[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]) extends PageRuleClient[F] with Http4sClientDsl[F] {
class PageRuleClientImpl[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]) extends PageRuleClient[F] with Http4sClientDsl[F] {
private def fetch(req: Request[F]): Stream[F, PageRule] =
executor.fetch[PageRule](req)

Expand Down
21 changes: 11 additions & 10 deletions client/src/main/scala/com/dwolla/cloudflare/RateLimitClient.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.dwolla.cloudflare

import cats.implicits._
import com.dwolla.cloudflare.domain.model.{ZoneId, tagZoneId}
import cats._
import cats.syntax.all._
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
import com.dwolla.cloudflare.domain.model.ratelimits._
import io.circe.syntax._
import com.dwolla.cloudflare.domain.model.{ZoneId, tagZoneId}
import io.circe._
import io.circe.optics.JsonPath._
import io.circe.syntax._
import fs2._
import cats.effect.Sync
import com.dwolla.cloudflare.domain.model.Exceptions.UnexpectedCloudflareErrorException
import org.http4s.Method._
import org.http4s.Request
import org.http4s.{Request, Uri}
import org.http4s.circe._
import org.http4s.client.dsl.Http4sClientDsl

import scala.util.matching.Regex
import org.http4s.syntax.all._

trait RateLimitClient[F[_]] {
def list(zoneId: ZoneId): Stream[F, RateLimit]
Expand All @@ -32,17 +33,17 @@ trait RateLimitClient[F[_]] {
case _ => None
}

def buildUri(zoneId: ZoneId, rateLimitId: RateLimitId): String =
s"https://api.cloudflare.com/client/v4/zones/$zoneId/rate_limits/$rateLimitId"
def buildUri(zoneId: ZoneId, rateLimitId: RateLimitId): Uri =
uri"https://api.cloudflare.com/client/v4/zones" / zoneId / "rate_limits" / rateLimitId
}

object RateLimitClient {
def apply[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]): RateLimitClient[F] = new RateLimitClientImpl[F](executor)
def apply[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]): RateLimitClient[F] = new RateLimitClientImpl[F](executor)

val uriRegex: Regex = """https://api.cloudflare.com/client/v4/zones/(.+?)/rate_limits/(.+)""".r
}

class RateLimitClientImpl[F[_] : Sync](executor: StreamingCloudflareApiExecutor[F]) extends RateLimitClient[F] with Http4sClientDsl[F] {
class RateLimitClientImpl[F[_] : ApplicativeThrow](executor: StreamingCloudflareApiExecutor[F]) extends RateLimitClient[F] with Http4sClientDsl[F] {
private def fetch(req: Request[F]): Stream[F, RateLimit] =
executor.fetch[RateLimit](req)

Expand Down
Loading

0 comments on commit 0bdaa4e

Please sign in to comment.