Skip to content

Commit

Permalink
Merge pull request #200 from rootstrap/feature/migrate-network-layer
Browse files Browse the repository at this point in the history
Use network layer from RSSwiftNetworking 1.1.0
  • Loading branch information
glm4 authored Sep 1, 2022
2 parents d60993a + 0c9f569 commit 6311f2e
Show file tree
Hide file tree
Showing 37 changed files with 198 additions and 935 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use_frameworks!
inhibit_all_warnings!

target 'ios-base' do
pod 'Alamofire', '~> 5.2.0'
pod 'RSSwiftNetworking/AlamofireProvider', '~> 1.1.0'
pod 'IQKeyboardManagerSwift', '~> 6.1.1'
pod 'RSFontSizes', '~> 1.2.0'
pod 'R.swift', '~> 5.0.3'
Expand Down
16 changes: 11 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Alamofire (5.2.1)
- Alamofire (5.2.0)
- Device (3.1.2)
- FBSDKCoreKit (5.5.0):
- FBSDKCoreKit/Basics (= 5.5.0)
Expand Down Expand Up @@ -106,11 +106,14 @@ PODS:
- R.swift.Library (5.0.1)
- RSFontSizes (1.2.0):
- Device (~> 3.1.2)
- RSSwiftNetworking/AlamofireProvider (1.1.0):
- Alamofire (= 5.2.0)
- RSSwiftNetworking/Core
- RSSwiftNetworking/Core (1.1.0)
- Swifter (1.5.0)
- SwiftLint (0.43.1)

DEPENDENCIES:
- Alamofire (~> 5.2.0)
- FBSDKCoreKit (~> 5.5.0)
- FBSDKLoginKit (~> 5.5.0)
- Firebase/Analytics (~> 8.6.0)
Expand All @@ -119,6 +122,7 @@ DEPENDENCIES:
- IQKeyboardManagerSwift (~> 6.1.1)
- R.swift (~> 5.0.3)
- RSFontSizes (~> 1.2.0)
- RSSwiftNetworking/AlamofireProvider (~> 1.1.0)
- Swifter (~> 1.5.0)
- SwiftLint (~> 0.43.1)

Expand All @@ -143,11 +147,12 @@ SPEC REPOS:
- R.swift
- R.swift.Library
- RSFontSizes
- RSSwiftNetworking
- Swifter
- SwiftLint

SPEC CHECKSUMS:
Alamofire: e911732990610fe89af59ac0077f923d72dc3dfd
Alamofire: c1ca147559e730bfb2182c8c7aafbdd90a867987
Device: 62242076214c30fb5760174b3601cefafa70a481
FBSDKCoreKit: 7ade9cfea30eef2f6cf105a1aa904f89ea68fb7d
FBSDKLoginKit: bb28062f24e79590c44ba03297ca9bea4b6436d2
Expand All @@ -166,9 +171,10 @@ SPEC CHECKSUMS:
R.swift: f5a87643b91ea569d23d6afb3eee9c743edde239
R.swift.Library: cfe85d569d9bae6cb262922db130e7c3a7a5fad1
RSFontSizes: 78158061f9f6121c6715f746395b1d8390fcb18b
RSSwiftNetworking: 64b76bc39cbce96cd34476a6ce97f2caa164f9ed
Swifter: e71dd674404923d7f03ebb03f3f222d1c570bc8e
SwiftLint: 99f82d07b837b942dd563c668de129a03fc3fb52

