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

- Task Completion #1

Open
wants to merge 1 commit 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
18 changes: 18 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Swifterviewing' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod "KRProgressHUD"
pod 'AlamofireImage', '~> 4.1'
pod 'Alamofire', '~> 5.2'
pod 'TrustKit'
# Pods for Swifterviewing

target 'SwifterviewingTests' do
inherit! :search_paths
# Pods for testing
end

end
33 changes: 33 additions & 0 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PODS:
- Alamofire (5.4.3)
- AlamofireImage (4.2.0):
- Alamofire (~> 5.4)
- KRActivityIndicatorView (3.0.7)
- KRProgressHUD (3.4.7):
- KRActivityIndicatorView (= 3.0.7)
- TrustKit (1.7.0)

DEPENDENCIES:
- Alamofire (~> 5.2)
- AlamofireImage (~> 4.1)
- KRProgressHUD
- TrustKit

SPEC REPOS:
trunk:
- Alamofire
- AlamofireImage
- KRActivityIndicatorView
- KRProgressHUD
- TrustKit

SPEC CHECKSUMS:
Alamofire: e447a2774a40c996748296fa2c55112fdbbc42f9
AlamofireImage: 34a2d90b0e5fe6a5605f85ae4b7b01e784c60192
KRActivityIndicatorView: ad69e89c4ce40c986cf580595be4829dcad0e35a
KRProgressHUD: a248f0bc6c9c2aed40a37b76e03ffecc7f85c887
TrustKit: dac38bb37e49bdfeca41b1a19d020da38017b51c

PODFILE CHECKSUM: 0a922a2ce00f56b86c4592bd99e39c097b2a4740

COCOAPODS: 1.10.1
289 changes: 276 additions & 13 deletions Swifterviewing.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Swifterviewing.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
24 changes: 0 additions & 24 deletions Swifterviewing/API.swift

This file was deleted.

23 changes: 23 additions & 0 deletions Swifterviewing/API/API.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// API.swift
// Swifterviewing
//
// Created by Tyler Thompson on 7/9/20.
// Copyright © 2020 World Wide Technology Application Services. All rights reserved.
//

import UIKit

//MARK: - API
struct API {
static let baseURL = "https://jsonplaceholder.typicode.com"
static let photosEndpoint = "/photos" //returns photos and their album ID
static let albumsEndpoint = "/albums" //returns an album, but without photos

//MARK: - Progressbar Colors

public enum Color {
static let color1 = UIColor(red: 0, green: 0.2, blue: 0.38, alpha: 1)
static let color2 = UIColor(red: 0.15, green: 0.61, blue: 0.83, alpha: 1)
}
}
88 changes: 88 additions & 0 deletions Swifterviewing/API/BaseWebservice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// BaseWebservice.swift
// Swifterviewing
//
// Created by Dharma Teja Kanneganti on 10/07/21.
// Copyright © 2021 World Wide Technology Application Services. All rights reserved.
//

import Foundation
import Alamofire
import TrustKit

public enum AlbumError {
case generic
case noNetwork
case noData
}

typealias DFCompletion = (AnyObject?, Error?) -> Void

//MARK: - SessionDelegate

class BaseWebService: SessionDelegate {

private var trustKitObj: TrustKit?
var sessionManager: Session?

init() {
super.init()
sessionManager = Session.init(configuration: URLSessionConfiguration.ephemeral, delegate: self)
// // UIApplication.appDelegate.remoteConfigService?.string(forKey: .iOS_publickey_hash),
}

func executeRequest(url: String, method: HTTPMethod, parameters: Parameters?, headers: HTTPHeaders?, completion: @escaping DFCompletion) {

guard let requestUrl = URL(string: url) else {
completion(nil, nil)
return
}

sessionManager?.request(requestUrl,
method: method,
parameters: parameters,
encoding: JSONEncoding.default,
headers: headers,
interceptor: nil,
requestModifier: nil).responseJSON { (response) in
switch response.result {
case .success(let value):
if let jsonDict = value as? NSDictionary {
completion(jsonDict, nil)
}else if let jsonArray = value as? NSArray
{
completion(jsonArray, nil)
} else {
completion(nil, response.error)
}
case .failure:
completion(nil, response.error)
}
}

}
}

extension BaseWebService {

//MARK: - Receiving Response

func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) ->
Void) {
completionHandler(.performDefaultHandling, nil)

/*if let serverTrust = challenge.protectionSpace.serverTrust {
let pinningValidator = TrustKit.sharedInstance().pinningValidator
let trustDecision = pinningValidator.evaluateTrust(serverTrust, forHostname: API.baseURL)

if trustDecision == .shouldAllowConnection {
completionHandler(.performDefaultHandling, nil)
} else if trustDecision == .shouldBlockConnection {
completionHandler(.cancelAuthenticationChallenge, nil)
} else {
completionHandler(.cancelAuthenticationChallenge, nil)
}
}*/
}
}
44 changes: 44 additions & 0 deletions Swifterviewing/API/Webservice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Webservice.swift
// Swifterviewing
//
// Created by Dharma Teja Kanneganti on 10/07/21.
// Copyright © 2021 World Wide Technology Application Services. All rights reserved.
//

import Foundation
import UIKit
import Alamofire

typealias AlbumResponseStatus = (Bool) -> Void

class WebService
{
//MARK: - fetchAlbumsData

func fetchAlbumsData(completion: @escaping DFCompletion)
{
let service = BaseWebService.init()
let fullUrl = API.baseURL + API.albumsEndpoint
service.executeRequest(url: fullUrl,
method: .get,
parameters: nil,
headers: nil) { (response, error) in
completion(response, error)
}
}

//MARK: - fetchPhotos

func fetchPhotos(completion: @escaping DFCompletion)
{
let service = BaseWebService.init()
let fullUrl = API.baseURL + API.photosEndpoint
service.executeRequest(url: fullUrl,
method: .get,
parameters: nil,
headers: nil) { (response, error) in
completion(response, error)
}
}
}
13 changes: 0 additions & 13 deletions Swifterviewing/Album.swift

This file was deleted.

23 changes: 23 additions & 0 deletions Swifterviewing/AlbumsViewController/Model/Album.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Album.swift
// Swifterviewing
//
// Created by Tyler Thompson on 7/9/20.
// Copyright © 2020 World Wide Technology Application Services. All rights reserved.
//

import Foundation

//Albums Model
struct Album : Codable {
var userId : Int
var id : Int
var title : String?

enum CodingKeys: String, CodingKey
{
case userId
case id
case title
}
}
28 changes: 28 additions & 0 deletions Swifterviewing/AlbumsViewController/Model/Photos.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Photos.swift
// Swifterviewing
//
// Created by Dharma Teja Kanneganti on 10/07/21.
// Copyright © 2021 World Wide Technology Application Services. All rights reserved.
//

import Foundation

//MARk: - Photos Model
struct Photos : Codable
{
var albumId : Int
var id : Int
var title : String?
var url : String?
var thumbnailUrl : String?

enum CodingKeys: String, CodingKey
{
case albumId
case id
case title
case url
case thumbnailUrl
}
}
Loading