Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions APIClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
874D065E1CEF295E009A494D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D065C1CEF295E009A494D /* Main.storyboard */; };
874D06601CEF295E009A494D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 874D065F1CEF295E009A494D /* Assets.xcassets */; };
874D06631CEF295E009A494D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D06611CEF295E009A494D /* LaunchScreen.storyboard */; };
A0A3FC001CF38D8C00FC6A8C /* PlanetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A3FBFF1CF38D8C00FC6A8C /* PlanetViewController.swift */; };
A0A3FC021CF38F6B00FC6A8C /* PlanetAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A3FC011CF38F6B00FC6A8C /* PlanetAPI.swift */; };
A0A3FC061CF399A400FC6A8C /* Planet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0A3FC051CF399A400FC6A8C /* Planet.swift */; };
A0C330C61CFC959F00442D0F /* PlanetAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0C330C51CFC959F00442D0F /* PlanetAPITests.swift */; };
A0C330C81CFC9CB700442D0F /* PlanetAPIUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0C330C71CFC9CB700442D0F /* PlanetAPIUITests.swift */; };
A526FDEE5BF2D1BC3C97B9FA /* Pods_APIClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BD8A5B3E1266D5298CABE44A /* Pods_APIClient.framework */; };
E9294E7F05F2671186BD1359 /* Pods_APIClientTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FFA0A7AA37697BD5CBC3211 /* Pods_APIClientTests.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -51,6 +56,11 @@
87EC715D1CFA381600FBDDDE /* APIClientUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = APIClientUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
87EC71611CFA381600FBDDDE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
93EFAB13AE62F1B6FB2683B2 /* Pods-APIClient.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClient.debug.xcconfig"; path = "Pods/Target Support Files/Pods-APIClient/Pods-APIClient.debug.xcconfig"; sourceTree = "<group>"; };
A0A3FBFF1CF38D8C00FC6A8C /* PlanetViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlanetViewController.swift; sourceTree = "<group>"; };
A0A3FC011CF38F6B00FC6A8C /* PlanetAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlanetAPI.swift; sourceTree = "<group>"; };
A0A3FC051CF399A400FC6A8C /* Planet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Planet.swift; sourceTree = "<group>"; };
A0C330C51CFC959F00442D0F /* PlanetAPITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlanetAPITests.swift; sourceTree = "<group>"; };
A0C330C71CFC9CB700442D0F /* PlanetAPIUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlanetAPIUITests.swift; sourceTree = "<group>"; };
BD8A5B3E1266D5298CABE44A /* Pods_APIClient.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_APIClient.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C67B3B3E7990BE278400974F /* Pods-APIClientUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClientUITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-APIClientUITests/Pods-APIClientUITests.debug.xcconfig"; sourceTree = "<group>"; };
F8B9811B1068B05E73195990 /* Pods-APIClientTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClientTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-APIClientTests/Pods-APIClientTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,6 +98,7 @@
872A27571CF0D4E200A988C4 /* View Controller */ = {
isa = PBXGroup;
children = (
A0A3FBFF1CF38D8C00FC6A8C /* PlanetViewController.swift */,
);
name = "View Controller";
sourceTree = "<group>";
Expand All @@ -103,6 +114,8 @@
isa = PBXGroup;
children = (
872A275B1CF0D87100A988C4 /* APIResource.swift */,
A0A3FC011CF38F6B00FC6A8C /* PlanetAPI.swift */,
A0A3FC051CF399A400FC6A8C /* Planet.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -156,6 +169,7 @@
isa = PBXGroup;
children = (
87EC71531CFA380F00FBDDDE /* Info.plist */,
A0C330C51CFC959F00442D0F /* PlanetAPITests.swift */,
);
path = APIClientTests;
sourceTree = "<group>";
Expand All @@ -164,6 +178,7 @@
isa = PBXGroup;
children = (
87EC71611CFA381600FBDDDE /* Info.plist */,
A0C330C71CFC9CB700442D0F /* PlanetAPIUITests.swift */,
);
path = APIClientUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -468,22 +483,27 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A0A3FC021CF38F6B00FC6A8C /* PlanetAPI.swift in Sources */,
872A275C1CF0D87100A988C4 /* APIResource.swift in Sources */,
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */,
A0A3FC001CF38D8C00FC6A8C /* PlanetViewController.swift in Sources */,
A0A3FC061CF399A400FC6A8C /* Planet.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
87EC714B1CFA380F00FBDDDE /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A0C330C61CFC959F00442D0F /* PlanetAPITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
87EC71591CFA381600FBDDDE /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A0C330C81CFC9CB700442D0F /* PlanetAPIUITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -636,10 +656,12 @@
baseConfigurationReference = F8B9811B1068B05E73195990 /* Pods-APIClientTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = APIClientTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClientTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/APIClient.app/APIClient";
};
name = Debug;
Expand All @@ -649,6 +671,7 @@
baseConfigurationReference = 65C820A0F52E3181871F5ECA /* Pods-APIClientTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = APIClientTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClientTests";
Expand All @@ -661,10 +684,12 @@
isa = XCBuildConfiguration;
baseConfigurationReference = C67B3B3E7990BE278400974F /* Pods-APIClientUITests.debug.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = APIClientUITests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClientUITests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TEST_TARGET_NAME = APIClient;
};
name = Debug;
Expand All @@ -673,6 +698,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 198B23CD94C6D84016A5208A /* Pods-APIClientUITests.release.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = APIClientUITests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClientUITests";
Expand Down
10 changes: 10 additions & 0 deletions APIClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@
//

import UIKit
import Moya

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

let planetAPI = MoyaProvider<PlanetAPI>()


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

if let planetViewController = (window?.rootViewController as? UINavigationController)?.topViewController as? PlanetViewController{

planetViewController.planetAPI = planetAPI

}

return true
}

Expand Down
41 changes: 33 additions & 8 deletions APIClient/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,49 @@
</objects>
<point key="canvasLocation" x="-658" y="301"/>
</scene>
<!--View Controller-->
<!--Planet View Controller-->
<scene sceneID="adh-8k-Iuh">
<objects>
<viewController id="rPr-Fp-ALE" sceneMemberID="viewController">
<viewController id="rPr-Fp-ALE" customClass="PlanetViewController" customModule="APIClient" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="pj8-zF-1z6"/>
<viewControllerLayoutGuide type="bottom" id="kt2-9S-3TK"/>
<viewControllerLayoutGuide type="top" id="f6Z-3s-u9f"/>
<viewControllerLayoutGuide type="bottom" id="pln-gQ-e42"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="rEB-Za-Zhx">
<view key="view" contentMode="scaleToFill" id="hTc-Zo-8Gz">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QsS-35-5PT">
<rect key="frame" x="57" y="248" width="196" height="81"/>
<accessibility key="accessibilityConfiguration" identifier="planetName"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="CZR-l9-xMg"/>
<navigationItem key="navigationItem" id="CZR-l9-xMg">
<nil key="title"/>
<textField key="titleView" opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" id="aZK-x1-BeE">
<rect key="frame" x="180" y="7" width="240" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<accessibility key="accessibilityConfiguration" identifier="searchField"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="rPr-Fp-ALE" id="J7k-gc-VuH"/>
</connections>
</textField>
</navigationItem>
<connections>
<outlet property="planetLab" destination="QsS-35-5PT" id="v1j-do-2DM"/>
<outlet property="searchField" destination="aZK-x1-BeE" id="A9N-sa-ivp"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OaC-W5-AeM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="65" y="301"/>
<point key="canvasLocation" x="77" y="301"/>
</scene>
</scenes>
</document>
11 changes: 11 additions & 0 deletions APIClient/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,16 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>swapi.co</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>
20 changes: 20 additions & 0 deletions APIClient/Planet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Planet.swift
// APIClient
//
// Created by Kleimaier, Dennis on 23.05.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Freddy

struct Planet: JSONDecodable {

let name: String

init(json: JSON) throws {
self.name = try json.string("name")
}

}
52 changes: 52 additions & 0 deletions APIClient/PlanetAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// PlanetAPI.swift
// APIClient
//
// Created by Kleimaier, Dennis on 23.05.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Moya
import Freddy

enum PlanetAPI: Moya.TargetType{
case planet(NamedResource<Planet>)

Copy link
Member

Choose a reason for hiding this comment

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

Du kannst hier auch eine NamedResource<Planet> statt eines name: String als Associated Value verwenden, damit wird die API noch besser modelliert ;)

var baseURL: NSURL { return NSURL(string: "http://swapi.co/api")! }

var path: String {
switch self{
case .planet(let namedResource): return "/planets/\(namedResource.name)"
}
Copy link
Member

@nilsvu nilsvu May 27, 2016

Choose a reason for hiding this comment

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

Hier fehlt ein \, so ist das nur ein String, und kein Wert wird eingesetzt ;) Daher kommt momentan immer der Status Code 404 zurück.

        case .planet(let namedResource): return "/planets/\(namedResource.name)"

}

var method: Moya.Method { return .GET }

var parameters: [String : AnyObject]? {
switch self {
default: return nil
}
}

// TODO: Provide sample data for testing
var sampleData: NSData {
switch self {
case .planet(let namedResource): return "{\"planets\": \"\(namedResource.name)\",\"planets\":\"Tatooine\"}".dataUsingEncoding(NSUTF8StringEncoding)!
default: return "".dataUsingEncoding(NSUTF8StringEncoding)!
}
}
}

struct NamedResource<Resource: Freddy.JSONDecodable>: Freddy.JSONDecodable {

let name:String

init(name: String) {
self.name = name
}

init(json: JSON) throws {
self.name = try json.string("name")
}
}
64 changes: 64 additions & 0 deletions APIClient/PlanetViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// PlanetViewController.swift
// APIClient
//
// Created by Kleimaier, Dennis on 23.05.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Moya
import Freddy

class PlanetViewController: UIViewController {


override func viewDidLoad() {
super.viewDidLoad()
}

var planetAPI: MoyaProvider<PlanetAPI>!
var planet: Planet? {
didSet {
self.planetLab.text = planet?.name
}
}


@IBOutlet weak var searchField: UITextField!
@IBOutlet weak var planetLab: UILabel!


func loadPlanet(planet: NamedResource<Planet>){
planetAPI.request(.planet(planet)){ result in
switch result {
case .Success(let response):
do {
try response.filterSuccessfulStatusCodes()
// Try to parse the response to JSON
let json = try JSON(data: response.data)
// Try to decode the JSON to the required type
let pokemonSpecies = try Planet(json: json)
// Configure view according to model
self.planet = pokemonSpecies
print(pokemonSpecies)
} catch {
print(error)
}
case .Failure(let error):
print(error)
}
}
}




func textFieldShouldReturn(textField: UITextField) -> Bool {
guard let name = textField.text else {
return true
}
self.loadPlanet(NamedResource(name: name))
return true
}
}
Loading