-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
29 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
package ba.sake.sharaf | ||
package ba.sake.sharaf.utils | ||
|
||
import java.net.ServerSocket | ||
import scala.util.Using | ||
|
||
import ba.sake.formson._ | ||
import ba.sake.querson.QueryStringMap | ||
|
||
object SharafUtils: | ||
def getFreePort(): Int = | ||
Using.resource(new ServerSocket(0)) { ss => | ||
ss.getLocalPort() | ||
} | ||
|
||
def getFreePort(): Int = | ||
Using.resource(new ServerSocket(0)) { ss => | ||
ss.getLocalPort() | ||
} | ||
|
||
// requests integration | ||
extension (formDataMap: FormDataMap) | ||
def toRequestsMultipart() = { | ||
val multiItems = formDataMap.flatMap { case (key, values) => | ||
values.map { | ||
case FormValue.Str(value) => requests.MultiItem(key, value) | ||
case FormValue.File(value) => requests.MultiItem(key, value, value.getFileName.toString) | ||
case FormValue.ByteArray(value) => requests.MultiItem(key, value) | ||
} | ||
// requests integration | ||
extension (formDataMap: FormDataMap) | ||
def toRequestsMultipart() = { | ||
val multiItems = formDataMap.flatMap { case (key, values) => | ||
values.map { | ||
case FormValue.Str(value) => requests.MultiItem(key, value) | ||
case FormValue.File(value) => requests.MultiItem(key, value, value.getFileName.toString) | ||
case FormValue.ByteArray(value) => requests.MultiItem(key, value) | ||
} | ||
requests.MultiPart(multiItems.toSeq*) | ||
} | ||
requests.MultiPart(multiItems.toSeq*) | ||
} | ||
|
||
extension (queryStringMap: QueryStringMap) | ||
def toRequestsQuery(): Map[String, String] = | ||
queryStringMap.map { (k, vs) => k -> vs.head } |