From a5046292bf49044576a2e7b273f3ec6137e0ae2c Mon Sep 17 00:00:00 2001 From: Joel Levin Date: Sat, 8 Jun 2013 18:46:07 -0700 Subject: [PATCH 01/69] Added SocketShuttle --- .gitmodules | 3 + ADNKit.xcodeproj/project.pbxproj | 106 +++++++++++++++++++++++++++++-- ADNKit/ANKClient.m | 1 + External/SocketShuttle | 1 + 4 files changed, 106 insertions(+), 5 deletions(-) create mode 160000 External/SocketShuttle diff --git a/.gitmodules b/.gitmodules index b80f714..2aa9ab3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,3 +3,6 @@ url = https://github.com/AFNetworking/AFNetworking ignore = dirty +[submodule "External/SocketShuttle"] + path = External/SocketShuttle + url = https://github.com/joeldev/SocketShuttle.git diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 436ba4e..105c1d7 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -348,6 +348,8 @@ 2592B81B16FF84A4004573FF /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DC3725016E3AE1500190862 /* AFNetworkActivityIndicatorManager.m */; }; 259A5EC616F2E1EF00AF9F35 /* ADNKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DC370E116E0805E00190862 /* ADNKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 25C0AA45171867B8006E47B7 /* CustomPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 25C0AA44171867B8006E47B7 /* CustomPost.m */; }; + 25D01E1117641043000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; + 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 5D2CFEE61703E8F200086FBD /* ANKTokenLimits.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5D2CFEE71703E8F200086FBD /* ANKTokenLimits.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */; }; 5D2CFEE81703E8F200086FBD /* ANKTokenLimits.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */; }; @@ -386,6 +388,34 @@ remoteGlobalIDString = 5DC3710716E0808C00190862; remoteInfo = "ADNKit-OSX"; }; + 25D01E0A17640FF1000D365D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 4DE9EB65170D870A005B295E; + remoteInfo = SocketShuttle; + }; + 25D01E0D1764101D000D365D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 4DE9EB64170D870A005B295E; + remoteInfo = SocketShuttle; + }; + 25D01E0F17641021000D365D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 4DE9EB64170D870A005B295E; + remoteInfo = SocketShuttle; + }; + 25D01E1217641047000D365D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 4DE9EB64170D870A005B295E; + remoteInfo = SocketShuttle; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -546,6 +576,7 @@ 2592B80916FF8410004573FF /* libADNKit-AFNetworking-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libADNKit-AFNetworking-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 25C0AA43171867B8006E47B7 /* CustomPost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomPost.h; sourceTree = ""; }; 25C0AA44171867B8006E47B7 /* CustomPost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomPost.m; sourceTree = ""; }; + 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SocketShuttle.xcodeproj; path = External/SocketShuttle/SocketShuttle.xcodeproj; sourceTree = ""; }; 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKTokenLimits.h; sourceTree = ""; }; 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKTokenLimits.m; sourceTree = ""; }; 5D955BE4174BD10B0077E387 /* ANKGeneralParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKGeneralParameters.h; sourceTree = ""; }; @@ -618,6 +649,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 25D01E1117641043000D365D /* libSocketShuttle.a in Frameworks */, 5DC3727E16E3AF6900190862 /* UIKit.framework in Frameworks */, 5DC3727B16E3AF4400190862 /* MobileCoreServices.framework in Frameworks */, 5DC3727916E3AF4000190862 /* SystemConfiguration.framework in Frameworks */, @@ -630,6 +662,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */, 252A87D416F79A09001F3E8F /* CoreServices.framework in Frameworks */, 5DC3728316E3AF8E00190862 /* SystemConfiguration.framework in Frameworks */, 5DC3728116E3AF8900190862 /* CoreLocation.framework in Frameworks */, @@ -819,6 +852,23 @@ name = "Supporting Files"; sourceTree = ""; }; + 25D01E0617640FF1000D365D /* Products */ = { + isa = PBXGroup; + children = ( + 25D01E0B17640FF1000D365D /* libSocketShuttle.a */, + ); + name = Products; + sourceTree = ""; + }; + 25D01E0C17640FFA000D365D /* External */ = { + isa = PBXGroup; + children = ( + 5DC3724616E3AE1500190862 /* AFNetworking */, + 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */, + ); + name = External; + sourceTree = ""; + }; 5DC370D016E0805E00190862 = { isa = PBXGroup; children = ( @@ -828,7 +878,7 @@ 5DC370DE16E0805E00190862 /* ADNKit */, 5DC370DF16E0805E00190862 /* Supporting Files */, 5DC3710A16E0808C00190862 /* ADNKit-OSX */, - 5DC3724616E3AE1500190862 /* AFNetworking */, + 25D01E0C17640FFA000D365D /* External */, 2592B7A916FCED64004573FF /* ADNKitTests */, 5DC370DB16E0805E00190862 /* Frameworks */, 5DC370DA16E0805E00190862 /* Products */, @@ -1166,6 +1216,7 @@ buildRules = ( ); dependencies = ( + 25D01E1017641021000D365D /* PBXTargetDependency */, ); name = "ADNKit-AFNetworking-iOS"; productName = ADNKit; @@ -1184,6 +1235,7 @@ buildRules = ( ); dependencies = ( + 25D01E0E1764101D000D365D /* PBXTargetDependency */, ); name = "ADNKit-iOS"; productName = ADNKit; @@ -1202,6 +1254,7 @@ buildRules = ( ); dependencies = ( + 25D01E1317641047000D365D /* PBXTargetDependency */, ); name = "ADNKit-OSX"; productName = "ADNKit-OSX"; @@ -1227,6 +1280,12 @@ mainGroup = 5DC370D016E0805E00190862; productRefGroup = 5DC370DA16E0805E00190862 /* Products */; projectDirPath = ""; + projectReferences = ( + { + ProductGroup = 25D01E0617640FF1000D365D /* Products */; + ProjectRef = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; + }, + ); projectRoot = ""; targets = ( 5DC370D816E0805E00190862 /* ADNKit-iOS */, @@ -1237,6 +1296,16 @@ }; /* End PBXProject section */ +/* Begin PBXReferenceProxy section */ + 25D01E0B17640FF1000D365D /* libSocketShuttle.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libSocketShuttle.a; + remoteRef = 25D01E0A17640FF1000D365D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + /* Begin PBXResourcesBuildPhase section */ 2592B79D16FCED64004573FF /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -1512,6 +1581,21 @@ target = 5DC3710716E0808C00190862 /* ADNKit-OSX */; targetProxy = 2592B7B616FCED92004573FF /* PBXContainerItemProxy */; }; + 25D01E0E1764101D000D365D /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = SocketShuttle; + targetProxy = 25D01E0D1764101D000D365D /* PBXContainerItemProxy */; + }; + 25D01E1017641021000D365D /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = SocketShuttle; + targetProxy = 25D01E0F17641021000D365D /* PBXContainerItemProxy */; + }; + 25D01E1317641047000D365D /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = SocketShuttle; + targetProxy = 25D01E1217641047000D365D /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ @@ -1577,7 +1661,7 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = "\"$(SRCROOT)\""; + HEADER_SEARCH_PATHS = ""; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "ADNKit-AFNetworking-iOS"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; @@ -1591,7 +1675,7 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = "\"$(SRCROOT)\""; + HEADER_SEARCH_PATHS = ""; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "ADNKit-AFNetworking-iOS"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; @@ -1623,6 +1707,12 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/../\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); IPHONEOS_DEPLOYMENT_TARGET = 5.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -1646,6 +1736,12 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/../\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); IPHONEOS_DEPLOYMENT_TARGET = 5.0; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -1658,7 +1754,7 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = "\"$(SRCROOT)\""; + HEADER_SEARCH_PATHS = ""; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; @@ -1672,7 +1768,7 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = "\"$(SRCROOT)\""; + HEADER_SEARCH_PATHS = ""; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index d2cffe4..b23f581 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -19,6 +19,7 @@ #import "ANKResourceMap.h" #import "ANKUser.h" #import "ANKClient+ANKTokenStatus.h" +#import @interface ANKClient () diff --git a/External/SocketShuttle b/External/SocketShuttle new file mode 160000 index 0000000..a766684 --- /dev/null +++ b/External/SocketShuttle @@ -0,0 +1 @@ +Subproject commit a766684d367945b246e47e21f138141fe07d424e From f46eb22e5a71f41d8f68a8fe1465f6532f223789 Mon Sep 17 00:00:00 2001 From: Joel Levin Date: Sat, 8 Jun 2013 18:46:30 -0700 Subject: [PATCH 02/69] Updated SocketShuttle --- External/SocketShuttle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/SocketShuttle b/External/SocketShuttle index a766684..bbe0848 160000 --- a/External/SocketShuttle +++ b/External/SocketShuttle @@ -1 +1 @@ -Subproject commit a766684d367945b246e47e21f138141fe07d424e +Subproject commit bbe0848a81c22120d0576ce9a8a3ad3e35663c41 From 1ffba12654e7b3addbde20a424c7adcc868d3247 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 8 Jun 2013 19:10:33 -0700 Subject: [PATCH 03/69] Fixes non-buildability. --- ADNKit.xcodeproj/project.pbxproj | 22 +++++++++++----------- ADNKit/ADNKit-iOS.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 105c1d7..70b80c2 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -348,8 +348,8 @@ 2592B81B16FF84A4004573FF /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DC3725016E3AE1500190862 /* AFNetworkActivityIndicatorManager.m */; }; 259A5EC616F2E1EF00AF9F35 /* ADNKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DC370E116E0805E00190862 /* ADNKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 25C0AA45171867B8006E47B7 /* CustomPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 25C0AA44171867B8006E47B7 /* CustomPost.m */; }; - 25D01E1117641043000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; + 335AC10C17641B1800AEFCFE /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 5D2CFEE61703E8F200086FBD /* ANKTokenLimits.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5D2CFEE71703E8F200086FBD /* ANKTokenLimits.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */; }; 5D2CFEE81703E8F200086FBD /* ANKTokenLimits.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */; }; @@ -395,21 +395,21 @@ remoteGlobalIDString = 4DE9EB65170D870A005B295E; remoteInfo = SocketShuttle; }; - 25D01E0D1764101D000D365D /* PBXContainerItemProxy */ = { + 25D01E0F17641021000D365D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; proxyType = 1; remoteGlobalIDString = 4DE9EB64170D870A005B295E; remoteInfo = SocketShuttle; }; - 25D01E0F17641021000D365D /* PBXContainerItemProxy */ = { + 25D01E1217641047000D365D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; proxyType = 1; remoteGlobalIDString = 4DE9EB64170D870A005B295E; remoteInfo = SocketShuttle; }; - 25D01E1217641047000D365D /* PBXContainerItemProxy */ = { + 335AC10A17641B1300AEFCFE /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; proxyType = 1; @@ -649,7 +649,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 25D01E1117641043000D365D /* libSocketShuttle.a in Frameworks */, + 335AC10C17641B1800AEFCFE /* libSocketShuttle.a in Frameworks */, 5DC3727E16E3AF6900190862 /* UIKit.framework in Frameworks */, 5DC3727B16E3AF4400190862 /* MobileCoreServices.framework in Frameworks */, 5DC3727916E3AF4000190862 /* SystemConfiguration.framework in Frameworks */, @@ -1235,7 +1235,7 @@ buildRules = ( ); dependencies = ( - 25D01E0E1764101D000D365D /* PBXTargetDependency */, + 335AC10B17641B1300AEFCFE /* PBXTargetDependency */, ); name = "ADNKit-iOS"; productName = ADNKit; @@ -1581,11 +1581,6 @@ target = 5DC3710716E0808C00190862 /* ADNKit-OSX */; targetProxy = 2592B7B616FCED92004573FF /* PBXContainerItemProxy */; }; - 25D01E0E1764101D000D365D /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = SocketShuttle; - targetProxy = 25D01E0D1764101D000D365D /* PBXContainerItemProxy */; - }; 25D01E1017641021000D365D /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = SocketShuttle; @@ -1596,6 +1591,11 @@ name = SocketShuttle; targetProxy = 25D01E1217641047000D365D /* PBXContainerItemProxy */; }; + 335AC10B17641B1300AEFCFE /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = SocketShuttle; + targetProxy = 335AC10A17641B1300AEFCFE /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ diff --git a/ADNKit/ADNKit-iOS.h b/ADNKit/ADNKit-iOS.h index eddb1bc..37d8a56 100644 --- a/ADNKit/ADNKit-iOS.h +++ b/ADNKit/ADNKit-iOS.h @@ -10,5 +10,5 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import -#import +#import "ANKOAuthViewController.h" +#import "ANKUsernamePasswordAuthViewController.h" From 04702e48fca076b9ca3f82d37aa9a4a22660a6ea Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 8 Jun 2013 19:55:50 -0700 Subject: [PATCH 04/69] Fix spacing --- ADNKit/ANKClient.m | 1 - 1 file changed, 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index b23f581..6f99429 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -21,7 +21,6 @@ #import "ANKClient+ANKTokenStatus.h" #import - @interface ANKClient () @property (strong) AFHTTPClient *authHTTPClient; From ceab058ce02a1d3030ca3321cfee37bd721fdfda Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 8 Jun 2013 20:38:19 -0700 Subject: [PATCH 05/69] Completes stream context objects and conform with Joel's fucking coding style. --- ADNKit.xcodeproj/project.pbxproj | 14 +++++++++++--- ADNKit/ANKClient.m | 2 ++ ADNKit/ANKStreamContext.h | 26 ++++++++++++++++++++++++++ ADNKit/ANKStreamContext.m | 25 +++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 ADNKit/ANKStreamContext.h create mode 100644 ADNKit/ANKStreamContext.m diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 70b80c2..60da7a9 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -350,6 +350,8 @@ 25C0AA45171867B8006E47B7 /* CustomPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 25C0AA44171867B8006E47B7 /* CustomPost.m */; }; 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 335AC10C17641B1800AEFCFE /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; + 335AC111176427C300AEFCFE /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; }; + 335AC112176427C300AEFCFE /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; 5D2CFEE61703E8F200086FBD /* ANKTokenLimits.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5D2CFEE71703E8F200086FBD /* ANKTokenLimits.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */; }; 5D2CFEE81703E8F200086FBD /* ANKTokenLimits.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */; }; @@ -577,6 +579,8 @@ 25C0AA43171867B8006E47B7 /* CustomPost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomPost.h; sourceTree = ""; }; 25C0AA44171867B8006E47B7 /* CustomPost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomPost.m; sourceTree = ""; }; 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SocketShuttle.xcodeproj; path = External/SocketShuttle/SocketShuttle.xcodeproj; sourceTree = ""; }; + 335AC10F176427C300AEFCFE /* ANKStreamContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKStreamContext.h; sourceTree = ""; }; + 335AC110176427C300AEFCFE /* ANKStreamContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKStreamContext.m; sourceTree = ""; }; 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKTokenLimits.h; sourceTree = ""; }; 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKTokenLimits.m; sourceTree = ""; }; 5D955BE4174BD10B0077E387 /* ANKGeneralParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKGeneralParameters.h; sourceTree = ""; }; @@ -676,13 +680,15 @@ 2592B70516F8D120004573FF /* ANKClient */ = { isa = PBXGroup; children = ( - 252A2C4316E5624700DAE393 /* ANKClient.h */, - 252A2C4416E5624700DAE393 /* ANKClient.m */, - 2592B70916F8D1CC004573FF /* App.net API */, 252A889216F8CDB8001F3E8F /* ANKClient+ANKHandlerBlocks.h */, 252A889316F8CDB8001F3E8F /* ANKClient+ANKHandlerBlocks.m */, 252AD7121745C76600E12492 /* ANKClient+ANKRequestsAPI.h */, 252AD7131745C76600E12492 /* ANKClient+ANKRequestsAPI.m */, + 252A2C4316E5624700DAE393 /* ANKClient.h */, + 252A2C4416E5624700DAE393 /* ANKClient.m */, + 335AC10F176427C300AEFCFE /* ANKStreamContext.h */, + 335AC110176427C300AEFCFE /* ANKStreamContext.m */, + 2592B70916F8D1CC004573FF /* App.net API */, ); name = ANKClient; sourceTree = ""; @@ -1102,6 +1108,7 @@ buildActionMask = 2147483647; files = ( 5D955BE6174BD10B0077E387 /* ANKGeneralParameters.h in Headers */, + 335AC111176427C300AEFCFE /* ANKStreamContext.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1495,6 +1502,7 @@ 252E632617421632003143D6 /* ANKClient+ANKStreamMarker.m in Sources */, 252AD7171745C76600E12492 /* ANKClient+ANKRequestsAPI.m in Sources */, 5D955BE9174BD10B0077E387 /* ANKGeneralParameters.m in Sources */, + 335AC112176427C300AEFCFE /* ANKStreamContext.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 6f99429..73ca41f 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -21,11 +21,13 @@ #import "ANKClient+ANKTokenStatus.h" #import + @interface ANKClient () @property (strong) AFHTTPClient *authHTTPClient; @property (strong) NSString *webAuthRedirectURI; @property (readwrite, strong) ANKUser *authenticatedUser; +@property (nonatomic, strong) NSMutableDictionary *sockets; - (void)initializeHTTPAuthClient; - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler; diff --git a/ADNKit/ANKStreamContext.h b/ADNKit/ANKStreamContext.h new file mode 100644 index 0000000..6612d54 --- /dev/null +++ b/ADNKit/ANKStreamContext.h @@ -0,0 +1,26 @@ +// +// ANKStreamContext.h +// ADNKit +// +// Created by Kolin Krewinkel on 6/8/13. +// Copyright (c) 2013 Afterwork Studios. All rights reserved. +// + +@class KATSocketShuttle; + +@interface ANKStreamContext : NSObject + +#pragma mark - Designated Initializer + +- (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle updateBlock:(ANKClientCompletionBlock)updateBlock; + +#pragma mark - Internal + +@property (nonatomic, strong) KATSocketShuttle *socketShuttle; +@property (nonatomic, copy) ANKClientCompletionBlock updateBlock; + +#pragma mark - API Level + +@property (nonatomic, copy) NSString *identifier; + +@end diff --git a/ADNKit/ANKStreamContext.m b/ADNKit/ANKStreamContext.m new file mode 100644 index 0000000..5eca600 --- /dev/null +++ b/ADNKit/ANKStreamContext.m @@ -0,0 +1,25 @@ +// +// ANKStreamContext.m +// ADNKit +// +// Created by Kolin Krewinkel on 6/8/13. +// Copyright (c) 2013 Afterwork Studios. All rights reserved. +// + +#import "ANKStreamContext.h" + +@implementation ANKStreamContext + +#pragma mark - Designated Initializer + +- (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle updateBlock:(ANKClientCompletionBlock)updateBlock { + if ((self = [super init])) { + self.identifier = identifier; + self.socketShuttle = socketShuttle; + self.updateBlock = updateBlock; + } + + return self; +} + +@end From d8bf35fff15257c1403aea54ce815819d5e30b68 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 8 Jun 2013 21:52:54 -0700 Subject: [PATCH 06/69] Begin outlining stream protocols. --- ADNKit/ANKClient.h | 26 +++++++++++++++++++++++++- ADNKit/ANKClient.m | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.h b/ADNKit/ANKClient.h index 9e5bfd5..737b59c 100644 --- a/ADNKit/ANKClient.h +++ b/ADNKit/ANKClient.h @@ -35,7 +35,26 @@ typedef NS_ENUM(NSUInteger, ANKResponseDecodingType) { }; -@class ANKAPIResponseMeta; +@class ANKClient, ANKAPIResponseMeta; + +#pragma mark - +#pragma mark - Protocols + +@protocol ANKStreamingDelegate + +@optional + +- (void)clientSocketDidConnect:(ANKClient *)client; +- (void)clientSocketDidDisconnect:(ANKClient *)client; + +- (void)client:(ANKClient *)client didDisconnectOnSocketError:(NSError *)error; + +@required + +- (void)client:(ANKClient *)client didReceiveObject:(id)responseObject withMeta:(ANKAPIResponseMeta *)meta; + +@end + typedef void (^ANKClientCompletionBlock)(id responseObject, ANKAPIResponseMeta *meta, NSError *error); @@ -107,4 +126,9 @@ typedef void (^ANKClientCompletionBlock)(id responseObject, ANKAPIResponseMeta * - (void)setObject:(id)object forKeyInAuthenticatedUserDefaults:(NSString *)key; - (id)objectForKeyInAuthenticatedUserDefaults:(NSString *)key; +#pragma mark - +#pragma mark - Streams + +- (void)beginGeneratingStreamingNotificationsWithDelegate:(id)delegate; + @end diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 73ca41f..fcb6bf4 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -22,6 +22,9 @@ #import +static const NSString *ADNAPIUserStreamEndpointURL = @"wss://stream-channel.app.net/stream/user"; + + @interface ANKClient () @property (strong) AFHTTPClient *authHTTPClient; From 2bcf3a8539c7b47e32938cef39ab4b6141d5c461 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 12:20:53 -0700 Subject: [PATCH 07/69] Revise naming of request method. --- ADNKit/ANKClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.h b/ADNKit/ANKClient.h index 737b59c..6f1c539 100644 --- a/ADNKit/ANKClient.h +++ b/ADNKit/ANKClient.h @@ -129,6 +129,6 @@ typedef void (^ANKClientCompletionBlock)(id responseObject, ANKAPIResponseMeta * #pragma mark - #pragma mark - Streams -- (void)beginGeneratingStreamingNotificationsWithDelegate:(id)delegate; +- (void)requestStreamingUpdatesWithDelegate:(id)delegate; @end From 4a9fb8f8063ec6ad804189209447f39563c0b706 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 12:27:55 -0700 Subject: [PATCH 08/69] Add method in implementation body. --- ADNKit/ANKClient.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index fcb6bf4..5bf6ca9 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -315,6 +315,15 @@ - (id)objectForKeyInAuthenticatedUserDefaults:(NSString *)key { } +#pragma mark - +#pragma mark + +- (void)requestStreamingUpdatesWithDelegate:(id)delegate +{ + +} + + #pragma mark - #pragma mark Internal API From d54afd76671cf377b4c3b28328f2ddfc6bc86c54 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 16:53:10 -0700 Subject: [PATCH 09/69] Conform to coding style and add a semaphore. --- ADNKit/ANKClient.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 5bf6ca9..515bc43 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -30,7 +30,10 @@ @interface ANKClient () @property (strong) AFHTTPClient *authHTTPClient; @property (strong) NSString *webAuthRedirectURI; @property (readwrite, strong) ANKUser *authenticatedUser; + @property (nonatomic, strong) NSMutableDictionary *sockets; +@property (nonatomic, weak) id queuedDelegate; +@property (nonatomic, copy) dispatch_semaphore_t streamingTokenSemaphore; - (void)initializeHTTPAuthClient; - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler; @@ -63,6 +66,8 @@ - (id)init { self.pagination = [[ANKPaginationSettings alloc] init]; self.generalParameters = [[ANKGeneralParameters alloc] init]; self.generalParameters.includeHTML = NO; + self.streamingTokenSemaphore = dispatch_semaphore_create(0); + [self setDefaultHeader:@"Accept" value:@"application/json"]; [self registerHTTPOperationClass:[ANKJSONRequestOperation class]]; @@ -316,11 +321,10 @@ - (id)objectForKeyInAuthenticatedUserDefaults:(NSString *)key { #pragma mark - -#pragma mark +#pragma mark Streams -- (void)requestStreamingUpdatesWithDelegate:(id)delegate -{ - +- (void)requestStreamingUpdatesWithDelegate:(id)delegate { + self.queuedDelegate = delegate; } From 82b39f6d8a9bbf546b5c7e7c99c12672babc9964 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 21:42:11 -0700 Subject: [PATCH 10/69] Begin attemps to connect. --- ADNKit/ANKClient.m | 30 ++++++++++++++++++++++++++++-- External/SocketShuttle | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 515bc43..53a1408 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -20,12 +20,13 @@ #import "ANKUser.h" #import "ANKClient+ANKTokenStatus.h" #import +#import "ANKStreamContext.h" static const NSString *ADNAPIUserStreamEndpointURL = @"wss://stream-channel.app.net/stream/user"; -@interface ANKClient () +@interface ANKClient () @property (strong) AFHTTPClient *authHTTPClient; @property (strong) NSString *webAuthRedirectURI; @@ -33,7 +34,7 @@ @interface ANKClient () @property (nonatomic, strong) NSMutableDictionary *sockets; @property (nonatomic, weak) id queuedDelegate; -@property (nonatomic, copy) dispatch_semaphore_t streamingTokenSemaphore; +@property (nonatomic) dispatch_semaphore_t streamingTokenSemaphore; - (void)initializeHTTPAuthClient; - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler; @@ -325,6 +326,8 @@ - (id)objectForKeyInAuthenticatedUserDefaults:(NSString *)key { - (void)requestStreamingUpdatesWithDelegate:(id)delegate { self.queuedDelegate = delegate; + + [self spawnUserStreamConnectionIDRequest]; } @@ -377,4 +380,27 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err } +- (void)spawnUserStreamConnectionIDRequest { + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:(NSString *)ADNAPIUserStreamEndpointURL]]; + [request setValue:self.accessToken ? [@"Bearer " stringByAppendingString:self.accessToken] : nil forHTTPHeaderField:@"Authorization"]; + + KATSocketShuttle *shuttle = [[KATSocketShuttle alloc] initWithRequest:request delegate:self]; + + ANKStreamContext *context = [[ANKStreamContext alloc] initWithIdentifier:nil socketShuttle:shuttle updateBlock:^(id responseObject, ANKAPIResponseMeta *meta, NSError *error) { + NSLog(@"%@ %@ %@", responseObject, meta, error); + }]; + + [self.sockets setObject:context forKey:@"socket"]; + +} + + +#pragma mark - +#pragma mark KATSocketShuttleDelegate + +- (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { + NSLog(@"%@", message); +} + + @end diff --git a/External/SocketShuttle b/External/SocketShuttle index bbe0848..44316e8 160000 --- a/External/SocketShuttle +++ b/External/SocketShuttle @@ -1 +1 @@ -Subproject commit bbe0848a81c22120d0576ce9a8a3ad3e35663c41 +Subproject commit 44316e893eff3b2ea893adbaba3210fe2c74278d From 87fa46fe7803c36f66a1c9159877a11911e35a7e Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 22:16:17 -0700 Subject: [PATCH 11/69] Make sure I\'m not missing anything. --- ADNKit.xcodeproj/project.pbxproj | 18 ++++++++++++------ External/SocketShuttle | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 60da7a9..452ae9c 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -349,7 +349,7 @@ 259A5EC616F2E1EF00AF9F35 /* ADNKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DC370E116E0805E00190862 /* ADNKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 25C0AA45171867B8006E47B7 /* CustomPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 25C0AA44171867B8006E47B7 /* CustomPost.m */; }; 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; - 335AC10C17641B1800AEFCFE /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; + 330BDCAA17659465009BD559 /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 335AC111176427C300AEFCFE /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; }; 335AC112176427C300AEFCFE /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; 5D2CFEE61703E8F200086FBD /* ANKTokenLimits.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -411,7 +411,7 @@ remoteGlobalIDString = 4DE9EB64170D870A005B295E; remoteInfo = SocketShuttle; }; - 335AC10A17641B1300AEFCFE /* PBXContainerItemProxy */ = { + 330BDCA81765945F009BD559 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; proxyType = 1; @@ -579,6 +579,9 @@ 25C0AA43171867B8006E47B7 /* CustomPost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomPost.h; sourceTree = ""; }; 25C0AA44171867B8006E47B7 /* CustomPost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomPost.m; sourceTree = ""; }; 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SocketShuttle.xcodeproj; path = External/SocketShuttle/SocketShuttle.xcodeproj; sourceTree = ""; }; + 330BDCB21765980E009BD559 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; + 330BDCB31765980E009BD559 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; }; + 330BDCB41765980E009BD559 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 335AC10F176427C300AEFCFE /* ANKStreamContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKStreamContext.h; sourceTree = ""; }; 335AC110176427C300AEFCFE /* ANKStreamContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKStreamContext.m; sourceTree = ""; }; 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKTokenLimits.h; sourceTree = ""; }; @@ -653,7 +656,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 335AC10C17641B1800AEFCFE /* libSocketShuttle.a in Frameworks */, + 330BDCAA17659465009BD559 /* libSocketShuttle.a in Frameworks */, 5DC3727E16E3AF6900190862 /* UIKit.framework in Frameworks */, 5DC3727B16E3AF4400190862 /* MobileCoreServices.framework in Frameworks */, 5DC3727916E3AF4000190862 /* SystemConfiguration.framework in Frameworks */, @@ -878,6 +881,9 @@ 5DC370D016E0805E00190862 = { isa = PBXGroup; children = ( + 330BDCB21765980E009BD559 /* CFNetwork.framework */, + 330BDCB31765980E009BD559 /* libicucore.dylib */, + 330BDCB41765980E009BD559 /* Security.framework */, 5DC370E116E0805E00190862 /* ADNKit.h */, 5DA357CB16EBC18B00FA21F8 /* ADNKit-iOS.h */, 5DA357CC16EBC18B00FA21F8 /* ADNKit-OSX.h */, @@ -1242,7 +1248,7 @@ buildRules = ( ); dependencies = ( - 335AC10B17641B1300AEFCFE /* PBXTargetDependency */, + 330BDCA91765945F009BD559 /* PBXTargetDependency */, ); name = "ADNKit-iOS"; productName = ADNKit; @@ -1599,10 +1605,10 @@ name = SocketShuttle; targetProxy = 25D01E1217641047000D365D /* PBXContainerItemProxy */; }; - 335AC10B17641B1300AEFCFE /* PBXTargetDependency */ = { + 330BDCA91765945F009BD559 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = SocketShuttle; - targetProxy = 335AC10A17641B1300AEFCFE /* PBXContainerItemProxy */; + targetProxy = 330BDCA81765945F009BD559 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ diff --git a/External/SocketShuttle b/External/SocketShuttle index 44316e8..0331e99 160000 --- a/External/SocketShuttle +++ b/External/SocketShuttle @@ -1 +1 @@ -Subproject commit 44316e893eff3b2ea893adbaba3210fe2c74278d +Subproject commit 0331e992abd94519bb2ea4930917911cee11490f From c4d621edf137a2ec72bb093621e2639bd6bf6edb Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 22:17:47 -0700 Subject: [PATCH 12/69] Remove frameworks from the list. --- ADNKit.xcodeproj/project.pbxproj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 452ae9c..929b6bb 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -579,9 +579,6 @@ 25C0AA43171867B8006E47B7 /* CustomPost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomPost.h; sourceTree = ""; }; 25C0AA44171867B8006E47B7 /* CustomPost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomPost.m; sourceTree = ""; }; 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SocketShuttle.xcodeproj; path = External/SocketShuttle/SocketShuttle.xcodeproj; sourceTree = ""; }; - 330BDCB21765980E009BD559 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; - 330BDCB31765980E009BD559 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; }; - 330BDCB41765980E009BD559 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 335AC10F176427C300AEFCFE /* ANKStreamContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKStreamContext.h; sourceTree = ""; }; 335AC110176427C300AEFCFE /* ANKStreamContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKStreamContext.m; sourceTree = ""; }; 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKTokenLimits.h; sourceTree = ""; }; @@ -881,9 +878,6 @@ 5DC370D016E0805E00190862 = { isa = PBXGroup; children = ( - 330BDCB21765980E009BD559 /* CFNetwork.framework */, - 330BDCB31765980E009BD559 /* libicucore.dylib */, - 330BDCB41765980E009BD559 /* Security.framework */, 5DC370E116E0805E00190862 /* ADNKit.h */, 5DA357CB16EBC18B00FA21F8 /* ADNKit-iOS.h */, 5DA357CC16EBC18B00FA21F8 /* ADNKit-OSX.h */, From b36fcfc9628428c9ed3e816bf1538f1cc273ff43 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 22:44:10 -0700 Subject: [PATCH 13/69] Spawns request and at least gets data back. --- ADNKit/ANKClient.m | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 53a1408..16cd81c 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -67,15 +67,17 @@ - (id)init { self.pagination = [[ANKPaginationSettings alloc] init]; self.generalParameters = [[ANKGeneralParameters alloc] init]; self.generalParameters.includeHTML = NO; - self.streamingTokenSemaphore = dispatch_semaphore_create(0); [self setDefaultHeader:@"Accept" value:@"application/json"]; [self registerHTTPOperationClass:[ANKJSONRequestOperation class]]; [self addObserver:self forKeyPath:@"accessToken" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:@"shouldRequestAnnotations" options:NSKeyValueObservingOptionNew context:nil]; + + self.streamingTokenSemaphore = dispatch_semaphore_create(0); + self.sockets = [[NSMutableDictionary alloc] init]; } - + return self; } @@ -382,7 +384,9 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err - (void)spawnUserStreamConnectionIDRequest { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:(NSString *)ADNAPIUserStreamEndpointURL]]; - [request setValue:self.accessToken ? [@"Bearer " stringByAppendingString:self.accessToken] : nil forHTTPHeaderField:@"Authorization"]; + + NSString *authorizationKey = @"Authorization"; + [request setValue:[self defaultValueForHeader:authorizationKey] forHTTPHeaderField:authorizationKey]; KATSocketShuttle *shuttle = [[KATSocketShuttle alloc] initWithRequest:request delegate:self]; @@ -390,8 +394,7 @@ - (void)spawnUserStreamConnectionIDRequest { NSLog(@"%@ %@ %@", responseObject, meta, error); }]; - [self.sockets setObject:context forKey:@"socket"]; - + [self.sockets setObject:context forKey:[NSString stringWithFormat:@"Socket_%i", self.sockets.count]]; } @@ -399,7 +402,8 @@ - (void)spawnUserStreamConnectionIDRequest { #pragma mark KATSocketShuttleDelegate - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { - NSLog(@"%@", message); + + NSLog(@"Message: %@", message); } From 3a01702be3507e43af306326a6083b1a78531af9 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 22:47:53 -0700 Subject: [PATCH 14/69] Switch to a set and add some basic handling code. --- ADNKit/ANKClient.m | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 16cd81c..0a2bfae 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -32,7 +32,7 @@ @interface ANKClient () @property (strong) NSString *webAuthRedirectURI; @property (readwrite, strong) ANKUser *authenticatedUser; -@property (nonatomic, strong) NSMutableDictionary *sockets; +@property (nonatomic, strong) NSMutableSet *sockets; @property (nonatomic, weak) id queuedDelegate; @property (nonatomic) dispatch_semaphore_t streamingTokenSemaphore; @@ -75,7 +75,7 @@ - (id)init { [self addObserver:self forKeyPath:@"shouldRequestAnnotations" options:NSKeyValueObservingOptionNew context:nil]; self.streamingTokenSemaphore = dispatch_semaphore_create(0); - self.sockets = [[NSMutableDictionary alloc] init]; + self.sockets = [[NSMutableSet alloc] init]; } return self; @@ -394,7 +394,7 @@ - (void)spawnUserStreamConnectionIDRequest { NSLog(@"%@ %@ %@", responseObject, meta, error); }]; - [self.sockets setObject:context forKey:[NSString stringWithFormat:@"Socket_%i", self.sockets.count]]; + [self.sockets addObject:context]; } @@ -402,7 +402,22 @@ - (void)spawnUserStreamConnectionIDRequest { #pragma mark KATSocketShuttleDelegate - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { - + NSDictionary *JSON = message; + BOOL isConnectionIDMessage = JSON[@"meta"][@"connection_id"] != nil; + + ANKStreamContext *context = [self.sockets filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"socket == %@", socket]].anyObject; + + if (!context) { + NSLog(@"Critical error: there was no stream context found."); + return; + } + + if (isConnectionIDMessage) { + + } else { + + } + NSLog(@"Message: %@", message); } From a8dfb3bd0a297acb4389120e1b64fd59ec39d4d1 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 9 Jun 2013 23:12:39 -0700 Subject: [PATCH 15/69] Connects and disconnects. Warns of the current issue; SocketShuttle also does not remove itself as an observer: will need to be fixed. --- ADNKit/ANKClient.m | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 0a2bfae..a2522b9 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -390,8 +390,12 @@ - (void)spawnUserStreamConnectionIDRequest { KATSocketShuttle *shuttle = [[KATSocketShuttle alloc] initWithRequest:request delegate:self]; + __weak typeof(self.queuedDelegate) weakQueuedDelegate = self.queuedDelegate; + __weak typeof(self) weakSelf = self; + +#warning This should be switched from referencing the block to using the delegate, so we can sort out what to do and message directly in the KATSocketShuttleDelegate method. ANKStreamContext *context = [[ANKStreamContext alloc] initWithIdentifier:nil socketShuttle:shuttle updateBlock:^(id responseObject, ANKAPIResponseMeta *meta, NSError *error) { - NSLog(@"%@ %@ %@", responseObject, meta, error); + [weakQueuedDelegate client:weakSelf didReceiveObject:responseObject withMeta:meta]; }]; [self.sockets addObject:context]; @@ -402,10 +406,20 @@ - (void)spawnUserStreamConnectionIDRequest { #pragma mark KATSocketShuttleDelegate - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { - NSDictionary *JSON = message; - BOOL isConnectionIDMessage = JSON[@"meta"][@"connection_id"] != nil; + NSError *error = nil; + NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error]; + + if (error) { + NSLog(@"Critical error getting JSON. %@", error); + return; + } + + NSDictionary *metaDict = JSON[@"meta"]; + NSString *connectionID = metaDict[@"connection_id"]; + + BOOL isConnectionIDMessage = connectionID != nil; - ANKStreamContext *context = [self.sockets filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"socket == %@", socket]].anyObject; + ANKStreamContext *context = [self.sockets filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"socketShuttle == %@", socket]].anyObject; if (!context) { NSLog(@"Critical error: there was no stream context found."); @@ -413,9 +427,12 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } if (isConnectionIDMessage) { + [socket disconnect]; + context.identifier = connectionID; + context.socketShuttle = nil; } else { - + context.updateBlock(message, nil, nil); } NSLog(@"Message: %@", message); From eada99a838ca90669a398108d4ae6e6c8b296933 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 10 Jun 2013 23:47:47 -0700 Subject: [PATCH 16/69] Switch away from using the easily-broken property-delegate method; passes method; passes it around instead. Now we can just filter with anyObject for one with a conn. ID and no socket shuttle and go, when connecting. --- ADNKit/ANKClient.m | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index a2522b9..e1e080d 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -33,7 +33,6 @@ @interface ANKClient () @property (readwrite, strong) ANKUser *authenticatedUser; @property (nonatomic, strong) NSMutableSet *sockets; -@property (nonatomic, weak) id queuedDelegate; @property (nonatomic) dispatch_semaphore_t streamingTokenSemaphore; - (void)initializeHTTPAuthClient; @@ -327,9 +326,7 @@ - (id)objectForKeyInAuthenticatedUserDefaults:(NSString *)key { #pragma mark Streams - (void)requestStreamingUpdatesWithDelegate:(id)delegate { - self.queuedDelegate = delegate; - - [self spawnUserStreamConnectionIDRequest]; + [self spawnUserStreamConnectionIDRequestWithDelegate:delegate]; } @@ -382,7 +379,7 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err } -- (void)spawnUserStreamConnectionIDRequest { +- (void)spawnUserStreamConnectionIDRequestWithDelegate:(id)streamingDelegate { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:(NSString *)ADNAPIUserStreamEndpointURL]]; NSString *authorizationKey = @"Authorization"; @@ -390,12 +387,11 @@ - (void)spawnUserStreamConnectionIDRequest { KATSocketShuttle *shuttle = [[KATSocketShuttle alloc] initWithRequest:request delegate:self]; - __weak typeof(self.queuedDelegate) weakQueuedDelegate = self.queuedDelegate; __weak typeof(self) weakSelf = self; #warning This should be switched from referencing the block to using the delegate, so we can sort out what to do and message directly in the KATSocketShuttleDelegate method. ANKStreamContext *context = [[ANKStreamContext alloc] initWithIdentifier:nil socketShuttle:shuttle updateBlock:^(id responseObject, ANKAPIResponseMeta *meta, NSError *error) { - [weakQueuedDelegate client:weakSelf didReceiveObject:responseObject withMeta:meta]; + [streamingDelegate client:weakSelf didReceiveObject:responseObject withMeta:meta]; }]; [self.sockets addObject:context]; From 50c92fe8252e0a1e0ebae14ac5df732730ab0752 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 11 Jun 2013 17:46:22 -0700 Subject: [PATCH 17/69] Switch context objects to store delegates instead of blocks. --- ADNKit/ANKClient.m | 8 +------- ADNKit/ANKStreamContext.h | 4 ++-- ADNKit/ANKStreamContext.m | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index e1e080d..888ac48 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -387,13 +387,7 @@ - (void)spawnUserStreamConnectionIDRequestWithDelegate:(id KATSocketShuttle *shuttle = [[KATSocketShuttle alloc] initWithRequest:request delegate:self]; - __weak typeof(self) weakSelf = self; - -#warning This should be switched from referencing the block to using the delegate, so we can sort out what to do and message directly in the KATSocketShuttleDelegate method. - ANKStreamContext *context = [[ANKStreamContext alloc] initWithIdentifier:nil socketShuttle:shuttle updateBlock:^(id responseObject, ANKAPIResponseMeta *meta, NSError *error) { - [streamingDelegate client:weakSelf didReceiveObject:responseObject withMeta:meta]; - }]; - + ANKStreamContext *context = [[ANKStreamContext alloc] initWithIdentifier:nil socketShuttle:shuttle streamingDelegate:streamingDelegate]; [self.sockets addObject:context]; } diff --git a/ADNKit/ANKStreamContext.h b/ADNKit/ANKStreamContext.h index 6612d54..2932878 100644 --- a/ADNKit/ANKStreamContext.h +++ b/ADNKit/ANKStreamContext.h @@ -12,12 +12,12 @@ #pragma mark - Designated Initializer -- (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle updateBlock:(ANKClientCompletionBlock)updateBlock; +- (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle streamingDelegate:(id)streamingDelegate; #pragma mark - Internal @property (nonatomic, strong) KATSocketShuttle *socketShuttle; -@property (nonatomic, copy) ANKClientCompletionBlock updateBlock; +@property (nonatomic, weak) id streamingDelegate; #pragma mark - API Level diff --git a/ADNKit/ANKStreamContext.m b/ADNKit/ANKStreamContext.m index 5eca600..08ccb5c 100644 --- a/ADNKit/ANKStreamContext.m +++ b/ADNKit/ANKStreamContext.m @@ -12,11 +12,11 @@ @implementation ANKStreamContext #pragma mark - Designated Initializer -- (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle updateBlock:(ANKClientCompletionBlock)updateBlock { +- (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle streamingDelegate:(id)streamingDelegate if ((self = [super init])) { self.identifier = identifier; self.socketShuttle = socketShuttle; - self.updateBlock = updateBlock; + self.streamingDelegate = streamingDelegate; } return self; From 47a49d29593705416b72a32852b514e0ab958530 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 11 Jun 2013 18:30:41 -0700 Subject: [PATCH 18/69] Call back the delegate. --- ADNKit/ANKClient.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 888ac48..dc80b7a 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -405,8 +405,11 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } NSDictionary *metaDict = JSON[@"meta"]; + ANKAPIResponseMeta *responseMeta = metaDict ? [ANKAPIResponseMeta objectFromJSONDictionary:metaDict] : nil; + NSString *connectionID = metaDict[@"connection_id"]; - + NSDictionary *dataDict = JSON[@"data"]; + BOOL isConnectionIDMessage = connectionID != nil; ANKStreamContext *context = [self.sockets filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"socketShuttle == %@", socket]].anyObject; @@ -422,11 +425,11 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { context.identifier = connectionID; context.socketShuttle = nil; } else { - context.updateBlock(message, nil, nil); +#warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... + [context.streamingDelegate client:self didReceiveObject:dataDict withMeta:responseMeta]; } NSLog(@"Message: %@", message); } - @end From 818baeed041bb25f23b32db5dbf919fa9735a33f Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 11 Jun 2013 19:33:53 -0700 Subject: [PATCH 19/69] Maybe we're getting somewhere... --- ADNKit/ANKClient.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index dc80b7a..5e37422 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -34,6 +34,7 @@ @interface ANKClient () @property (nonatomic, strong) NSMutableSet *sockets; @property (nonatomic) dispatch_semaphore_t streamingTokenSemaphore; +@property (nonatomic) dispatch_queue_t streamingWaitQueue; - (void)initializeHTTPAuthClient; - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler; @@ -74,6 +75,8 @@ - (id)init { [self addObserver:self forKeyPath:@"shouldRequestAnnotations" options:NSKeyValueObservingOptionNew context:nil]; self.streamingTokenSemaphore = dispatch_semaphore_create(0); + self.streamingWaitQueue = dispatch_queue_create("com.adnkit.adnkit.streaming", DISPATCH_QUEUE_SERIAL); + self.sockets = [[NSMutableSet alloc] init]; } @@ -389,6 +392,8 @@ - (void)spawnUserStreamConnectionIDRequestWithDelegate:(id ANKStreamContext *context = [[ANKStreamContext alloc] initWithIdentifier:nil socketShuttle:shuttle streamingDelegate:streamingDelegate]; [self.sockets addObject:context]; + + [self.operationQueue setSuspended:YES]; } @@ -424,6 +429,10 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { context.identifier = connectionID; context.socketShuttle = nil; + + dispatch_semaphore_signal(self.streamingTokenSemaphore); + + [self.operationQueue setSuspended:[self.sockets filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == nil"]].count > 0]; } else { #warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... [context.streamingDelegate client:self didReceiveObject:dataDict withMeta:responseMeta]; From c45ba57ce2cda97c70926f00da5e103e6c267d1a Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 11 Jun 2013 22:41:15 -0700 Subject: [PATCH 20/69] There, this fixes things and prevents hold ups and queue bullshit. --- ADNKit/ANKClient.m | 29 +++++++++-------------------- ADNKit/ANKStreamContext.h | 5 ++++- ADNKit/ANKStreamContext.m | 18 ++++++++++++++++-- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 5e37422..eaaf1f1 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -328,8 +328,14 @@ - (id)objectForKeyInAuthenticatedUserDefaults:(NSString *)key { #pragma mark - #pragma mark Streams -- (void)requestStreamingUpdatesWithDelegate:(id)delegate { - [self spawnUserStreamConnectionIDRequestWithDelegate:delegate]; +- (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation withDelegate:(id)delegate { + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:(NSString *)ADNAPIUserStreamEndpointURL]]; + + NSString *authorizationKey = @"Authorization"; + [request setValue:[self defaultValueForHeader:authorizationKey] forHTTPHeaderField:authorizationKey]; + + ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:operation identifier:nil socketShuttle:[[KATSocketShuttle alloc] initWithRequest:request delegate:self] streamingDelegate:delegate]; + [self.sockets addObject:context]; } @@ -382,21 +388,6 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err } -- (void)spawnUserStreamConnectionIDRequestWithDelegate:(id)streamingDelegate { - NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:(NSString *)ADNAPIUserStreamEndpointURL]]; - - NSString *authorizationKey = @"Authorization"; - [request setValue:[self defaultValueForHeader:authorizationKey] forHTTPHeaderField:authorizationKey]; - - KATSocketShuttle *shuttle = [[KATSocketShuttle alloc] initWithRequest:request delegate:self]; - - ANKStreamContext *context = [[ANKStreamContext alloc] initWithIdentifier:nil socketShuttle:shuttle streamingDelegate:streamingDelegate]; - [self.sockets addObject:context]; - - [self.operationQueue setSuspended:YES]; -} - - #pragma mark - #pragma mark KATSocketShuttleDelegate @@ -429,10 +420,8 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { context.identifier = connectionID; context.socketShuttle = nil; - - dispatch_semaphore_signal(self.streamingTokenSemaphore); - [self.operationQueue setSuspended:[self.sockets filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == nil"]].count > 0]; +#warning This is where we should connect to the now-provided URL request from the context. } else { #warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... [context.streamingDelegate client:self didReceiveObject:dataDict withMeta:responseMeta]; diff --git a/ADNKit/ANKStreamContext.h b/ADNKit/ANKStreamContext.h index 2932878..6d27147 100644 --- a/ADNKit/ANKStreamContext.h +++ b/ADNKit/ANKStreamContext.h @@ -12,15 +12,18 @@ #pragma mark - Designated Initializer -- (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle streamingDelegate:(id)streamingDelegate; +- (id)initWithBaseOperation:(ANKJSONRequestOperation *)operation identifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle streamingDelegate:(id)streamingDelegate; #pragma mark - Internal @property (nonatomic, strong) KATSocketShuttle *socketShuttle; @property (nonatomic, weak) id streamingDelegate; +@property (nonatomic, strong) ANKJSONRequestOperation *baseOperation; #pragma mark - API Level @property (nonatomic, copy) NSString *identifier; +- (NSURLRequest *)streamingOperationRequest; + @end diff --git a/ADNKit/ANKStreamContext.m b/ADNKit/ANKStreamContext.m index 08ccb5c..77f8441 100644 --- a/ADNKit/ANKStreamContext.m +++ b/ADNKit/ANKStreamContext.m @@ -10,10 +10,12 @@ @implementation ANKStreamContext -#pragma mark - Designated Initializer +#pragma mark - +#pragma mark Designated Initializer -- (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle streamingDelegate:(id)streamingDelegate +- (id)initWithBaseOperation:(ANKJSONRequestOperation *)operation identifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle streamingDelegate:(id)streamingDelegate { if ((self = [super init])) { + self.baseOperation = operation; self.identifier = identifier; self.socketShuttle = socketShuttle; self.streamingDelegate = streamingDelegate; @@ -22,4 +24,16 @@ - (id)initWithIdentifier:(NSString *)identifier socketShuttle:(KATSocketShuttle return self; } +#pragma mark - +#pragma mark Convenience + +- (NSURLRequest *)streamingOperationRequest +{ + NSMutableURLRequest *request = self.baseOperation.request.mutableCopy; + request.URL = [NSURL URLWithString:[request.URL.absoluteString stringByAppendingFormat:@"&connection_id=%@", self.identifier]]; + + return request; +} + + @end From 41c5d6788c4163ae975b627fab0e9acf30ee9e8c Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 11 Jun 2013 22:41:59 -0700 Subject: [PATCH 21/69] Fixes header and removes unneeded properties and initializers. --- ADNKit/ANKClient.h | 2 +- ADNKit/ANKClient.m | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/ADNKit/ANKClient.h b/ADNKit/ANKClient.h index 6f1c539..039d3bc 100644 --- a/ADNKit/ANKClient.h +++ b/ADNKit/ANKClient.h @@ -129,6 +129,6 @@ typedef void (^ANKClientCompletionBlock)(id responseObject, ANKAPIResponseMeta * #pragma mark - #pragma mark - Streams -- (void)requestStreamingUpdatesWithDelegate:(id)delegate; +- (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation withDelegate:(id)delegate; @end diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index eaaf1f1..f5edc25 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -33,8 +33,6 @@ @interface ANKClient () @property (readwrite, strong) ANKUser *authenticatedUser; @property (nonatomic, strong) NSMutableSet *sockets; -@property (nonatomic) dispatch_semaphore_t streamingTokenSemaphore; -@property (nonatomic) dispatch_queue_t streamingWaitQueue; - (void)initializeHTTPAuthClient; - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler; @@ -74,9 +72,6 @@ - (id)init { [self addObserver:self forKeyPath:@"accessToken" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:@"shouldRequestAnnotations" options:NSKeyValueObservingOptionNew context:nil]; - self.streamingTokenSemaphore = dispatch_semaphore_create(0); - self.streamingWaitQueue = dispatch_queue_create("com.adnkit.adnkit.streaming", DISPATCH_QUEUE_SERIAL); - self.sockets = [[NSMutableSet alloc] init]; } From e39b8f8641b3d1c1f19484bf59dcdad8f85d9348 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 15 Jun 2013 14:43:36 -0700 Subject: [PATCH 22/69] Hey, it actually works now. --- ADNKit/ANKClient.m | 63 +++++++++++++++++++++++++-------------- ADNKit/ANKStreamContext.m | 16 +++++----- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index f5edc25..f2e4561 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -32,7 +32,9 @@ @interface ANKClient () @property (strong) NSString *webAuthRedirectURI; @property (readwrite, strong) ANKUser *authenticatedUser; -@property (nonatomic, strong) NSMutableSet *sockets; +@property (nonatomic, strong) KATSocketShuttle *socketShuttle; +@property (nonatomic, copy) NSString *streamingConnectionID; +@property (nonatomic, strong) NSMutableSet *socketContexts; - (void)initializeHTTPAuthClient; - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler; @@ -68,11 +70,11 @@ - (id)init { [self setDefaultHeader:@"Accept" value:@"application/json"]; [self registerHTTPOperationClass:[ANKJSONRequestOperation class]]; - + [self addObserver:self forKeyPath:@"accessToken" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:@"shouldRequestAnnotations" options:NSKeyValueObservingOptionNew context:nil]; - self.sockets = [[NSMutableSet alloc] init]; + self.socketContexts = [[NSMutableSet alloc] init]; } return self; @@ -324,13 +326,37 @@ - (id)objectForKeyInAuthenticatedUserDefaults:(NSString *)key { #pragma mark Streams - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation withDelegate:(id)delegate { - NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:(NSString *)ADNAPIUserStreamEndpointURL]]; + [operation pause]; + + ANKJSONRequestOperation *finalizedOperation = operation; - NSString *authorizationKey = @"Authorization"; - [request setValue:[self defaultValueForHeader:authorizationKey] forHTTPHeaderField:authorizationKey]; + if (!self.streamingConnectionID) { + + NSMutableURLRequest *streamingRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"wss://stream-channel.app.net/stream/user"]]; + [streamingRequest setValue:[self defaultValueForHeader:@"Authorization"] forHTTPHeaderField:@"Authorization"]; + self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:streamingRequest delegate:self]; + } else { + finalizedOperation = [self reconfigureOperationForStreaming:operation]; + } - ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:operation identifier:nil socketShuttle:[[KATSocketShuttle alloc] initWithRequest:request delegate:self] streamingDelegate:delegate]; - [self.sockets addObject:context]; + ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:finalizedOperation identifier:[[NSProcessInfo processInfo] globallyUniqueString] socketShuttle:nil streamingDelegate:delegate]; + [self.socketContexts addObject:context]; +} + + +- (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOperation *)operation +{ + NSURL *modifiedURL = [NSURL URLWithString:[operation.request.URL.absoluteString stringByAppendingFormat:@"&connection_id=%@", self.streamingConnectionID]]; + NSMutableURLRequest *request = [operation.request mutableCopy]; + request.URL = modifiedURL; + + [operation cancel]; + + + ANKJSONRequestOperation *newOperation = [[ANKJSONRequestOperation alloc] initWithRequest:request]; + [self enqueueHTTPRequestOperation:newOperation]; + + return newOperation; } @@ -399,26 +425,19 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { ANKAPIResponseMeta *responseMeta = metaDict ? [ANKAPIResponseMeta objectFromJSONDictionary:metaDict] : nil; NSString *connectionID = metaDict[@"connection_id"]; + NSString *subscriptionID = metaDict[@"subscription_id"]; NSDictionary *dataDict = JSON[@"data"]; BOOL isConnectionIDMessage = connectionID != nil; - ANKStreamContext *context = [self.sockets filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"socketShuttle == %@", socket]].anyObject; - - if (!context) { - NSLog(@"Critical error: there was no stream context found."); - return; - } - if (isConnectionIDMessage) { - [socket disconnect]; - - context.identifier = connectionID; - context.socketShuttle = nil; - -#warning This is where we should connect to the now-provided URL request from the context. + self.streamingConnectionID = connectionID; + for (ANKStreamContext *streamContext in self.socketContexts) { + streamContext.baseOperation = [self reconfigureOperationForStreaming:streamContext.baseOperation]; + } } else { -#warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... + #warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... + ANKStreamContext *context = [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]].anyObject; [context.streamingDelegate client:self didReceiveObject:dataDict withMeta:responseMeta]; } diff --git a/ADNKit/ANKStreamContext.m b/ADNKit/ANKStreamContext.m index 77f8441..e0806b8 100644 --- a/ADNKit/ANKStreamContext.m +++ b/ADNKit/ANKStreamContext.m @@ -27,13 +27,13 @@ - (id)initWithBaseOperation:(ANKJSONRequestOperation *)operation identifier:(NSS #pragma mark - #pragma mark Convenience -- (NSURLRequest *)streamingOperationRequest -{ - NSMutableURLRequest *request = self.baseOperation.request.mutableCopy; - request.URL = [NSURL URLWithString:[request.URL.absoluteString stringByAppendingFormat:@"&connection_id=%@", self.identifier]]; - - return request; -} - +//- (NSURLRequest *)streamingOperationRequest +//{ +// NSMutableURLRequest *request = self.baseOperation.request.mutableCopy; +// request.URL = [NSURL URLWithString:[[[[request.URL.absoluteString stringByAppendingFormat:@"&connection_id=%@", self.identifier] stringByReplacingOccurrencesOfString:request.URL.scheme withString:@"wss"] stringByReplacingOccurrencesOfString:request.URL.host withString:@"stream-channel.app.net"]]]; +// +// return request; +//} +// @end From ea19975ee9c7e884294666ec015c61491bd586ac Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 15 Jun 2013 14:56:00 -0700 Subject: [PATCH 23/69] Minor revisions to structuring and verbiage. --- ADNKit/ANKClient.m | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index f2e4561..ac85c8d 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -417,7 +417,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error]; if (error) { - NSLog(@"Critical error getting JSON. %@", error); + NSLog(@"JSON couldn't be parsed. %@", error); return; } @@ -432,16 +432,17 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { if (isConnectionIDMessage) { self.streamingConnectionID = connectionID; - for (ANKStreamContext *streamContext in self.socketContexts) { + + for (ANKStreamContext *streamContext in self.socketContexts) streamContext.baseOperation = [self reconfigureOperationForStreaming:streamContext.baseOperation]; - } + } else { - #warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... - ANKStreamContext *context = [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]].anyObject; - [context.streamingDelegate client:self didReceiveObject:dataDict withMeta:responseMeta]; - } - NSLog(@"Message: %@", message); + for (ANKStreamContext *streamContext in [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { + #warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... + [streamContext.streamingDelegate client:self didReceiveObject:dataDict withMeta:responseMeta]; + } + } } @end From 6668c325f0b4842dcebc2df1fb5b7b68d7aa2a1b Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 15 Jun 2013 15:04:31 -0700 Subject: [PATCH 24/69] Switch to just passing back the entirety of the JSON. --- ADNKit/ANKClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index ac85c8d..4650acd 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -440,7 +440,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { for (ANKStreamContext *streamContext in [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { #warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... - [streamContext.streamingDelegate client:self didReceiveObject:dataDict withMeta:responseMeta]; + [streamContext.streamingDelegate client:self didReceiveObject:JSON withMeta:responseMeta]; } } } From 5b9b561f891d93b08a3d63aec00d7900c1454f07 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 15 Jun 2013 16:04:27 -0700 Subject: [PATCH 25/69] Okay, now it actually messages the delegate. Yes. --- ADNKit/ANKClient.m | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 4650acd..9d0541b 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -329,6 +329,7 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation [operation pause]; ANKJSONRequestOperation *finalizedOperation = operation; + NSString *subscriptionID = nil; if (!self.streamingConnectionID) { @@ -336,17 +337,21 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation [streamingRequest setValue:[self defaultValueForHeader:@"Authorization"] forHTTPHeaderField:@"Authorization"]; self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:streamingRequest delegate:self]; } else { - finalizedOperation = [self reconfigureOperationForStreaming:operation]; + + finalizedOperation = [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID]; } - ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:finalizedOperation identifier:[[NSProcessInfo processInfo] globallyUniqueString] socketShuttle:nil streamingDelegate:delegate]; + ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:finalizedOperation identifier:subscriptionID socketShuttle:nil streamingDelegate:delegate]; [self.socketContexts addObject:context]; } -- (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOperation *)operation +- (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOperation *)operation subscriptionID:(NSString **)subscriptionID { - NSURL *modifiedURL = [NSURL URLWithString:[operation.request.URL.absoluteString stringByAppendingFormat:@"&connection_id=%@", self.streamingConnectionID]]; + NSString *uniqueString = [[NSProcessInfo processInfo] globallyUniqueString]; + *subscriptionID = uniqueString; + + NSURL *modifiedURL = [NSURL URLWithString:[operation.request.URL.absoluteString stringByAppendingFormat:@"&connection_id=%@&subscription_id=%@", self.streamingConnectionID, uniqueString]]; NSMutableURLRequest *request = [operation.request mutableCopy]; request.URL = modifiedURL; @@ -425,22 +430,24 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { ANKAPIResponseMeta *responseMeta = metaDict ? [ANKAPIResponseMeta objectFromJSONDictionary:metaDict] : nil; NSString *connectionID = metaDict[@"connection_id"]; - NSString *subscriptionID = metaDict[@"subscription_id"]; + NSArray *subscriptionIDs = metaDict[@"subscription_ids"]; NSDictionary *dataDict = JSON[@"data"]; - BOOL isConnectionIDMessage = connectionID != nil; - - if (isConnectionIDMessage) { + if (!self.streamingConnectionID) { self.streamingConnectionID = connectionID; - for (ANKStreamContext *streamContext in self.socketContexts) - streamContext.baseOperation = [self reconfigureOperationForStreaming:streamContext.baseOperation]; + for (ANKStreamContext *streamContext in self.socketContexts) { + NSString *newID = nil; + streamContext.baseOperation = [self reconfigureOperationForStreaming:streamContext.baseOperation subscriptionID:&newID]; + streamContext.identifier = newID; + } } else { - - for (ANKStreamContext *streamContext in [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { - #warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... - [streamContext.streamingDelegate client:self didReceiveObject:JSON withMeta:responseMeta]; + for (NSString *subscriptionID in subscriptionIDs) { + for (ANKStreamContext *streamContext in [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { +#warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... + [streamContext.streamingDelegate client:self didReceiveObject:JSON withMeta:responseMeta]; + } } } } From cb68b86c1bacf67cfd69dd5f2bc7729f8d90ab63 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 16 Jun 2013 16:46:37 -0700 Subject: [PATCH 26/69] Minor revisions. --- ADNKit/ANKClient+ANKRequestsAPI.m | 2 +- ADNKit/ANKClient.m | 9 ++++----- ADNKit/ANKJSONRequestOperation.h | 2 ++ ADNKit/ANKJSONRequestOperation.m | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ADNKit/ANKClient+ANKRequestsAPI.m b/ADNKit/ANKClient+ANKRequestsAPI.m index 476c3f5..e21ee28 100644 --- a/ADNKit/ANKClient+ANKRequestsAPI.m +++ b/ADNKit/ANKClient+ANKRequestsAPI.m @@ -1,4 +1,4 @@ -/* + /* Copyright (c) 2013, Joel Levin All rights reserved. diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 9d0541b..508fbd6 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -15,6 +15,7 @@ #import "ANKPaginationSettings.h" #import "ANKGeneralParameters.h" #import "ANKAPIResponseMeta.h" +#import "ANKAPIResponse.h" #import "ANKTokenStatus.h" #import "ANKResourceMap.h" #import "ANKUser.h" @@ -357,7 +358,6 @@ - (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOpe [operation cancel]; - ANKJSONRequestOperation *newOperation = [[ANKJSONRequestOperation alloc] initWithRequest:request]; [self enqueueHTTPRequestOperation:newOperation]; @@ -427,11 +427,10 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } NSDictionary *metaDict = JSON[@"meta"]; - ANKAPIResponseMeta *responseMeta = metaDict ? [ANKAPIResponseMeta objectFromJSONDictionary:metaDict] : nil; - NSString *connectionID = metaDict[@"connection_id"]; NSArray *subscriptionIDs = metaDict[@"subscription_ids"]; - NSDictionary *dataDict = JSON[@"data"]; + + ANKAPIResponse *response = [[ANKAPIResponse alloc] initWithResponseObject:JSON]; if (!self.streamingConnectionID) { self.streamingConnectionID = connectionID; @@ -446,7 +445,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { for (NSString *subscriptionID in subscriptionIDs) { for (ANKStreamContext *streamContext in [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { #warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... - [streamContext.streamingDelegate client:self didReceiveObject:JSON withMeta:responseMeta]; + [streamContext.streamingDelegate client:self didReceiveObject:JSON withMeta:response.meta]; } } } diff --git a/ADNKit/ANKJSONRequestOperation.h b/ADNKit/ANKJSONRequestOperation.h index 7257799..8b2c8b4 100644 --- a/ADNKit/ANKJSONRequestOperation.h +++ b/ADNKit/ANKJSONRequestOperation.h @@ -13,4 +13,6 @@ @interface ANKJSONRequestOperation : AFJSONRequestOperation +@property (nonatomic) Class resourceClass; + @end diff --git a/ADNKit/ANKJSONRequestOperation.m b/ADNKit/ANKJSONRequestOperation.m index f6771b7..69759e6 100644 --- a/ADNKit/ANKJSONRequestOperation.m +++ b/ADNKit/ANKJSONRequestOperation.m @@ -37,4 +37,5 @@ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *, id))su }]; } + @end From 6252e6d546bfd1aa4efa3d96f250b7bdf8ebee0c Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 16 Jun 2013 19:04:17 -0700 Subject: [PATCH 27/69] Okay, so we\'ll have to identify the incoming JSON\'s type to parse it. --- ADNKit/ANKClient.m | 20 +++++++++++++++----- ADNKit/ANKJSONRequestOperation.h | 2 -- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 508fbd6..421a9bf 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -339,7 +339,7 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:streamingRequest delegate:self]; } else { - finalizedOperation = [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID]; + finalizedOperation = [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID streamingDelegate:delegate]; } ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:finalizedOperation identifier:subscriptionID socketShuttle:nil streamingDelegate:delegate]; @@ -347,7 +347,7 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation } -- (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOperation *)operation subscriptionID:(NSString **)subscriptionID +- (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOperation *)operation subscriptionID:(NSString **)subscriptionID streamingDelegate:(id)streamingDelegate { NSString *uniqueString = [[NSProcessInfo processInfo] globallyUniqueString]; *subscriptionID = uniqueString; @@ -365,6 +365,15 @@ - (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOpe } +- (id)parsedObjectFromJSON:(NSDictionary *)JSON +{ + NSDictionary *dataDictionary = JSON[@"data"]; + + + return JSON; +} + + #pragma mark - #pragma mark Internal API @@ -437,18 +446,19 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { for (ANKStreamContext *streamContext in self.socketContexts) { NSString *newID = nil; - streamContext.baseOperation = [self reconfigureOperationForStreaming:streamContext.baseOperation subscriptionID:&newID]; + streamContext.baseOperation = [self reconfigureOperationForStreaming:streamContext.baseOperation subscriptionID:&newID streamingDelegate:streamContext.streamingDelegate]; streamContext.identifier = newID; } } else { for (NSString *subscriptionID in subscriptionIDs) { for (ANKStreamContext *streamContext in [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { -#warning No parsing is completed. Not really sure how to map this into ADNKit's existing parsing model, so... - [streamContext.streamingDelegate client:self didReceiveObject:JSON withMeta:response.meta]; + [streamContext.streamingDelegate client:self didReceiveObject:[self parsedObjectFromJSON:JSON] withMeta:response.meta]; } } } + + NSLog(@"%@", JSON); } @end diff --git a/ADNKit/ANKJSONRequestOperation.h b/ADNKit/ANKJSONRequestOperation.h index 8b2c8b4..7257799 100644 --- a/ADNKit/ANKJSONRequestOperation.h +++ b/ADNKit/ANKJSONRequestOperation.h @@ -13,6 +13,4 @@ @interface ANKJSONRequestOperation : AFJSONRequestOperation -@property (nonatomic) Class resourceClass; - @end From 6ea1bee238d3b582e3dce356077728a4cf750590 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 16 Jun 2013 21:22:23 -0700 Subject: [PATCH 28/69] This should add parsing. --- ADNKit/ANKClient.m | 83 +++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 421a9bf..5ca76ba 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -1,9 +1,9 @@ /* Copyright (c) 2013, Joel Levin All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of ADNKit nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -19,6 +19,9 @@ #import "ANKTokenStatus.h" #import "ANKResourceMap.h" #import "ANKUser.h" +#import "ANKMessage.h" +#import "ANKFile.h" +#import "ANKPost.h" #import "ANKClient+ANKTokenStatus.h" #import #import "ANKStreamContext.h" @@ -52,7 +55,7 @@ + (instancetype)sharedClient { dispatch_once(&onceToken, ^{ sharedANKClient = [[ANKClient alloc] init]; }); - + return sharedANKClient; } @@ -90,7 +93,7 @@ - (void)dealloc { - (id)copyWithZone:(NSZone *)zone { ANKClient *copy = [[[self class] alloc] init]; - + copy.accessToken = [self.accessToken copyWithZone:zone]; copy.authenticatedUser = [self.authenticatedUser copyWithZone:zone]; copy.generalParameters = [self.generalParameters copyWithZone:zone]; @@ -98,7 +101,7 @@ - (id)copyWithZone:(NSZone *)zone { copy.shouldUseSharedUserDefaultsController = self.shouldUseSharedUserDefaultsController; copy.shouldSynchronizeOnUserDefaultsWrite = self.shouldSynchronizeOnUserDefaultsWrite; copy.responseDecodingType = self.responseDecodingType; - + return copy; } @@ -140,7 +143,7 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)p - (void)authenticateUsername:(NSString *)username password:(NSString *)password clientID:(NSString *)clientID passwordGrantSecret:(NSString *)passwordGrantSecret authScopes:(ANKAuthScope)authScopes completionHandler:(void (^)(BOOL success, NSError *error))completionHander { // http://developers.app.net/docs/authentication/flows/password/ - + NSDictionary *parameters = @{@"client_id": clientID, @"password_grant_secret": passwordGrantSecret, @"grant_type": @"password", @"username": username, @"password": password, @"scope": [[self class] scopeStringForAuthScopes:authScopes]}; [self authenticateWithParameters:parameters handler:completionHander]; } @@ -150,23 +153,23 @@ - (NSURLRequest *)webAuthRequestForClientID:(NSString *)clientID redirectURI:(NS // http://developers.app.net/docs/authentication/flows/web/ self.webAuthRedirectURI = redirectURI; NSMutableString *URLString = [NSMutableString stringWithFormat:@"https://account.app.net/oauth/authenticate?client_id=%@&response_type=code", clientID]; - + if (authScopes) { [URLString appendFormat:@"&scope=%@", [[self class] scopeStringForAuthScopes:authScopes]]; } - + if (redirectURI) { [URLString appendFormat:@"&redirect_uri=%@", redirectURI]; } - + if (shouldBeAppStoreCompliant) { [URLString appendString:@"&adnview=appstore"]; } - + if (state) { [URLString appendFormat:@"&state=%@", state]; } - + NSURL *URL = [NSURL URLWithString:URLString]; return [NSURLRequest requestWithURL:URL cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:60]; } @@ -181,9 +184,9 @@ - (void)authenticateWebAuthAccessCode:(NSString *)accessCode forClientID:(NSStri + (NSString *)scopeStringForAuthScopes:(ANKAuthScope)scopes { if (scopes == ANKAuthScopeNone) return nil; - + NSMutableArray *scopeValues = [NSMutableArray array]; - + if ((scopes & ANKAuthScopeBasic) == ANKAuthScopeBasic) [scopeValues addObject:@"basic"]; if ((scopes & ANKAuthScopeStream) == ANKAuthScopeStream) [scopeValues addObject:@"stream"]; if ((scopes & ANKAuthScopeEmail) == ANKAuthScopeEmail) [scopeValues addObject:@"email"]; @@ -194,14 +197,14 @@ + (NSString *)scopeStringForAuthScopes:(ANKAuthScope)scopes { if ((scopes & ANKAuthScopeUpdateProfile) == ANKAuthScopeUpdateProfile) [scopeValues addObject:@"update_profile"]; if ((scopes & ANKAuthScopeExport) == ANKAuthScopeExport) [scopeValues addObject:@"export"]; if ((scopes & ANKAuthScopeFiles) == ANKAuthScopeFiles) [scopeValues addObject:@"files"]; - + return [scopeValues componentsJoinedByString:@","]; } + (NSArray *)scopeDescriptionsForScope:(ANKAuthScope)scope { NSMutableArray *scopeDescriptions = [NSMutableArray array]; - + static NSDictionary *scopeDescriptionMap = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -216,15 +219,15 @@ + (NSArray *)scopeDescriptionsForScope:(ANKAuthScope)scope { mapping[@"update_profile"] = @"Update your profile information"; mapping[@"export"] = @"Bulk export all of your App.net data"; mapping[@"files"] = @"Manage your files for you"; - + scopeDescriptionMap = mapping; }); - + NSArray *scopeKeys = [[self scopeStringForAuthScopes:scope] componentsSeparatedByString:@","]; for (NSString *scopeKey in scopeKeys) { [scopeDescriptions addObject:scopeDescriptionMap[scopeKey]]; } - + return scopeDescriptions; } @@ -264,7 +267,7 @@ - (void)logOutAndDeauthorizeUserTokenWithCompletion:(ANKClientCompletionBlock)co if (!meta.isError && !error) { [self logOut]; } - + if (completionHandler) { completionHandler(responseObject, meta, error); } @@ -303,13 +306,13 @@ - (void)setObject:(id)object forKeyInAuthenticatedUserDefaults:(NSString *)key { if (self.isAuthenticated) { NSDictionary *settings = [self authenticatedUserDefaults] ?: @{}; NSMutableDictionary *modifiedSettings = [NSMutableDictionary dictionaryWithDictionary:settings]; - + if (object) { modifiedSettings[key] = object; } else { [modifiedSettings removeObjectForKey:key]; } - + [self.userDefaults setObject:modifiedSettings forKey:[NSString stringWithFormat:@"ANKUser%@", self.authenticatedUser.userID]]; if (self.shouldSynchronizeOnUserDefaultsWrite) { [self.userDefaults synchronize]; @@ -351,7 +354,7 @@ - (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOpe { NSString *uniqueString = [[NSProcessInfo processInfo] globallyUniqueString]; *subscriptionID = uniqueString; - + NSURL *modifiedURL = [NSURL URLWithString:[operation.request.URL.absoluteString stringByAppendingFormat:@"&connection_id=%@&subscription_id=%@", self.streamingConnectionID, uniqueString]]; NSMutableURLRequest *request = [operation.request mutableCopy]; request.URL = modifiedURL; @@ -367,8 +370,36 @@ - (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOpe - (id)parsedObjectFromJSON:(NSDictionary *)JSON { - NSDictionary *dataDictionary = JSON[@"data"]; - + if (self.responseDecodingType != ANKResponseDecodingTypeNone) { + + NSSet *dataSet = [[NSSet alloc] initWithArray:JSON[@"data"]]; + NSDictionary *sampleObject = [dataSet anyObject]; + + if (sampleObject) { + BOOL isUser = sampleObject[@"username"] && sampleObject[@"timezone"] && sampleObject[@"avatar_image"]; + BOOL isMessage = sampleObject[@"channel_id"] && !sampleObject[@"canonical_url"] && !sampleObject[@"num_stars"]; + BOOL isPost = sampleObject[@"num_stars"] && sampleObject[@"user"] && sampleObject[@"canonical_url"] && sampleObject[@"text"]; + // BOOL isChannel = sampleObject[@"has_unread"] && sampleObject[@"readers"]; + BOOL isFile = sampleObject[@"complete"] && sampleObject[@"derived_files"]; + + ANKAPIResponse *response = [[ANKAPIResponse alloc] initWithResponseObject:JSON]; + Class resourceClass = nil; + + if (isUser) + resourceClass = [ANKUser class]; + else if (isMessage) + resourceClass = [ANKMessage class]; + else if (isPost) + resourceClass = [ANKPost class]; + else if (isFile) + resourceClass = [ANKFile class]; + // else if (isChannel) + // resourceClass = [ANKChannel class]; + + if (resourceClass) + return [self unboxCollectionResponse:response ofResourceClass:resourceClass]; + } + } return JSON; } @@ -416,7 +447,7 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err if (handler) { handler(wasSuccessful, error); } - + self.authHTTPClient = nil; self.webAuthCompletionHandler = nil; self.webAuthRedirectURI = nil; @@ -457,7 +488,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } } } - + NSLog(@"%@", JSON); } From f310af8759f90ba3ca50c3f203fd71e69ba940ee Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 16 Jun 2013 21:33:10 -0700 Subject: [PATCH 29/69] Remove debug log. --- ADNKit/ANKClient.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 5ca76ba..9faa568 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -488,8 +488,6 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } } } - - NSLog(@"%@", JSON); } @end From 8121bb8e1ea24e68ee1bb95000885d6c999f34f0 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 14:20:56 -0700 Subject: [PATCH 30/69] Minor optimization. --- ADNKit/ANKClient.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 9faa568..fc4e4c4 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -483,8 +483,10 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } else { for (NSString *subscriptionID in subscriptionIDs) { + id object = [self parsedObjectFromJSON:JSON]; + for (ANKStreamContext *streamContext in [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { - [streamContext.streamingDelegate client:self didReceiveObject:[self parsedObjectFromJSON:JSON] withMeta:response.meta]; + [streamContext.streamingDelegate client:self didReceiveObject:object withMeta:response.meta]; } } } From b960cd3b8172ea03cc8b8ae86b800ec3e04df9a5 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 14:26:25 -0700 Subject: [PATCH 31/69] Implement all of the new KATSocketShuttleDelegate methods and send ones for connecting/opening. --- ADNKit/ANKClient.m | 18 ++++++++++++++++++ External/SocketShuttle | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index fc4e4c4..3801923 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -457,6 +457,14 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err #pragma mark - #pragma mark KATSocketShuttleDelegate +- (void)socketDidOpen:(KATSocketShuttle *)socket +{ + for (iddelegate in [self.socketContexts valueForKey:@"streamingDelegate"]) { + if ([delegate respondsToSelector:@selector(clientSocketDidConnect:)]) + [delegate clientSocketDidConnect:self]; + } +} + - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { NSError *error = nil; NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error]; @@ -492,4 +500,14 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } } +- (void)socket:(KATSocketShuttle *)socket didFailWithError:(NSError *)error +{ + +} + +- (void)socket:(KATSocketShuttle *)socket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean +{ + +} + @end diff --git a/External/SocketShuttle b/External/SocketShuttle index 0331e99..5703f18 160000 --- a/External/SocketShuttle +++ b/External/SocketShuttle @@ -1 +1 @@ -Subproject commit 0331e992abd94519bb2ea4930917911cee11490f +Subproject commit 5703f186074b7de966e77a4a63031305f721be90 From eed88e585640b9ecbe6dee1f2e0463a5f069353e Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 14:27:39 -0700 Subject: [PATCH 32/69] Add convenience method. --- ADNKit/ANKClient.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 3801923..a95531a 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -404,6 +404,11 @@ - (id)parsedObjectFromJSON:(NSDictionary *)JSON return JSON; } +- (NSArray *)streamingDelegates +{ + return [self.socketContexts valueForKey:@"streamingDelegate"]; +} + #pragma mark - #pragma mark Internal API From c2fb14917d2350f9a824109c5f67344b53db7ba2 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 14:28:06 -0700 Subject: [PATCH 33/69] Revise to match project coding style. --- ADNKit/ANKClient.m | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index a95531a..d323848 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -404,8 +404,7 @@ - (id)parsedObjectFromJSON:(NSDictionary *)JSON return JSON; } -- (NSArray *)streamingDelegates -{ +- (NSArray *)streamingDelegates { return [self.socketContexts valueForKey:@"streamingDelegate"]; } @@ -462,8 +461,7 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err #pragma mark - #pragma mark KATSocketShuttleDelegate -- (void)socketDidOpen:(KATSocketShuttle *)socket -{ +- (void)socketDidOpen:(KATSocketShuttle *)socket { for (iddelegate in [self.socketContexts valueForKey:@"streamingDelegate"]) { if ([delegate respondsToSelector:@selector(clientSocketDidConnect:)]) [delegate clientSocketDidConnect:self]; @@ -505,13 +503,11 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } } -- (void)socket:(KATSocketShuttle *)socket didFailWithError:(NSError *)error -{ +- (void)socket:(KATSocketShuttle *)socket didFailWithError:(NSError *)error { } -- (void)socket:(KATSocketShuttle *)socket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean -{ +- (void)socket:(KATSocketShuttle *)socket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { } From 8875e90242c1a6ce3de6201c5c33208ecd222e98 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 14:36:53 -0700 Subject: [PATCH 34/69] Add some convenience methods for getting the right delegates and generally improving how things are dispatched. --- ADNKit/ANKClient.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index d323848..8443af9 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -408,6 +408,12 @@ - (NSArray *)streamingDelegates { return [self.socketContexts valueForKey:@"streamingDelegate"]; } +- (NSArray *)streamingDelegatesImplementingDelegateMethod:(SEL)delegateMethod { + return [[self streamingDelegates] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id streamingDelegate, NSDictionary *bindings) { + return [streamingDelegate respondsToSelector:delegateMethod]; + }]]; +} + #pragma mark - #pragma mark Internal API @@ -462,10 +468,11 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err #pragma mark KATSocketShuttleDelegate - (void)socketDidOpen:(KATSocketShuttle *)socket { - for (iddelegate in [self.socketContexts valueForKey:@"streamingDelegate"]) { - if ([delegate respondsToSelector:@selector(clientSocketDidConnect:)]) - [delegate clientSocketDidConnect:self]; - } + + __weak typeof(self) weakSelf = self; + [[self streamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidConnect:)] enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(idstreamingDelegate, NSUInteger idx, BOOL *stop) { + [streamingDelegate clientSocketDidConnect:weakSelf]; + }]; } - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { From e191178911ca1cbdae191a60737558f27053285e Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 14:39:01 -0700 Subject: [PATCH 35/69] Get your types right, idiot. --- ADNKit/ANKClient.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 8443af9..bffa00d 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -404,12 +404,12 @@ - (id)parsedObjectFromJSON:(NSDictionary *)JSON return JSON; } -- (NSArray *)streamingDelegates { +- (NSSet *)streamingDelegates { return [self.socketContexts valueForKey:@"streamingDelegate"]; } -- (NSArray *)streamingDelegatesImplementingDelegateMethod:(SEL)delegateMethod { - return [[self streamingDelegates] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id streamingDelegate, NSDictionary *bindings) { +- (NSSet *)streamingDelegatesImplementingDelegateMethod:(SEL)delegateMethod { + return [[self streamingDelegates] filteredSetUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id streamingDelegate, NSDictionary *bindings) { return [streamingDelegate respondsToSelector:delegateMethod]; }]]; } @@ -470,7 +470,7 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err - (void)socketDidOpen:(KATSocketShuttle *)socket { __weak typeof(self) weakSelf = self; - [[self streamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidConnect:)] enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(idstreamingDelegate, NSUInteger idx, BOOL *stop) { + [[self streamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidConnect:)] enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id streamingDelegate, BOOL *stop) { [streamingDelegate clientSocketDidConnect:weakSelf]; }]; } From 040a21a526c9242943410b94d57d2fb75decdff7 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 14:44:26 -0700 Subject: [PATCH 36/69] Concurrency = no. --- ADNKit/ANKClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index bffa00d..b52c529 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -470,7 +470,7 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err - (void)socketDidOpen:(KATSocketShuttle *)socket { __weak typeof(self) weakSelf = self; - [[self streamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidConnect:)] enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id streamingDelegate, BOOL *stop) { + [[self streamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidConnect:)] enumerateObjectsUsingBlock:^(id streamingDelegate, BOOL *stop) { [streamingDelegate clientSocketDidConnect:weakSelf]; }]; } From 116d613c57695c94f32169acd70034c07c40a67f Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 17:58:35 -0700 Subject: [PATCH 37/69] Adds a convenience method and sends the rest of the methods. --- ADNKit/ANKClient.m | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index b52c529..ad8ca6a 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -38,7 +38,7 @@ @interface ANKClient () @property (nonatomic, strong) KATSocketShuttle *socketShuttle; @property (nonatomic, copy) NSString *streamingConnectionID; -@property (nonatomic, strong) NSMutableSet *socketContexts; +@property (nonatomic, strong) NSMutableSet *streamContexts; - (void)initializeHTTPAuthClient; - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler; @@ -78,7 +78,7 @@ - (id)init { [self addObserver:self forKeyPath:@"accessToken" options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:@"shouldRequestAnnotations" options:NSKeyValueObservingOptionNew context:nil]; - self.socketContexts = [[NSMutableSet alloc] init]; + self.streamContexts = [[NSMutableSet alloc] init]; } return self; @@ -405,9 +405,10 @@ - (id)parsedObjectFromJSON:(NSDictionary *)JSON } - (NSSet *)streamingDelegates { - return [self.socketContexts valueForKey:@"streamingDelegate"]; + return [self.streamContexts valueForKey:@"streamingDelegate"]; } + - (NSSet *)streamingDelegatesImplementingDelegateMethod:(SEL)delegateMethod { return [[self streamingDelegates] filteredSetUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id streamingDelegate, NSDictionary *bindings) { return [streamingDelegate respondsToSelector:delegateMethod]; @@ -415,6 +416,12 @@ - (NSSet *)streamingDelegatesImplementingDelegateMethod:(SEL)delegateMethod { } +- (void)iterateOverStreamingDelegatesImplementingDelegateMethod:(SEL)delegateMethod withBlock:(void (^)(idstreamingDelegate))iterativeBlock { + [[self streamingDelegatesImplementingDelegateMethod:delegateMethod] enumerateObjectsUsingBlock:^(idstreamingDelegate, BOOL *stop) { + iterativeBlock(streamingDelegate); + }]; +} + #pragma mark - #pragma mark Internal API @@ -468,9 +475,8 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err #pragma mark KATSocketShuttleDelegate - (void)socketDidOpen:(KATSocketShuttle *)socket { - __weak typeof(self) weakSelf = self; - [[self streamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidConnect:)] enumerateObjectsUsingBlock:^(id streamingDelegate, BOOL *stop) { + [self iterateOverStreamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidConnect:) withBlock:^(id streamingDelegate) { [streamingDelegate clientSocketDidConnect:weakSelf]; }]; } @@ -493,7 +499,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { if (!self.streamingConnectionID) { self.streamingConnectionID = connectionID; - for (ANKStreamContext *streamContext in self.socketContexts) { + for (ANKStreamContext *streamContext in self.streamContexts) { NSString *newID = nil; streamContext.baseOperation = [self reconfigureOperationForStreaming:streamContext.baseOperation subscriptionID:&newID streamingDelegate:streamContext.streamingDelegate]; streamContext.identifier = newID; @@ -503,7 +509,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { for (NSString *subscriptionID in subscriptionIDs) { id object = [self parsedObjectFromJSON:JSON]; - for (ANKStreamContext *streamContext in [self.socketContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { + for (ANKStreamContext *streamContext in [self.streamContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { [streamContext.streamingDelegate client:self didReceiveObject:object withMeta:response.meta]; } } @@ -511,11 +517,17 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } - (void)socket:(KATSocketShuttle *)socket didFailWithError:(NSError *)error { - + __weak typeof(self) weakSelf = self; + [self iterateOverStreamingDelegatesImplementingDelegateMethod:@selector(client:didDisconnectOnSocketError:) withBlock:^(id streamingDelegate) { + [streamingDelegate client:weakSelf didDisconnectOnSocketError:error]; + }]; } - (void)socket:(KATSocketShuttle *)socket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { - + __weak typeof(self) weakSelf = self; + [self iterateOverStreamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidDisconnect:) withBlock:^(id streamingDelegate) { + [streamingDelegate clientSocketDidDisconnect:weakSelf]; + }]; } @end From af68b08c27354296e649ffd7b4338a3811a37854 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 18:15:48 -0700 Subject: [PATCH 38/69] >_> --- ADNKit/ANKClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index ad8ca6a..4c31408 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -346,7 +346,7 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation } ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:finalizedOperation identifier:subscriptionID socketShuttle:nil streamingDelegate:delegate]; - [self.socketContexts addObject:context]; + [self.streamContexts addObject:context]; } From b06fc83cf8673a1714b78eeae6d815943fe52435 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Tue, 18 Jun 2013 22:58:03 -0700 Subject: [PATCH 39/69] More minor cleanup --- ADNKit/ANKClient.m | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 4c31408..3b31c7b 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -485,10 +485,8 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { NSError *error = nil; NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error]; - if (error) { - NSLog(@"JSON couldn't be parsed. %@", error); + if (error) return; - } NSDictionary *metaDict = JSON[@"meta"]; NSString *connectionID = metaDict[@"connection_id"]; @@ -509,9 +507,8 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { for (NSString *subscriptionID in subscriptionIDs) { id object = [self parsedObjectFromJSON:JSON]; - for (ANKStreamContext *streamContext in [self.streamContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]]) { - [streamContext.streamingDelegate client:self didReceiveObject:object withMeta:response.meta]; - } + for (id streamingDelegate in [[self.streamContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]] valueForKey:@"streamingDelegate"]) + [streamingDelegate client:self didReceiveObject:object withMeta:response.meta]; } } } From b0b2c3de84ef1ec04db54d06bed15cc49f66f1ea Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Thu, 20 Jun 2013 18:16:16 -0700 Subject: [PATCH 40/69] Transfers over the completion block. Kinda critical, and really it should just be copied. --- ADNKit/ANKClient.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 3b31c7b..0dbb436 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -362,6 +362,7 @@ - (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOpe [operation cancel]; ANKJSONRequestOperation *newOperation = [[ANKJSONRequestOperation alloc] initWithRequest:request]; + newOperation.completionBlock = operation.completionBlock; [self enqueueHTTPRequestOperation:newOperation]; return newOperation; From 9dfd1676975d37d47d2d11a9ea5a5dee0d42b4a1 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Fri, 21 Jun 2013 00:10:45 -0700 Subject: [PATCH 41/69] This is ghetto, but it will work. --- ADNKit.xcodeproj/project.pbxproj | 159 +++++++++++++++++++++++++++++-- ADNKit/ANKClient.m | 9 +- ADNKit/ANKJSONRequestOperation.m | 3 + 3 files changed, 157 insertions(+), 14 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 929b6bb..d610ffb 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -1691,10 +1691,128 @@ }; name = Release; }; + 331FA3CA1773E7FB0011DF8E /* TestFlight */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); + IPHONEOS_DEPLOYMENT_TARGET = 5.0; + ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); + SDKROOT = iphoneos; + }; + name = TestFlight; + }; + 331FA3CB1773E7FB0011DF8E /* TestFlight */ = { + isa = XCBuildConfiguration; + buildSettings = { + DSTROOT = /tmp/ADNKit.dst; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); + ONLY_ACTIVE_ARCH = NO; + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + PUBLIC_HEADERS_FOLDER_PATH = ADNKit; + SKIP_INSTALL = YES; + }; + name = TestFlight; + }; + 331FA3CC1773E7FB0011DF8E /* TestFlight */ = { + isa = XCBuildConfiguration; + buildSettings = { + DSTROOT = /tmp/ADNKit.dst; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; + HEADER_SEARCH_PATHS = ""; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "ADNKit-AFNetworking-iOS"; + PUBLIC_HEADERS_FOLDER_PATH = ADNKit; + SKIP_INSTALL = YES; + }; + name = TestFlight; + }; + 331FA3CD1773E7FB0011DF8E /* TestFlight */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + COMBINE_HIDPI_IMAGES = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"", + ); + FRAMEWORK_VERSION = A; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + INFOPLIST_FILE = "ADNKit-OSX/ADNKit-OSX-Info.plist"; + INSTALL_PATH = "@executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.7; + PRODUCT_NAME = ADNKit; + SDKROOT = macosx; + WRAPPER_EXTENSION = framework; + }; + name = TestFlight; + }; + 331FA3CE1773E7FB0011DF8E /* TestFlight */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\""; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "ADNKitTests/ADNKitTests-Prefix.pch"; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + INFOPLIST_FILE = "ADNKitTests/ADNKitTests-Info.plist"; + MACOSX_DEPLOYMENT_TARGET = 10.8; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + WRAPPER_EXTENSION = octest; + }; + name = TestFlight; + }; 5DC370E516E0805E00190862 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; + ALWAYS_SEARCH_USER_PATHS = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; @@ -1717,12 +1835,15 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( "\"$(SRCROOT)\"", - "\"$(SRCROOT)/../\"", "\"$(SRCROOT)/External/SocketShuttle\"", "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", ); IPHONEOS_DEPLOYMENT_TARGET = 5.0; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); SDKROOT = iphoneos; }; name = Debug; @@ -1730,7 +1851,7 @@ 5DC370E616E0805E00190862 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; + ALWAYS_SEARCH_USER_PATHS = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; @@ -1746,11 +1867,14 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ( "\"$(SRCROOT)\"", - "\"$(SRCROOT)/../\"", "\"$(SRCROOT)/External/SocketShuttle\"", "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", ); IPHONEOS_DEPLOYMENT_TARGET = 5.0; + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; @@ -1762,8 +1886,15 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = ""; - OTHER_LDFLAGS = "-ObjC"; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); PRODUCT_NAME = "$(TARGET_NAME)"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; SKIP_INSTALL = YES; @@ -1776,8 +1907,15 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = ""; - OTHER_LDFLAGS = "-ObjC"; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); + OTHER_LDFLAGS = ( + "-ObjC", + "-all_load", + ); PRODUCT_NAME = "$(TARGET_NAME)"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; SKIP_INSTALL = YES; @@ -1842,6 +1980,7 @@ isa = XCConfigurationList; buildConfigurations = ( 2592B7B316FCED64004573FF /* Debug */, + 331FA3CE1773E7FB0011DF8E /* TestFlight */, 2592B7B416FCED64004573FF /* Release */, ); defaultConfigurationIsVisible = 0; @@ -1851,6 +1990,7 @@ isa = XCConfigurationList; buildConfigurations = ( 2592B80716FF8410004573FF /* Debug */, + 331FA3CC1773E7FB0011DF8E /* TestFlight */, 2592B80816FF8410004573FF /* Release */, ); defaultConfigurationIsVisible = 0; @@ -1860,6 +2000,7 @@ isa = XCConfigurationList; buildConfigurations = ( 5DC370E516E0805E00190862 /* Debug */, + 331FA3CA1773E7FB0011DF8E /* TestFlight */, 5DC370E616E0805E00190862 /* Release */, ); defaultConfigurationIsVisible = 0; @@ -1869,6 +2010,7 @@ isa = XCConfigurationList; buildConfigurations = ( 5DC370E816E0805E00190862 /* Debug */, + 331FA3CB1773E7FB0011DF8E /* TestFlight */, 5DC370E916E0805E00190862 /* Release */, ); defaultConfigurationIsVisible = 0; @@ -1878,6 +2020,7 @@ isa = XCConfigurationList; buildConfigurations = ( 5DC3711516E0808C00190862 /* Debug */, + 331FA3CD1773E7FB0011DF8E /* TestFlight */, 5DC3711616E0808C00190862 /* Release */, ); defaultConfigurationIsVisible = 0; diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 0dbb436..5ce0e11 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -359,13 +359,10 @@ - (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOpe NSMutableURLRequest *request = [operation.request mutableCopy]; request.URL = modifiedURL; - [operation cancel]; + [operation setValue:request forKey:@"request"]; + [operation resume]; - ANKJSONRequestOperation *newOperation = [[ANKJSONRequestOperation alloc] initWithRequest:request]; - newOperation.completionBlock = operation.completionBlock; - [self enqueueHTTPRequestOperation:newOperation]; - - return newOperation; + return operation; } diff --git a/ADNKit/ANKJSONRequestOperation.m b/ADNKit/ANKJSONRequestOperation.m index 69759e6..a2600d1 100644 --- a/ADNKit/ANKJSONRequestOperation.m +++ b/ADNKit/ANKJSONRequestOperation.m @@ -25,6 +25,9 @@ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *, id))su success(operation, response); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { + if (error.code == NSURLErrorCancelled) + return; + ANKAPIResponse *response = [[ANKAPIResponse alloc] initWithResponseObject:((AFJSONRequestOperation *)operation).responseJSON]; NSMutableDictionary *modifiedUserInfo = [error.userInfo mutableCopy]; From b1f6537c7da4d17f0ba12d097b6c3262f7bea884 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Thu, 25 Jul 2013 16:11:37 -0700 Subject: [PATCH 42/69] Leftovers or something. --- ADNKit/ANKClient.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 5ce0e11..d6d8d46 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -361,6 +361,7 @@ - (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOpe [operation setValue:request forKey:@"request"]; [operation resume]; + [self.operationQueue setSuspended:NO]; return operation; } From 66bad7a34b17e4fe0d6a7b9ecfcdcb4ba498470f Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Fri, 26 Jul 2013 20:29:36 -0700 Subject: [PATCH 43/69] Add stream contexts to combination-AFNetworking target. --- ADNKit.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index d610ffb..4af42ed 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -349,6 +349,8 @@ 259A5EC616F2E1EF00AF9F35 /* ADNKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DC370E116E0805E00190862 /* ADNKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 25C0AA45171867B8006E47B7 /* CustomPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 25C0AA44171867B8006E47B7 /* CustomPost.m */; }; 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; + 33041CE917A3760A00C4B25A /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; }; + 33041CEA17A3760D00C4B25A /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; 330BDCAA17659465009BD559 /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 335AC111176427C300AEFCFE /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; }; 335AC112176427C300AEFCFE /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; @@ -1100,6 +1102,7 @@ 252AD7151745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */, 24FC43931745F685004B5D5B /* ANKClient+ANKStreamMarker.h in Headers */, 5D955BE7174BD10B0077E387 /* ANKGeneralParameters.h in Headers */, + 33041CE917A3760A00C4B25A /* ANKStreamContext.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1426,6 +1429,7 @@ 2592B80F16FF8440004573FF /* AFURLConnectionOperation.m in Sources */, 2592B81016FF8440004573FF /* AFXMLRequestOperation.m in Sources */, 2592B81116FF8440004573FF /* AFNetworkActivityIndicatorManager.m in Sources */, + 33041CEA17A3760D00C4B25A /* ANKStreamContext.m in Sources */, 2592B81216FF847F004573FF /* UIImageView+AFNetworking.m in Sources */, 5D2CFEE81703E8F200086FBD /* ANKTokenLimits.m in Sources */, 256768111711539D00C57D47 /* NSString+ANKAdditions.m in Sources */, From e545d26d1fa0399d4e954459c98effc71d7eaae1 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Fri, 26 Jul 2013 21:54:54 -0700 Subject: [PATCH 44/69] Add SocketShuttle to the AFNetworking-hybrid target. --- ADNKit.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 4af42ed..4cca66e 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -351,6 +351,7 @@ 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 33041CE917A3760A00C4B25A /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; }; 33041CEA17A3760D00C4B25A /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; + 33041CF017A38A0F00C4B25A /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 330BDCAA17659465009BD559 /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 335AC111176427C300AEFCFE /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; }; 335AC112176427C300AEFCFE /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; @@ -643,6 +644,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 33041CF017A38A0F00C4B25A /* libSocketShuttle.a in Frameworks */, 2592B7FF16FF8410004573FF /* UIKit.framework in Frameworks */, 2592B80016FF8410004573FF /* MobileCoreServices.framework in Frameworks */, 2592B80116FF8410004573FF /* SystemConfiguration.framework in Frameworks */, From a3d0a64a2491b86e7ebcbc3a8083bffaccc33c61 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Fri, 26 Jul 2013 23:49:30 -0700 Subject: [PATCH 45/69] Fixes the issue with freezing queues (but with a hacky approach) and cleans the code a little. Needs further review. --- ADNKit/ANKClient.m | 56 ++++++++++++++++++++------------ ADNKit/ANKJSONRequestOperation.m | 3 -- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index d6d8d46..c9d3d3c 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -22,9 +22,10 @@ #import "ANKMessage.h" #import "ANKFile.h" #import "ANKPost.h" +#import "ANKChannel.h" #import "ANKClient+ANKTokenStatus.h" -#import #import "ANKStreamContext.h" +#import static const NSString *ADNAPIUserStreamEndpointURL = @"wss://stream-channel.app.net/stream/user"; @@ -137,6 +138,17 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)p return request; } +- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation { + [super enqueueHTTPRequestOperation:operation]; + + if (!operation.isExecuting) { + [operation start]; + + NSLog(@"ADNKit -- Operation had to be started manually as it wasn't executing when added to the queue."); +#warning I'm not sure why this happens, but this fixes it. Sometimes the queue will just freeze and not start any of the operations going into it. It's not good. + } +} + #pragma mark - #pragma mark Authentication @@ -329,29 +341,33 @@ - (id)objectForKeyInAuthenticatedUserDefaults:(NSString *)key { #pragma mark - #pragma mark Streams +- (NSURLRequest *)streamingRequest { + NSMutableURLRequest *streamingRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"wss://stream-channel.app.net/stream/user"]]; + [streamingRequest setValue:[self defaultValueForHeader:@"Authorization"] forHTTPHeaderField:@"Authorization"]; + + return streamingRequest; +} + - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation withDelegate:(id)delegate { - [operation pause]; - ANKJSONRequestOperation *finalizedOperation = operation; NSString *subscriptionID = nil; if (!self.streamingConnectionID) { + if (operation.isExecuting) { + [operation pause]; + } - NSMutableURLRequest *streamingRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"wss://stream-channel.app.net/stream/user"]]; - [streamingRequest setValue:[self defaultValueForHeader:@"Authorization"] forHTTPHeaderField:@"Authorization"]; - self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:streamingRequest delegate:self]; + self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self]; } else { - - finalizedOperation = [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID streamingDelegate:delegate]; + [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID]; } - ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:finalizedOperation identifier:subscriptionID socketShuttle:nil streamingDelegate:delegate]; + ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:operation identifier:subscriptionID socketShuttle:nil streamingDelegate:delegate]; [self.streamContexts addObject:context]; } -- (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOperation *)operation subscriptionID:(NSString **)subscriptionID streamingDelegate:(id)streamingDelegate -{ +- (void)reconfigureOperationForStreaming:(ANKJSONRequestOperation *)operation subscriptionID:(NSString **)subscriptionID { NSString *uniqueString = [[NSProcessInfo processInfo] globallyUniqueString]; *subscriptionID = uniqueString; @@ -360,17 +376,15 @@ - (ANKJSONRequestOperation *)reconfigureOperationForStreaming:(ANKJSONRequestOpe request.URL = modifiedURL; [operation setValue:request forKey:@"request"]; - [operation resume]; - [self.operationQueue setSuspended:NO]; - return operation; + if (operation.isPaused) { + [operation resume]; + } } -- (id)parsedObjectFromJSON:(NSDictionary *)JSON -{ +- (id)parsedObjectFromJSON:(NSDictionary *)JSON { if (self.responseDecodingType != ANKResponseDecodingTypeNone) { - NSSet *dataSet = [[NSSet alloc] initWithArray:JSON[@"data"]]; NSDictionary *sampleObject = [dataSet anyObject]; @@ -378,7 +392,7 @@ - (id)parsedObjectFromJSON:(NSDictionary *)JSON BOOL isUser = sampleObject[@"username"] && sampleObject[@"timezone"] && sampleObject[@"avatar_image"]; BOOL isMessage = sampleObject[@"channel_id"] && !sampleObject[@"canonical_url"] && !sampleObject[@"num_stars"]; BOOL isPost = sampleObject[@"num_stars"] && sampleObject[@"user"] && sampleObject[@"canonical_url"] && sampleObject[@"text"]; - // BOOL isChannel = sampleObject[@"has_unread"] && sampleObject[@"readers"]; + BOOL isChannel = sampleObject[@"has_unread"] && sampleObject[@"readers"]; BOOL isFile = sampleObject[@"complete"] && sampleObject[@"derived_files"]; ANKAPIResponse *response = [[ANKAPIResponse alloc] initWithResponseObject:JSON]; @@ -392,8 +406,8 @@ - (id)parsedObjectFromJSON:(NSDictionary *)JSON resourceClass = [ANKPost class]; else if (isFile) resourceClass = [ANKFile class]; - // else if (isChannel) - // resourceClass = [ANKChannel class]; + else if (isChannel) + resourceClass = [ANKChannel class]; if (resourceClass) return [self unboxCollectionResponse:response ofResourceClass:resourceClass]; @@ -498,7 +512,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { for (ANKStreamContext *streamContext in self.streamContexts) { NSString *newID = nil; - streamContext.baseOperation = [self reconfigureOperationForStreaming:streamContext.baseOperation subscriptionID:&newID streamingDelegate:streamContext.streamingDelegate]; + [self reconfigureOperationForStreaming:streamContext.baseOperation subscriptionID:&newID]; streamContext.identifier = newID; } diff --git a/ADNKit/ANKJSONRequestOperation.m b/ADNKit/ANKJSONRequestOperation.m index a2600d1..69759e6 100644 --- a/ADNKit/ANKJSONRequestOperation.m +++ b/ADNKit/ANKJSONRequestOperation.m @@ -25,9 +25,6 @@ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *, id))su success(operation, response); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - if (error.code == NSURLErrorCancelled) - return; - ANKAPIResponse *response = [[ANKAPIResponse alloc] initWithResponseObject:((AFJSONRequestOperation *)operation).responseJSON]; NSMutableDictionary *modifiedUserInfo = [error.userInfo mutableCopy]; From 8af576b9c84391ac502316af7a6a7a9c8a2beee1 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 27 Jul 2013 01:13:55 -0700 Subject: [PATCH 46/69] Fixes non-building status. --- ADNKit.xcodeproj/project.pbxproj | 84 ++++++++++++++++++++++++++++---- ADNKit/ANKGeolocation.h | 1 - ADNKit/ANKOEmbed.h | 3 -- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 8becf04..b6a5073 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -244,7 +244,7 @@ 252A898D16F8CDF3001F3E8F /* NSDictionary+ANKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88E816F8CDF1001F3E8F /* NSDictionary+ANKAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 252A898E16F8CDF3001F3E8F /* NSDictionary+ANKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 252A88E916F8CDF2001F3E8F /* NSDictionary+ANKAdditions.m */; }; 252A898F16F8CDF3001F3E8F /* NSDictionary+ANKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 252A88E916F8CDF2001F3E8F /* NSDictionary+ANKAdditions.m */; }; - 252AD7151745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 252AD7121745C76600E12492 /* ANKClient+ANKRequestsAPI.h */; }; + 252AD7151745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 252AD7121745C76600E12492 /* ANKClient+ANKRequestsAPI.h */; settings = {ATTRIBUTES = (Public, ); }; }; 252AD7161745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 252AD7121745C76600E12492 /* ANKClient+ANKRequestsAPI.h */; }; 252AD7171745C76600E12492 /* ANKClient+ANKRequestsAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 252AD7131745C76600E12492 /* ANKClient+ANKRequestsAPI.m */; }; 252AD7181745C76600E12492 /* ANKClient+ANKRequestsAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 252AD7131745C76600E12492 /* ANKClient+ANKRequestsAPI.m */; }; @@ -349,16 +349,49 @@ 259A5EC616F2E1EF00AF9F35 /* ADNKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DC370E116E0805E00190862 /* ADNKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 25C0AA45171867B8006E47B7 /* CustomPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 25C0AA44171867B8006E47B7 /* CustomPost.m */; }; 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; - 33041CE917A3760A00C4B25A /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; }; + 33041CE917A3760A00C4B25A /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 33041CEA17A3760D00C4B25A /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; 33041CF017A38A0F00C4B25A /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 330BDCAA17659465009BD559 /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; - 335AC111176427C300AEFCFE /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; }; - 335AC112176427C300AEFCFE /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; - 331B250F17A247DF000E553E /* ANKSearchQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 331B250D17A247DF000E553E /* ANKSearchQuery.h */; }; + 331B250F17A247DF000E553E /* ANKSearchQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 331B250D17A247DF000E553E /* ANKSearchQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; 331B251017A247DF000E553E /* ANKSearchQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 331B250D17A247DF000E553E /* ANKSearchQuery.h */; }; 331B251117A247DF000E553E /* ANKSearchQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 331B250E17A247DF000E553E /* ANKSearchQuery.m */; }; 331B251217A247DF000E553E /* ANKSearchQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 331B250E17A247DF000E553E /* ANKSearchQuery.m */; }; + 3326109617A3B75B00665C05 /* ANKSearchQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 331B250D17A247DF000E553E /* ANKSearchQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3326109717A3B77000665C05 /* ANKSearchQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 331B250E17A247DF000E553E /* ANKSearchQuery.m */; }; + 3326109817A3B7E500665C05 /* ADNKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DC370E116E0805E00190862 /* ADNKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3326109917A3B7E500665C05 /* ADNKit-iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DA357CB16EBC18B00FA21F8 /* ADNKit-iOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3326109A17A3B7E500665C05 /* ADNKit-OSX.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DA357CC16EBC18B00FA21F8 /* ADNKit-OSX.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3326109B17A3B7E500665C05 /* ANKClient+ANKHandlerBlocks.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A889216F8CDB8001F3E8F /* ANKClient+ANKHandlerBlocks.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3326109C17A3B7E500665C05 /* ANKClient+ANKRequestsAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 252AD7121745C76600E12492 /* ANKClient+ANKRequestsAPI.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3326109D17A3B7E500665C05 /* ANKClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A2C4316E5624700DAE393 /* ANKClient.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3326109E17A3B7E500665C05 /* ANKClient+ANKChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A888A16F8CDB7001F3E8F /* ANKClient+ANKChannel.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3326109F17A3B7E500665C05 /* ANKClient+ANKExploreStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A888C16F8CDB7001F3E8F /* ANKClient+ANKExploreStream.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A017A3B7E500665C05 /* ANKClient+ANKFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A888E16F8CDB7001F3E8F /* ANKClient+ANKFile.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A117A3B7E500665C05 /* ANKClient+ANKFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A889016F8CDB8001F3E8F /* ANKClient+ANKFilter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A217A3B7E500665C05 /* ANKClient+ANKInteraction.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A889416F8CDB8001F3E8F /* ANKClient+ANKInteraction.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A317A3B7E500665C05 /* ANKClient+ANKMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A889616F8CDB9001F3E8F /* ANKClient+ANKMessage.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A417A3B7E500665C05 /* ANKClient+ANKPlace.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A889816F8CDB9001F3E8F /* ANKClient+ANKPlace.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A517A3B7E500665C05 /* ANKClient+ANKPost.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A889A16F8CDBA001F3E8F /* ANKClient+ANKPost.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A617A3B7E500665C05 /* ANKClient+ANKPostStreams.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A889C16F8CDBA001F3E8F /* ANKClient+ANKPostStreams.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A717A3B7E500665C05 /* ANKClient+ANKStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A889E16F8CDBB001F3E8F /* ANKClient+ANKStream.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A817A3B7E500665C05 /* ANKClient+ANKTokenStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88A016F8CDBB001F3E8F /* ANKClient+ANKTokenStatus.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610A917A3B7E500665C05 /* ANKClient+ANKUser.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88A216F8CDBC001F3E8F /* ANKClient+ANKUser.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610AA17A3B7E500665C05 /* ANKClient+ANKStreamMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = 252E632317421632003143D6 /* ANKClient+ANKStreamMarker.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610AB17A3B7E500665C05 /* ANKOAuthViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88C016F8CDCC001F3E8F /* ANKOAuthViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610AC17A3B7E500665C05 /* ANKTextFieldCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88D616F8CDDD001F3E8F /* ANKTextFieldCell.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610AD17A3B7E500665C05 /* ANKUsernamePasswordAuthViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88E216F8CDEA001F3E8F /* ANKUsernamePasswordAuthViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610AE17A3B7E500665C05 /* ANKValueTransformations.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88E416F8CDED001F3E8F /* ANKValueTransformations.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610AF17A3B7E500665C05 /* ANKUsernameFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88E016F8CDE8001F3E8F /* ANKUsernameFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610B017A3B7E500665C05 /* ANKResourceMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 2567682517153E3100C57D47 /* ANKResourceMap.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610B117A3B7E500665C05 /* ANKAPIResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A888216F8CDB6001F3E8F /* ANKAPIResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610B217A3B7E500665C05 /* ANKAPIResponseMeta.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A888416F8CDB6001F3E8F /* ANKAPIResponseMeta.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610B317A3B7E500665C05 /* ANKJSONRequestOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88B816F8CDC7001F3E8F /* ANKJSONRequestOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610B417A3B7E500665C05 /* NSArray+ANKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88E616F8CDEF001F3E8F /* NSArray+ANKAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610B517A3B7E500665C05 /* NSDictionary+ANKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 252A88E816F8CDF1001F3E8F /* NSDictionary+ANKAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 332610B617A3B7E500665C05 /* NSString+ANKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 2567680D1711539D00C57D47 /* NSString+ANKAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 335AC111176427C300AEFCFE /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 335AC112176427C300AEFCFE /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; 5D2CFEE61703E8F200086FBD /* ANKTokenLimits.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5D2CFEE71703E8F200086FBD /* ANKTokenLimits.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */; }; 5D2CFEE81703E8F200086FBD /* ANKTokenLimits.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */; }; @@ -587,10 +620,10 @@ 25C0AA43171867B8006E47B7 /* CustomPost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomPost.h; sourceTree = ""; }; 25C0AA44171867B8006E47B7 /* CustomPost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomPost.m; sourceTree = ""; }; 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SocketShuttle.xcodeproj; path = External/SocketShuttle/SocketShuttle.xcodeproj; sourceTree = ""; }; - 335AC10F176427C300AEFCFE /* ANKStreamContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKStreamContext.h; sourceTree = ""; }; - 335AC110176427C300AEFCFE /* ANKStreamContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKStreamContext.m; sourceTree = ""; }; 331B250D17A247DF000E553E /* ANKSearchQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKSearchQuery.h; sourceTree = ""; }; 331B250E17A247DF000E553E /* ANKSearchQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKSearchQuery.m; sourceTree = ""; }; + 335AC10F176427C300AEFCFE /* ANKStreamContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKStreamContext.h; sourceTree = ""; }; + 335AC110176427C300AEFCFE /* ANKStreamContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKStreamContext.m; sourceTree = ""; }; 5D2CFEE41703E8F200086FBD /* ANKTokenLimits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKTokenLimits.h; sourceTree = ""; }; 5D2CFEE51703E8F200086FBD /* ANKTokenLimits.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANKTokenLimits.m; sourceTree = ""; }; 5D955BE4174BD10B0077E387 /* ANKGeneralParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANKGeneralParameters.h; sourceTree = ""; }; @@ -1113,10 +1146,11 @@ 24DA122A1741FC2E00CAA8C5 /* AFXMLRequestOperation.h in Headers */, 24DA122B1741FC2E00CAA8C5 /* UIImageView+AFNetworking.h in Headers */, 24DA122C1741FC2E00CAA8C5 /* AFNetworkActivityIndicatorManager.h in Headers */, - 252AD7151745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */, 24FC43931745F685004B5D5B /* ANKClient+ANKStreamMarker.h in Headers */, - 5D955BE7174BD10B0077E387 /* ANKGeneralParameters.h in Headers */, + 252AD7151745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */, 33041CE917A3760A00C4B25A /* ANKStreamContext.h in Headers */, + 3326109617A3B75B00665C05 /* ANKSearchQuery.h in Headers */, + 5D955BE7174BD10B0077E387 /* ANKGeneralParameters.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1127,6 +1161,37 @@ 331B250F17A247DF000E553E /* ANKSearchQuery.h in Headers */, 5D955BE6174BD10B0077E387 /* ANKGeneralParameters.h in Headers */, 335AC111176427C300AEFCFE /* ANKStreamContext.h in Headers */, + 3326109817A3B7E500665C05 /* ADNKit.h in Headers */, + 3326109917A3B7E500665C05 /* ADNKit-iOS.h in Headers */, + 3326109A17A3B7E500665C05 /* ADNKit-OSX.h in Headers */, + 3326109B17A3B7E500665C05 /* ANKClient+ANKHandlerBlocks.h in Headers */, + 3326109C17A3B7E500665C05 /* ANKClient+ANKRequestsAPI.h in Headers */, + 3326109D17A3B7E500665C05 /* ANKClient.h in Headers */, + 3326109E17A3B7E500665C05 /* ANKClient+ANKChannel.h in Headers */, + 3326109F17A3B7E500665C05 /* ANKClient+ANKExploreStream.h in Headers */, + 332610A017A3B7E500665C05 /* ANKClient+ANKFile.h in Headers */, + 332610A117A3B7E500665C05 /* ANKClient+ANKFilter.h in Headers */, + 332610A217A3B7E500665C05 /* ANKClient+ANKInteraction.h in Headers */, + 332610A317A3B7E500665C05 /* ANKClient+ANKMessage.h in Headers */, + 332610A417A3B7E500665C05 /* ANKClient+ANKPlace.h in Headers */, + 332610A517A3B7E500665C05 /* ANKClient+ANKPost.h in Headers */, + 332610A617A3B7E500665C05 /* ANKClient+ANKPostStreams.h in Headers */, + 332610A717A3B7E500665C05 /* ANKClient+ANKStream.h in Headers */, + 332610A817A3B7E500665C05 /* ANKClient+ANKTokenStatus.h in Headers */, + 332610A917A3B7E500665C05 /* ANKClient+ANKUser.h in Headers */, + 332610AA17A3B7E500665C05 /* ANKClient+ANKStreamMarker.h in Headers */, + 332610AB17A3B7E500665C05 /* ANKOAuthViewController.h in Headers */, + 332610AC17A3B7E500665C05 /* ANKTextFieldCell.h in Headers */, + 332610AD17A3B7E500665C05 /* ANKUsernamePasswordAuthViewController.h in Headers */, + 332610AE17A3B7E500665C05 /* ANKValueTransformations.h in Headers */, + 332610AF17A3B7E500665C05 /* ANKUsernameFormatter.h in Headers */, + 332610B017A3B7E500665C05 /* ANKResourceMap.h in Headers */, + 332610B117A3B7E500665C05 /* ANKAPIResponse.h in Headers */, + 332610B217A3B7E500665C05 /* ANKAPIResponseMeta.h in Headers */, + 332610B317A3B7E500665C05 /* ANKJSONRequestOperation.h in Headers */, + 332610B417A3B7E500665C05 /* NSArray+ANKAdditions.h in Headers */, + 332610B517A3B7E500665C05 /* NSDictionary+ANKAdditions.h in Headers */, + 332610B617A3B7E500665C05 /* NSString+ANKAdditions.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1381,6 +1446,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 3326109717A3B77000665C05 /* ANKSearchQuery.m in Sources */, 2592B7C616FF8410004573FF /* ANKClient.m in Sources */, 2592B7C716FF8410004573FF /* ANKACL.m in Sources */, 2592B7C816FF8410004573FF /* ANKAnnotatableResource.m in Sources */, diff --git a/ADNKit/ANKGeolocation.h b/ADNKit/ANKGeolocation.h index 3ba3868..7272d2d 100644 --- a/ADNKit/ANKGeolocation.h +++ b/ADNKit/ANKGeolocation.h @@ -10,7 +10,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import #import diff --git a/ADNKit/ANKOEmbed.h b/ADNKit/ANKOEmbed.h index 311e7e0..6949cb3 100644 --- a/ADNKit/ANKOEmbed.h +++ b/ADNKit/ANKOEmbed.h @@ -10,9 +10,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import - - @interface ANKOEmbed : ANKResource @property (strong) NSString *type; From 6ea1d9b6607583a40fb35a0649967803512fadf7 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 27 Jul 2013 15:49:26 -0700 Subject: [PATCH 47/69] Code cleanup. --- ADNKit/ANKClient.m | 117 +++++++++++++++++++------------------- ADNKit/ANKStreamContext.h | 10 ++-- ADNKit/ANKStreamContext.m | 30 +++++----- 3 files changed, 78 insertions(+), 79 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 77dfb93..81ef06c 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -137,7 +137,7 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)p - (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation { [super enqueueHTTPRequestOperation:operation]; - if (!operation.isExecuting) { + if (!operation.isExecuting && operation.isReady) { [operation start]; NSLog(@"ADNKit -- Operation had to be started manually as it wasn't executing when added to the queue."); @@ -344,6 +344,55 @@ - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue failureCa } +#pragma mark - +#pragma mark Internal API + +- (void)initializeHTTPAuthClient { + self.authHTTPClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"https://account.app.net/oauth"]]; + self.authHTTPClient.parameterEncoding = AFFormURLParameterEncoding; + [self.authHTTPClient registerHTTPOperationClass:[AFJSONRequestOperation class]]; +} + + +- (void)authenticateWithParameters:(NSDictionary *)params handler:(void (^)(BOOL successful, NSError *error))handler { + [self initializeHTTPAuthClient]; + [self.authHTTPClient postPath:@"access_token" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { + NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil]; + if (responseDictionary[@"access_token"]) { + if (responseDictionary[@"token"]) { + ANKTokenStatus *token = [ANKResolve(ANKTokenStatus) objectFromJSONDictionary:responseDictionary[@"token"]]; + self.authenticatedUser = token.user; + } + self.accessToken = responseDictionary[@"access_token"]; + [self HTTPAuthDidCompleteSuccessfully:YES error:nil handler:handler]; + } else { + NSError *error = [NSError errorWithDomain:kANKErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Could not find key access_token in response", NSLocalizedFailureReasonErrorKey: responseDictionary}]; + [self HTTPAuthDidCompleteSuccessfully:NO error:error handler:handler]; + } + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { + [self HTTPAuthDidCompleteSuccessfully:NO error:error handler:handler]; + }]; +} + + +- (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler { + if (error.localizedRecoverySuggestion) { + NSDictionary *errorDictionary = [NSJSONSerialization JSONObjectWithData:[error.localizedRecoverySuggestion dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; + if (errorDictionary) { + NSError *modifiedError = [NSError errorWithDomain:kANKErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: errorDictionary[@"error"]}]; + error = modifiedError; + } + } + if (handler) { + handler(wasSuccessful, error); + } + + self.authHTTPClient = nil; + self.webAuthCompletionHandler = nil; + self.webAuthRedirectURI = nil; +} + + #pragma mark - #pragma mark Streams @@ -354,8 +403,8 @@ - (NSURLRequest *)streamingRequest { return streamingRequest; } -- (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation withDelegate:(id)delegate { +- (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation withDelegate:(id)delegate { NSString *subscriptionID = nil; if (!self.streamingConnectionID) { @@ -368,8 +417,7 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID]; } - ANKStreamContext *context = [[ANKStreamContext alloc] initWithBaseOperation:operation identifier:subscriptionID socketShuttle:nil streamingDelegate:delegate]; - [self.streamContexts addObject:context]; + [self.streamContexts addObject:[ANKStreamContext streamContextWithOperation:operation identifier:subscriptionID delegate:delegate]]; } @@ -423,6 +471,7 @@ - (id)parsedObjectFromJSON:(NSDictionary *)JSON { return JSON; } + - (NSSet *)streamingDelegates { return [self.streamContexts valueForKey:@"streamingDelegate"]; } @@ -441,54 +490,6 @@ - (void)iterateOverStreamingDelegatesImplementingDelegateMethod:(SEL)delegateMet }]; } -#pragma mark - -#pragma mark Internal API - -- (void)initializeHTTPAuthClient { - self.authHTTPClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"https://account.app.net/oauth"]]; - self.authHTTPClient.parameterEncoding = AFFormURLParameterEncoding; - [self.authHTTPClient registerHTTPOperationClass:[AFJSONRequestOperation class]]; -} - - -- (void)authenticateWithParameters:(NSDictionary *)params handler:(void (^)(BOOL successful, NSError *error))handler { - [self initializeHTTPAuthClient]; - [self.authHTTPClient postPath:@"access_token" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { - NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil]; - if (responseDictionary[@"access_token"]) { - if (responseDictionary[@"token"]) { - ANKTokenStatus *token = [ANKResolve(ANKTokenStatus) objectFromJSONDictionary:responseDictionary[@"token"]]; - self.authenticatedUser = token.user; - } - self.accessToken = responseDictionary[@"access_token"]; - [self HTTPAuthDidCompleteSuccessfully:YES error:nil handler:handler]; - } else { - NSError *error = [NSError errorWithDomain:kANKErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Could not find key access_token in response", NSLocalizedFailureReasonErrorKey: responseDictionary}]; - [self HTTPAuthDidCompleteSuccessfully:NO error:error handler:handler]; - } - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - [self HTTPAuthDidCompleteSuccessfully:NO error:error handler:handler]; - }]; -} - - -- (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)error handler:(void (^)(BOOL successful, NSError *error))handler { - if (error.localizedRecoverySuggestion) { - NSDictionary *errorDictionary = [NSJSONSerialization JSONObjectWithData:[error.localizedRecoverySuggestion dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; - if (errorDictionary) { - NSError *modifiedError = [NSError errorWithDomain:kANKErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: errorDictionary[@"error"]}]; - error = modifiedError; - } - } - if (handler) { - handler(wasSuccessful, error); - } - - self.authHTTPClient = nil; - self.webAuthCompletionHandler = nil; - self.webAuthRedirectURI = nil; -} - #pragma mark - #pragma mark KATSocketShuttleDelegate @@ -500,17 +501,17 @@ - (void)socketDidOpen:(KATSocketShuttle *)socket { }]; } + - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { NSError *error = nil; NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error]; - - if (error) + if (error) { return; + } NSDictionary *metaDict = JSON[@"meta"]; NSString *connectionID = metaDict[@"connection_id"]; NSArray *subscriptionIDs = metaDict[@"subscription_ids"]; - ANKAPIResponse *response = [[ANKAPIResponse alloc] initWithResponseObject:JSON]; if (!self.streamingConnectionID) { @@ -518,10 +519,9 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { for (ANKStreamContext *streamContext in self.streamContexts) { NSString *newID = nil; - [self reconfigureOperationForStreaming:streamContext.baseOperation subscriptionID:&newID]; + [self reconfigureOperationForStreaming:streamContext.operation subscriptionID:&newID]; streamContext.identifier = newID; } - } else { for (NSString *subscriptionID in subscriptionIDs) { id object = [self parsedObjectFromJSON:JSON]; @@ -532,6 +532,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { } } + - (void)socket:(KATSocketShuttle *)socket didFailWithError:(NSError *)error { __weak typeof(self) weakSelf = self; [self iterateOverStreamingDelegatesImplementingDelegateMethod:@selector(client:didDisconnectOnSocketError:) withBlock:^(id streamingDelegate) { @@ -539,6 +540,7 @@ - (void)socket:(KATSocketShuttle *)socket didFailWithError:(NSError *)error { }]; } + - (void)socket:(KATSocketShuttle *)socket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { __weak typeof(self) weakSelf = self; [self iterateOverStreamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidDisconnect:) withBlock:^(id streamingDelegate) { @@ -546,4 +548,5 @@ - (void)socket:(KATSocketShuttle *)socket didCloseWithCode:(NSInteger)code reaso }]; } + @end diff --git a/ADNKit/ANKStreamContext.h b/ADNKit/ANKStreamContext.h index 6d27147..86d6d49 100644 --- a/ADNKit/ANKStreamContext.h +++ b/ADNKit/ANKStreamContext.h @@ -12,18 +12,16 @@ #pragma mark - Designated Initializer -- (id)initWithBaseOperation:(ANKJSONRequestOperation *)operation identifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle streamingDelegate:(id)streamingDelegate; ++ (instancetype)streamContextWithOperation:(ANKJSONRequestOperation *)operation identifier:(NSString *)identifier delegate:(id)delegate; +- (instancetype)initWithOperation:(ANKJSONRequestOperation *)operation identifier:(NSString *)identifier delegate:(id)delegate; #pragma mark - Internal -@property (nonatomic, strong) KATSocketShuttle *socketShuttle; -@property (nonatomic, weak) id streamingDelegate; -@property (nonatomic, strong) ANKJSONRequestOperation *baseOperation; +@property (nonatomic, weak, readonly) id delegate; +@property (nonatomic, strong, readonly) ANKJSONRequestOperation *operation; #pragma mark - API Level @property (nonatomic, copy) NSString *identifier; -- (NSURLRequest *)streamingOperationRequest; - @end diff --git a/ADNKit/ANKStreamContext.m b/ADNKit/ANKStreamContext.m index e0806b8..f60b2a1 100644 --- a/ADNKit/ANKStreamContext.m +++ b/ADNKit/ANKStreamContext.m @@ -8,32 +8,30 @@ #import "ANKStreamContext.h" +@interface ANKStreamContext () + +@property (nonatomic, weak) id delegate; +@property (nonatomic, strong) ANKJSONRequestOperation *operation; + +@end + @implementation ANKStreamContext #pragma mark - #pragma mark Designated Initializer -- (id)initWithBaseOperation:(ANKJSONRequestOperation *)operation identifier:(NSString *)identifier socketShuttle:(KATSocketShuttle *)socketShuttle streamingDelegate:(id)streamingDelegate { ++ (instancetype)streamContextWithOperation:(ANKJSONRequestOperation *)operation identifier:(NSString *)identifier delegate:(id)delegate { + return [[[self class] alloc] initWithOperation:operation identifier:identifier delegate:delegate]; +} + +- (instancetype)initWithOperation:(ANKJSONRequestOperation *)operation identifier:(NSString *)identifier delegate:(id)delegate { if ((self = [super init])) { - self.baseOperation = operation; + self.operation = operation; self.identifier = identifier; - self.socketShuttle = socketShuttle; - self.streamingDelegate = streamingDelegate; + self.delegate = delegate; } return self; } -#pragma mark - -#pragma mark Convenience - -//- (NSURLRequest *)streamingOperationRequest -//{ -// NSMutableURLRequest *request = self.baseOperation.request.mutableCopy; -// request.URL = [NSURL URLWithString:[[[[request.URL.absoluteString stringByAppendingFormat:@"&connection_id=%@", self.identifier] stringByReplacingOccurrencesOfString:request.URL.scheme withString:@"wss"] stringByReplacingOccurrencesOfString:request.URL.host withString:@"stream-channel.app.net"]]]; -// -// return request; -//} -// - @end From 8007c312ae8d108c84d8e6033083cd3910889acc Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sat, 27 Jul 2013 15:51:44 -0700 Subject: [PATCH 48/69] Fix a compiler warning over ANKOEmbed... which was out of nowhere. --- ADNKit/ANKAnnotation.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ADNKit/ANKAnnotation.m b/ADNKit/ANKAnnotation.m index bc03cf3..9aec80f 100644 --- a/ADNKit/ANKAnnotation.m +++ b/ADNKit/ANKAnnotation.m @@ -15,6 +15,7 @@ #import "ANKPlace.h" #import "ANKChannel.h" #import "ANKGeolocation.h" +#import "ANKOEmbed.h" @interface ANKAnnotation () From ea385724d120b3b23230cda0a4c6354df861b8f8 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 28 Jul 2013 17:44:15 -0700 Subject: [PATCH 49/69] Fix kv coding error. Test things first kolin --- ADNKit/ANKClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 81ef06c..3a35f9b 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -473,7 +473,7 @@ - (id)parsedObjectFromJSON:(NSDictionary *)JSON { - (NSSet *)streamingDelegates { - return [self.streamContexts valueForKey:@"streamingDelegate"]; + return [self.streamContexts valueForKey:@"delegate"]; } From 3e706c41c7cb76f2231d131a0095688619366beb Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 28 Jul 2013 18:12:12 -0700 Subject: [PATCH 50/69] ...And again with the KV coding. --- ADNKit/ANKClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 3a35f9b..d25e58c 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -526,7 +526,7 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { for (NSString *subscriptionID in subscriptionIDs) { id object = [self parsedObjectFromJSON:JSON]; - for (id streamingDelegate in [[self.streamContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]] valueForKey:@"streamingDelegate"]) + for (id streamingDelegate in [[self.streamContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]] valueForKey:@"delegate"]) [streamingDelegate client:self didReceiveObject:object withMeta:response.meta]; } } From 5770c89747c2c9108d65da580c9911db2221bec6 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Sun, 28 Jul 2013 18:13:22 -0700 Subject: [PATCH 51/69] Switch to use the constant. --- ADNKit/ANKClient.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index d25e58c..ff7a89d 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -28,7 +28,7 @@ #import -static const NSString *ADNAPIUserStreamEndpointURL = @"wss://stream-channel.app.net/stream/user"; +static const NSString *kANKUserStreamEndpointURL = @"wss://stream-channel.app.net/stream/user"; @interface ANKClient () @@ -397,7 +397,7 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err #pragma mark Streams - (NSURLRequest *)streamingRequest { - NSMutableURLRequest *streamingRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"wss://stream-channel.app.net/stream/user"]]; + NSMutableURLRequest *streamingRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:(NSString *)kANKUserStreamEndpointURL]]; [streamingRequest setValue:[self defaultValueForHeader:@"Authorization"] forHTTPHeaderField:@"Authorization"]; return streamingRequest; From 99bec30457daf5d6b87ba59586fb207883d7c2cf Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Mon, 29 Jul 2013 21:44:48 -0700 Subject: [PATCH 52/69] Hmm...this might actually be fixed. --- ADNKit/ANKClient.m | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index ff7a89d..9ae5961 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -134,16 +134,18 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)p return request; } -- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation { - [super enqueueHTTPRequestOperation:operation]; - - if (!operation.isExecuting && operation.isReady) { - [operation start]; - - NSLog(@"ADNKit -- Operation had to be started manually as it wasn't executing when added to the queue."); -#warning I'm not sure why this happens, but this fixes it. Sometimes the queue will just freeze and not start any of the operations going into it. It's not good. - } -} +//- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation { +// [super enqueueHTTPRequestOperation:operation]; +// +// dispatch_async(dispatch_get_main_queue(), ^{ +// if (!operation.isExecuting && operation.isReady) { +//// [operation start]; +// +// NSLog(@"ADNKit -- Operation had to be started manually as it wasn't executing when added to the queue."); +// #warning I'm not sure why this happens, but this fixes it. Sometimes the queue will just freeze and not start any of the operations going into it. It's not good. +// } +// }); +//} #pragma mark - From 9bd1d4dd4d433d03ad5b46654d82c4d40080753b Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Wed, 31 Jul 2013 12:12:38 -0700 Subject: [PATCH 53/69] ...Fixes the never-resuming operation. --- ADNKit/ANKClient.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 9ae5961..4b2f2b2 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -410,9 +410,7 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation NSString *subscriptionID = nil; if (!self.streamingConnectionID) { - if (operation.isExecuting) { - [operation pause]; - } + [operation pause]; self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self]; } else { From f01c302d1b884325838b65e6a518855de00040ac Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Wed, 31 Jul 2013 21:47:14 -0700 Subject: [PATCH 54/69] This adds reconnect support. Both SocketShuttle and SocketRocket have been updated on my local machine though... but both need major updates (and ARC) as they're riddled with leaks. Subsequently, on reconnects the SRWebSocket calls a dangling pointer and causes crashes. --- ADNKit/ANKClient.m | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 4b2f2b2..3a37599 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -39,6 +39,7 @@ @interface ANKClient () @property (nonatomic, strong) KATSocketShuttle *socketShuttle; @property (nonatomic, copy) NSString *streamingConnectionID; +@property (nonatomic, copy) NSString *lastSuccessfulStreamingConnectionID; @property (nonatomic, strong) NSMutableSet *streamContexts; - (void)initializeHTTPAuthClient; @@ -399,7 +400,11 @@ - (void)HTTPAuthDidCompleteSuccessfully:(BOOL)wasSuccessful error:(NSError *)err #pragma mark Streams - (NSURLRequest *)streamingRequest { - NSMutableURLRequest *streamingRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:(NSString *)kANKUserStreamEndpointURL]]; + if (!self.streamingConnectionID) { + self.streamingConnectionID = [[NSProcessInfo processInfo] globallyUniqueString]; + } + + NSMutableURLRequest *streamingRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[(NSString *)kANKUserStreamEndpointURL stringByAppendingFormat:@"?connection_id=%@", self.streamingConnectionID]]]; [streamingRequest setValue:[self defaultValueForHeader:@"Authorization"] forHTTPHeaderField:@"Authorization"]; return streamingRequest; @@ -413,7 +418,7 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation [operation pause]; self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self]; - } else { + } else if (self.socketShuttle.socketState == KATSocketStateConnected) { [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID]; } @@ -433,6 +438,8 @@ - (void)reconfigureOperationForStreaming:(ANKJSONRequestOperation *)operation su if (operation.isPaused) { [operation resume]; + } else if (operation.isFinished) { + [operation start]; } } @@ -491,6 +498,11 @@ - (void)iterateOverStreamingDelegatesImplementingDelegateMethod:(SEL)delegateMet } +- (void)socketShuttleDisconnectCommon { + self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self]; +} + + #pragma mark - #pragma mark KATSocketShuttleDelegate @@ -512,28 +524,40 @@ - (void)socket:(KATSocketShuttle *)socket didReceiveMessage:(id)message { NSDictionary *metaDict = JSON[@"meta"]; NSString *connectionID = metaDict[@"connection_id"]; NSArray *subscriptionIDs = metaDict[@"subscription_ids"]; + BOOL isInitialConnectionResponse = (JSON.count == 1 && connectionID); ANKAPIResponse *response = [[ANKAPIResponse alloc] initWithResponseObject:JSON]; - if (!self.streamingConnectionID) { + if (isInitialConnectionResponse) { + BOOL connectionWasRevived = [self.streamingConnectionID isEqualToString:self.lastSuccessfulStreamingConnectionID]; self.streamingConnectionID = connectionID; - - for (ANKStreamContext *streamContext in self.streamContexts) { - NSString *newID = nil; - [self reconfigureOperationForStreaming:streamContext.operation subscriptionID:&newID]; - streamContext.identifier = newID; + self.lastSuccessfulStreamingConnectionID = self.streamingConnectionID; + + if (!connectionWasRevived) { + for (ANKStreamContext *streamContext in self.streamContexts) { + NSString *newID = nil; + [self reconfigureOperationForStreaming:streamContext.operation subscriptionID:&newID]; + streamContext.identifier = newID; + } } } else { for (NSString *subscriptionID in subscriptionIDs) { id object = [self parsedObjectFromJSON:JSON]; - - for (id streamingDelegate in [[self.streamContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]] valueForKey:@"delegate"]) + + NSLog(@"Received object: %@ for subscription ID: %@", object, subscriptionID); + + for (id streamingDelegate in [[self.streamContexts filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"identifier == %@", subscriptionID]] valueForKey:@"delegate"]) { + NSLog(@"Messaging delegate %@", streamingDelegate); + [streamingDelegate client:self didReceiveObject:object withMeta:response.meta]; + } } } } - (void)socket:(KATSocketShuttle *)socket didFailWithError:(NSError *)error { + [self socketShuttleDisconnectCommon]; + __weak typeof(self) weakSelf = self; [self iterateOverStreamingDelegatesImplementingDelegateMethod:@selector(client:didDisconnectOnSocketError:) withBlock:^(id streamingDelegate) { [streamingDelegate client:weakSelf didDisconnectOnSocketError:error]; @@ -542,6 +566,8 @@ - (void)socket:(KATSocketShuttle *)socket didFailWithError:(NSError *)error { - (void)socket:(KATSocketShuttle *)socket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { + [self socketShuttleDisconnectCommon]; + __weak typeof(self) weakSelf = self; [self iterateOverStreamingDelegatesImplementingDelegateMethod:@selector(clientSocketDidDisconnect:) withBlock:^(id streamingDelegate) { [streamingDelegate clientSocketDidDisconnect:weakSelf]; From 3b19b97a0b01243e5d6180e53cd9c0ec07dcf9ea Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Thu, 1 Aug 2013 14:49:38 -0700 Subject: [PATCH 55/69] ..Maybe this is the trick? --- ADNKit/ANKClient.m | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 3a37599..9db93f0 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -135,18 +135,11 @@ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)p return request; } -//- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation { -// [super enqueueHTTPRequestOperation:operation]; -// -// dispatch_async(dispatch_get_main_queue(), ^{ -// if (!operation.isExecuting && operation.isReady) { -//// [operation start]; -// -// NSLog(@"ADNKit -- Operation had to be started manually as it wasn't executing when added to the queue."); -// #warning I'm not sure why this happens, but this fixes it. Sometimes the queue will just freeze and not start any of the operations going into it. It's not good. -// } -// }); -//} +- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation { + [super enqueueHTTPRequestOperation:operation]; + + [self.operationQueue setSuspended:NO]; +} #pragma mark - From 216a6ff768363e02ae2cf08d6e8716d69605f726 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Thu, 1 Aug 2013 15:23:07 -0700 Subject: [PATCH 56/69] Begin adding reachability-connection-type flags --- ADNKit/ANKClient.h | 7 +++++++ ADNKit/ANKClient.m | 5 +++-- External/SocketShuttle | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ADNKit/ANKClient.h b/ADNKit/ANKClient.h index 66a7e99..47115f5 100644 --- a/ADNKit/ANKClient.h +++ b/ADNKit/ANKClient.h @@ -34,6 +34,11 @@ typedef NS_ENUM(NSUInteger, ANKResponseDecodingType) { ANKResponseDecodingTypeNone // don't decode server response }; +typedef NS_ENUM(NSUInteger, ANKStreamingAvailability) { + ANKStreamingAvailabilityAllConnections, + ANKStreamingAvailabilityWiFi +}; + @class ANKClient, ANKAPIResponseMeta; @@ -77,6 +82,8 @@ typedef void (^ANKClientCompletionBlock)(id responseObject, ANKAPIResponseMeta * @property (assign) dispatch_queue_t successCallbackQueue; @property (assign) dispatch_queue_t failureCallbackQueue; +@property (assign) ANKStreamingAvailability streamingAvailbility; + @property (copy) void (^webAuthCompletionHandler)(BOOL success, NSError *error); // set as completion block for oauth authentication #pragma mark - diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index 9db93f0..ae139be 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -80,6 +80,7 @@ - (id)init { [self addObserver:self forKeyPath:@"accessToken" options:NSKeyValueObservingOptionNew context:nil]; self.streamContexts = [[NSMutableSet alloc] init]; + self.streamingAvailbility = ANKStreamingAvailabilityWiFi; } return self; @@ -410,7 +411,7 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation if (!self.streamingConnectionID) { [operation pause]; - self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self]; + self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self connectConditions:self.streamingAvailbility == ANKStreamingAvailabilityWiFi ? KATSocketConnectConditionWLAN : KATSocketConnectConditionAlways]; } else if (self.socketShuttle.socketState == KATSocketStateConnected) { [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID]; } @@ -492,7 +493,7 @@ - (void)iterateOverStreamingDelegatesImplementingDelegateMethod:(SEL)delegateMet - (void)socketShuttleDisconnectCommon { - self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self]; + self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self connectConditions:self.streamingAvailbility == ANKStreamingAvailabilityWiFi ? KATSocketConnectConditionWLAN : KATSocketConnectConditionAlways]; } diff --git a/External/SocketShuttle b/External/SocketShuttle index a11f162..d388703 160000 --- a/External/SocketShuttle +++ b/External/SocketShuttle @@ -1 +1 @@ -Subproject commit a11f162a552b5663c057419b52d36c6558542734 +Subproject commit d388703da95fb0152d1aebc76f808d7e5a75fe86 From 7db99448dc9169549d7aed4a2a8134af1098a392 Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Thu, 1 Aug 2013 16:57:57 -0700 Subject: [PATCH 57/69] Fixes non-building status with AFNetworking-bundled target. --- ADNKit.xcodeproj/project.pbxproj | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index b6a5073..12951b3 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -1757,7 +1757,11 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "ADNKit-AFNetworking-iOS"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; @@ -1771,7 +1775,11 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "ADNKit-AFNetworking-iOS"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; @@ -1846,7 +1854,12 @@ DSTROOT = /tmp/ADNKit.dst; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "ADNKit/ADNKit-Prefix.pch"; - HEADER_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ( + "\"$(SRCROOT)\"", + "\"$(SRCROOT)/External/SocketShuttle\"", + "\"$(SRCROOT)/External/SocketShuttle/Third-Party/SocketRocket\"", + ); + ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "ADNKit-AFNetworking-iOS"; PUBLIC_HEADERS_FOLDER_PATH = ADNKit; From c4107c5aacf91677f18e747509ba7debd265f7bf Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Fri, 2 Aug 2013 14:23:59 -0700 Subject: [PATCH 58/69] Prevents operations from stalling out forever. --- ADNKit/ADNKit-Prefix.pch | 2 -- ADNKit/ANKClient.m | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ADNKit/ADNKit-Prefix.pch b/ADNKit/ADNKit-Prefix.pch index a34720d..a797d77 100644 --- a/ADNKit/ADNKit-Prefix.pch +++ b/ADNKit/ADNKit-Prefix.pch @@ -13,8 +13,6 @@ #ifdef __OBJC__ #import - #define _AFNETWORKING_PIN_SSL_CERTIFICATES_ - #if __IPHONE_OS_VERSION_MIN_REQUIRED #import #endif diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index ae139be..f892097 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -412,7 +412,9 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation [operation pause]; self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self connectConditions:self.streamingAvailbility == ANKStreamingAvailabilityWiFi ? KATSocketConnectConditionWLAN : KATSocketConnectConditionAlways]; - } else if (self.socketShuttle.socketState == KATSocketStateConnected) { + } + + if (self.socketShuttle.socketState != KATSocketStateConnecting) { [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID]; } From b8193c342766c82bff8d65bb051bd03d40feef3f Mon Sep 17 00:00:00 2001 From: Kolin Krewinkel Date: Fri, 2 Aug 2013 14:31:41 -0700 Subject: [PATCH 59/69] ...now it works. removed the dispatch_async stuff in the socketshuttle. it could've been fixed by running the reconfigure block in a dispatch_async, but it would've made the double indirection not work. --- ADNKit/ANKClient.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index f892097..fc4c00d 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -414,8 +414,14 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation self.socketShuttle = [[KATSocketShuttle alloc] initWithRequest:[self streamingRequest] delegate:self connectConditions:self.streamingAvailbility == ANKStreamingAvailabilityWiFi ? KATSocketConnectConditionWLAN : KATSocketConnectConditionAlways]; } - if (self.socketShuttle.socketState != KATSocketStateConnecting) { + if (self.socketShuttle.socketState == KATSocketStateConnected) { [self reconfigureOperationForStreaming:operation subscriptionID:&subscriptionID]; + } else if (self.socketShuttle.socketState == KATSocketStateDisconnected || self.socketShuttle.socketState == KATSocketStateOffline) { + if (operation.isPaused) { + [operation resume]; + } else if (operation.isReady) { + [operation start]; + } } [self.streamContexts addObject:[ANKStreamContext streamContextWithOperation:operation identifier:subscriptionID delegate:delegate]]; From 3ab25f6c590956da79b725233c7edf2f8c43170c Mon Sep 17 00:00:00 2001 From: Tony Arnold Date: Wed, 14 Aug 2013 14:00:09 +1000 Subject: [PATCH 60/69] Use the correct developer frameworks variable so that builds work properly under Xcode 5 --- ADNKit.xcodeproj/project.pbxproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 12951b3..9d2f0d4 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -1876,7 +1876,7 @@ DYLIB_CURRENT_VERSION = 1; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"", + $DEVELOPER_FRAMEWORKS_DIR_QUOTED, ); FRAMEWORK_VERSION = A; GCC_ENABLE_OBJC_EXCEPTIONS = YES; @@ -2032,7 +2032,7 @@ DYLIB_CURRENT_VERSION = 1; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"", + $DEVELOPER_FRAMEWORKS_DIR_QUOTED, ); FRAMEWORK_VERSION = A; GCC_ENABLE_OBJC_EXCEPTIONS = YES; @@ -2058,7 +2058,7 @@ DYLIB_CURRENT_VERSION = 1; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"", + $DEVELOPER_FRAMEWORKS_DIR_QUOTED, ); FRAMEWORK_VERSION = A; GCC_ENABLE_OBJC_EXCEPTIONS = YES; From 13e60f28abbe2827ceeaee1446788f4e389b439c Mon Sep 17 00:00:00 2001 From: Tony Arnold Date: Wed, 14 Aug 2013 14:26:57 +1000 Subject: [PATCH 61/69] Update SocketShuttle submodule to use HTTPS URL --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 05cb21d..f889196 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,4 +4,4 @@ ignore = dirty [submodule "SocketShuttle"] path = External/SocketShuttle - url = git@github.com:joeldev/SocketShuttle.git + url=https://github.com/joeldev/SocketShuttle.git From b69cf626f7b0b272e4f3218e503a0cdd45d58477 Mon Sep 17 00:00:00 2001 From: Tony Arnold Date: Wed, 14 Aug 2013 14:41:56 +1000 Subject: [PATCH 62/69] Re-enable OS X support --- ADNKit.xcodeproj/project.pbxproj | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 9d2f0d4..4145b86 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -348,7 +348,6 @@ 2592B81B16FF84A4004573FF /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DC3725016E3AE1500190862 /* AFNetworkActivityIndicatorManager.m */; }; 259A5EC616F2E1EF00AF9F35 /* ADNKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DC370E116E0805E00190862 /* ADNKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 25C0AA45171867B8006E47B7 /* CustomPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 25C0AA44171867B8006E47B7 /* CustomPost.m */; }; - 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 33041CE917A3760A00C4B25A /* ANKStreamContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 335AC10F176427C300AEFCFE /* ANKStreamContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 33041CEA17A3760D00C4B25A /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; 33041CF017A38A0F00C4B25A /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; @@ -420,6 +419,9 @@ 5DC3727E16E3AF6900190862 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DC3727D16E3AF6900190862 /* UIKit.framework */; }; 5DC3728116E3AF8900190862 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DC3728016E3AF8800190862 /* CoreLocation.framework */; }; 5DC3728316E3AF8E00190862 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DC3728216E3AF8E00190862 /* SystemConfiguration.framework */; }; + 905AF9D817BB41B1002FDE4E /* SocketShuttle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 905AF9D717BB41AD002FDE4E /* SocketShuttle.framework */; }; + 905AF9DA17BB41CC002FDE4E /* SocketShuttle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 905AF9D717BB41AD002FDE4E /* SocketShuttle.framework */; }; + 905AF9DB17BB41E3002FDE4E /* ANKStreamContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 335AC110176427C300AEFCFE /* ANKStreamContext.m */; }; F153F9AA1773C1DE0018BC16 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F153F9A91773C1DE0018BC16 /* Security.framework */; }; /* End PBXBuildFile section */ @@ -459,6 +461,13 @@ remoteGlobalIDString = 4DE9EB64170D870A005B295E; remoteInfo = SocketShuttle; }; + 905AF9D617BB41AD002FDE4E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 905AF99F17BB3F40002FDE4E; + remoteInfo = SocketShuttleOSX; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -480,6 +489,16 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 905AF9D917BB41C3002FDE4E /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 905AF9DA17BB41CC002FDE4E /* SocketShuttle.framework in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ @@ -711,7 +730,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 25D01E141764104A000D365D /* libSocketShuttle.a in Frameworks */, + 905AF9D817BB41B1002FDE4E /* SocketShuttle.framework in Frameworks */, F153F9AA1773C1DE0018BC16 /* Security.framework in Frameworks */, 252A87D416F79A09001F3E8F /* CoreServices.framework in Frameworks */, 5DC3728316E3AF8E00190862 /* SystemConfiguration.framework in Frameworks */, @@ -910,6 +929,7 @@ isa = PBXGroup; children = ( 25D01E0B17640FF1000D365D /* libSocketShuttle.a */, + 905AF9D717BB41AD002FDE4E /* SocketShuttle.framework */, ); name = Products; sourceTree = ""; @@ -1341,6 +1361,7 @@ 5DC3710416E0808C00190862 /* Frameworks */, 5DC3710516E0808C00190862 /* Headers */, 5DC3710616E0808C00190862 /* Resources */, + 905AF9D917BB41C3002FDE4E /* CopyFiles */, ); buildRules = ( ); @@ -1395,6 +1416,13 @@ remoteRef = 25D01E0A17640FF1000D365D /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 905AF9D717BB41AD002FDE4E /* SocketShuttle.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SocketShuttle.framework; + remoteRef = 905AF9D617BB41AD002FDE4E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ @@ -1659,6 +1687,7 @@ 2592B81816FF84A4004573FF /* AFURLConnectionOperation.m in Sources */, 2592B81916FF84A4004573FF /* AFXMLRequestOperation.m in Sources */, 2592B81A16FF84A4004573FF /* UIImageView+AFNetworking.m in Sources */, + 905AF9DB17BB41E3002FDE4E /* ANKStreamContext.m in Sources */, 2592B81B16FF84A4004573FF /* AFNetworkActivityIndicatorManager.m in Sources */, 5D2CFEE91703E8F200086FBD /* ANKTokenLimits.m in Sources */, 256768121711539D00C57D47 /* NSString+ANKAdditions.m in Sources */, From b1fbe69d8d2e2508415940ff678726f436358f2b Mon Sep 17 00:00:00 2001 From: Tony Arnold Date: Wed, 14 Aug 2013 14:49:32 +1000 Subject: [PATCH 63/69] Update submodule reference to latest SocketShuttle changes that include OS X support --- External/SocketShuttle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/SocketShuttle b/External/SocketShuttle index d388703..2e2f37a 160000 --- a/External/SocketShuttle +++ b/External/SocketShuttle @@ -1 +1 @@ -Subproject commit d388703da95fb0152d1aebc76f808d7e5a75fe86 +Subproject commit 2e2f37af20c6662f23a3140c0b933d0acd26c388 From 449e1ed64a0dec629aefee6e221ab9a80fa4f6fe Mon Sep 17 00:00:00 2001 From: Tony Arnold Date: Wed, 14 Aug 2013 14:56:05 +1000 Subject: [PATCH 64/69] Make missing project headers public in the framework --- ADNKit.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 4145b86..63fc343 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -245,7 +245,7 @@ 252A898E16F8CDF3001F3E8F /* NSDictionary+ANKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 252A88E916F8CDF2001F3E8F /* NSDictionary+ANKAdditions.m */; }; 252A898F16F8CDF3001F3E8F /* NSDictionary+ANKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 252A88E916F8CDF2001F3E8F /* NSDictionary+ANKAdditions.m */; }; 252AD7151745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 252AD7121745C76600E12492 /* ANKClient+ANKRequestsAPI.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 252AD7161745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 252AD7121745C76600E12492 /* ANKClient+ANKRequestsAPI.h */; }; + 252AD7161745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 252AD7121745C76600E12492 /* ANKClient+ANKRequestsAPI.h */; settings = {ATTRIBUTES = (Public, ); }; }; 252AD7171745C76600E12492 /* ANKClient+ANKRequestsAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 252AD7131745C76600E12492 /* ANKClient+ANKRequestsAPI.m */; }; 252AD7181745C76600E12492 /* ANKClient+ANKRequestsAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 252AD7131745C76600E12492 /* ANKClient+ANKRequestsAPI.m */; }; 252AD7191745C76600E12492 /* ANKClient+ANKRequestsAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 252AD7131745C76600E12492 /* ANKClient+ANKRequestsAPI.m */; }; @@ -353,7 +353,7 @@ 33041CF017A38A0F00C4B25A /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 330BDCAA17659465009BD559 /* libSocketShuttle.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25D01E0B17640FF1000D365D /* libSocketShuttle.a */; }; 331B250F17A247DF000E553E /* ANKSearchQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 331B250D17A247DF000E553E /* ANKSearchQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 331B251017A247DF000E553E /* ANKSearchQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 331B250D17A247DF000E553E /* ANKSearchQuery.h */; }; + 331B251017A247DF000E553E /* ANKSearchQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 331B250D17A247DF000E553E /* ANKSearchQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; 331B251117A247DF000E553E /* ANKSearchQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 331B250E17A247DF000E553E /* ANKSearchQuery.m */; }; 331B251217A247DF000E553E /* ANKSearchQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 331B250E17A247DF000E553E /* ANKSearchQuery.m */; }; 3326109617A3B75B00665C05 /* ANKSearchQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 331B250D17A247DF000E553E /* ANKSearchQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -1286,10 +1286,10 @@ 252A898A16F8CDF3001F3E8F /* NSArray+ANKAdditions.h in Headers */, 252A898D16F8CDF3001F3E8F /* NSDictionary+ANKAdditions.h in Headers */, 5D2CFEE61703E8F200086FBD /* ANKTokenLimits.h in Headers */, - 331B251017A247DF000E553E /* ANKSearchQuery.h in Headers */, - 2567680F1711539D00C57D47 /* NSString+ANKAdditions.h in Headers */, 2567682717153E3200C57D47 /* ANKResourceMap.h in Headers */, + 331B251017A247DF000E553E /* ANKSearchQuery.h in Headers */, 252AD7161745C76600E12492 /* ANKClient+ANKRequestsAPI.h in Headers */, + 2567680F1711539D00C57D47 /* NSString+ANKAdditions.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; From 7a7c5204d0da68924bbfc16d3a60e3d2f3707cbe Mon Sep 17 00:00:00 2001 From: Mark Thurman Date: Sat, 25 Jan 2014 19:11:20 -0800 Subject: [PATCH 65/69] Allow multiple streaming operations to be started When trying to subscribe to multiple UserStream topics, only the first one was succeeding (since it got paused and then resumed on didReceiveMessage in the isInitialConnectionResponse state). This pauses subsequent operations that come in while we're trying to connect the websocket so once we successfully connect, we can resume (and subscribe with the correct connection_id). --- ADNKit/ANKClient.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ADNKit/ANKClient.m b/ADNKit/ANKClient.m index fc4c00d..0c8e4e3 100644 --- a/ADNKit/ANKClient.m +++ b/ADNKit/ANKClient.m @@ -422,6 +422,8 @@ - (void)requestStreamingUpdatesForOperation:(ANKJSONRequestOperation *)operation } else if (operation.isReady) { [operation start]; } + } else if (self.socketShuttle.socketState == KATSocketStateConnecting){ + [operation pause]; } [self.streamContexts addObject:[ANKStreamContext streamContextWithOperation:operation identifier:subscriptionID delegate:delegate]]; From ab36edb514808e8bbdd40b60590c2de7ea8a49b7 Mon Sep 17 00:00:00 2001 From: Mark Thurman Date: Sat, 25 Jan 2014 19:47:24 -0800 Subject: [PATCH 66/69] Add meta params applicable to user streams --- ADNKit/ANKAPIResponseMeta.h | 7 +++++++ ADNKit/ANKAPIResponseMeta.m | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ADNKit/ANKAPIResponseMeta.h b/ADNKit/ANKAPIResponseMeta.h index 17f9d73..b88c1ea 100644 --- a/ADNKit/ANKAPIResponseMeta.h +++ b/ADNKit/ANKAPIResponseMeta.h @@ -59,6 +59,13 @@ static NSString *const kANKErrorIDKey = @"ANKErrorID"; @property (strong) NSString *errorSlug; @property (strong) NSString *errorID; +// user streaming properties +@property (assign) BOOL isDeleted; +@property (strong) NSString *deletedID; +@property (strong) NSArray *subscriptionIDs; +@property (strong) NSString *connectionID; +@property (strong) NSString *type; + - (NSError *)error; - (BOOL)isError; - (ANKErrorType)errorType; diff --git a/ADNKit/ANKAPIResponseMeta.m b/ADNKit/ANKAPIResponseMeta.m index 84563ae..9f28632 100644 --- a/ADNKit/ANKAPIResponseMeta.m +++ b/ADNKit/ANKAPIResponseMeta.m @@ -23,7 +23,12 @@ + (NSDictionary *)JSONToLocalKeyMapping { @"more": @"moreDataAvailable", @"error_message": @"errorMessage", @"error_slug": @"errorSlug", - @"error_id": @"errorID"}]; + @"error_id": @"errorID", + @"is_deleted": @"isDeleted", + @"deleted_id": @"deletedID", + @"subscription_ids": @"subscriptionIDs", + @"connection_id": @"connectionID", + @"type": @"type"}]; } From ed17977776000f02209f868057ca22f1aaf7205f Mon Sep 17 00:00:00 2001 From: Tony Arnold Date: Tue, 18 Feb 2014 14:26:27 +1100 Subject: [PATCH 67/69] ADNKit-OSX had the iOS SocketShuttle as a target dependency, fixed. --- ADNKit.xcodeproj/project.pbxproj | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 63fc343..27ec966 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -447,19 +447,19 @@ remoteGlobalIDString = 4DE9EB64170D870A005B295E; remoteInfo = SocketShuttle; }; - 25D01E1217641047000D365D /* PBXContainerItemProxy */ = { + 330BDCA81765945F009BD559 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; proxyType = 1; remoteGlobalIDString = 4DE9EB64170D870A005B295E; remoteInfo = SocketShuttle; }; - 330BDCA81765945F009BD559 /* PBXContainerItemProxy */ = { + 902756DC18B3076E00CB0579 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 25D01E0517640FF1000D365D /* SocketShuttle.xcodeproj */; proxyType = 1; - remoteGlobalIDString = 4DE9EB64170D870A005B295E; - remoteInfo = SocketShuttle; + remoteGlobalIDString = 905AF99E17BB3F40002FDE4E; + remoteInfo = SocketShuttleOSX; }; 905AF9D617BB41AD002FDE4E /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; @@ -1366,7 +1366,7 @@ buildRules = ( ); dependencies = ( - 25D01E1317641047000D365D /* PBXTargetDependency */, + 902756DD18B3076E00CB0579 /* PBXTargetDependency */, ); name = "ADNKit-OSX"; productName = "ADNKit-OSX"; @@ -1711,16 +1711,16 @@ name = SocketShuttle; targetProxy = 25D01E0F17641021000D365D /* PBXContainerItemProxy */; }; - 25D01E1317641047000D365D /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = SocketShuttle; - targetProxy = 25D01E1217641047000D365D /* PBXContainerItemProxy */; - }; 330BDCA91765945F009BD559 /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = SocketShuttle; targetProxy = 330BDCA81765945F009BD559 /* PBXContainerItemProxy */; }; + 902756DD18B3076E00CB0579 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = SocketShuttleOSX; + targetProxy = 902756DC18B3076E00CB0579 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ From a6feb2eddb71f36db6e78b5ea667c3ab64ad0d86 Mon Sep 17 00:00:00 2001 From: Tony Arnold Date: Tue, 18 Feb 2014 15:36:51 +1100 Subject: [PATCH 68/69] NSString+ANKAdditions header should be public --- ADNKit.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ADNKit.xcodeproj/project.pbxproj b/ADNKit.xcodeproj/project.pbxproj index 27ec966..9f819b6 100644 --- a/ADNKit.xcodeproj/project.pbxproj +++ b/ADNKit.xcodeproj/project.pbxproj @@ -253,7 +253,7 @@ 252E632617421632003143D6 /* ANKClient+ANKStreamMarker.m in Sources */ = {isa = PBXBuildFile; fileRef = 252E632417421632003143D6 /* ANKClient+ANKStreamMarker.m */; }; 252E632717421632003143D6 /* ANKClient+ANKStreamMarker.m in Sources */ = {isa = PBXBuildFile; fileRef = 252E632417421632003143D6 /* ANKClient+ANKStreamMarker.m */; }; 252E632817421632003143D6 /* ANKClient+ANKStreamMarker.m in Sources */ = {isa = PBXBuildFile; fileRef = 252E632417421632003143D6 /* ANKClient+ANKStreamMarker.m */; }; - 2567680F1711539D00C57D47 /* NSString+ANKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 2567680D1711539D00C57D47 /* NSString+ANKAdditions.h */; }; + 2567680F1711539D00C57D47 /* NSString+ANKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 2567680D1711539D00C57D47 /* NSString+ANKAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 256768101711539D00C57D47 /* NSString+ANKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 2567680E1711539D00C57D47 /* NSString+ANKAdditions.m */; }; 256768111711539D00C57D47 /* NSString+ANKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 2567680E1711539D00C57D47 /* NSString+ANKAdditions.m */; }; 256768121711539D00C57D47 /* NSString+ANKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 2567680E1711539D00C57D47 /* NSString+ANKAdditions.m */; }; From 59be43a73b4d010b5ee9007553b0ae3a074e001e Mon Sep 17 00:00:00 2001 From: Tony Arnold Date: Thu, 27 Feb 2014 17:12:40 +1100 Subject: [PATCH 69/69] Add support for the inactive field on Channel objects --- ADNKit/ANKChannel.h | 1 + ADNKit/ANKChannel.m | 3 ++- ADNKit/ANKGeneralParameters.h | 1 + ADNKit/ANKGeneralParameters.m | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ADNKit/ANKChannel.h b/ADNKit/ANKChannel.h index a71bb62..9f69f3c 100644 --- a/ADNKit/ANKChannel.h +++ b/ADNKit/ANKChannel.h @@ -28,6 +28,7 @@ @property (strong) ANKACL *writers; @property (assign) BOOL isCurrentUserSubscribed; @property (assign) BOOL isEditableByCurrentUser; +@property (assign) BOOL isInactive; @property (assign) BOOL hasUnreadMessages; - (BOOL)isPrivateMessageChannel; diff --git a/ADNKit/ANKChannel.m b/ADNKit/ANKChannel.m index 574c7e8..3dd3ae8 100644 --- a/ADNKit/ANKChannel.m +++ b/ADNKit/ANKChannel.m @@ -23,7 +23,8 @@ + (NSDictionary *)JSONToLocalKeyMapping { @"you_can_edit": @"isEditableByCurrentUser", @"has_unread": @"hasUnreadMessages", @"recent_message_id": @"latestMessageID", - @"recent_message": @"latestMessage"}]; + @"recent_message": @"latestMessage", + @"is_inactive" : @"isInactive"}]; } diff --git a/ADNKit/ANKGeneralParameters.h b/ADNKit/ANKGeneralParameters.h index 9d9f2a4..60b1105 100644 --- a/ADNKit/ANKGeneralParameters.h +++ b/ADNKit/ANKGeneralParameters.h @@ -18,6 +18,7 @@ @property (assign) BOOL includeMuted; @property (assign) BOOL includeDeleted; @property (assign) BOOL includeDirectedPosts; +@property (assign) BOOL includeInactive; @property (assign) BOOL includeMachine; @property (assign) BOOL includeStarredBy; @property (assign) BOOL includeReposters; diff --git a/ADNKit/ANKGeneralParameters.m b/ADNKit/ANKGeneralParameters.m index 982ee73..531d116 100644 --- a/ADNKit/ANKGeneralParameters.m +++ b/ADNKit/ANKGeneralParameters.m @@ -19,6 +19,7 @@ + (NSDictionary *)JSONToLocalKeyMapping { return [[super JSONToLocalKeyMapping] ank_dictionaryByAppendingDictionary:@{ @"include_muted": @"includeMuted", @"include_deleted": @"includeDeleted", + @"include_inactive": @"includeInactive", @"include_directed_posts": @"includeDirectedPosts", @"include_machine": @"includeMachine", @"include_starred_by": @"includeStarredBy",