Skip to content

Commit

Permalink
Open Source FeatureKit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lara Marie Reimer authored and jpbernius committed Apr 27, 2018
1 parent a94313f commit a96c5b4
Show file tree
Hide file tree
Showing 33 changed files with 1,500 additions and 1 deletion.
35 changes: 34 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
*.DS_Store
# OS X
.DS_Store

# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
*.xccheckout
profile
*.moved-aside
DerivedData
*.hmap
*.ipa

# Bundler
.bundle

Carthage
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Note: if you ignore the Pods directory, make sure to uncomment
# `pod install` in .travis.yml
#
# Pods/
Example/Pods/
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
osx_image: xcode9.3
language: objective-c
xcode_workspace: Example/CUU.xcworkspace
xcode_scheme:
- CUU-Example
xcode_sdk:
- iphonesimulator11.3
podfile: Example/Podfile

before_install:
- gem install cocoapods
- pod install --project-directory=Example
56 changes: 56 additions & 0 deletions CUU.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Be sure to run `pod lib lint CUU.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = 'CUU'
s.version = '1.0.0'
s.summary = 'CUU is a framework to help analyzing th usage of your applications.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = <<-DESC
CUU is a project to help analyzing the usage of your app by providing functionality to track user interactions within your app. This data can then be used to track usage of your features.
DESC

s.homepage = 'https://cuu.ase.in.tum.de'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.authors = 'Lara Marie Reimer', 'Jan Philip Bernius', 'Jan Ole Johanßen'
s.source = { :git => 'https://github.com/cures-hub/cures-cuu-sdk.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/ls1intum'

s.ios.deployment_target = '10.0'

s.source_files = 'CUU/Classes/**/*'
s.swift_version = "4.0"

#s.resource_bundles = {
# 'CUU' => ['CUU/Assets/*.png']
# }

# --- Subspecs --- #

s.subspec 'CUUCore' do |cuucore|
cuucore.source_files = 'CUU/Classes/CUUCore/**/*'
end

s.subspec 'FeatureKit' do |featurekit|
featurekit.source_files = 'CUU/Classes/FeatureKit/**/*'
featurekit.dependency 'CUU/CUUCore'
end

s.subspec 'InteractionKit' do |interactionkit|
interactionkit.source_files = 'CUU/Classes/InteractionKit/**/*'
interactionkit.dependency 'CUU/CUUCore'
end

end
Empty file added CUU/Assets/.gitkeep
Empty file.
Empty file added CUU/Classes/.gitkeep
Empty file.
Empty file added CUU/Classes/CUU.swift
Empty file.
14 changes: 14 additions & 0 deletions CUU/Classes/CUUCore/CUUConstants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// CUUConstants.swift
// CUU
//
// Created by Lara Marie Reimer on 16.01.18.
//

import Foundation

struct CUUConstants {
struct CUUUserDefaultsKeys {
static let userIdKey = "de.tum.in.ase.cuu.featurekit.userid"
}
}
46 changes: 46 additions & 0 deletions CUU/Classes/CUUCore/CUUCrumb.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// FKCrumb.swift
// CUU
//
// Created by Lara Marie Reimer on 10.12.17.
//

import Foundation

public protocol CUUCrumb : Codable {
var name: String { get }
var type: String { get }
var timestamp: Date { get }
var sessionId: String { get }
var userId: String { get }
}

extension CUUCrumb {
func send(projectId: String, commitHash: String, trackingToken: String) {
guard let baseUrl = CUUUtils.baseUrl else { return }
let urlString = baseUrl + "/v1/projects/" + projectId + "/commits/" + commitHash + "/crumbs"
let url = URL(string: urlString)

print(urlString)

var urlRequest = URLRequest(url: url!)
urlRequest.httpMethod = "POST"
urlRequest.setValue(trackingToken, forHTTPHeaderField: "X-Tracking-Token")
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")

do {
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .iso8601
let json = try encoder.encode(self)
urlRequest.httpBody = json
} catch _ {
print ("Error serializing crumb of type " + self.type)
return
}

let task = URLSession.shared.dataTask(with: urlRequest)
task.resume()

print("Crumb sent.")
}
}
14 changes: 14 additions & 0 deletions CUU/Classes/CUUCore/CUUSessionManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// FKSessionManager.swift
// CUU
//
// Created by Lara Marie Reimer on 18.12.17.
//

class CUUSessionManager {
static let sharedManager = CUUSessionManager()

let currentSession: String = {
return UUID().uuidString
}()
}
32 changes: 32 additions & 0 deletions CUU/Classes/CUUCore/CUUUserManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// CUUUserManager.swift
// CUU
//
// Created by Lara Marie Reimer on 16.01.18.
//



import Foundation

class CUUUserManager {
static let sharedManager = CUUUserManager()

let userId: String = {
let id = UserDefaults.standard.string(forKey: CUUConstants.CUUUserDefaultsKeys.userIdKey)

if let id = id {
// Return the stored id
return id
} else {
// Return a new id
// Create a unique id
let uuid = UUID().uuidString

// Store it in user defaults
UserDefaults.standard.set(uuid, forKey: CUUConstants.CUUUserDefaultsKeys.userIdKey)

return uuid
}
}()
}
69 changes: 69 additions & 0 deletions CUU/Classes/CUUCore/CUUUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// FKUtils.swift
// CUU
//
// Created by Lara Marie Reimer on 14.01.18.
//

import Foundation

class CUUUtils {
static let projectId: String? = {
if let plist = CUUConstants.infoPlistDictionary {if let projectId = plist.object(forKey: "CUUProjectID") as? String {
return projectId
} else {
return nil
}
} else {
return nil
}
}()

static let commitHash: String? = {
if let plist = CUUConstants.infoPlistDictionary {
if let commitHash = plist.object(forKey: "CUUCommitHash") as? String {
return commitHash
} else {
return nil
}
} else {
return nil
}
}()

static let trackingToken: String? = {
if let plist = CUUConstants.infoPlistDictionary {
if let trackingToken = plist.object(forKey: "CUUTrackingToken") as? String {
return trackingToken
} else {
return nil
}
} else {
return nil
}
}()

static let baseUrl: String? = {
if let plist = CUUConstants.infoPlistDictionary {
if let url = plist.object(forKey: "CUUApiEndpoint") as? String {
return url
} else {
return nil
}
} else {
return nil
}
}()

struct CUUConstants {
static var infoPlistDictionary: NSDictionary? {
get {
if let path = Bundle.main.path(forResource: "CUU", ofType: "plist") {
return NSDictionary(contentsOfFile: path)
} else {
return nil
}
}
}
}
}
21 changes: 21 additions & 0 deletions CUU/Classes/FeatureKit/FKActionCrumb.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// FKActionCrumb.swift
// CUU
//
// Created by Lara Marie Reimer on 10.12.17.
//

struct FKActionCrumb : CUUCrumb {
let name: String
let type = "action"
let timestamp: Date
let sessionId: String
let userId: String

init(name: String) {
self.name = name
self.timestamp = Date()
self.sessionId = CUUSessionManager.sharedManager.currentSession
self.userId = CUUUserManager.sharedManager.userId
}
}
19 changes: 19 additions & 0 deletions CUU/Classes/FeatureKit/FeatureKit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// FeatureKit.swift
// CUU
//
// Created by Lara Marie Reimer on 10.12.17.
//

import Foundation

open class FeatureKit {

open static func seed(name: String) {
let actionCrumb = FKActionCrumb(name: name)

if let projectId = CUUUtils.projectId, let commitHash = CUUUtils.commitHash, let trackingToken = CUUUtils.trackingToken {
actionCrumb.send(projectId: projectId, commitHash: commitHash, trackingToken: trackingToken)
}
}
}
Empty file.
Loading

0 comments on commit a96c5b4

Please sign in to comment.