Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
move common things to core module
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Oct 8, 2020
1 parent b7e330d commit ba5b729
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.forkhandles.result4k.Failure
import dev.forkhandles.result4k.Success
import org.http4k.aws.AwsCredentialScope
import org.http4k.aws.AwsCredentials
import org.http4k.connect.RemoteFailure
import org.http4k.core.HttpHandler
import org.http4k.core.Method.DELETE
import org.http4k.core.Method.GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.forkhandles.result4k.Failure
import dev.forkhandles.result4k.Success
import org.http4k.aws.AwsCredentialScope
import org.http4k.aws.AwsCredentials
import org.http4k.connect.RemoteFailure
import org.http4k.core.HttpHandler
import org.http4k.core.Method.DELETE
import org.http4k.core.Method.GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package org.http4k.connect.amazon.s3

import dev.forkhandles.result4k.Result
import org.http4k.core.Status
import org.http4k.core.Uri
import org.http4k.connect.RemoteFailure
import java.io.InputStream

data class RemoteFailure(val uri: Uri, val status: Status)


/**
* Interface for global S3 operations
*/
Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ allprojects {
implementation project(":http4k-connect-core")
} else if (project.name.endsWith("fake")) {
implementation project(":http4k-connect-core-fake")
testImplementation project(path: ":http4k-connect-core-fake", configuration: 'testArtifacts')
implementation project(":${project.name.substring(0, project.name.length() - 5)}")
testImplementation project(path: ":http4k-connect-core-fake", configuration: 'testArtifacts')
} else if (project.name.startsWith("http4k-connect-storage")) {
implementation project(":http4k-connect-core-fake")
testImplementation project(path: ":http4k-connect-core-fake", configuration: 'testArtifacts')
} else if (project.name == "http4k-connect") {
//
// uber project
} else if (project.name == "http4k-connect-bom") {
//
} else if (!project.name.endsWith("core")) {
// bom - no code
} else if (project.name != "http4k-connect-core") {
implementation project(":http4k-connect-core")
testImplementation project(":${project.name}-fake")
testImplementation project(path: ":http4k-connect-core-fake", configuration: 'testArtifacts')
}
Expand Down
6 changes: 6 additions & 0 deletions core/client/src/main/kotlin/org/http4k/connect/common.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.http4k.connect

import org.http4k.core.Status
import org.http4k.core.Uri

data class RemoteFailure(val uri: Uri, val status: Status)
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.http4k.connect.example

import dev.forkhandles.result4k.Result
import org.http4k.core.Status

data class RemoteFailure(val status: Status)
import org.http4k.connect.RemoteFailure

interface Example {
fun echo(input: String): Result<String, RemoteFailure>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.http4k.connect.google.analytics

import dev.forkhandles.result4k.Result
import org.http4k.core.Status

data class RemoteFailure(val status: Status)
import org.http4k.connect.RemoteFailure

interface GoogleAnalytics {
fun pageView(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package org.http4k.connect.google.analytics

import dev.forkhandles.result4k.Failure
import dev.forkhandles.result4k.Result
import dev.forkhandles.result4k.Success
import org.http4k.connect.RemoteFailure
import org.http4k.core.HttpHandler
import org.http4k.core.Method
import org.http4k.core.Method.POST
import org.http4k.core.Request
import org.http4k.core.Uri
import org.http4k.core.body.form

fun GoogleAnalytics.Companion.Http(http: HttpHandler, trackingId: TrackingId) = object : GoogleAnalytics {
override fun pageView(userAgent: String, clientId: ClientId, documentTitle: String, documentPath: String, documentHost: String): Result<Unit, RemoteFailure> {
val status = http(Request(Method.POST, "/collect")
.header("User-Agent", userAgent)
.form(VERSION, "1")
.form(MEASUREMENT_ID, trackingId.value)
.form(CLIENT_ID, clientId.value)
.form(DOCUMENT_TITLE, documentTitle)
.form(DOCUMENT_PATH, documentPath)
.form(DOCUMENT_HOST, documentHost)
).status

return if (status.successful) Success(Unit) else Failure(RemoteFailure(status))
}
override fun pageView(userAgent: String, clientId: ClientId, documentTitle: String, documentPath: String, documentHost: String) =
Uri.of("/collect").let {
with(http(Request(POST, it)
.header("User-Agent", userAgent)
.form(VERSION, "1")
.form(MEASUREMENT_ID, trackingId.value)
.form(CLIENT_ID, clientId.value)
.form(DOCUMENT_TITLE, documentTitle)
.form(DOCUMENT_PATH, documentPath)
.form(DOCUMENT_HOST, documentHost)
)) {
if (status.successful) Success(Unit) else Failure(RemoteFailure(it, status))
}
}
}

const val VERSION = "v"
Expand Down

0 comments on commit ba5b729

Please sign in to comment.