Skip to content

Commit

Permalink
Factoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lfaoro committed Oct 18, 2015
1 parent 6dee898 commit 5e75aaf
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 138 deletions.
File renamed without changes.
59 changes: 0 additions & 59 deletions Cast Release-Info.plist

This file was deleted.

32 changes: 21 additions & 11 deletions Cast.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
A17EA4801B7F8EDE0080CF8B /* GistClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17EA47F1B7F8EDE0080CF8B /* GistClient.swift */; };
A19285261B88AEED00587ACB /* OAuthClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A14BE0AD1B7D3CC200CD6AAC /* OAuthClient.swift */; };
A198EC3B1B89E7F300E9D718 /* ShortenClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A198EC3A1B89E7F300E9D718 /* ShortenClient.swift */; };
A1F6CCC11BD2DD7200BDBE21 /* OptionsWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1F6CCBF1BD2DD7200BDBE21 /* OptionsWindowController.swift */; settings = {ASSET_TAGS = (); }; };
A1F6CCC21BD2DD7200BDBE21 /* OptionsWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1F6CCBF1BD2DD7200BDBE21 /* OptionsWindowController.swift */; settings = {ASSET_TAGS = (); }; };
A1F6CCC31BD2DD7200BDBE21 /* OptionsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A1F6CCC01BD2DD7200BDBE21 /* OptionsWindow.xib */; settings = {ASSET_TAGS = (); }; };
A1F6CCC41BD2DD7200BDBE21 /* OptionsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A1F6CCC01BD2DD7200BDBE21 /* OptionsWindow.xib */; settings = {ASSET_TAGS = (); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -108,7 +112,6 @@
A146B9FF1B90D218003B4EA3 /* RxBlocking.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxBlocking.framework; path = Carthage/Build/Mac/RxBlocking.framework; sourceTree = SOURCE_ROOT; };
A14B7C431BA39EA700831C8B /* Cast.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Cast.entitlements; sourceTree = "<group>"; };
A14B7C611BA3A34400831C8B /* Cast (Mac App Store).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Cast (Mac App Store).app"; sourceTree = BUILT_PRODUCTS_DIR; };
A14B7C621BA3A34400831C8B /* Cast Release-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Cast Release-Info.plist"; path = "/Users/lfaoro/Dev/Cast/Cast Release-Info.plist"; sourceTree = "<absolute>"; };
A14BE0AD1B7D3CC200CD6AAC /* OAuthClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuthClient.swift; sourceTree = "<group>"; };
A150495D1B693DD8009BF6A9 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; };
A15049641B69767A009BF6A9 /* Secrets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Secrets.swift; sourceTree = "<group>"; };
Expand All @@ -127,7 +130,9 @@
A19D4F941B779BAD00BEB08B /* Cartfile.private */ = {isa = PBXFileReference; lastKnownFileType = text; path = Cartfile.private; sourceTree = SOURCE_ROOT; };
A19D4F951B779E9400BEB08B /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = SOURCE_ROOT; };
A19D4F961B779E9400BEB08B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = SOURCE_ROOT; };
A1B2EB381BA9DCBE003E5E84 /* Cast Release.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Cast Release.entitlements"; sourceTree = "<group>"; };
A1B2EB381BA9DCBE003E5E84 /* Cast AppStore.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Cast AppStore.entitlements"; sourceTree = SOURCE_ROOT; };
A1F6CCBF1BD2DD7200BDBE21 /* OptionsWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OptionsWindowController.swift; path = Cast/OptionsWindowController.swift; sourceTree = "<group>"; };
A1F6CCC01BD2DD7200BDBE21 /* OptionsWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = OptionsWindow.xib; path = Cast/OptionsWindow.xib; sourceTree = "<group>"; };
EBE9DF5E1B68E38B00D11407 /* Cartfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Cartfile; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -167,7 +172,6 @@
A13145D71B5AA34E00AA4406 = {
isa = PBXGroup;
children = (
A1B2EB381BA9DCBE003E5E84 /* Cast Release.entitlements */,
A13145E21B5AA34E00AA4406 /* Cast */,
A13145F61B5AA67700AA4406 /* User Interface */,
A13145F51B5AA65B00AA4406 /* Assets */,
Expand Down Expand Up @@ -221,14 +225,14 @@
A13145F51B5AA65B00AA4406 /* Assets */ = {
isa = PBXGroup;
children = (
A150495D1B693DD8009BF6A9 /* README.md */,
A13145E71B5AA34E00AA4406 /* Assets.xcassets */,
A13145EC1B5AA34E00AA4406 /* Info.plist */,
A14B7C621BA3A34400831C8B /* Cast Release-Info.plist */,
A14B7C431BA39EA700831C8B /* Cast.entitlements */,
A1B2EB381BA9DCBE003E5E84 /* Cast AppStore.entitlements */,
A150495D1B693DD8009BF6A9 /* README.md */,
A13961B51B5C605200E9CB98 /* .gitignore */,
A13145E71B5AA34E00AA4406 /* Assets.xcassets */,
83BC9D901B6586DE002F35FA /* Dragging.swift */,
A15049641B69767A009BF6A9 /* Secrets.swift */,
A14B7C431BA39EA700831C8B /* Cast.entitlements */,
);
name = Assets;
path = Cast;
Expand All @@ -238,6 +242,8 @@
isa = PBXGroup;
children = (
A13145E91B5AA34E00AA4406 /* Main.storyboard */,
A1F6CCBF1BD2DD7200BDBE21 /* OptionsWindowController.swift */,
A1F6CCC01BD2DD7200BDBE21 /* OptionsWindow.xib */,
);
name = "User Interface";
sourceTree = "<group>";
Expand Down Expand Up @@ -380,6 +386,7 @@
files = (
A13145F81B5AA6C700AA4406 /* Services.plist in Resources */,
A13145E81B5AA34E00AA4406 /* Assets.xcassets in Resources */,
A1F6CCC31BD2DD7200BDBE21 /* OptionsWindow.xib in Resources */,
A13145EB1B5AA34E00AA4406 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -390,6 +397,7 @@
files = (
A14B7C531BA3A34400831C8B /* Services.plist in Resources */,
A14B7C541BA3A34400831C8B /* Assets.xcassets in Resources */,
A1F6CCC41BD2DD7200BDBE21 /* OptionsWindow.xib in Resources */,
A14B7C551BA3A34400831C8B /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -493,6 +501,7 @@
A13145E41B5AA34E00AA4406 /* AppDelegate.swift in Sources */,
A19285261B88AEED00587ACB /* OAuthClient.swift in Sources */,
A15049651B69767A009BF6A9 /* Secrets.swift in Sources */,
A1F6CCC11BD2DD7200BDBE21 /* OptionsWindowController.swift in Sources */,
A11025C01B75796300720866 /* ImgurClient.swift in Sources */,
A15049681B6979E5009BF6A9 /* UserNotifications.swift in Sources */,
A13961B41B5BF4C400E9CB98 /* Globals.swift in Sources */,
Expand All @@ -512,6 +521,7 @@
A14B7C461BA3A34400831C8B /* AppDelegate.swift in Sources */,
A14B7C471BA3A34400831C8B /* OAuthClient.swift in Sources */,
A14B7C481BA3A34400831C8B /* Secrets.swift in Sources */,
A1F6CCC21BD2DD7200BDBE21 /* OptionsWindowController.swift in Sources */,
A14B7C491BA3A34400831C8B /* ImgurClient.swift in Sources */,
A14B7C4A1BA3A34400831C8B /* UserNotifications.swift in Sources */,
A14B7C4B1BA3A34400831C8B /* Globals.swift in Sources */,
Expand Down Expand Up @@ -682,7 +692,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "Cast Release.entitlements";
CODE_SIGN_ENTITLEMENTS = "Cast AppStore.entitlements";
CODE_SIGN_IDENTITY = "Mac Developer";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
Expand All @@ -691,7 +701,7 @@
"$(SRCROOT)/Carthage/Build/Mac/",
/System/Library/Frameworks,
);
INFOPLIST_FILE = "Cast Release-Info.plist";
INFOPLIST_FILE = Cast/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
OTHER_CODE_SIGN_FLAGS = "--deep";
Expand All @@ -705,7 +715,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "Cast Release.entitlements";
CODE_SIGN_ENTITLEMENTS = "Cast AppStore.entitlements";
CODE_SIGN_IDENTITY = "Mac Developer";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
Expand All @@ -714,7 +724,7 @@
"$(SRCROOT)/Carthage/Build/Mac/",
/System/Library/Frameworks,
);
INFOPLIST_FILE = "Cast Release-Info.plist";
INFOPLIST_FILE = Cast/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
OTHER_CODE_SIGN_FLAGS = "--deep";
Expand Down
8 changes: 0 additions & 8 deletions Cast/Globals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

import Cocoa

public var recentUploads: [String:String] = [
"TestTitle1":"https://apple.com/",
"TestTitle2":"https://github.com"
]
public let pasteboardTypes = [NSFilenamesPboardType]

public func extractExcerptFromString(string: String, length: Int) -> String {
Expand All @@ -20,8 +16,4 @@ public func extractExcerptFromString(string: String, length: Int) -> String {
}
}

/**
- todo: find a way to add a global hotkey for sharing gists
- todo: research about auto-update
*/
public func todo() {}
45 changes: 22 additions & 23 deletions Cast/MenuSendersAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import RxSwift
final class MenuSendersAction: NSObject {


let shortenClient = ShortenClient()


func shareClipboardContentsAction(sender: NSMenuItem) {

let _ = PasteboardClient.getPasteboardItems()
Expand All @@ -22,7 +25,7 @@ final class MenuSendersAction: NSObject {
app.gistClient.setGist(content: item)
.debug("setGist")
.retry(3)
.flatMap { ShortenClient.shortenWithIsGd(URL: $0) }
.flatMap { self.shortenClient.shorten(URL: $0) }
.subscribe { event in
switch event {

Expand Down Expand Up @@ -62,7 +65,7 @@ final class MenuSendersAction: NSObject {
app.gistClient.setGist(content: item, updateGist: true)
.debug("setGist")
.retry(3)
.flatMap { ShortenClient.shortenWithIsGd(URL: $0) }
.flatMap { self.shortenClient.shorten(URL: $0) }
.subscribe { event in
switch event {

Expand Down Expand Up @@ -95,30 +98,25 @@ final class MenuSendersAction: NSObject {

let _ = PasteboardClient.getPasteboardItems()
.debug("getPasteboardItems")
.retry(3)
.subscribe(next: { value in
switch value {

case .Text(let item):
guard let url = NSURL(string: item) else { fallthrough }
self.shortenClient.shorten(URL: url)
.subscribe { event in
switch event {
case .Next(let shortenedURL):
guard let URL = shortenedURL else { fallthrough }
PasteboardClient.putInPasteboard(items: [URL])
app.userNotification.pushNotification(openURL: URL,
title: "Shortened with \(app.prefs.shortenService!)")

if let url = NSURL(string: item) {

ShortenClient.shortenWithIsGd(URL: url)
.debug("shortenWithHive")
.subscribe { event in
switch event {
case .Next(let URL):
PasteboardClient.putInPasteboard(items: [URL!])
app.userNotification.pushNotification(openURL: URL!, title: "Shortened with Is.Gd")
case .Completed:
print("completed")
case .Error(let error):
print("\(error)")
}
}
case .Completed:
print("completed")

} else {
fallthrough
case .Error(let error):
print("\(error)")
}
}

default:
Expand Down Expand Up @@ -166,7 +164,8 @@ final class MenuSendersAction: NSObject {
}
}

func openOptionsWindow(sender: NSMenuItem) {

func optionsAction(sender: NSMenuItem) {
NSApp.activateIgnoringOtherApps(true)
app.optionsWindowController.showWindow(nil)
}
}
50 changes: 50 additions & 0 deletions Cast/ShortenClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,57 @@ import SwiftyJSON

public class ShortenClient {

var shortenURL: NSURL?
var responseKey: String?


// MARK: - Public

public func shorten(URL URL: NSURL) -> Observable<String?> {
guard let shortenURLPref = app.prefs.shortenService else {
return failWith(ConnectionError.InvalidData("shortenURLPref"))
}

keepRecent(URL: URL)

switch shortenURLPref {
case "Is.Gd":
shortenURL = NSURL(string: "https://is.gd/create.php?format=json&url=" +
URL.absoluteString)!
responseKey = "shorturl"

case "Hive":
self.shortenURL = NSURL(string: "https://hive.am/api?api=spublic&url=\(URL.absoluteString)" +
"&description=cast.lfaoro.com&type=DIRECT")!
responseKey = "short"

case "Bitly":
let bitlyAPIurl = "https://api-ssl.bitly.com"
let bitlyAPIshorten = bitlyAPIurl + "/v3/shorten?access_token=" + bitlyOAuth2Token +
"&longUrl=" + URL.relativeString!
shortenURL = NSURL(string: bitlyAPIshorten)!

default: shortenURL = nil
}

let session = NSURLSession.sharedSession()
return session.rx_JSON(shortenURL!)
.debug("Shortening with: \(shortenURLPref)")
.retry(3)
.map {

if shortenURLPref != "Bitly" {
return $0[self.responseKey!] as? String
} else {
guard let data = $0["data"] as? NSDictionary, url = data["url"] as? String else {
return nil }
return url
}
}
}


@available(*, deprecated=1.2, renamed="shorten")
public class func shortenWithIsGd(URL URL: NSURL) -> Observable<String?> {
let session = NSURLSession.sharedSession()
let shorten = NSURL(string: "https://is.gd/create.php?format=json&url=" + URL.absoluteString)!
Expand All @@ -21,6 +69,7 @@ public class ShortenClient {
.map { $0["shorturl"] as? String }
}

@available(*, deprecated=1.2, renamed="shorten")
public class func shortenWithHive(URL URL: NSURL) -> Observable<String?> {


Expand All @@ -36,6 +85,7 @@ public class ShortenClient {
.map { $0["short"] as? String }
}

@available(*, deprecated=1.2, renamed="shorten")
public class func shortenWithBitly(URL: NSURL) -> Observable<NSURL> {
let bitlyAPIurl = "https://api-ssl.bitly.com"
let bitlyAPIshorten = bitlyAPIurl + "/v3/shorten?access_token=" + bitlyOAuth2Token +
Expand Down
Loading

0 comments on commit 5e75aaf

Please sign in to comment.