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
15 changes: 15 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 */; };
14450E9C1E9E178C0045AB83 /* APODViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14450E9B1E9E178C0045AB83 /* APODViewController.swift */; };
14450E9E1E9E1EA80045AB83 /* APOD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14450E9D1E9E1EA80045AB83 /* APOD.swift */; };
14450EA01E9E2BCB0045AB83 /* APODResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14450E9F1E9E2BCB0045AB83 /* APODResult.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 */
14450E9B1E9E178C0045AB83 /* APODViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APODViewController.swift; sourceTree = "<group>"; };
14450E9D1E9E1EA80045AB83 /* APOD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APOD.swift; sourceTree = "<group>"; };
14450E9F1E9E2BCB0045AB83 /* APODResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APODResult.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 = (
14450E9B1E9E178C0045AB83 /* APODViewController.swift */,
14450E9D1E9E1EA80045AB83 /* APOD.swift */,
);
name = "View Controller";
sourceTree = "<group>";
Expand All @@ -100,6 +108,7 @@
872A27591CF0D64A00A988C4 /* Model */ = {
isa = PBXGroup;
children = (
14450E9F1E9E2BCB0045AB83 /* APODResult.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -265,6 +274,7 @@
TargetAttributes = {
874D06541CEF295E009A494D = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = C4DBNLN23D;
LastSwiftMigration = 0830;
};
87EC714E1CFA380F00FBDDDE = {
Expand Down Expand Up @@ -468,6 +478,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
14450E9C1E9E178C0045AB83 /* APODViewController.swift in Sources */,
14450E9E1E9E1EA80045AB83 /* APOD.swift in Sources */,
14450EA01E9E2BCB0045AB83 /* APODResult.swift in Sources */,
874D06591CEF295E009A494D /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -611,6 +624,7 @@
baseConfigurationReference = 93EFAB13AE62F1B6FB2683B2 /* Pods-APIClient.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = C4DBNLN23D;
INFOPLIST_FILE = APIClient/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClient";
Expand All @@ -624,6 +638,7 @@
baseConfigurationReference = FFE13D543A95D28F27CFBDA4 /* Pods-APIClient.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = C4DBNLN23D;
INFOPLIST_FILE = APIClient/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.APIClient";
Expand Down
52 changes: 52 additions & 0 deletions APIClient/APOD.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// APOD.swift
// APIClient
//
// Created by Alex Golovin on 12.04.17.
// Copyright © 2017 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Moya

enum APODapi: Moya.TargetType {
case apodImage(date: String)

var baseURL: URL {
return URL(string: "https://api.nasa.gov/planetary")!
}

var path: String {
switch self {
case .apodImage:
return "apod"
}
}

var method: Moya.Method {
return .get
}

var parameters: [String : Any]? {
switch self {
case .apodImage(date: let date):
return [
"api_key": "ytjs7RGfT3lokh41NHQH914MFWra7PfwaVu2bqXx",
"date": date,
]

}
}

var parameterEncoding: ParameterEncoding {
return URLEncoding.default
}

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

var task: Moya.Task {
return .request
}
}
26 changes: 26 additions & 0 deletions APIClient/APODResult.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// APODResult.swift
// APIClient
//
// Created by Alex Golovin on 12.04.17.
// Copyright © 2017 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Freddy

struct APODResult: JSONDecodable {

//let copyright: String
//let date: String
//let explanation: String
//let hdurl: URL
//let media_type: String
let title: String
let url: URL

init(json: JSON) throws {
try self.url = URL(string:json.getString(at: "url"))!
try self.title = json.getString(at: "title")
}
}
73 changes: 73 additions & 0 deletions APIClient/APODViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// APODViewController.swift
// APIClient
//
// Created by Alex Golovin on 12.04.17.
// Copyright © 2017 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import UIKit
import Moya
import Freddy
import AlamofireImage

class APODViewController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var inputAPODQuerry: UITextField!

@IBOutlet weak var datePickerField: UIDatePicker!

@IBAction func dateConfirm(_ sender: Any) {



let date = datePickerField.date
let formater = DateFormatter()
formater.dateFormat = "yyyy-MM-dd"
let dateString = formater.string(from: date)

self.imageLoading.startAnimating()

let provider = MoyaProvider<APODapi>()

let query = APODapi.apodImage(date: dateString)

provider.request(query) {result in
self.imageLoading.stopAnimating()

switch result {
case .success(let response):

//print(String(data: response.data)) response.data
do{

let jsonResponse = try JSON(data: response.data)
print(jsonResponse)
let apodResult = try APODResult(json: jsonResponse)
self.outputAPOD.af_setImage(withURL: apodResult.url)
} catch {
print(error)
}

case .failure(let error):
print(error)
}
}
}
@IBOutlet weak var imageLoading: UIActivityIndicatorView!

func textFieldShouldReturn(_ textField: UITextField) -> Bool {

guard let input = inputAPODQuerry.text else {
//guard let input = datePickerField.text else {
return true
}


inputAPODQuerry.resignFirstResponder()
return true
}

@IBOutlet weak var outputAPOD: UIImageView!
}
61 changes: 52 additions & 9 deletions APIClient/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?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="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
<scene sceneID="Xrb-yS-kMZ">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="hfS-9i-aMM" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController id="E10-YL-lxp" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="amJ-5H-qs5">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
Expand All @@ -17,28 +22,66 @@
<segue destination="rPr-Fp-ALE" kind="relationship" relationship="rootViewController" id="g8j-CJ-uaE"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="hfS-9i-aMM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-658" y="301"/>
</scene>
<!--View Controller-->
<scene sceneID="adh-8k-Iuh">
<objects>
<viewController id="rPr-Fp-ALE" sceneMemberID="viewController">
<viewController id="rPr-Fp-ALE" customClass="APODViewController" 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" translatesAutoresizingMaskIntoConstraints="NO" id="pw2-aJ-gA8">
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<subviews>
<datePicker contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="top" datePickerMode="date" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="Cwl-Tf-qaK">
<rect key="frame" x="27.5" y="0.0" width="320" height="0.0"/>
<date key="date" timeIntervalSinceReferenceDate="513764211.247284">
<!--2017-04-13 08:16:51 +0000-->
</date>
</datePicker>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="top" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0gP-lQ-GcF">
<rect key="frame" x="164.5" y="0.0" width="46" height="0.0"/>
<state key="normal" title="Button"/>
<connections>
<action selector="dateConfirm:" destination="rPr-Fp-ALE" eventType="touchUpInside" id="yRi-C4-vYV"/>
</connections>
</button>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="gy4-g6-zB5">
<rect key="frame" x="177.5" y="0.0" width="20" height="0.0"/>
</activityIndicatorView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="uqy-JK-CHB">
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
</imageView>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="pw2-aJ-gA8" secondAttribute="bottom" id="EYy-If-pZd"/>
<constraint firstAttribute="trailing" secondItem="pw2-aJ-gA8" secondAttribute="trailing" id="UbO-RI-Z6N"/>
<constraint firstItem="pw2-aJ-gA8" firstAttribute="top" secondItem="pj8-zF-1z6" secondAttribute="bottom" id="m7F-50-qfg"/>
<constraint firstItem="pw2-aJ-gA8" firstAttribute="leading" secondItem="rEB-Za-Zhx" secondAttribute="leading" id="w0H-a3-Oo7"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="CZR-l9-xMg"/>
<navigationItem key="navigationItem" id="CZR-l9-xMg">
<nil key="title"/>
</navigationItem>
<connections>
<outlet property="datePickerField" destination="Cwl-Tf-qaK" id="HkZ-1j-fXO"/>
<outlet property="imageLoading" destination="gy4-g6-zB5" id="pdX-cp-7I0"/>
<outlet property="outputAPOD" destination="uqy-JK-CHB" id="V1Q-1O-2lR"/>
</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="134" y="-88"/>
</scene>
</scenes>
</document>