Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
131 changes: 102 additions & 29 deletions APIClient.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

112 changes: 0 additions & 112 deletions APIClient.xcodeproj/xcshareddata/xcschemes/APIClient.xcscheme

This file was deleted.

74 changes: 74 additions & 0 deletions APIClient/APIViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// APIViewController.swift
// kanyeAPIClient
//
// Created by Arthur Heimbrecht on 30.5.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import UIKit
import Freddy
import Moya

class APIViewController: UIViewController {

var kanyeAPI: MoyaProvider<kanyeREST>!
var target = kanyeREST.track(title: "good_morning")
var fetchedtrack: Track!

var allalbums: [Album] = []
var allalbumnames: [String]!

@IBOutlet private var lyricsLabel: UILabel!

override func viewDidLoad() {
print("didload")
kanyeAPI.request(target){
result in
switch result {
case .Success(let response):
do {
try response.filterSuccessfulStatusCodes()
print(response)
let json = try JSON(data: response.data)
self.fetchedtrack = try Track(json: json)
self.lyricsLabel.numberOfLines = 0
self.lyricsLabel.text = self.fetchedtrack.lyrics
let tracknalbum = self.fetchedtrack.title + " / " + self.fetchedtrack.album
self.title = tracknalbum
} catch {
print(error)
}
case .Failure(let error):
print(error)
}
}

for albumname in allalbumnames{
kanyeAPI.request(kanyeREST.album(title: albumname)){
result in
//print(title)
switch result {
case .Success(let response):
do {
try response.filterSuccessfulStatusCodes()
print(response)
let json = try JSON(data: response.data)
let tracks = try json.array("result").map(Track.init)
self.allalbums.append(try Album(tracksfetched: tracks))
print(self.allalbums[0])
} catch {
print(error)
break
}
case .Failure(let error):
print("failure")
print(error)
break
}
}
}

}
}
22 changes: 22 additions & 0 deletions APIClient/Album.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// album.swift
// APIClient
//
// Created by Arthur Heimbrecht on 30.5.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import Foundation
import Freddy


struct Album {

let name: String
let tracks: [Track]

init(tracksfetched: [Track]) throws {
tracks = tracksfetched
name = tracksfetched[0].album
}
}
79 changes: 71 additions & 8 deletions APIClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,79 @@
//

import UIKit
import Moya
import Freddy

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


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


var window: UIWindow?

/// The PokeAPI Provider representing the Server
let kanyeAPI = MoyaProvider<kanyeREST>()

let allalbumnames = [
"the_college_dropout",
"late_registration",
"graduation",
"808s_&amp;_heartbreak",
"my_beautiful_dark_twisted_fantasy",
"watch_the_throne",
"yeezus",
"the_life_of_pablo"
]

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

if let APIViewController = (window?.rootViewController as? UINavigationController)?.topViewController as? APIViewController {
print("test")
// Pass the PokeAPI Provider on to the root view controller
APIViewController.kanyeAPI = kanyeAPI
APIViewController.allalbumnames = allalbumnames

}

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

print("albumviewcontroller")
//print(albumnames)
var allalbums: [Album] = []
/*for albumname in self.allalbumnames{
kanyeAPI.request(kanyeREST.album(title: albumname)){
result in
//print(title)
switch result {
case .Success(let response):
do {
try response.filterSuccessfulStatusCodes()
//print(response)
let json = try JSON(data: response.data)
let tracks = try json.array("result").map(Track.init)
allalbums.append(Album(tracksfetched: tracks))
//print(self.allalbums[0])
//print(allalbums)
} catch {
print(error)
break
}
case .Failure(let error):
print("failure")
print(error)
break
}
}
}*/


albumViewController.kanyeAPI = kanyeAPI
albumViewController.allalbumnames = self.allalbumnames
//albumViewController.allalbums = allalbums
print("albums loaded")

}

return true
}

}

Loading