Skip to content

Commit 7a8158f

Browse files
committed
Fix web api was separated to WebAPIFramework as Embedded Framework
1 parent 43c1a2a commit 7a8158f

20 files changed

+676
-242
lines changed

PyCon-JP.xcodeproj/project.pbxproj

+344-29
Large diffs are not rendered by default.

PyCon-JP.xcodeproj/xcshareddata/xcschemes/PyConJP2016.xcscheme

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
ReferencedContainer = "container:PyCon-JP.xcodeproj">
4949
</BuildableReference>
5050
</TestableReference>
51+
<TestableReference
52+
skipped = "NO">
53+
<BuildableReference
54+
BuildableIdentifier = "primary"
55+
BlueprintIdentifier = "DB77FD511E06720D00504869"
56+
BuildableName = "WebAPIFrameworkTests.xctest"
57+
BlueprintName = "WebAPIFrameworkTests"
58+
ReferencedContainer = "container:PyCon-JP.xcodeproj">
59+
</BuildableReference>
60+
</TestableReference>
5161
</Testables>
5262
<MacroExpansion>
5363
<BuildableReference

PyCon-JP/Application/PCJConfig.swift

-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ import UIKit
1010

1111
enum PCJConfig {
1212

13-
static let hostURL = ProcessInfo.processInfo.environment["APIBaseURL"] ?? "https://pycon.jp"
14-
15-
static let baseURL = PCJConfig.hostURL + "/2016/" + Locale.currentLanguageLocaleIdentifier + "/"
16-
17-
static let apiURL = PCJConfig.baseURL + "api/"
18-
19-
static let authUser = ProcessInfo.processInfo.environment["APIAuthUser"] ?? ""
20-
21-
static let authPassword = ProcessInfo.processInfo.environment["APIAuthPassword"] ?? ""
22-
2313
static let mailAddress = "[email protected]"
2414

2515
}

PyCon-JP/Protocol/Alamofire/TalkDetailAPIProtocol.swift

-63
This file was deleted.

PyCon-JP/Protocol/Alamofire/TalksAPIProtocol.swift

-101
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// RealmTalkDetailProtocol.swift
3+
// PyCon-JP
4+
//
5+
// Created by Yutaro Muta on 2016/12/18.
6+
// Copyright © 2016 PyCon JP. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
protocol RealmTalkDetailProtocol {
12+
func getTalksFromLocalDummyJson(completionHandler: ((Result<Void>) -> Void)) -> Void
13+
}
14+
15+
extension RealmTalkDetailProtocol {
16+
17+
func getTalkDetailFromLocalDummyJson(completionHandler: ((Result<TalkDetail>) -> Void)) -> Void {
18+
let path = Bundle.main.path(forResource: "DummyTalkDetail", ofType: "json")
19+
let fileHandle = FileHandle(forReadingAtPath: path!)
20+
let data = fileHandle?.readDataToEndOfFile()
21+
let dictionary = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! Dictionary<String, Any>
22+
23+
let talkDetail = TalkDetail(dictionary: dictionary)
24+
completionHandler(.success(talkDetail))
25+
26+
}
27+
28+
}

PyCon-JP/Protocol/Realm/RealmTalksProtocol.swift

+28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ protocol RealmTalksProtocol {
1414
var sortProperties: Array<SortDescriptor> { get }
1515

1616
func loadTalkObjects(_ completionHandler: ((Result<Array<TalkObject>>) -> Void)) -> Void
17+
func getTalksFromLocalDummyJson(completionHandler: ((Result<Void>) -> Void)) -> Void
1718
}
1819

1920
extension RealmTalksProtocol {
@@ -29,3 +30,30 @@ extension RealmTalksProtocol {
2930
}
3031

3132
}
33+
34+
extension RealmTalksProtocol {
35+
36+
func getTalksFromLocalDummyJson(completionHandler: ((Result<Void>) -> Void)) -> Void {
37+
let path = Bundle.main.path(forResource: "DummyTalks", ofType: "json")
38+
let fileHandle = FileHandle(forReadingAtPath: path!)
39+
let data = fileHandle?.readDataToEndOfFile()
40+
let dictionary = try! JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! Dictionary<String, AnyObject>
41+
let presentations = dictionary["presentations"] as? Array<Dictionary<String, AnyObject>> ?? [Dictionary<String, AnyObject>]()
42+
43+
do {
44+
let realm = try Realm()
45+
try realm.write({
46+
presentations.forEach({
47+
let talkObject = TalkObject(dictionary: $0)
48+
realm.add(talkObject, update: true)
49+
})
50+
})
51+
52+
completionHandler(.success())
53+
} catch let error as NSError {
54+
completionHandler(.failure(error))
55+
}
56+
57+
}
58+
59+
}

