Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moya Network 모듈 세팅 #11

Merged
merged 10 commits into from
Jul 20, 2023

Conversation

enebin
Copy link
Member

@enebin enebin commented Jul 16, 2023

ADDED

  • Moya 디펜던시
  • Moya를 래핑한 KeymeAPIManager
  • KeymeAPIManager 테스트

사용(수정)

API 요청

// async-await
let rawResult = try await KeymeAPIManager.shared.request(.test) // (statusCode: Int, data: Data)
let decodedResult = try await KeymeAPIManager.shared.request(.test,. object: TestItem.self) // TestItem
print(result)

// Combine
let cancellable = KeymeAPIManager.shared.request(.test)
    .sink(receiveValue: { response in
        if 200..<300 ~= response.statusCode {
            print("Not Ok")
            return
        }
        
        print(response.data)
    })

let cancellable = KeymeAPIManager.shared.request(.test, object: TestItem.self)
    .sink(receiveValue: { item in
        print(item) // ex. TestItem(id: 123)
    })
  • 디코딩, 안 디코딩 둘 다 지원함
  • 디코딩 해주는 메서드에서 statusCode를 지원할지는 미정

인증토큰 추가하기

KeymeAPIManager.shared.registerAuthorizationToken("adfjao;wenu1241bgo")

참고

  • 디바이스 테스트도 끝냄
  • 베이스 브랜치가 메인이 아님. 외부의존성 세팅이 저 브랜치에 되어 있어서 그냥 저기를 베이스 브랜치로 잡음..
  • 네이밍 괜찮은지 봐주시면 좋을 듯
  • 이외에 쓰기 괜찮은지 첫인상 부탁

더 참고

  • 네트워크 통신 기능을 Core 로 옮기고 디코딩에 관한 부분을 APIRequestable이라는 레이어로 추가함
  • 프로토콜로 리턴 타입을 고정해서 object: TestItem.self를 안 해도 깔쌈하게 돌아가게끔 하려고 했으나 JSON과 struct가 반드시 1대 1 매칭이 아닐 수 있다는 생각이 들어서 일단 보류
// ex. for case `.test`
var sampleData: Data {
    """
    {
        "id": 1,
        "name": "Test Item"
    }
    """
        .data(using: .utf8)!
}

struct TestName {
  let name: String
}

struct TestItem {
  let id: Int
  let name: String
}

let item = try await KeymeAPIManager.shared.request(.test,. object: TestItem.self) // TestItem
let name = try await KeymeAPIManager.shared.request(.test,. object: TestName.self) // TestName

써보고 영 거지같으면 그때그때 수정할게요.. API 나오면 한 번쯤 엎어야될 것 같은데 지금 뭐 타이트하게 해봤자 나중에 할 일만 늘어날 듯ㅋㅋ

@enebin enebin self-assigned this Jul 16, 2023
@enebin enebin added enhancement New feature or request module labels Jul 16, 2023
@enebin enebin linked an issue Jul 16, 2023 that may be closed by this pull request
@enebin enebin marked this pull request as ready for review July 16, 2023 11:29
@enebin enebin requested review from k906506 and 0inn July 16, 2023 11:29
k906506

This comment was marked as resolved.

Copy link
Contributor

@0inn 0inn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코멘트가 좀 늦어서 죄송합니다 . .
궁금한 점이랑 리뷰 달아뒀어요 ! 고생하셨습니다 👍🏻

Targets/KeymeKit/Sources/Network/APIs/KeymeAPI.swift Outdated Show resolved Hide resolved
Targets/KeymeKit/Sources/Network/NetworkManager.swift Outdated Show resolved Hide resolved
Targets/KeymeKit/Sources/Network/NetworkManager.swift Outdated Show resolved Hide resolved
@enebin enebin marked this pull request as draft July 18, 2023 11:07
@enebin enebin marked this pull request as ready for review July 18, 2023 13:30
@enebin enebin requested review from k906506 and 0inn July 18, 2023 13:31
@enebin enebin mentioned this pull request Jul 18, 2023
1 task
Copy link
Contributor

@0inn 0inn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳 ! 확인 완 :)

@enebin enebin merged commit 799d343 into feature/push&deeplink-setting Jul 20, 2023
1 check passed
@enebin enebin deleted the feature/network-module branch July 20, 2023 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

네트워크 모듈 추가
3 participants