Skip to content

Commit

Permalink
Merge pull request #9 from joselinoneto/feature/enablewatchos
Browse files Browse the repository at this point in the history
enable watchos
  • Loading branch information
joselinoneto authored Jun 1, 2021
2 parents 61fbc29 + 507d8c1 commit 0c4f63d
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 128 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "ToolboxAPIClient",
platforms: [.iOS(.v13)],
platforms: [.iOS(.v13), .macOS(.v10_15), .watchOS(.v5)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand Down
17 changes: 0 additions & 17 deletions Sources/ToolboxAPIClient/BaseNetworkWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,4 @@ public class BaseNetworkWorker<T> where T: Codable {
.decode(type: T?.self, decoder: JSONDecoder())
.eraseToAnyPublisher()
}

// internal func urlRequestNoMap(httpverb: String, httpBody: Data?, url: URL, headers: Headers) -> AnyPublisher<HTTPURLResponse, Error> {
// var urlRequest = URLRequest(url: url)
// urlRequest.httpMethod = httpverb
// urlRequest.httpBody = httpBody
//
// headers.forEach { (key, value) in
// if let value = value as? String {
// urlRequest.setValue(value, forHTTPHeaderField: key)
// }
// }
//
// return URLSession.shared.dataTaskPublisher(for: urlRequest)
// .compactMap { $0.response as? HTTPURLResponse }
// .mapError { $0 as Error }
// .eraseToAnyPublisher()
// }
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// File.swift
//
//
// Created by Zé on 21/03/21.
//

import Foundation
import Combine
//
import ToolboxAPIClient

public class StoryManagerAPI: StoryRequestable {
public func getStorys() -> AnyPublisher<[StoryDto]?, Error> {
BaseNetworkWorker<[StoryDto]>(target: StoryTarget.getStorys).urlRequest()
}

public func getStorys(limit: Int) -> AnyPublisher<[StoryDto]?, Error> {
BaseNetworkWorker<[StoryDto]>(target: StoryTarget.getStorysWith(limit)).urlRequest()
}

public func getStory(storyId: String) -> AnyPublisher<StoryDto?, Error> {
BaseNetworkWorker<StoryDto>(target: StoryTarget.getStoryBy(storyId)).urlRequest()
}

public func createStory(_ model: StoryDto) -> AnyPublisher<StoryDto?, Error> {
BaseNetworkWorker<StoryDto>(target: StoryTarget.postStory).urlRequest(contentBody: model)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ProfessionDto: Codable {
let id: String?
public struct StoryDto: Codable {
let id: UUID?
let title: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// File.swift
//
//
// Created by Zé on 20/03/21.
//

import Foundation
import Combine
import ToolboxAPIClient

public protocol StoryRequestable {
func getStorys() -> AnyPublisher<[StoryDto]?, Error>
func getStorys(limit: Int) -> AnyPublisher<[StoryDto]?, Error>
func getStory(storyId: String) -> AnyPublisher<StoryDto?, Error>
func createStory(_ model: StoryDto) -> AnyPublisher<StoryDto?, Error>
}

public enum StoryTarget {
case getStorys
case getStorysWith(_ limt: Int)
case getStoryBy(_ professionId: String)
case postStory
}

extension StoryTarget: TargetType {
public var queryString: [URLQueryItem] {
switch self {
case .getStorysWith(let limit):
return [URLQueryItem(name: "limit", value: "\(limit)")]
default:
return []
}
}

public var baseURL: URL {
URL(string: "https://astronomia-api.herokuapp.com/")!
}

public var path: String {
switch self {
case .getStorys,
.getStorysWith:
return "stories"
case .postStory:
return "stories"
case .getStoryBy(let storyid):
return "stories/\(storyid)"
}
}

public var method: HttpMethodEnum {
switch self {
case .getStorys, .getStoryBy, .getStorysWith:
return .get
case .postStory:
return .post
}
}

public var headers: [String : String]? {
["Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiIxMTY3MDNFOS1CRjdFLTQyMEEtQjhFRi1BMjY1MTI5NzlEMjEiLCJzdWIiOiJhc3Ryb25vbWlhX2FwaSIsImV4cCI6NjQwOTIyMTEyMDAsImFkbWluIjp0cnVlfQ.D-ZoYLLVfdGaXrIfVl5BlKslN2oFezBpa0PguKCXmhs"]
}
}
27 changes: 12 additions & 15 deletions Tests/ToolboxAPIClientTests/Tests/app_zeneto_api_moduleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import Combine

@testable import ToolboxAPIClient
class app_zeneto_api_moduleTests: XCTestCase {
let expectation = XCTestExpectation(description: "GET PROFESSIONS DATA FROM MOCKS")
let expectation = XCTestExpectation(description: "GET STORIES DATA FROM MOCKS")
let timeout: TimeInterval = 5.0

static var allTests = [
("getProfessions", testGetProfessions),
// ("getUsersByID", testGetUserById),
// ("getUsersWithLimit", testGetUserWithLimit),
// ("getUsers", testGetUser),
// ("deleteUser", testDeleteUserById)
("getStories", testGetStorys),
("createStrory", testCreateStory)
]

override func setUpWithError() throws {
Expand All @@ -30,15 +27,15 @@ class app_zeneto_api_moduleTests: XCTestCase {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testGetProfessions() throws {
func testGetStorys() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// let networkManager = NetworkManager()
// let userManager = UserNetworkManager(networkController: networkManager)
let professionWorker = ProfessionsManagerAPI()
let professionWorker = StoryManagerAPI()
var subscriptions = Set<AnyCancellable>()

professionWorker.getProfessions()
professionWorker.getStorys()
.sink(receiveCompletion: { [weak self] completion in
switch completion {
case let .failure(error):
Expand All @@ -48,7 +45,7 @@ class app_zeneto_api_moduleTests: XCTestCase {
self?.expectation.fulfill()
break
}
}, receiveValue: { (value: [ProfessionDto]?) in
}, receiveValue: { (value: [StoryDto]?) in
guard let professions = value else {
XCTFail()
return
Expand All @@ -59,13 +56,13 @@ class app_zeneto_api_moduleTests: XCTestCase {
wait(for: [expectation], timeout: timeout)
}

func testCreateProfession() throws {
let professionWorker = ProfessionsManagerAPI()
func testCreateStory() throws {
let professionWorker = StoryManagerAPI()
var subscriptions = Set<AnyCancellable>()

let profession = ProfessionDto(id: nil, title: "iOS Engineer")
let profession = StoryDto(id: nil, title: "iOS Engineer")
professionWorker
.createProfession(profession)
.createStory(profession)
.sink(receiveCompletion: { [weak self] completion in
switch completion {
case let .failure(error):
Expand All @@ -75,7 +72,7 @@ class app_zeneto_api_moduleTests: XCTestCase {
self?.expectation.fulfill()
break
}
}, receiveValue: { (value: ProfessionDto?) in
}, receiveValue: { (value: StoryDto?) in
XCTAssertNotNil(value)
}).store(in: &subscriptions)

Expand Down

0 comments on commit 0c4f63d

Please sign in to comment.