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
12 changes: 12 additions & 0 deletions APIClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/* Begin PBXBuildFile section */
078B558C6C77F3C6DCDC4678 /* Pods_APIClientUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 82531BA6D6228998A00AB5B6 /* Pods_APIClientUITests.framework */; };
0D60CECA1E9E174A00A8E67A /* quotesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D60CEC91E9E174A00A8E67A /* quotesViewController.swift */; };
0D93F9151E9E1E6A0095065E /* quotes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D93F9141E9E1E6A0095065E /* quotes.swift */; };
0D93F9171E9E2C250095065E /* results.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D93F9161E9E2C250095065E /* results.swift */; };
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 874D06581CEF295E009A494D /* AppDelegate.swift */; };
874D065E1CEF295E009A494D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 874D065C1CEF295E009A494D /* Main.storyboard */; };
874D06601CEF295E009A494D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 874D065F1CEF295E009A494D /* Assets.xcassets */; };
Expand All @@ -34,6 +37,9 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0D60CEC91E9E174A00A8E67A /* quotesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = quotesViewController.swift; sourceTree = "<group>"; };
0D93F9141E9E1E6A0095065E /* quotes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = quotes.swift; sourceTree = "<group>"; };
0D93F9161E9E2C250095065E /* results.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = results.swift; sourceTree = "<group>"; };
198B23CD94C6D84016A5208A /* Pods-APIClientUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClientUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-APIClientUITests/Pods-APIClientUITests.release.xcconfig"; sourceTree = "<group>"; };
4FFA0A7AA37697BD5CBC3211 /* Pods_APIClientTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_APIClientTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
65C820A0F52E3181871F5ECA /* Pods-APIClientTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIClientTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-APIClientTests/Pods-APIClientTests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,6 +92,8 @@
872A27571CF0D4E200A988C4 /* View Controller */ = {
isa = PBXGroup;
children = (
0D60CEC91E9E174A00A8E67A /* quotesViewController.swift */,
0D93F9141E9E1E6A0095065E /* quotes.swift */,
);
name = "View Controller";
sourceTree = "<group>";
Expand All @@ -100,6 +108,7 @@
872A27591CF0D64A00A988C4 /* Model */ = {
isa = PBXGroup;
children = (
0D93F9161E9E2C250095065E /* results.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -468,7 +477,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0D93F9151E9E1E6A0095065E /* quotes.swift in Sources */,
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */,
0D93F9171E9E2C250095065E /* results.swift in Sources */,
0D60CECA1E9E174A00A8E67A /* quotesViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
74 changes: 65 additions & 9 deletions APIClient/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="E10-YL-lxp">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="E10-YL-lxp">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
Expand All @@ -21,24 +26,75 @@
</objects>
<point key="canvasLocation" x="-658" y="301"/>
</scene>
<!--View Controller-->
<!--Quotes View Controller-->
<scene sceneID="adh-8k-Iuh">
<objects>
<viewController id="rPr-Fp-ALE" sceneMemberID="viewController">
<viewController id="rPr-Fp-ALE" customClass="quotesViewController" customModule="APIClient" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="pj8-zF-1z6"/>
<viewControllerLayoutGuide type="bottom" id="kt2-9S-3TK"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="rEB-Za-Zhx">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="27" translatesAutoresizingMaskIntoConstraints="NO" id="EEX-t0-JKc">
<rect key="frame" x="16" y="94" width="343" height="129"/>
<subviews>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="751" verticalHuggingPriority="751" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="Fkf-J3-nWK">
<rect key="frame" x="161.5" y="0.0" width="20" height="20"/>
</activityIndicatorView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="LZV-Bb-WyU">
<rect key="frame" x="134" y="47" width="75" height="82"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="K99-T7-m9q">
<rect key="frame" x="0.0" y="0.0" width="75" height="46.5"/>
<fontDescription key="fontDescription" name="Papyrus" family="Papyrus" pointSize="30"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="siC-fb-Ba6">
<rect key="frame" x="16.5" y="62.5" width="42.5" height="19.5"/>
<fontDescription key="fontDescription" name="Georgia-Italic" family="Georgia" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="EEX-t0-JKc" secondAttribute="trailing" id="dNP-P9-7cf"/>
<constraint firstItem="EEX-t0-JKc" firstAttribute="top" secondItem="pj8-zF-1z6" secondAttribute="bottom" constant="30" id="v7C-84-9QX"/>
<constraint firstItem="EEX-t0-JKc" firstAttribute="leading" secondItem="rEB-Za-Zhx" secondAttribute="leadingMargin" id="yzZ-Ge-ig9"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="CZR-l9-xMg"/>
<toolbarItems/>
<navigationItem key="navigationItem" id="CZR-l9-xMg">
<nil key="title"/>
<barButtonItem key="leftBarButtonItem" title="Movies" id="fpO-hf-TUj">
<connections>
<action selector="moviesButton:" destination="rPr-Fp-ALE" id="NYd-AK-65Y"/>
</connections>
</barButtonItem>
<barButtonItem key="rightBarButtonItem" title="Famous" id="QY7-IX-Q1A">
<connections>
<action selector="famousButton:" destination="rPr-Fp-ALE" id="8rd-Zd-OD3"/>
</connections>
</barButtonItem>
</navigationItem>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="activityView" destination="Fkf-J3-nWK" id="aeF-TE-FPW"/>
<outlet property="authorLabel" destination="siC-fb-Ba6" id="dz2-FU-SXo"/>
<outlet property="nameLabel" destination="K99-T7-m9q" id="3Ce-iw-vbL"/>
</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="65" y="319"/>
</scene>
</scenes>
</document>
53 changes: 53 additions & 0 deletions APIClient/quotes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// quotes.swift
// APIClient
//
// Created by Elvira Beisel on 12.04.17.
// Copyright © 2017 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Moya

enum Quotesapi: Moya.TargetType {

case quote(category: String)

var baseURL: URL {
return URL(string: "https://andruxnet-random-famous-quotes.p.mashape.com/")!
}

var path: String {

switch self {
case .quote:
return ""
}
}

var method: Moya.Method {
return.get
}

var parameters: [String: Any]? {
switch self {
case .quote(category: let category):
return [
"cat": category
]
}
}

var parameterEncoding: ParameterEncoding {
return URLEncoding.default
}

var sampleData: Data {
return "".data(using: .utf8)!
}

var task: Moya.Task {
return .request
}

}
83 changes: 83 additions & 0 deletions APIClient/quotesViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// quotesViewController.swift
// APIClient
//
// Created by Elvira Beisel on 12.04.17.
// Copyright © 2017 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import UIKit
import Moya

import Freddy

class quotesViewController: UIViewController, UITextFieldDelegate {


@IBOutlet weak var activityView: UIActivityIndicatorView!
// @IBOutlet weak var inputTextField: UITextField!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var authorLabel: UILabel!
@IBAction func moviesButton(_ sender: Any) {

showQuote(for: "movies")

}
@IBAction func famousButton(_ sender: Any) {
showQuote(for: "famous")
}

override func viewDidLoad() {
super.viewDidLoad()

nameLabel.text = ""
authorLabel.text = ""
self.title = "It´s your choice!"
self.activityView.hidesWhenStopped = true

}

func showQuote(for category: String) {

activityView.startAnimating()

let endpointClosure = { (target: Quotesapi) -> Endpoint<Quotesapi> in
let headers = [
"X-Mashape-Key": "gpYkdsl5x9msho9B1uCnd5LtHdVqp1932RLjsn3egoFcCcYng9"
]
let defaultEndpoint = MoyaProvider.defaultEndpointMapping(for: target)
return defaultEndpoint
.adding(newHTTPHeaderFields: headers)
}

let provider = MoyaProvider<Quotesapi>(endpointClosure: endpointClosure)

let query = Quotesapi.quote(category: category)


provider.request(query) { result in

self.activityView.stopAnimating()
switch result {
case .success(let response):
do {
let jsonResponse = try JSON(data: response.data)
print(jsonResponse)
let result = try results (json: jsonResponse)
self.nameLabel.text = result.quote
self.authorLabel.text = result.author
} catch {
print(error)
}


case .failure(let error):

print(error)

}
}

}
}
25 changes: 25 additions & 0 deletions APIClient/results.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// results.swift
// APIClient
//
// Created by Elvira Beisel on 12.04.17.
// Copyright © 2017 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Freddy

struct results: JSONDecodable {

let quote: String
let author: String
let category: String

init(json: JSON) throws {
try self.quote = json.getString(at: "quote")
try self.author = json.getString(at: "author")
try self.category = json.getString(at: "category")

}

}