PODFILE CHECKSUM: ad8b2fa0cef07782327d22c0570f1659eddad970
PODFILE CHECKSUM: 0979596c2c2fa4d9f8b647d437a0550781538f1a

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
164 changes: 28 additions & 136 deletions ios-base.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ios-base/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func unexpectedLogout() {
UserDataManager.deleteUser()
SessionManager.deleteSession()
SessionManager.shared.deleteSession()
// Clear any local data if needed
// Take user to onboarding if needed, do NOT redirect the user
// if is already in the landing to avoid losing the current VC stack state.
Expand Down
10 changes: 6 additions & 4 deletions ios-base/Common/Models/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import RSSwiftNetworking

struct Session: Codable {
var uid: String?
Expand All @@ -31,12 +32,13 @@ struct Session: Codable {
self.expiry = expires
}

init?(headers: [String: Any]) {
var loweredHeaders = headers
loweredHeaders.lowercaseKeys()
guard let stringHeaders = loweredHeaders as? [String: String] else {
init?(headers: [AnyHashable: Any]) {
guard var stringHeaders = headers as? [String: String] else {
return nil
}

stringHeaders.lowercaseKeys()

if let expiryString = stringHeaders[HTTPHeader.expiry.rawValue],
let expiryNumber = Double(expiryString) {
expiry = Date(timeIntervalSince1970: expiryNumber)
Expand Down
16 changes: 0 additions & 16 deletions ios-base/Extensions/DataExtension.swift

This file was deleted.

17 changes: 14 additions & 3 deletions ios-base/Home/ViewModels/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ class HomeViewModel {
delegate?.didUpdateState(to: state)
}
}

private let userServices: UserServices
private let authServices: AuthenticationServices

init(
userServices: UserServices = UserServices(),
authServices: AuthenticationServices = AuthenticationServices()
) {
self.userServices = userServices
self.authServices = authServices
}

func loadUserProfile() {
state = .network(state: .loading)

UserServices.getMyProfile { [weak self] (result: Result<User, Error>) in
userServices.getMyProfile { [weak self] (result: Result<User, Error>) in
switch result {
case .success(let user):
self?.userEmail = user.email
Expand All @@ -47,7 +58,7 @@ class HomeViewModel {
func logoutUser() {
state = .network(state: .loading)

AuthenticationServices.logout { [weak self] result in
authServices.logout { [weak self] result in
switch result {
case .success:
self?.didlogOutAccount()
Expand All @@ -60,7 +71,7 @@ class HomeViewModel {
func deleteAccount() {
state = .network(state: .loading)

AuthenticationServices.deleteAccount { [weak self] result in
authServices.deleteAccount { [weak self] result in
switch result {
case .success:
self?.didlogOutAccount()
Expand Down
22 changes: 15 additions & 7 deletions ios-base/Managers/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@

import UIKit

class SessionManager: NSObject {
internal class SessionManager: CurrentUserSessionProvider {

static var currentSession: Session? {
static let shared = SessionManager()

private let userDefaults: UserDefaults

init(userDefaults: UserDefaults = .standard) {
self.userDefaults = userDefaults
}

var currentSession: Session? {
get {
if
let data = UserDefaults.standard.data(forKey: "ios-base-session"),
let data = userDefaults.data(forKey: "ios-base-session"),
let session = try? JSONDecoder().decode(Session.self, from: data)
{
return session
Expand All @@ -23,15 +31,15 @@ class SessionManager: NSObject {

set {
let session = try? JSONEncoder().encode(newValue)
UserDefaults.standard.set(session, forKey: "ios-base-session")
userDefaults.set(session, forKey: "ios-base-session")
}
}

class func deleteSession() {
UserDefaults.standard.removeObject(forKey: "ios-base-session")
func deleteSession() {
userDefaults.removeObject(forKey: "ios-base-session")
}

static var validSession: Bool {
var validSession: Bool {
if let session = currentSession, let uid = session.uid,
let tkn = session.accessToken, let client = session.client {
return !uid.isEmpty && !tkn.isEmpty && !client.isEmpty
Expand Down
12 changes: 7 additions & 5 deletions ios-base/Navigators/AppNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

import Foundation

class AppNavigator: BaseNavigator {
static let shared = AppNavigator()
internal class AppNavigator: BaseNavigator {

init() {
let initialRoute: Route = SessionManager.validSession ?
HomeRoutes.home : OnboardingRoutes.firstScreen
static let shared = AppNavigator(isLoggedIn: SessionManager.shared.validSession)

init(isLoggedIn: Bool) {
let initialRoute: Route = isLoggedIn
? HomeRoutes.home
: OnboardingRoutes.firstScreen
super.init(with: initialRoute)
}

Expand Down
20 changes: 0 additions & 20 deletions ios-base/Networking/Errors/APIClientError.swift

This file was deleted.

74 changes: 0 additions & 74 deletions ios-base/Networking/Errors/APIError.swift

This file was deleted.

10 changes: 10 additions & 0 deletions ios-base/Networking/Extensions/APIClient+Application.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import RSSwiftNetworking

/// Provides an easy-access APIClient implementation to use across the application
/// You can define and configure as many APIClients as needed
internal enum iOSBaseAPIClient {
static let shared = BaseAPIClient(
networkProvider: AlamofireNetworkProvider(),
headersProvider: RailsAPIHeadersProvider(sessionProvider: SessionHeadersProvider())
)
}
11 changes: 0 additions & 11 deletions ios-base/Networking/Extensions/APIClient+Product.swift

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions ios-base/Networking/Models/Base64Media.swift

This file was deleted.

Loading

0 comments on commit 6311f2e

Please sign in to comment.