diff --git a/tree/tree.xcodeproj/project.pbxproj b/tree/tree.xcodeproj/project.pbxproj index 528e713..b6b7913 100644 --- a/tree/tree.xcodeproj/project.pbxproj +++ b/tree/tree.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ BC2656C321FD94EE00003413 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC2656BB21FD94EE00003413 /* NetworkResult.swift */; }; BC2656C421FD94EE00003413 /* NetworkError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC2656BC21FD94EE00003413 /* NetworkError.swift */; }; BC2656C721FD950900003413 /* Articles.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC2656C621FD950900003413 /* Articles.swift */; }; + BC2656CB21FE97E700003413 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC2656CA21FE97E700003413 /* Config.swift */; }; D9C6AB3D21FA9B3E001C0AB8 /* Extension+UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9C6AB3721FA9B3E001C0AB8 /* Extension+UIColor.swift */; }; D9C6AB4421FA9CF8001C0AB8 /* Search.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D9C6AB4321FA9CF8001C0AB8 /* Search.storyboard */; }; D9C6AB4D21FAAD0A001C0AB8 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9C6AB4A21FAAD09001C0AB8 /* SearchViewController.swift */; }; @@ -60,6 +61,7 @@ BC2656BB21FD94EE00003413 /* NetworkResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = ""; }; BC2656BC21FD94EE00003413 /* NetworkError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkError.swift; sourceTree = ""; }; BC2656C621FD950900003413 /* Articles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Articles.swift; sourceTree = ""; }; + BC2656CA21FE97E700003413 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Config.swift; path = ../../../../Documents/Config.swift; sourceTree = ""; }; BF0163F8362378789ACC30D4 /* Pods_tree.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_tree.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D9C6AB3721FA9B3E001C0AB8 /* Extension+UIColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Extension+UIColor.swift"; sourceTree = ""; }; D9C6AB4321FA9CF8001C0AB8 /* Search.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Search.storyboard; sourceTree = ""; }; @@ -110,6 +112,7 @@ 35DC0DCD21F6F3C700F30416 /* tree */ = { isa = PBXGroup; children = ( + BC2656C921FE97D200003413 /* Config */, BC2656C521FD950900003413 /* Model */, D9C6AB3F21FA9CB4001C0AB8 /* View */, D9C6AB4821FAAD09001C0AB8 /* Controller */, @@ -181,6 +184,14 @@ path = Model; sourceTree = ""; }; + BC2656C921FE97D200003413 /* Config */ = { + isa = PBXGroup; + children = ( + BC2656CA21FE97E700003413 /* Config.swift */, + ); + path = Config; + sourceTree = ""; + }; D9C6AB3621FA9B3E001C0AB8 /* Extension */ = { isa = PBXGroup; children = ( @@ -367,6 +378,7 @@ BC2656BF21FD94EE00003413 /* APIManager.swift in Sources */, 35CB482021FB6306000D96CF /* ArticleFeedTableViewCell.swift in Sources */, D9C6AB4D21FAAD0A001C0AB8 /* SearchViewController.swift in Sources */, + BC2656CB21FE97E700003413 /* Config.swift in Sources */, BC2656C721FD950900003413 /* Articles.swift in Sources */, D9C6AB5D21FC152D001C0AB8 /* SearchScrollEnum.swift in Sources */, D9C6AB3D21FA9B3E001C0AB8 /* Extension+UIColor.swift in Sources */, diff --git a/tree/tree/Model/Articles.swift b/tree/tree/Model/Articles.swift index 2c61cd8..819cd70 100644 --- a/tree/tree/Model/Articles.swift +++ b/tree/tree/Model/Articles.swift @@ -13,6 +13,9 @@ struct Articles: Codable { } struct Results: Codable { + let page: Int // Current page number + let totalResults: Int // Total articles count + let pages: Int // Total pages count let results: [Article] } diff --git a/tree/tree/Network Layer/API/EventRegistryAPI.swift b/tree/tree/Network Layer/API/EventRegistryAPI.swift index 1fe63ac..65b16f9 100644 --- a/tree/tree/Network Layer/API/EventRegistryAPI.swift +++ b/tree/tree/Network Layer/API/EventRegistryAPI.swift @@ -8,6 +8,26 @@ import Foundation +private enum DefaultParameter { + case articleBodyLen + case includeArticleImage + case articlesCount + case resultType + case action +} + +extension DefaultParameter { + var value: Any { + switch self { + case .articleBodyLen: return -1 + case .includeArticleImage: return true + case .articlesCount: return 20 + case .resultType: return "articles" + case .action: return "getArticles" + } + } +} + enum EventRegistryAPI { case getArticles( keyword: String, @@ -45,19 +65,20 @@ extension EventRegistryAPI: APIService { let keywordLoc, let lang, let articlesSortBy, - let articlesPage): + let articlesPage + ): return [ "keyword": keyword, "keywordLoc": keywordLoc, "lang": lang, "articlesSortBy": articlesSortBy, "articlesPage": articlesPage, - "action": "getArticles", - "resultType": "articles", - "articlesCount": 20, - "includeArticleImage": true, - "articleBodyLen": -1, - "apiKey": "553fab57-e89f-4a1c-8941-3dcb37cf7e30" + "action": DefaultParameter.action.value, + "resultType": DefaultParameter.resultType.value, + "articlesCount": DefaultParameter.articlesCount.value, + "includeArticleImage": DefaultParameter.includeArticleImage.value, + "articleBodyLen": DefaultParameter.articleBodyLen.value, + "apiKey": APIConstant.eventRegistryKey ] } } diff --git a/tree/tree/Network Layer/NetworkHelper/NetworkResponse.swift b/tree/tree/Network Layer/NetworkHelper/NetworkResponse.swift index f057941..27bb948 100644 --- a/tree/tree/Network Layer/NetworkHelper/NetworkResponse.swift +++ b/tree/tree/Network Layer/NetworkHelper/NetworkResponse.swift @@ -18,7 +18,7 @@ enum ResponseTypes { struct NetworkResponse { func result(_ response: HTTPURLResponse) -> ResponseTypes { switch response.statusCode { - case 200: return .success + case 200..<300: return .success case 400..<500: return .clientError case 500..<600: return .serverError default: return .failure