Skip to content

Commit

Permalink
Image/Attachment support, Youtube support, improved twitter, new comm…
Browse files Browse the repository at this point in the history
…ands, new URL routing scheme
  • Loading branch information
ZekeSnider committed Apr 12, 2016
1 parent 2844e34 commit 26831a6
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/amain.swift"
timestampString = "481901931.42767"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "71"
endingLineNumber = "71"
startingLineNumber = "144"
endingLineNumber = "144"
landmarkName = "routeMessage(_:fromBuddy:forRoom:)"
landmarkType = "5">
</BreakpointContent>
Expand All @@ -26,11 +26,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/amain.swift"
timestampString = "481901931.42767"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "63"
endingLineNumber = "63"
startingLineNumber = "126"
endingLineNumber = "126"
landmarkName = "routeMessage(_:fromBuddy:forRoom:)"
landmarkType = "5">
</BreakpointContent>
Expand All @@ -42,27 +42,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "481901109.289393"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "40"
endingLineNumber = "40"
landmarkName = "youtubeCall(_:myRoom:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "481901109.289393"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "47"
endingLineNumber = "47"
startingLineNumber = "85"
endingLineNumber = "85"
landmarkName = "RESTModule"
landmarkType = "3">
<Locations>
Expand Down Expand Up @@ -106,11 +90,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/amain.swift"
timestampString = "481901931.42767"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
startingLineNumber = "145"
endingLineNumber = "145"
landmarkName = "routeMessage(_:fromBuddy:forRoom:)"
landmarkType = "5">
</BreakpointContent>
Expand All @@ -122,11 +106,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "481901109.289393"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "64"
endingLineNumber = "64">
startingLineNumber = "102"
endingLineNumber = "102">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -136,11 +120,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "481901109.289393"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "58"
endingLineNumber = "58">
startingLineNumber = "96"
endingLineNumber = "96">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand All @@ -150,13 +134,13 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/amain.swift"
timestampString = "481901931.42767"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "61"
endingLineNumber = "61"
landmarkName = "routeMessage(_:fromBuddy:forRoom:)"
landmarkType = "5">
startingLineNumber = "118"
endingLineNumber = "118"
landmarkName = "MessageRouting"
landmarkType = "3">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand Down Expand Up @@ -196,12 +180,12 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "481901109.289393"
timestampString = "482153142.353186"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
landmarkName = "apiTest()"
startingLineNumber = "45"
endingLineNumber = "45"
landmarkName = "getVideo(_:toChat:)"
landmarkType = "5">
<Locations>
<Location
Expand Down Expand Up @@ -237,5 +221,53 @@
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/amain.swift"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "130"
endingLineNumber = "130"
landmarkName = "routeMessage(_:fromBuddy:forRoom:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/amain.swift"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "131"
endingLineNumber = "131"
landmarkName = "routeMessage(_:fromBuddy:forRoom:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jared/RESTModule.swift"
timestampString = "482155098.731986"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "80"
endingLineNumber = "80"
landmarkName = "youtubeCall(_:myRoom:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
7 changes: 4 additions & 3 deletions Jared/CoreModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ struct CoreModule: RoutingModule {
let ping = Route(comparisons: [.StartsWith: "/ping"], call: self.pingCall)
let thankYou = Route(comparisons: [.StartsWith: "Thank you Jared"], call: self.thanksJared)
let version = Route(comparisons: [.StartsWith: "/version"], call: self.getVersion)
let send = Route(comparisons: [.StartsWith: "/send"], call: self.hello)
let send = Route(comparisons: [.StartsWith: "/send"], call: self.sendRepeat)
let test = Route(comparisons: [.StartsWith: "/test"], call: self.hello)


routes = [ping, thankYou, version, send]
routes = [ping, thankYou, version, send, test]
}

func hello(message:String, myRoom: Room) -> Void{
print("shitty")
SendImage("/Users/Jared/Desktop/Video Message.mov", toRoom: myRoom)
}

