Skip to content

Commit

Permalink
Merge pull request #15 from boostcamp3-iOS/local
Browse files Browse the repository at this point in the history
Add : API Default parameters at EventRegistryAPI
  • Loading branch information
godpp authored Jan 28, 2019
2 parents 500bef9 + 0a32570 commit 95d7f06
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
12 changes: 12 additions & 0 deletions tree/tree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -60,6 +61,7 @@
BC2656BB21FD94EE00003413 /* NetworkResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
BC2656BC21FD94EE00003413 /* NetworkError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkError.swift; sourceTree = "<group>"; };
BC2656C621FD950900003413 /* Articles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Articles.swift; sourceTree = "<group>"; };
BC2656CA21FE97E700003413 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Config.swift; path = ../../../../Documents/Config.swift; sourceTree = "<group>"; };
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 = "<group>"; };
D9C6AB4321FA9CF8001C0AB8 /* Search.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Search.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -110,6 +112,7 @@
35DC0DCD21F6F3C700F30416 /* tree */ = {
isa = PBXGroup;
children = (
BC2656C921FE97D200003413 /* Config */,
BC2656C521FD950900003413 /* Model */,
D9C6AB3F21FA9CB4001C0AB8 /* View */,
D9C6AB4821FAAD09001C0AB8 /* Controller */,
Expand Down Expand Up @@ -181,6 +184,14 @@
path = Model;
sourceTree = "<group>";
};
BC2656C921FE97D200003413 /* Config */ = {
isa = PBXGroup;
children = (
BC2656CA21FE97E700003413 /* Config.swift */,
);
path = Config;
sourceTree = "<group>";
};
D9C6AB3621FA9B3E001C0AB8 /* Extension */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -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 */,
Expand Down
3 changes: 3 additions & 0 deletions tree/tree/Model/Articles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
35 changes: 28 additions & 7 deletions tree/tree/Network Layer/API/EventRegistryAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95d7f06

Please sign in to comment.