Skip to content

Commit

Permalink
rename endpoint to request
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrauel committed Feb 18, 2021
1 parent 63ce5fe commit 91d7f65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public struct Mock: Decodable {
}

let url = URL(string: "https://test.com/mock")!
let endpoint = Request<MockResource>(
let request = Request<MockResource>(
url: url,
method: .get([
.init(name: "foobar", value: "1"),
.init(name: "barfoo", value: "2")
])
)

URLSession.shared.publisher(for: endpoint)
URLSession.shared.publisher(for: request)
.sink( receiveCompletion: { completion in
print(completion)
},
Expand Down
16 changes: 8 additions & 8 deletions Sources/TinyNetwork/URLSession+Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ public extension URLSession {
}

@available(iOS 13, watchOS 6, OSX 10.15, *)
func publisher(for endpoint: Request<Data>) -> AnyPublisher<Data, Swift.Error> {
dataTaskPublisher(for: endpoint.urlRequest)
func publisher(for request: Request<Data>) -> AnyPublisher<Data, Swift.Error> {
dataTaskPublisher(for: request.urlRequest)
.mapError(Error.networking)
.map(\.data)
.eraseToAnyPublisher()
}

@available(iOS 13, watchOS 6, OSX 10.15, *)
func publisher<Response: Decodable>(
for endpoint: Request<Response>,
for request: Request<Response>,
using decoder: JSONDecoder = .init()
) -> AnyPublisher<Response, Swift.Error> {
dataTaskPublisher(for: endpoint.urlRequest)
dataTaskPublisher(for: request.urlRequest)
.mapError(Error.networking)
.map(\.data)
.decode(type: Response.self, decoder: decoder)
Expand All @@ -38,10 +38,10 @@ public extension URLSession {

public extension URLSession {
func dataTask(
for endpoint: Request<Data>,
for request: Request<Data>,
completionHandler: @escaping (Swift.Result<Data, Swift.Error>) -> Void
) -> URLSessionDataTask {
dataTask(with: endpoint.urlRequest) { data, _, error in
dataTask(with: request.urlRequest) { data, _, error in
do {
if let error = error {
throw error
Expand All @@ -54,11 +54,11 @@ public extension URLSession {
}

func dataTask<Response: Decodable>(
for endpoint: Request<Response>,
for request: Request<Response>,
using decoder: JSONDecoder = .init(),
completionHandler: @escaping (Swift.Result<Response, Swift.Error>) -> Void
) -> URLSessionDataTask {
dataTask(with: endpoint.urlRequest) { data, _, error in
dataTask(with: request.urlRequest) { data, _, error in
do {
if let error = error {
throw error
Expand Down

0 comments on commit 91d7f65

Please sign in to comment.