func pingCall(message:String, myRoom: Room) -> Void {
Expand Down
2 changes: 1 addition & 1 deletion Jared/MessageReceive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MessageReceive: NSScriptCommand {
print(groupID)

if let appDelegate = NSApplication.sharedApplication().delegate as? AppDelegate {
backgroundThread(0.0, background: {appDelegate.Router.routeMessage(message!, fromBuddy: buddyName!, forRoom: Room(GUID: groupID!))})
backgroundThread(0.0, background: {appDelegate.Router.routeMessage(message!, fromBuddy: buddyName!, forRoom: Room(GUID: groupID!, buddyName: buddyName))})
}


Expand Down
76 changes: 57 additions & 19 deletions Jared/RESTModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,72 @@ struct RESTModule: RoutingModule {
var routes: [Route] = []

init() {
let youtube = Route(comparisons: [.Contains: "https://www.youtube.com"], call: self.youtubeCall)
let youtube = Route(comparisons: [.ContainsURL: "youtu.be"], call: self.youtubeCall)
routes = [youtube]

/*
var localPath: NSURL?
Alamofire.download(.GET,
"http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v",
destination: { (temporaryURL, response) in
let directoryURL = getAppSupportDirectory()
let pathComponent = response.suggestedFilename
localPath = directoryURL.URLByAppendingPathComponent(pathComponent!)
return localPath!
})
.response { (request, response, _, error) in
print(response)
print("Downloaded file to !)")
}*/


}

func apiTest() {
Alamofire.request(.GET, "https://www.googleapis.com/youtube/v3/videos", parameters: ["key": "AIzaSyCVvhTV-pnl4Ue6Y8-lZWIrhSsoYxPy-fM", "part": "snippet", "id": "eXhNtH8CrbA"]).responseJSON {response in
print(response.result.value)
func getVideo(videoID: String, toChat: Room) {
print(videoID)
Alamofire.request(.GET, "https://www.googleapis.com/youtube/v3/videos", parameters: ["key": "AIzaSyCVvhTV-pnl4Ue6Y8-lZWIrhSsoYxPy-fM", "part": "snippet", "id": videoID]).responseString {response in
print(response.result.value!)
self.sendVideoInfo(response.result.value!, toChat: toChat)
}
}

func youtubeCall(message:String, myRoom: Room) -> Void {
apiTest()
/*
do {
let regex = try NSRegularExpression(pattern: "v=(.+?)(?=$|&)", options: NSRegularExpressionOptions.CaseInsensitive)
let match: NSTextCheckingResult? = regex.firstMatchInString(message, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, message.characters.count))
print(match)
let videoID = (message as NSString).substringWithRange(match!.range).stringByReplacingOccurrencesOfString("v=", withString: "")
print(videoID)
func sendVideoInfo(videoJSON: String, toChat: Room) {
if let dataFromString = videoJSON.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
let JSONParse = JSON(data: dataFromString)
let myVideo = JSONParse["items"][0]["snippet"].dictionaryValue

Alamofire.request(.GET, "https://gdata.youtube.com/feeds/api/videos/\(videoID)?v=2").responseJSON { response in
if let videoTitle = myVideo["title"], uploader = myVideo["channelTitle"], publishDate = myVideo["publishedAt"]
{
let VideoString = "\(videoTitle) uploaded by \(uploader) \non \(publishDate)"
SendText(VideoString, toRoom: toChat)

let localFileName = NSUUID().UUIDString

if let thumbnailURL = myVideo["thumbnails"]?["standard"]["url"].string {
Alamofire.download(.GET, thumbnailURL,
destination: { (temporaryURL, response) in
let localPath = getAppSupportDirectory().URLByAppendingPathComponent(localFileName + response.suggestedFilename!)
return localPath
})
.response { (request, response, _, error) in
print(response)
let localPath = getAppSupportDirectory().URLByAppendingPathComponent(localFileName + response!.suggestedFilename!)
SendImageAndDelete(localPath.path!, toRoom: toChat)


print("Downloaded file to \(localPath)!")
}
}
}
} catch _ {
print("error")
}*/
}
}

func youtubeCall(url:String, myRoom: Room) -> Void {
let regexMatches = matchesForRegexInText("(?<=v(=|/))([-a-zA-Z0-9_]+)|(?<=youtu.be/)([-a-zA-Z0-9_]+)", text:url)
if let youtubeID = regexMatches[safe:0] {
getVideo(youtubeID, toChat: myRoom)
}
}
}

Expand Down
Binary file added Jared/SendImage.scpt
Binary file not shown.
6 changes: 3 additions & 3 deletions Jared/TwitterModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TwitterModule: RoutingModule {
let pageSize = 20

init() {
let twitterStatus = Route(comparisons: [.Contains: "twitter.com"], call: self.twitterStatusID)
let twitterStatus = Route(comparisons: [.ContainsURL: "twitter.com"], call: self.twitterStatusID)

routes = [twitterStatus]

Expand Down Expand Up @@ -90,8 +90,8 @@ class TwitterModule: RoutingModule {
func sendTweet(tweetJSON: String, toChat: String) {
if let dataFromString = tweetJSON.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {
let JSONParse = JSON(data: dataFromString)
let TweetString = "\"\(JSONParse["text"].stringValue)\" -\(JSONParse["user"]["name"].stringValue) \(JSONParse["created_at"])"
SendText(TweetString, toRoom: Room(GUID: toChat))
let TweetString = "\"\(JSONParse["text"].stringValue)\" -\(JSONParse["user"]["name"].stringValue) \n\(JSONParse["created_at"])"
SendText(TweetString, toRoom: Room(GUID: toChat, buddyName: nil))
}
}

Expand Down
Loading

0 comments on commit 26831a6

Please sign in to comment.