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

GlobantPlus example App and Lambdas #297

Closed
wants to merge 7 commits into from
Closed
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
966 changes: 966 additions & 0 deletions Examples/GlobantPlus/App/GlobantPlus.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "91334796299FC5CA00F2ECF4"
BuildableName = "GlobantPlus.app"
BlueprintName = "GlobantPlus"
ReferencedContainer = "container:GlobantPlus.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "91334796299FC5CA00F2ECF4"
BuildableName = "GlobantPlus.app"
BlueprintName = "GlobantPlus"
ReferencedContainer = "container:GlobantPlus.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Debug"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "91334796299FC5CA00F2ECF4"
BuildableName = "GlobantPlus.app"
BlueprintName = "GlobantPlus"
ReferencedContainer = "container:GlobantPlus.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Debug"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// Environment.swift
// GlobantPlus
//
// Created by Adolfo Vera Blasco on 3/1/23.
//

import Foundation

final class ApplicationEnvironment {
enum Keys: String {
case apiURL = "API_KEY"
case apiToken = "API_AUTH_KEY"
case awsAccessKey = "AWS_ACCESS_KEY_ID"
case awsSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
case awsSQSQueueURL = "SQS_QUEUE_URL"
case awsAPIGatewayURL = "API_GATEWAY_URL"
}

static let shared = ApplicationEnvironment()

let dictionary: [String : Any]?

private init() {
self.dictionary = Bundle.main.infoDictionary
}
}

extension ApplicationEnvironment {
var apiKey: String {
guard let dictionary = self.dictionary,
let value = dictionary[Keys.apiURL.rawValue] as? String
else {
fatalError("Non value for API_KEY key")
}

return value
}

var apiToken: String {
guard let dictionary = self.dictionary,
let token = dictionary[Keys.apiToken.rawValue] as? String
else {
fatalError("Non value for API_AUTH_KEY key")
}

return token
}

var awsAccessKey: String {
guard let dictionary = self.dictionary,
let token = dictionary[Keys.awsAccessKey.rawValue] as? String
else {
fatalError("Non value for MY_AWS_ACCESS_KEY_ID key")
}

return token
}

var awsSecretAccessKey: String {
guard let dictionary = self.dictionary,
let token = dictionary[Keys.awsSecretAccessKey.rawValue] as? String
else {
fatalError("Non value for MY_AWS_SECRET_ACCESS_KEY key")
}

return token
}

var awsAPIGatewayURL: String {
guard let dictionary = self.dictionary,
let token = dictionary[Keys.awsAPIGatewayURL.rawValue] as? String
else {
fatalError("Non value for API_GATEWAY_URL key")
}

return token
}

var awsSQSQueueURL: String {
guard let dictionary = self.dictionary,
let token = dictionary[Keys.awsSQSQueueURL.rawValue] as? String
else {
fatalError("Non value for AWS_SQS_QUEUE_URL key")
}

return token
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// AppConfig.xcconfig
// Premiere
//
// Created by Adolfo Vera Blasco on 3/1/23.
//

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

TMDB_API_KEY = ae18023495231d6c234fd8f8ba1e2eb0
TMDB_API_AUTH_KEY = eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhZTE4MDIzNDk1MjMxZDZjMjM0ZmQ4ZjhiYTFlMmViMCIsInN1YiI6IjUyNzBlNjRlMTljMjk1MmFjMDAzNWI1MyIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.WFrdV7VnZQAhgFzhc-O9jIvpWEL2-JMxCC6rMhwE4l8

AWS_ACCESS_KEY_ID = AKIATDXGUYITWP7KXS4S
AWS_SECRET_ACCESS_KEY = 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

AWS_SQS_QUEUE_URL = https:/$()/sqs.us-east-1.amazonaws.com/214158328359/user_activity
AWS_API_GATEWAY_URL = https:/$()/fhlymaqeol.execute-api.us-east-1.amazonaws.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// PremiereApp.swift
// GlobantPlus
//
// Created by Adolfo Vera Blasco on 3/1/23.
//

import SwiftUI

@main
struct GlobantPlusApp: App {
var body: some Scene {
WindowGroup {
TabView {
NavigationStack {
DashboardView()
.edgesIgnoringSafeArea([ .horizontal ])
}
.tabItem {
Image(systemName: "flame")
}

Text("Search")
.tabItem {
Image(systemName: "magnifyingglass")
}
}
.padding(0)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Int+Runtime.swift
// GlobantPlus
//
// Created by Adolfo Vera Blasco on 10/3/23.
//

import Foundation

extension Array where Element == Int {
func average() -> Int {
let amount = self.reduce(0) { $0 + $1 }
return (self.count == 0 ? 0 : amount / self.count)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation
import Resty

class AmazonFavoriteTrainingBaseRepository {
func process(mediaID: Int, forUser userID: String, httpMethod verb: NetworkRequest.HttpMethod) async throws {
let resty = Resty()

let amazonFavorite = AmazonFavorite(media: mediaID, user: userID)

let favoriteRequest = NetworkRequest(
httpHeaders: [ "Content-Type" : "application/json" ],
body: amazonFavorite.encoded(),
httpMethod: verb)

let favoriteResponse = try await resty.fetch(endpoint: AmazonFavoriteEndpoint.favorite, withParameters: favoriteRequest)

if favoriteResponse.httpCodeResponse != 200 {
throw GlobantPlusError.dataSourceFailure
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// AmazonFavoriteTrainingRepository.swift
// GlobantPlus
//
// Created by Adolfo Vera Blasco on 15/3/23.
//

import Foundation
import Resty

final class AmazonFavoriteTrainingRepository: AmazonFavoriteTrainingBaseRepository, FavoriteTrainingRepository {
func post(mediaID: Int, forUser userID: String) async throws {
try await super.process(mediaID: mediaID, forUser: userID, httpMethod: .post)
}

func delete(mediaID: Int, forUser userID: String) async throws {
try await super.process(mediaID: mediaID, forUser: userID, httpMethod: .delete)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// AmazonFavorite.swift
// GlobantPlus
//
// Created by Adolfo Vera Blasco on 15/3/23.
//

import Foundation

struct AmazonFavorite: Encodable {
let userID: String
let showID: Int
let recordID: String

init(media: Int, user: String) {
self.userID = user
self.showID = media
self.recordID = "\(user.description)-\(media)"
}

func encoded() -> Data? {
let jsonEncoder = JSONEncoder()

let meEncoded = try? jsonEncoder.encode(self)

return meEncoded
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// AmazonFavoriteEndpoint.swift
// GlobantPlus
//
// Created by Adolfo Vera Blasco on 15/3/23.
//

import Foundation
import Resty

enum AmazonFavoriteEndpoint {
case favorite
}

extension AmazonFavoriteEndpoint {
var baseURL: String {
return ApplicationEnvironment.shared.awsAPIGatewayURL
}
}

extension AmazonFavoriteEndpoint: Endpoint {
var path: String {
switch self {
case .favorite:
return "\(baseURL)/favorites"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// SQSActivity.swift
// GlobantPlus
//
// Created by Adolfo Vera Blasco on 13/3/23.
//

import Foundation

struct SQSActivity: Codable {
let createdAt: Date
let activity: String
let mediaId: Int
let userId: String
}
Loading