PyCon-JP/Protocol/Alamofire/StaffListAPIProtocol.swift PyCon-JP/Protocol/WebAPI/StaffListAPIProtocol.swift

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import WebAPIFramework
1011

1112
protocol StaffListAPIProtocol: AlamofireProtocol {
1213
func getStaffs(completionHandler: @escaping ((Result<Array<Staff>>) -> Void)) -> Void
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// TalkDetailAPIProtocol.swift
3+
// PyConJP2016
4+
//
5+
// Created by Yutaro Muta on 7/25/16.
6+
// Copyright © 2016 PyCon JP. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import WebAPIFramework
11+
import RealmSwift
12+
13+
protocol TalkDetailAPIProtocol: AlamofireProtocol {
14+
var id: Int? { get set }
15+
16+
func getTalkDetail(completionHandler: @escaping ((Result<TalkDetail>) -> Void)) -> Void
17+
}
18+
19+
extension TalkDetailAPIProtocol {
20+
21+
var path: String {
22+
guard let id = id else { return "" }
23+
return "presentation/\(id)/"
24+
}
25+
26+
}
27+
28+
extension TalkDetailAPIProtocol {
29+
30+
func getTalkDetail(completionHandler: @escaping ((Result<TalkDetail>) -> Void)) -> Void {
31+
get() { result in
32+
switch result {
33+
case .success(let value):
34+
let talkDetail = TalkDetail(dictionary: value)
35+
completionHandler(.success(talkDetail))
36+
case .failure(let error):
37+
completionHandler(.failure(error))
38+
}
39+
}
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// TalksAPIProtocol.swift
3+
// PyConJP2016
4+
//
5+
// Created by Yutaro Muta on 4/23/16.
6+
// Copyright © 2016 PyCon JP. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import WebAPIFramework
11+
import RealmSwift
12+
13+
protocol TalksAPIProtocol: AlamofireProtocol {
14+
func getTalks(completionHandler: @escaping ((Result<Void>) -> Void)) -> Void
15+
}
16+
17+
extension TalksAPIProtocol {
18+
19+
var path: String {
20+
return "talks/list/"
21+
}
22+
23+
}
24+
25+
extension TalksAPIProtocol {
26+
27+
func getTalks(completionHandler: @escaping ((Result<Void>) -> Void)) -> Void {
28+
get() { result in
29+
switch result {
30+
case .success(let value):
31+
let presentations = value["presentations"] as? Array<Dictionary<String, AnyObject>> ?? [Dictionary<String, AnyObject>]()
32+
33+
do {
34+
let apiTalks = presentations.map({ TalkObject(dictionary: $0) })
35+
36+
let realm = try Realm()
37+
let rejectedLocalTalks = realm.objects(TalkObject.self).filter("NOT(id IN %@)", apiTalks.map({ $0.id }))
38+
try realm.write({
39+
realm.delete(rejectedLocalTalks)
40+
realm.add(apiTalks, update: true)
41+
})
42+
43+
completionHandler(.success())
44+
} catch let error as NSError {
45+
completionHandler(.failure(error))
46+
}
47+
case .failure(let error):
48+
completionHandler(.failure(error))
49+
}
50+
}
51+
}
52+
53+
}

PyCon-JP/View/UICollectionViewCell/SpeakerCollectionViewCell.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import WebAPIFramework
1011
import AlamofireImage
1112

1213
class SpeakerCollectionViewCell: UICollectionViewCell {
@@ -22,7 +23,7 @@ class SpeakerCollectionViewCell: UICollectionViewCell {
2223
}
2324

2425
func fill(speaker: Speaker) {
25-
if let imageURL = speaker.imageURL, let url = URL(string: PCJConfig.hostURL + imageURL) {
26+
if let imageURL = speaker.imageURL, let url = URL(string: WebConfig.hostURL + imageURL) {
2627
iconImageView.af_setImage(withURL: url)
2728
}
2829
nameLabel.text = speaker.name

0 commit comments

Comments
 (0)