From d236e14041760da9eb7e27640424b31b8994590a Mon Sep 17 00:00:00 2001 From: Derek316x Date: Mon, 21 Sep 2015 23:18:42 -0400 Subject: [PATCH 1/5] added pods --- TalkinToTheNet/Podfile | 2 + .../TalkinToTheNet.xcodeproj/project.pbxproj | 290 ++++ TalkinToTheNet/TalkinToTheNet/APIManager.h | 16 + TalkinToTheNet/TalkinToTheNet/APIManager.m | 31 + .../FourSquareKit/FourSquareKit.h | 42 + .../NSAlert+MKNetworkKitAdditions.h | 15 + .../NSAlert+MKNetworkKitAdditions.m | 20 + .../MKNetworkKit/Categories/NSData+MKBase64.h | 42 + .../MKNetworkKit/Categories/NSData+MKBase64.m | 312 ++++ .../MKNetworkKit/Categories/NSDate+RFC1123.h | 27 + .../MKNetworkKit/Categories/NSDate+RFC1123.m | 76 + .../Categories/NSDictionary+RequestEncoding.h | 33 + .../Categories/NSDictionary+RequestEncoding.m | 74 + .../NSImageView+MKNetworkKitAdditions.h | 45 + .../NSImageView+MKNetworkKitAdditions.m | 99 ++ .../NSString+MKNetworkKitAdditions.h | 34 + .../NSString+MKNetworkKitAdditions.m | 81 + .../UIAlertView+MKNetworkKitAdditions.h | 31 + .../UIAlertView+MKNetworkKitAdditions.m | 41 + .../UIImageView+MKNetworkKitAdditions.h | 42 + .../UIImageView+MKNetworkKitAdditions.m | 109 ++ .../MKNetworkKit/MKNetworkEngine.h | 425 +++++ .../MKNetworkKit/MKNetworkEngine.m | 766 +++++++++ .../FourSquareKit/MKNetworkKit/MKNetworkKit.h | 95 ++ .../MKNetworkKit/MKNetworkOperation.h | 692 ++++++++ .../MKNetworkKit/MKNetworkOperation.m | 1518 +++++++++++++++++ .../categories/CLLocation+Testing.h | 21 + .../categories/CLLocation+Testing.m | 63 + .../categories/CLLocation+isEmpty.h | 13 + .../categories/CLLocation+isEmpty.m | 17 + .../categories/NSDictionary+PList.h | 15 + .../categories/NSDictionary+PList.m | 21 + .../categories/NSString+Location.h | 24 + .../categories/NSString+Location.m | 48 + .../FourSquareKit/categories/NSString+Utils.h | 19 + .../FourSquareKit/categories/NSString+Utils.m | 49 + .../FourSquareKit/models/UXRBaseModel.h | 13 + .../FourSquareKit/models/UXRBaseModel.m | 17 + .../models/UXRExploreQueryBaseModel.h | 21 + .../models/UXRExploreQueryBaseModel.m | 52 + .../models/UXRFourSquareAttributesModel.h | 13 + .../models/UXRFourSquareAttributesModel.m | 65 + .../models/UXRFourSquareCategoryModel.h | 20 + .../models/UXRFourSquareCategoryModel.m | 25 + .../models/UXRFourSquareContactModel.h | 15 + .../models/UXRFourSquareContactModel.m | 13 + .../models/UXRFourSquareExploreResultsModel.h | 17 + .../models/UXRFourSquareExploreResultsModel.m | 42 + .../models/UXRFourSquareGeoCodeModel.h | 18 + .../models/UXRFourSquareGeoCodeModel.m | 13 + .../models/UXRFourSquareHoursModel.h | 15 + .../models/UXRFourSquareHoursModel.m | 31 + .../models/UXRFourSquareLikesModel.h | 15 + .../models/UXRFourSquareLikesModel.m | 13 + .../models/UXRFourSquareLocationModel.h | 21 + .../models/UXRFourSquareLocationModel.m | 14 + .../models/UXRFourSquareMenuModel.h | 17 + .../models/UXRFourSquareMenuModel.m | 36 + .../models/UXRFourSquareOpenTime.h | 13 + .../models/UXRFourSquareOpenTime.m | 12 + .../models/UXRFourSquarePhotoModel.h | 22 + .../models/UXRFourSquarePhotoModel.m | 63 + .../models/UXRFourSquarePriceModel.h | 14 + .../models/UXRFourSquarePriceModel.m | 13 + .../models/UXRFourSquareReservationsModel.h | 13 + .../models/UXRFourSquareReservationsModel.m | 25 + .../models/UXRFourSquareRestaurantModel.h | 42 + .../models/UXRFourSquareRestaurantModel.m | 221 +++ .../models/UXRFourSquareStatsModel.h | 17 + .../models/UXRFourSquareStatsModel.m | 12 + .../models/UXRFourSquareTimeFramesModel.h | 16 + .../models/UXRFourSquareTimeFramesModel.m | 31 + .../models/UXRFourSquareTipModel.h | 19 + .../models/UXRFourSquareTipModel.m | 50 + .../models/UXRFourSquareUserModel.h | 17 + .../models/UXRFourSquareUserModel.m | 26 + .../models/UXRJSONDeserializableObject.h | 66 + .../models/UXRJSONDeserializableObject.m | 178 ++ .../models/UXRJSONSerializableObject.h | 22 + .../networking/UXRBaseNetworkingEngine.h | 17 + .../networking/UXRBaseNetworkingEngine.m | 34 + .../UXRFourSquareNetworkingEngine.h | 60 + .../UXRFourSquareNetworkingEngine.m | 375 ++++ .../TalkinToTheNet/ViewController.m | 5 - 84 files changed, 7132 insertions(+), 5 deletions(-) create mode 100644 TalkinToTheNet/Podfile create mode 100644 TalkinToTheNet/TalkinToTheNet/APIManager.h create mode 100644 TalkinToTheNet/TalkinToTheNet/APIManager.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/FourSquareKit.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkKit.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONSerializableObject.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.m create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.h create mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.m diff --git a/TalkinToTheNet/Podfile b/TalkinToTheNet/Podfile new file mode 100644 index 0000000..86a5040 --- /dev/null +++ b/TalkinToTheNet/Podfile @@ -0,0 +1,2 @@ +platform :ios, '8.4' +pod 'FourSquareKit' \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj index ee35a70..b367b79 100644 --- a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj +++ b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj @@ -7,6 +7,45 @@ objects = { /* Begin PBXBuildFile section */ + 69E41EF71BB0F5F600D7324C /* APIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41EF61BB0F5F600D7324C /* APIManager.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FB41BB0FFCF00D7324C /* CLLocation+isEmpty.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F791BB0FFCF00D7324C /* CLLocation+isEmpty.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FB51BB0FFCF00D7324C /* CLLocation+Testing.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F7B1BB0FFCF00D7324C /* CLLocation+Testing.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FB61BB0FFCF00D7324C /* NSDictionary+PList.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F7D1BB0FFCF00D7324C /* NSDictionary+PList.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FB71BB0FFCF00D7324C /* NSString+Location.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F7F1BB0FFCF00D7324C /* NSString+Location.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FB81BB0FFCF00D7324C /* NSString+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F811BB0FFCF00D7324C /* NSString+Utils.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FB91BB0FFCF00D7324C /* UXRBaseModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F851BB0FFCF00D7324C /* UXRBaseModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FBA1BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F871BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FBB1BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F891BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FBC1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F8B1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FBD1BB0FFCF00D7324C /* UXRFourSquareContactModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F8D1BB0FFCF00D7324C /* UXRFourSquareContactModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FBE1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F8F1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FBF1BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F911BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC01BB0FFCF00D7324C /* UXRFourSquareHoursModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F931BB0FFCF00D7324C /* UXRFourSquareHoursModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC11BB0FFCF00D7324C /* UXRFourSquareLikesModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F951BB0FFCF00D7324C /* UXRFourSquareLikesModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC21BB0FFCF00D7324C /* UXRFourSquareLocationModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F971BB0FFCF00D7324C /* UXRFourSquareLocationModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC31BB0FFCF00D7324C /* UXRFourSquareMenuModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F991BB0FFCF00D7324C /* UXRFourSquareMenuModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC41BB0FFCF00D7324C /* UXRFourSquareOpenTime.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F9B1BB0FFCF00D7324C /* UXRFourSquareOpenTime.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC51BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F9D1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC61BB0FFCF00D7324C /* UXRFourSquarePriceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F9F1BB0FFCF00D7324C /* UXRFourSquarePriceModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC71BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA11BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC81BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA31BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FC91BB0FFCF00D7324C /* UXRFourSquareStatsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA51BB0FFCF00D7324C /* UXRFourSquareStatsModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FCA1BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA71BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FCB1BB0FFCF00D7324C /* UXRFourSquareTipModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA91BB0FFCF00D7324C /* UXRFourSquareTipModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FCC1BB0FFCF00D7324C /* UXRFourSquareUserModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FAB1BB0FFCF00D7324C /* UXRFourSquareUserModel.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FCD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FAD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FCE1BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FB11BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FCF1BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FB31BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FE71BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FD31BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FE81BB0FFDD00D7324C /* NSData+MKBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FD51BB0FFDD00D7324C /* NSData+MKBase64.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FE91BB0FFDD00D7324C /* NSDate+RFC1123.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FD71BB0FFDD00D7324C /* NSDate+RFC1123.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FEA1BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FD91BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FEB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FDB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FEC1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FDD1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FED1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FDF1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FEE1BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FE11BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FEF1BB0FFDD00D7324C /* MKNetworkEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FE31BB0FFDD00D7324C /* MKNetworkEngine.m */; settings = {ASSET_TAGS = (); }; }; + 69E41FF01BB0FFDD00D7324C /* MKNetworkOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FE61BB0FFDD00D7324C /* MKNetworkOperation.m */; settings = {ASSET_TAGS = (); }; }; 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4A1BAF859400A92AD2 /* main.m */; }; 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */; }; 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD501BAF859400A92AD2 /* ViewController.m */; }; @@ -16,6 +55,87 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 69E41EF51BB0F5F600D7324C /* APIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIManager.h; sourceTree = ""; }; + 69E41EF61BB0F5F600D7324C /* APIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIManager.m; sourceTree = ""; }; + 69E41F781BB0FFCF00D7324C /* CLLocation+isEmpty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CLLocation+isEmpty.h"; sourceTree = ""; }; + 69E41F791BB0FFCF00D7324C /* CLLocation+isEmpty.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CLLocation+isEmpty.m"; sourceTree = ""; }; + 69E41F7A1BB0FFCF00D7324C /* CLLocation+Testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CLLocation+Testing.h"; sourceTree = ""; }; + 69E41F7B1BB0FFCF00D7324C /* CLLocation+Testing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CLLocation+Testing.m"; sourceTree = ""; }; + 69E41F7C1BB0FFCF00D7324C /* NSDictionary+PList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+PList.h"; sourceTree = ""; }; + 69E41F7D1BB0FFCF00D7324C /* NSDictionary+PList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+PList.m"; sourceTree = ""; }; + 69E41F7E1BB0FFCF00D7324C /* NSString+Location.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Location.h"; sourceTree = ""; }; + 69E41F7F1BB0FFCF00D7324C /* NSString+Location.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Location.m"; sourceTree = ""; }; + 69E41F801BB0FFCF00D7324C /* NSString+Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Utils.h"; sourceTree = ""; }; + 69E41F811BB0FFCF00D7324C /* NSString+Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Utils.m"; sourceTree = ""; }; + 69E41F821BB0FFCF00D7324C /* FourSquareKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FourSquareKit.h; sourceTree = ""; }; + 69E41F841BB0FFCF00D7324C /* UXRBaseModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRBaseModel.h; sourceTree = ""; }; + 69E41F851BB0FFCF00D7324C /* UXRBaseModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRBaseModel.m; sourceTree = ""; }; + 69E41F861BB0FFCF00D7324C /* UXRExploreQueryBaseModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRExploreQueryBaseModel.h; sourceTree = ""; }; + 69E41F871BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRExploreQueryBaseModel.m; sourceTree = ""; }; + 69E41F881BB0FFCF00D7324C /* UXRFourSquareAttributesModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareAttributesModel.h; sourceTree = ""; }; + 69E41F891BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareAttributesModel.m; sourceTree = ""; }; + 69E41F8A1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareCategoryModel.h; sourceTree = ""; }; + 69E41F8B1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareCategoryModel.m; sourceTree = ""; }; + 69E41F8C1BB0FFCF00D7324C /* UXRFourSquareContactModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareContactModel.h; sourceTree = ""; }; + 69E41F8D1BB0FFCF00D7324C /* UXRFourSquareContactModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareContactModel.m; sourceTree = ""; }; + 69E41F8E1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareExploreResultsModel.h; sourceTree = ""; }; + 69E41F8F1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareExploreResultsModel.m; sourceTree = ""; }; + 69E41F901BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareGeoCodeModel.h; sourceTree = ""; }; + 69E41F911BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareGeoCodeModel.m; sourceTree = ""; }; + 69E41F921BB0FFCF00D7324C /* UXRFourSquareHoursModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareHoursModel.h; sourceTree = ""; }; + 69E41F931BB0FFCF00D7324C /* UXRFourSquareHoursModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareHoursModel.m; sourceTree = ""; }; + 69E41F941BB0FFCF00D7324C /* UXRFourSquareLikesModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareLikesModel.h; sourceTree = ""; }; + 69E41F951BB0FFCF00D7324C /* UXRFourSquareLikesModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareLikesModel.m; sourceTree = ""; }; + 69E41F961BB0FFCF00D7324C /* UXRFourSquareLocationModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareLocationModel.h; sourceTree = ""; }; + 69E41F971BB0FFCF00D7324C /* UXRFourSquareLocationModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareLocationModel.m; sourceTree = ""; }; + 69E41F981BB0FFCF00D7324C /* UXRFourSquareMenuModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareMenuModel.h; sourceTree = ""; }; + 69E41F991BB0FFCF00D7324C /* UXRFourSquareMenuModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareMenuModel.m; sourceTree = ""; }; + 69E41F9A1BB0FFCF00D7324C /* UXRFourSquareOpenTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareOpenTime.h; sourceTree = ""; }; + 69E41F9B1BB0FFCF00D7324C /* UXRFourSquareOpenTime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareOpenTime.m; sourceTree = ""; }; + 69E41F9C1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquarePhotoModel.h; sourceTree = ""; }; + 69E41F9D1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquarePhotoModel.m; sourceTree = ""; }; + 69E41F9E1BB0FFCF00D7324C /* UXRFourSquarePriceModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquarePriceModel.h; sourceTree = ""; }; + 69E41F9F1BB0FFCF00D7324C /* UXRFourSquarePriceModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquarePriceModel.m; sourceTree = ""; }; + 69E41FA01BB0FFCF00D7324C /* UXRFourSquareReservationsModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareReservationsModel.h; sourceTree = ""; }; + 69E41FA11BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareReservationsModel.m; sourceTree = ""; }; + 69E41FA21BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareRestaurantModel.h; sourceTree = ""; }; + 69E41FA31BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareRestaurantModel.m; sourceTree = ""; }; + 69E41FA41BB0FFCF00D7324C /* UXRFourSquareStatsModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareStatsModel.h; sourceTree = ""; }; + 69E41FA51BB0FFCF00D7324C /* UXRFourSquareStatsModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareStatsModel.m; sourceTree = ""; }; + 69E41FA61BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareTimeFramesModel.h; sourceTree = ""; }; + 69E41FA71BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareTimeFramesModel.m; sourceTree = ""; }; + 69E41FA81BB0FFCF00D7324C /* UXRFourSquareTipModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareTipModel.h; sourceTree = ""; }; + 69E41FA91BB0FFCF00D7324C /* UXRFourSquareTipModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareTipModel.m; sourceTree = ""; }; + 69E41FAA1BB0FFCF00D7324C /* UXRFourSquareUserModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareUserModel.h; sourceTree = ""; }; + 69E41FAB1BB0FFCF00D7324C /* UXRFourSquareUserModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareUserModel.m; sourceTree = ""; }; + 69E41FAC1BB0FFCF00D7324C /* UXRJSONDeserializableObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRJSONDeserializableObject.h; sourceTree = ""; }; + 69E41FAD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRJSONDeserializableObject.m; sourceTree = ""; }; + 69E41FAE1BB0FFCF00D7324C /* UXRJSONSerializableObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRJSONSerializableObject.h; sourceTree = ""; }; + 69E41FB01BB0FFCF00D7324C /* UXRBaseNetworkingEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRBaseNetworkingEngine.h; sourceTree = ""; }; + 69E41FB11BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRBaseNetworkingEngine.m; sourceTree = ""; }; + 69E41FB21BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareNetworkingEngine.h; sourceTree = ""; }; + 69E41FB31BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareNetworkingEngine.m; sourceTree = ""; }; + 69E41FD21BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAlert+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E41FD31BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSAlert+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E41FD41BB0FFDD00D7324C /* NSData+MKBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+MKBase64.h"; sourceTree = ""; }; + 69E41FD51BB0FFDD00D7324C /* NSData+MKBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+MKBase64.m"; sourceTree = ""; }; + 69E41FD61BB0FFDD00D7324C /* NSDate+RFC1123.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+RFC1123.h"; sourceTree = ""; }; + 69E41FD71BB0FFDD00D7324C /* NSDate+RFC1123.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+RFC1123.m"; sourceTree = ""; }; + 69E41FD81BB0FFDD00D7324C /* NSDictionary+RequestEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+RequestEncoding.h"; sourceTree = ""; }; + 69E41FD91BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+RequestEncoding.m"; sourceTree = ""; }; + 69E41FDA1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImageView+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E41FDB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImageView+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E41FDC1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E41FDD1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E41FDE1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertView+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E41FDF1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertView+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E41FE01BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E41FE11BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E41FE21BB0FFDD00D7324C /* MKNetworkEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkEngine.h; sourceTree = ""; }; + 69E41FE31BB0FFDD00D7324C /* MKNetworkEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKNetworkEngine.m; sourceTree = ""; }; + 69E41FE41BB0FFDD00D7324C /* MKNetworkKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkKit.h; sourceTree = ""; }; + 69E41FE51BB0FFDD00D7324C /* MKNetworkOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkOperation.h; sourceTree = ""; }; + 69E41FE61BB0FFDD00D7324C /* MKNetworkOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKNetworkOperation.m; sourceTree = ""; }; 8D7DCD461BAF859400A92AD2 /* TalkinToTheNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TalkinToTheNet.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D7DCD4A1BAF859400A92AD2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -39,6 +159,132 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 69E41F761BB0FFCF00D7324C /* FourSquareKit */ = { + isa = PBXGroup; + children = ( + 69E41F771BB0FFCF00D7324C /* categories */, + 69E41F821BB0FFCF00D7324C /* FourSquareKit.h */, + 69E41F831BB0FFCF00D7324C /* models */, + 69E41FAF1BB0FFCF00D7324C /* networking */, + ); + path = FourSquareKit; + sourceTree = ""; + }; + 69E41F771BB0FFCF00D7324C /* categories */ = { + isa = PBXGroup; + children = ( + 69E41F781BB0FFCF00D7324C /* CLLocation+isEmpty.h */, + 69E41F791BB0FFCF00D7324C /* CLLocation+isEmpty.m */, + 69E41F7A1BB0FFCF00D7324C /* CLLocation+Testing.h */, + 69E41F7B1BB0FFCF00D7324C /* CLLocation+Testing.m */, + 69E41F7C1BB0FFCF00D7324C /* NSDictionary+PList.h */, + 69E41F7D1BB0FFCF00D7324C /* NSDictionary+PList.m */, + 69E41F7E1BB0FFCF00D7324C /* NSString+Location.h */, + 69E41F7F1BB0FFCF00D7324C /* NSString+Location.m */, + 69E41F801BB0FFCF00D7324C /* NSString+Utils.h */, + 69E41F811BB0FFCF00D7324C /* NSString+Utils.m */, + ); + path = categories; + sourceTree = ""; + }; + 69E41F831BB0FFCF00D7324C /* models */ = { + isa = PBXGroup; + children = ( + 69E41F841BB0FFCF00D7324C /* UXRBaseModel.h */, + 69E41F851BB0FFCF00D7324C /* UXRBaseModel.m */, + 69E41F861BB0FFCF00D7324C /* UXRExploreQueryBaseModel.h */, + 69E41F871BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m */, + 69E41F881BB0FFCF00D7324C /* UXRFourSquareAttributesModel.h */, + 69E41F891BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m */, + 69E41F8A1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.h */, + 69E41F8B1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m */, + 69E41F8C1BB0FFCF00D7324C /* UXRFourSquareContactModel.h */, + 69E41F8D1BB0FFCF00D7324C /* UXRFourSquareContactModel.m */, + 69E41F8E1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.h */, + 69E41F8F1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m */, + 69E41F901BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.h */, + 69E41F911BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m */, + 69E41F921BB0FFCF00D7324C /* UXRFourSquareHoursModel.h */, + 69E41F931BB0FFCF00D7324C /* UXRFourSquareHoursModel.m */, + 69E41F941BB0FFCF00D7324C /* UXRFourSquareLikesModel.h */, + 69E41F951BB0FFCF00D7324C /* UXRFourSquareLikesModel.m */, + 69E41F961BB0FFCF00D7324C /* UXRFourSquareLocationModel.h */, + 69E41F971BB0FFCF00D7324C /* UXRFourSquareLocationModel.m */, + 69E41F981BB0FFCF00D7324C /* UXRFourSquareMenuModel.h */, + 69E41F991BB0FFCF00D7324C /* UXRFourSquareMenuModel.m */, + 69E41F9A1BB0FFCF00D7324C /* UXRFourSquareOpenTime.h */, + 69E41F9B1BB0FFCF00D7324C /* UXRFourSquareOpenTime.m */, + 69E41F9C1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.h */, + 69E41F9D1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m */, + 69E41F9E1BB0FFCF00D7324C /* UXRFourSquarePriceModel.h */, + 69E41F9F1BB0FFCF00D7324C /* UXRFourSquarePriceModel.m */, + 69E41FA01BB0FFCF00D7324C /* UXRFourSquareReservationsModel.h */, + 69E41FA11BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m */, + 69E41FA21BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.h */, + 69E41FA31BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m */, + 69E41FA41BB0FFCF00D7324C /* UXRFourSquareStatsModel.h */, + 69E41FA51BB0FFCF00D7324C /* UXRFourSquareStatsModel.m */, + 69E41FA61BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.h */, + 69E41FA71BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m */, + 69E41FA81BB0FFCF00D7324C /* UXRFourSquareTipModel.h */, + 69E41FA91BB0FFCF00D7324C /* UXRFourSquareTipModel.m */, + 69E41FAA1BB0FFCF00D7324C /* UXRFourSquareUserModel.h */, + 69E41FAB1BB0FFCF00D7324C /* UXRFourSquareUserModel.m */, + 69E41FAC1BB0FFCF00D7324C /* UXRJSONDeserializableObject.h */, + 69E41FAD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m */, + 69E41FAE1BB0FFCF00D7324C /* UXRJSONSerializableObject.h */, + ); + path = models; + sourceTree = ""; + }; + 69E41FAF1BB0FFCF00D7324C /* networking */ = { + isa = PBXGroup; + children = ( + 69E41FB01BB0FFCF00D7324C /* UXRBaseNetworkingEngine.h */, + 69E41FB11BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m */, + 69E41FB21BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.h */, + 69E41FB31BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m */, + ); + path = networking; + sourceTree = ""; + }; + 69E41FD01BB0FFDD00D7324C /* MKNetworkKit */ = { + isa = PBXGroup; + children = ( + 69E41FD11BB0FFDD00D7324C /* Categories */, + 69E41FE21BB0FFDD00D7324C /* MKNetworkEngine.h */, + 69E41FE31BB0FFDD00D7324C /* MKNetworkEngine.m */, + 69E41FE41BB0FFDD00D7324C /* MKNetworkKit.h */, + 69E41FE51BB0FFDD00D7324C /* MKNetworkOperation.h */, + 69E41FE61BB0FFDD00D7324C /* MKNetworkOperation.m */, + ); + name = MKNetworkKit; + path = FourSquareKit/MKNetworkKit; + sourceTree = ""; + }; + 69E41FD11BB0FFDD00D7324C /* Categories */ = { + isa = PBXGroup; + children = ( + 69E41FD21BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.h */, + 69E41FD31BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m */, + 69E41FD41BB0FFDD00D7324C /* NSData+MKBase64.h */, + 69E41FD51BB0FFDD00D7324C /* NSData+MKBase64.m */, + 69E41FD61BB0FFDD00D7324C /* NSDate+RFC1123.h */, + 69E41FD71BB0FFDD00D7324C /* NSDate+RFC1123.m */, + 69E41FD81BB0FFDD00D7324C /* NSDictionary+RequestEncoding.h */, + 69E41FD91BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m */, + 69E41FDA1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.h */, + 69E41FDB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m */, + 69E41FDC1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.h */, + 69E41FDD1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m */, + 69E41FDE1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.h */, + 69E41FDF1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m */, + 69E41FE01BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.h */, + 69E41FE11BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m */, + ); + path = Categories; + sourceTree = ""; + }; 8D7DCD3D1BAF859400A92AD2 = { isa = PBXGroup; children = ( @@ -58,8 +304,12 @@ 8D7DCD481BAF859400A92AD2 /* TalkinToTheNet */ = { isa = PBXGroup; children = ( + 69E41FD01BB0FFDD00D7324C /* MKNetworkKit */, + 69E41F761BB0FFCF00D7324C /* FourSquareKit */, 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */, 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */, + 69E41EF51BB0F5F600D7324C /* APIManager.h */, + 69E41EF61BB0F5F600D7324C /* APIManager.m */, 8D7DCD4F1BAF859400A92AD2 /* ViewController.h */, 8D7DCD501BAF859400A92AD2 /* ViewController.m */, 8D7DCD521BAF859400A92AD2 /* Main.storyboard */, @@ -149,9 +399,48 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 69E41FBE1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m in Sources */, + 69E41FC11BB0FFCF00D7324C /* UXRFourSquareLikesModel.m in Sources */, + 69E41FB51BB0FFCF00D7324C /* CLLocation+Testing.m in Sources */, + 69E41FC51BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m in Sources */, + 69E41FCF1BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m in Sources */, + 69E41EF71BB0F5F600D7324C /* APIManager.m in Sources */, + 69E41FEE1BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m in Sources */, + 69E41FEC1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m in Sources */, + 69E41FB91BB0FFCF00D7324C /* UXRBaseModel.m in Sources */, + 69E41FED1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m in Sources */, + 69E41FCD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m in Sources */, + 69E41FC41BB0FFCF00D7324C /* UXRFourSquareOpenTime.m in Sources */, + 69E41FEF1BB0FFDD00D7324C /* MKNetworkEngine.m in Sources */, + 69E41FC01BB0FFCF00D7324C /* UXRFourSquareHoursModel.m in Sources */, + 69E41FEB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m in Sources */, + 69E41FCB1BB0FFCF00D7324C /* UXRFourSquareTipModel.m in Sources */, + 69E41FCE1BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m in Sources */, + 69E41FB71BB0FFCF00D7324C /* NSString+Location.m in Sources */, + 69E41FC21BB0FFCF00D7324C /* UXRFourSquareLocationModel.m in Sources */, + 69E41FC71BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m in Sources */, + 69E41FE81BB0FFDD00D7324C /* NSData+MKBase64.m in Sources */, + 69E41FCA1BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m in Sources */, 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */, + 69E41FC91BB0FFCF00D7324C /* UXRFourSquareStatsModel.m in Sources */, + 69E41FF01BB0FFDD00D7324C /* MKNetworkOperation.m in Sources */, + 69E41FEA1BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m in Sources */, + 69E41FE71BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m in Sources */, + 69E41FBB1BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m in Sources */, + 69E41FCC1BB0FFCF00D7324C /* UXRFourSquareUserModel.m in Sources */, + 69E41FC61BB0FFCF00D7324C /* UXRFourSquarePriceModel.m in Sources */, + 69E41FE91BB0FFDD00D7324C /* NSDate+RFC1123.m in Sources */, + 69E41FC81BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m in Sources */, + 69E41FB81BB0FFCF00D7324C /* NSString+Utils.m in Sources */, + 69E41FB61BB0FFCF00D7324C /* NSDictionary+PList.m in Sources */, + 69E41FBF1BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m in Sources */, 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */, 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */, + 69E41FB41BB0FFCF00D7324C /* CLLocation+isEmpty.m in Sources */, + 69E41FBC1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m in Sources */, + 69E41FC31BB0FFCF00D7324C /* UXRFourSquareMenuModel.m in Sources */, + 69E41FBA1BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m in Sources */, + 69E41FBD1BB0FFCF00D7324C /* UXRFourSquareContactModel.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -300,6 +589,7 @@ 8D7DCD5F1BAF859400A92AD2 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/TalkinToTheNet/TalkinToTheNet/APIManager.h b/TalkinToTheNet/TalkinToTheNet/APIManager.h new file mode 100644 index 0000000..c4be67f --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/APIManager.h @@ -0,0 +1,16 @@ +// +// APIManager.h +// LearnAPI +// +// Created by Z on 9/20/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface APIManager : NSObject + ++ (void)GETRequestWithURL:(NSURL *)URL + completionHandler:(void(^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/APIManager.m b/TalkinToTheNet/TalkinToTheNet/APIManager.m new file mode 100644 index 0000000..41672a7 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/APIManager.m @@ -0,0 +1,31 @@ +// +// APIManager.m +// LearnAPI +// +// Created by Z on 9/20/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "APIManager.h" + +@implementation APIManager + +//class methods +//no instance of an object +//no state ++ (void)GETRequestWithURL:(NSURL *)URL + completionHandler:(void(^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler { + + NSURLSession *session = [NSURLSession sharedSession]; + + NSURLSessionDataTask *task = [session dataTaskWithURL:URL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + + dispatch_async(dispatch_get_main_queue(), ^{ + completionHandler(data, response, error); + }); + }]; + + [task resume]; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/FourSquareKit.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/FourSquareKit.h new file mode 100644 index 0000000..d73bcfa --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/FourSquareKit.h @@ -0,0 +1,42 @@ + // +// FourSquareKit.h +// FourSquareKit +// +// Created by Rex St. John on 3/9/14. +// Copyright (c) 2014 UX-RX. All rights reserved. +// + +// Engines +#import "UXRFourSquareNetworkingEngine.h" +#import "UXRBaseNetworkingEngine.h" + +// Models +#import "UXRBaseModel.h" +#import "UXRExploreQueryBaseModel.h" +#import "UXRFourSquareAttributesModel.h" +#import "UXRFourSquareCategoryModel.h" +#import "UXRFourSquareContactModel.h" +#import "UXRFourSquareExploreResultsModel.h" +#import "UXRFourSquareGeoCodeModel.h" +#import "UXRFourSquareHoursModel.h" +#import "UXRFourSquareLikesModel.h" +#import "UXRFourSquareLocationModel.h" +#import "UXRFourSquareMenuModel.h" +#import "UXRFourSquareOpenTime.h" +#import "UXRFourSquarePhotoModel.h" +#import "UXRFourSquarePriceModel.h" +#import "UXRFourSquareReservationsModel.h" +#import "UXRFourSquareRestaurantModel.h" +#import "UXRFourSquareStatsModel.h" +#import "UXRFourSquareTimeFramesModel.h" +#import "UXRFourSquareTipModel.h" +#import "UXRFourSquareUserModel.h" +#import "UXRJSONDeserializableObject.h" +#import "UXRJSONSerializableObject.h" + +// Categories. +#import "CLLocation+isEmpty.h" +#import "CLLocation+Testing.h" +#import "NSDictionary+PList.h" +#import "NSString+Location.h" +#import "NSString+Utils.h" \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h new file mode 100644 index 0000000..c2ec0db --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h @@ -0,0 +1,15 @@ +// +// NSAlert+MKNetworkKitAdditions.h +// FourSquareKit-OSX +// +// Created by JASON CROSS on 3/6/15. +// Copyright (c) 2015 UX RX. All rights reserved. +// + +#if TARGET_OS_MAC +#import + +@interface NSAlert (MKNetworkKitAdditions) ++(NSAlert*) showWithError:(NSError*) networkError; +@end +#endif \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m new file mode 100644 index 0000000..80ff6e4 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m @@ -0,0 +1,20 @@ +// +// NSAlert+MKNetworkKitAdditions.m +// FourSquareKit-OSX +// +// Created by JASON CROSS on 3/6/15. +// Copyright (c) 2015 UX RX. All rights reserved. +// + +#if TARGET_OS_MAC +#import "NSAlert+MKNetworkKitAdditions.h" + +@implementation NSAlert (MKNetworkKitAdditions) + ++(NSAlert*) showWithError:(NSError*) networkError; { + + NSAlert * alert = [NSAlert alertWithError:networkError]; + [alert show]; +} +@end +#endif \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.h new file mode 100644 index 0000000..ec8147d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.h @@ -0,0 +1,42 @@ +// +// NSData+MKNKBase64.h +// base64 +// +// Created by Matt Gallagher on 2009/06/03. +// Copyright 2009 Matt Gallagher. All rights reserved. +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. Permission is granted to anyone to +// use this software for any purpose, including commercial applications, and to +// alter it and redistribute it freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source +// distribution. +// + +#import + +void *mk_NewBase64Decode( + const char *inputBuffer, + size_t length, + size_t *outputLength); + +char *mk_NewBase64Encode( + const void *inputBuffer, + size_t length, + bool separateLines, + size_t *outputLength); + +@interface NSData (MKNKBase64) + ++ (NSData *)dataFromBase64String:(NSString *)aString; +- (NSString *)base64EncodedString; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.m new file mode 100644 index 0000000..5802fac --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.m @@ -0,0 +1,312 @@ +// +// NSData+MKNKBase64.m +// base64 +// +// Created by Matt Gallagher on 2009/06/03. +// Copyright 2009 Matt Gallagher. All rights reserved. +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. Permission is granted to anyone to +// use this software for any purpose, including commercial applications, and to +// alter it and redistribute it freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// 3. This notice may not be removed or altered from any source +// distribution. +// + +#import "NSData+MKBase64.h" + +// +// Mapping from 6 bit pattern to ASCII character. +// +static unsigned char mk_base64EncodeLookup[65] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +// +// Definition for "masked-out" areas of the base64DecodeLookup mapping +// +#define xx 65 + +// +// Mapping from ASCII character to 6 bit pattern. +// +static unsigned char mk_base64DecodeLookup[256] = +{ + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 62, xx, xx, xx, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, xx, xx, xx, xx, xx, xx, + xx, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, xx, xx, xx, xx, xx, + xx, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, + xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, +}; + +// +// Fundamental sizes of the binary and base64 encode/decode units in bytes +// +#define BINARY_UNIT_SIZE 3 +#define BASE64_UNIT_SIZE 4 + +// +// NewBase64Decode +// +// Decodes the base64 ASCII string in the inputBuffer to a newly malloced +// output buffer. +// +// inputBuffer - the source ASCII string for the decode +// length - the length of the string or -1 (to specify strlen should be used) +// outputLength - if not-NULL, on output will contain the decoded length +// +// returns the decoded buffer. Must be free'd by caller. Length is given by +// outputLength. +// +void *mk_NewBase64Decode( + const char *inputBuffer, + size_t length, + size_t *outputLength) +{ + if (length == (size_t)-1) + { + length = strlen(inputBuffer); + } + + size_t outputBufferSize = + ((length+BASE64_UNIT_SIZE-1) / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE; + unsigned char *outputBuffer = (unsigned char *)malloc(outputBufferSize); + + size_t i = 0; + size_t j = 0; + while (i < length) + { + // + // Accumulate 4 valid characters (ignore everything else) + // + unsigned char accumulated[BASE64_UNIT_SIZE]; + size_t accumulateIndex = 0; + while (i < length) + { + unsigned char decode = mk_base64DecodeLookup[inputBuffer[i++]]; + if (decode != xx) + { + accumulated[accumulateIndex] = decode; + accumulateIndex++; + + if (accumulateIndex == BASE64_UNIT_SIZE) + { + break; + } + } + } + + // + // Store the 6 bits from each of the 4 characters as 3 bytes + // + // (Uses improved bounds checking suggested by Alexandre Colucci) + // + if(accumulateIndex >= 2) + outputBuffer[j] = (unsigned char)(accumulated[0] << 2) | (accumulated[1] >> 4); + if(accumulateIndex >= 3) + outputBuffer[j + 1] = (unsigned char)(accumulated[1] << 4) | (accumulated[2] >> 2); + if(accumulateIndex >= 4) + outputBuffer[j + 2] = (unsigned char)(accumulated[2] << 6) | accumulated[3]; + j += accumulateIndex - 1; + } + + if (outputLength) + { + *outputLength = j; + } + return outputBuffer; +} + +// +// NewBase64Encode +// +// Encodes the arbitrary data in the inputBuffer as base64 into a newly malloced +// output buffer. +// +// inputBuffer - the source data for the encode +// length - the length of the input in bytes +// separateLines - if zero, no CR/LF characters will be added. Otherwise +// a CR/LF pair will be added every 64 encoded chars. +// outputLength - if not-NULL, on output will contain the encoded length +// (not including terminating 0 char) +// +// returns the encoded buffer. Must be free'd by caller. Length is given by +// outputLength. +// +char *mk_NewBase64Encode( + const void *buffer, + size_t length, + bool separateLines, + size_t *outputLength) +{ + const unsigned char *inputBuffer = (const unsigned char *)buffer; + + #define MAX_NUM_PADDING_CHARS 2 + #define OUTPUT_LINE_LENGTH 64 + #define INPUT_LINE_LENGTH ((OUTPUT_LINE_LENGTH / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE) + #define CR_LF_SIZE 2 + + // + // Byte accurate calculation of final buffer size + // + size_t outputBufferSize = + ((length / BINARY_UNIT_SIZE) + + ((length % BINARY_UNIT_SIZE) ? 1 : 0)) + * BASE64_UNIT_SIZE; + if (separateLines) + { + outputBufferSize += + (outputBufferSize / OUTPUT_LINE_LENGTH) * CR_LF_SIZE; + } + + // + // Include space for a terminating zero + // + outputBufferSize += 1; + + // + // Allocate the output buffer + // + char *outputBuffer = (char *)malloc(outputBufferSize); + if (!outputBuffer) + { + return NULL; + } + + size_t i = 0; + size_t j = 0; + const size_t lineLength = separateLines ? INPUT_LINE_LENGTH : length; + size_t lineEnd = lineLength; + + while (true) + { + if (lineEnd > length) + { + lineEnd = length; + } + + for (; i + BINARY_UNIT_SIZE - 1 < lineEnd; i += BINARY_UNIT_SIZE) + { + // + // Inner loop: turn 48 bytes into 64 base64 characters + // + outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; + outputBuffer[j++] = (char)mk_base64EncodeLookup[((inputBuffer[i] & 0x03) << 4) + | ((inputBuffer[i + 1] & 0xF0) >> 4)]; + outputBuffer[j++] = (char)mk_base64EncodeLookup[((inputBuffer[i + 1] & 0x0F) << 2) + | ((inputBuffer[i + 2] & 0xC0) >> 6)]; + outputBuffer[j++] = (char)mk_base64EncodeLookup[inputBuffer[i + 2] & 0x3F]; + } + + if (lineEnd == length) + { + break; + } + + // + // Add the newline + // + outputBuffer[j++] = '\r'; + outputBuffer[j++] = '\n'; + lineEnd += lineLength; + } + + if (i + 1 < length) + { + // + // Handle the single '=' case + // + outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; + outputBuffer[j++] = (char)mk_base64EncodeLookup[((inputBuffer[i] & 0x03) << 4) + | ((inputBuffer[i + 1] & 0xF0) >> 4)]; + outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i + 1] & 0x0F) << 2]; + outputBuffer[j++] = '='; + } + else if (i < length) + { + // + // Handle the double '=' case + // + outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; + outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i] & 0x03) << 4]; + outputBuffer[j++] = '='; + outputBuffer[j++] = '='; + } + outputBuffer[j] = 0; + + // + // Set the output length and return the buffer + // + if (outputLength) + { + *outputLength = j; + } + return outputBuffer; +} + +@implementation NSData (MKNKBase64) + +// +// dataFromBase64String: +// +// Creates an NSData object containing the base64 decoded representation of +// the base64 string 'aString' +// +// Parameters: +// aString - the base64 string to decode +// +// returns the autoreleased NSData representation of the base64 string +// ++ (NSData *)dataFromBase64String:(NSString *)aString +{ + NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding]; + size_t outputLength; + void *outputBuffer = mk_NewBase64Decode([data bytes], [data length], &outputLength); + NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength]; + free(outputBuffer); + return result; +} + +// +// base64EncodedString +// +// Creates an NSString object that contains the base 64 encoding of the +// receiver's data. Lines are broken at 64 characters long. +// +// returns an autoreleased NSString being the base 64 representation of the +// receiver. +// +- (NSString *)base64EncodedString +{ + size_t outputLength = 0; + char *outputBuffer = + mk_NewBase64Encode([self bytes], [self length], false, &outputLength); + + NSString *result = + [[NSString alloc] + initWithBytes:outputBuffer + length:outputLength + encoding:NSASCIIStringEncoding]; + free(outputBuffer); + return result; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.h new file mode 100644 index 0000000..12b3f2e --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.h @@ -0,0 +1,27 @@ +// +// NSDate+RFC1123.h +// MKNetworkKit +// +// Created by Marcus Rohrmoser +// http://blog.mro.name/2009/08/nsdateformatter-http-header/ +// http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 + +// No obvious license attached + +#import + +@interface NSDate (RFC1123) +/** + Convert a RFC1123 'Full-Date' string + (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1) + into NSDate. + */ ++(NSDate*)dateFromRFC1123:(NSString*)value_; + +/** + Convert NSDate into a RFC1123 'Full-Date' string + (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1). + */ +-(NSString*)rfc1123String; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.m new file mode 100644 index 0000000..261e467 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.m @@ -0,0 +1,76 @@ +// +// NSDate+RFC1123.m +// MKNetworkKit +// +// Originally created by Marcus Rohrmoser +// http://blog.mro.name/2009/08/nsdateformatter-http-header/ +// Updated with strptime methods by Bo98 +// +// No obvious license attached + +#import "NSDate+RFC1123.h" +#import +#import + +@implementation NSDate (RFC1123) + ++(NSDate*)dateFromRFC1123:(NSString*)value_ +{ + if(value_ == nil) + return nil; + + const char *str = [value_ UTF8String]; + const char *fmt; + NSDate *retDate; + char *ret; + + fmt = "%a, %d %b %Y %H:%M:%S %Z"; + struct tm rfc1123timeinfo; + memset(&rfc1123timeinfo, 0, sizeof(rfc1123timeinfo)); + ret = strptime_l(str, fmt, &rfc1123timeinfo, NULL); + if (ret) { + time_t rfc1123time = mktime(&rfc1123timeinfo); + retDate = [NSDate dateWithTimeIntervalSince1970:rfc1123time]; + if (retDate != nil) + return retDate; + } + + + fmt = "%A, %d-%b-%y %H:%M:%S %Z"; + struct tm rfc850timeinfo; + memset(&rfc850timeinfo, 0, sizeof(rfc850timeinfo)); + ret = strptime_l(str, fmt, &rfc850timeinfo, NULL); + if (ret) { + time_t rfc850time = mktime(&rfc850timeinfo); + retDate = [NSDate dateWithTimeIntervalSince1970:rfc850time]; + if (retDate != nil) + return retDate; + } + + fmt = "%a %b %e %H:%M:%S %Y"; + struct tm asctimeinfo; + memset(&asctimeinfo, 0, sizeof(asctimeinfo)); + ret = strptime_l(str, fmt, &asctimeinfo, NULL); + if (ret) { + time_t asctime = mktime(&asctimeinfo); + return [NSDate dateWithTimeIntervalSince1970:asctime]; + } + + return nil; +} + +-(NSString*)rfc1123String +{ + time_t date = (time_t)[self timeIntervalSince1970]; + struct tm timeinfo; + gmtime_r(&date, &timeinfo); + char buffer[32]; + size_t ret = strftime_l(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S GMT", &timeinfo, NULL); + if (ret) { + return @(buffer); + } else { + return nil; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h new file mode 100644 index 0000000..1f2593e --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h @@ -0,0 +1,33 @@ +// +// NSDictionary+RequestEncoding.h +// MKNetworkKitDemo +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import + +@interface NSDictionary (RequestEncoding) + +-(NSString*) urlEncodedKeyValueString; +-(NSString*) jsonEncodedKeyValueString; +-(NSString*) plistEncodedKeyValueString; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m new file mode 100644 index 0000000..a8fac4b --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m @@ -0,0 +1,74 @@ +// +// NSDictionary+RequestEncoding.m +// MKNetworkKitDemo +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "MKNetworkKit.h" + +@implementation NSDictionary (RequestEncoding) + +-(NSString*) urlEncodedKeyValueString { + + NSMutableString *string = [NSMutableString string]; + for (NSString *key in self) { + + NSObject *value = [self valueForKey:key]; + if([value isKindOfClass:[NSString class]]) + [string appendFormat:@"%@=%@&", [key mk_urlEncodedString], [((NSString*)value) mk_urlEncodedString]]; + else + [string appendFormat:@"%@=%@&", [key mk_urlEncodedString], value]; + } + + if([string length] > 0) + [string deleteCharactersInRange:NSMakeRange([string length] - 1, 1)]; + + return string; +} + + +-(NSString*) jsonEncodedKeyValueString { + + NSError *error = nil; + NSData *data = [NSJSONSerialization dataWithJSONObject:self + options:0 // non-pretty printing + error:&error]; + if(error) + DLog(@"JSON Parsing Error: %@", error); + + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; +} + + +-(NSString*) plistEncodedKeyValueString { + + NSError *error = nil; + NSData *data = [NSPropertyListSerialization dataWithPropertyList:self + format:NSPropertyListXMLFormat_v1_0 + options:0 error:&error]; + if(error) + DLog(@"JSON Parsing Error: %@", error); + + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h new file mode 100644 index 0000000..098cff0 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h @@ -0,0 +1,45 @@ +// +// NSImageView+MKNetworkKitAdditions.h +// FourSquareKit-OSX +// +// Created by JASON CROSS on 3/6/15. +// Copyright (c) 2015 UX RX. All rights reserved. +// +// Originally Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if TARGET_OS_MAC +#import + +extern const float kFromCacheAnimationDuration; +extern const float kFreshLoadAnimationDuration; + +@class MKNetworkEngine; +@class MKNetworkOperation; + +@interface NSImageView (MKNetworkKitAdditions) ++(void) setDefaultEngine:(MKNetworkEngine*) engine; +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url; +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image; +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image animation:(BOOL) yesOrNo; +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) yesOrNo; +@end +#endif \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m new file mode 100644 index 0000000..5a532ac --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m @@ -0,0 +1,99 @@ +// +// NSImageView+MKNetworkKitAdditions.m +// FourSquareKit-OSX +// +// Created by JASON CROSS on 3/6/15. +// Copyright (c) 2015 UX RX. All rights reserved. +// +// Originally Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + + +#import "NSImageView+MKNetworkKitAdditions.h" + +#import "MKNetworkEngine.h" + +#import + +static MKNetworkEngine *DefaultEngine; +static char imageFetchOperationKey; + +const float kFromCacheAnimationDuration = 0.1f; +const float kFreshLoadAnimationDuration = 0.35f; + +@interface NSImageView (/*Private Methods*/) +@property (strong, nonatomic) MKNetworkOperation *imageFetchOperation; +@end + +@implementation NSImageView (MKNetworkKitAdditions) + +-(MKNetworkOperation*) imageFetchOperation { + + return (MKNetworkOperation*) objc_getAssociatedObject(self, &imageFetchOperationKey); +} + +-(void) setImageFetchOperation:(MKNetworkOperation *)imageFetchOperation { + + objc_setAssociatedObject(self, &imageFetchOperationKey, imageFetchOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + ++(void) setDefaultEngine:(MKNetworkEngine*) engine; { + + DefaultEngine = engine; +} + +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url; { + + return [self setImageFromURL:url placeHolderImage:nil]; +} + +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image; { + + return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:YES]; +} + +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image animation:(BOOL) yesOrNo; { + + return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:yesOrNo]; +} + +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) yesOrNo; { + + if(image) self.image = image; + [self.imageFetchOperation cancel]; + if(!imageCacheEngine) imageCacheEngine = DefaultEngine; + + if(imageCacheEngine) { + self.imageFetchOperation = [imageCacheEngine imageAtURL:url completionHandler:^(NSImage *fetchedImage, NSURL *url, BOOL isInCache) { + self.image = fetchedImage; + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + DLog(@"%@", error); + }]; + } else { + + DLog(@"No default engine found and imageCacheEngine parameter is null") + } + + return self.imageFetchOperation; + +} + +@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h new file mode 100644 index 0000000..99514c8 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h @@ -0,0 +1,34 @@ +// +// NSString+MKNetworkKitAdditions.h +// MKNetworkKitDemo +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import + +@interface NSString (MKNetworkKitAdditions) + +- (NSString *) md5; ++ (NSString*) uniqueString; +- (NSString*) mk_urlEncodedString; +- (NSString*) urlDecodedString; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m new file mode 100644 index 0000000..adf2e3d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m @@ -0,0 +1,81 @@ +// +// NSString+MKNetworkKitAdditions.m +// MKNetworkKitDemo +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "NSString+MKNetworkKitAdditions.h" +#import + +@implementation NSString (MKNetworkKitAdditions) + +- (NSString *) md5 +{ + const char *cStr = [self UTF8String]; + unsigned char result[16]; + CC_MD5( cStr, (unsigned int) strlen(cStr), result); + return [NSString stringWithFormat: + @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + result[0], result[1], result[2], result[3], + result[4], result[5], result[6], result[7], + result[8], result[9], result[10], result[11], + result[12], result[13], result[14], result[15] + ]; +} + ++ (NSString*) uniqueString +{ + CFUUIDRef uuidObj = CFUUIDCreate(nil); + NSString *uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(nil, uuidObj); + CFRelease(uuidObj); + return uuidString; +} + +- (NSString*) mk_urlEncodedString { // mk_ prefix prevents a clash with a private api + + CFStringRef encodedCFString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, + (__bridge CFStringRef) self, + nil, + CFSTR("?!@#$^&%*+,:;='\"`<>()[]{}/\\| "), + kCFStringEncodingUTF8); + + NSString *encodedString = [[NSString alloc] initWithString:(__bridge_transfer NSString*) encodedCFString]; + + if(!encodedString) + encodedString = @""; + + return encodedString; +} + +- (NSString*) urlDecodedString { + + CFStringRef decodedCFString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, + (__bridge CFStringRef) self, + CFSTR(""), + kCFStringEncodingUTF8); + + // We need to replace "+" with " " because the CF method above doesn't do it + NSString *decodedString = [[NSString alloc] initWithString:(__bridge_transfer NSString*) decodedCFString]; + return (!decodedString) ? @"" : [decodedString stringByReplacingOccurrencesOfString:@"+" withString:@" "]; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h new file mode 100644 index 0000000..89c9205 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h @@ -0,0 +1,31 @@ +// +// UIAlertView+MKNetworkKitAdditions.h +// MKNetworkKitDemo +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +#if TARGET_OS_IPHONE +#import + +@interface UIAlertView (MKNetworkKitAdditions) ++(UIAlertView*) showWithError:(NSError*) networkError; +@end +#endif diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m new file mode 100644 index 0000000..887deba --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m @@ -0,0 +1,41 @@ +// +// UIAlertView+MKNetworkKitAdditions.m +// MKNetworkKitDemo +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +#if TARGET_OS_IPHONE +#import "UIAlertView+MKNetworkKitAdditions.h" + +@implementation UIAlertView (MKNetworkKitAdditions) + ++(UIAlertView*) showWithError:(NSError*) networkError { + + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[networkError localizedDescription] + message:[networkError localizedRecoverySuggestion] + delegate:nil + cancelButtonTitle:NSLocalizedString(@"Dismiss", @"") + otherButtonTitles:nil]; + [alert show]; + return alert; +} +@end +#endif diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h new file mode 100644 index 0000000..46f343d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h @@ -0,0 +1,42 @@ +// +// UIImageView+MKNetworkKitAdditions.h +// MKNetworkKit-iOS +// +// Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if TARGET_OS_IPHONE +#import + +extern const float kFromCacheAnimationDuration; +extern const float kFreshLoadAnimationDuration; + +@class MKNetworkEngine; +@class MKNetworkOperation; + +@interface UIImageView (MKNetworkKitAdditions) ++(void) setDefaultEngine:(MKNetworkEngine*) engine; +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url; +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image; +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image animation:(BOOL) yesOrNo; +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) yesOrNo; +@end +#endif \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m new file mode 100644 index 0000000..77f4054 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m @@ -0,0 +1,109 @@ +// +// UIImageView+MKNetworkKitAdditions.m +// MKNetworkKitDemo +// +// Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#if TARGET_OS_IPHONE +#import "UIImageView+MKNetworkKitAdditions.h" + +#import "MKNetworkEngine.h" + +#import + +static MKNetworkEngine *DefaultEngine; +static char imageFetchOperationKey; + +const float kFromCacheAnimationDuration = 0.1f; +const float kFreshLoadAnimationDuration = 0.35f; + +@interface UIImageView (/*Private Methods*/) +@property (strong, nonatomic) MKNetworkOperation *imageFetchOperation; +@end + +@implementation UIImageView (MKNetworkKitAdditions) + +-(MKNetworkOperation*) imageFetchOperation { + + return (MKNetworkOperation*) objc_getAssociatedObject(self, &imageFetchOperationKey); +} + +-(void) setImageFetchOperation:(MKNetworkOperation *)imageFetchOperation { + + objc_setAssociatedObject(self, &imageFetchOperationKey, imageFetchOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + ++(void) setDefaultEngine:(MKNetworkEngine*) engine { + + DefaultEngine = engine; +} + +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url { + + return [self setImageFromURL:url placeHolderImage:nil]; +} + +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image { + + return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:YES]; +} + +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image animation:(BOOL) yesOrNo { + + return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:yesOrNo]; +} + +-(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) animation { + + if(image) self.image = image; + [self.imageFetchOperation cancel]; + if(!imageCacheEngine) imageCacheEngine = DefaultEngine; + + if(imageCacheEngine) { + self.imageFetchOperation = [imageCacheEngine imageAtURL:url + size:self.frame.size + completionHandler:^(UIImage *fetchedImage, NSURL *url, BOOL isInCache) { + + if(animation) { + [UIView transitionWithView:self.superview + duration:isInCache?kFromCacheAnimationDuration:kFreshLoadAnimationDuration + options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction + animations:^{ + self.image = fetchedImage; + } completion:nil]; + } else { + self.image = fetchedImage; + } + + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + + DLog(@"%@", error); + }]; + } else { + + DLog(@"No default engine found and imageCacheEngine parameter is null") + } + + return self.imageFetchOperation; +} +@end +#endif diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.h new file mode 100644 index 0000000..5f67587 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.h @@ -0,0 +1,425 @@ +// +// MKNetworkEngine.h +// MKNetworkKit +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "MKNetworkKit.h" +/*! + @header MKNetworkEngine.h + @abstract Represents a subclassable Network Engine for your app + */ + +/*! + * @class MKNetworkEngine + * @abstract Represents a subclassable Network Engine for your app + * + * @discussion + * This class is the heart of MKNetworkEngine + * You create network operations and enqueue them here + * MKNetworkEngine encapsulates a Reachability object that relieves you of managing network connectivity losses + * MKNetworkEngine also allows you to provide custom header fields that gets appended automatically to every request + */ +@interface MKNetworkEngine : NSObject +/*! + * @abstract Initializes your network engine with a hostname + * + * @discussion + * Creates an engine for a given host name + * The hostname parameter is optional + * The hostname, if not null, initializes a Reachability notifier. + * Network reachability notifications are automatically taken care of by MKNetworkEngine + * + */ +- (id) initWithHostName:(NSString*) hostName; + +/*! + * @abstract Initializes your network engine with a hostname and custom header fields + * + * @discussion + * Creates an engine for a given host name + * The default headers you specify here will be appened to every operation created in this engine + * The hostname, if not null, initializes a Reachability notifier. + * Network reachability notifications are automatically taken care of by MKNetworkEngine + * Both parameters are optional + * + */ +- (id) initWithHostName:(NSString*) hostName customHeaderFields:(NSDictionary*) headers; + +/*! + * @abstract Initializes your network engine with a hostname + * + * @discussion + * Creates an engine for a given host name + * The hostname parameter is optional + * The apiPath paramter is optional + * The apiPath is prefixed to every call to operationWithPath: You can use this method if your server's API location is not at the root (/) + * The hostname, if not null, initializes a Reachability notifier. + * Network reachability notifications are automatically taken care of by MKNetworkEngine + * + */ +- (id) initWithHostName:(NSString*) hostName apiPath:(NSString*) apiPath customHeaderFields:(NSDictionary*) headers; + +/*! + * @abstract Initializes your network engine with a hostname, port, path, and headers. + * + * @discussion + * Creates an engine for a given host name + * The hostname parameter is optional + * The port parameter can be 0, which means to use the appropriate default port (80 or 443 for HTTP or HTTPS respectively). + * The apiPath paramter is optional + * The apiPath is prefixed to every call to operationWithPath: You can use this method if your server's API location is not at the root (/) + * The hostname, if not null, initializes a Reachability notifier. + * Network reachability notifications are automatically taken care of by MKNetworkEngine + * + */ +- (id) initWithHostName:(NSString*) hostName portNumber:(int)portNumber apiPath:(NSString*) apiPath customHeaderFields:(NSDictionary*) headers; + +/*! + * @abstract Creates a simple GET Operation with a request URL + * + * @discussion + * Creates an operation with the given URL path. + * The default headers you specified in your MKNetworkEngine subclass gets added to the headers + * The HTTP Method is implicitly assumed to be GET + * + */ + +-(MKNetworkOperation*) operationWithPath:(NSString*) path; + +/*! + * @abstract Creates a simple GET Operation with a request URL and parameters + * + * @discussion + * Creates an operation with the given URL path. + * The default headers you specified in your MKNetworkEngine subclass gets added to the headers + * The body dictionary in this method gets attached to the URL as query parameters + * The HTTP Method is implicitly assumed to be GET + * + */ +-(MKNetworkOperation*) operationWithPath:(NSString*) path + params:(NSDictionary*) body; + +/*! + * @abstract Creates a simple GET Operation with a request URL, parameters and HTTP Method + * + * @discussion + * Creates an operation with the given URL path. + * The default headers you specified in your MKNetworkEngine subclass gets added to the headers + * The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE + * The params dictionary is attached to the body if the HTTP Method is POST/PUT + * The HTTP Method is implicitly assumed to be GET + */ +-(MKNetworkOperation*) operationWithPath:(NSString*) path + params:(NSDictionary*) body + httpMethod:(NSString*)method; + +/*! + * @abstract Creates a simple GET Operation with a request URL, parameters, HTTP Method and the SSL switch + * + * @discussion + * Creates an operation with the given URL path. + * The ssl option when true changes the URL to https. + * The ssl option when false changes the URL to http. + * The default headers you specified in your MKNetworkEngine subclass gets added to the headers + * The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE + * The params dictionary is attached to the body if the HTTP Method is POST/PUT + * The previously mentioned methods operationWithPath: and operationWithPath:params: call this internally + */ +-(MKNetworkOperation*) operationWithPath:(NSString*) path + params:(NSDictionary*) body + httpMethod:(NSString*)method + ssl:(BOOL) useSSL; + +/*! + * @abstract Creates a simple GET Operation with a request URL + * + * @discussion + * Creates an operation with the given absolute URL. + * The hostname of the engine is *NOT* prefixed + * The default headers you specified in your MKNetworkEngine subclass gets added to the headers + * The HTTP method is implicitly assumed to be GET. + */ +-(MKNetworkOperation*) operationWithURLString:(NSString*) urlString; + +/*! + * @abstract Creates a simple GET Operation with a request URL and parameters + * + * @discussion + * Creates an operation with the given absolute URL. + * The hostname of the engine is *NOT* prefixed + * The default headers you specified in your MKNetworkEngine subclass gets added to the headers + * The body dictionary in this method gets attached to the URL as query parameters + * The HTTP method is implicitly assumed to be GET. + */ +-(MKNetworkOperation*) operationWithURLString:(NSString*) urlString + params:(NSDictionary*) body; + +/*! + * @abstract Creates a simple Operation with a request URL, parameters and HTTP Method + * + * @discussion + * Creates an operation with the given absolute URL. + * The hostname of the engine is *NOT* prefixed + * The default headers you specified in your MKNetworkEngine subclass gets added to the headers + * The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE + * The params dictionary is attached to the body if the HTTP Method is POST/PUT + * This method can be over-ridden by subclasses to tweak the operation creation mechanism. + * You would typically over-ride this method to create a subclass of MKNetworkOperation (if you have one). After you create it, you should call [super prepareHeaders:operation] to attach any custom headers from super class. + * @seealso + * prepareHeaders: + */ +-(MKNetworkOperation*) operationWithURLString:(NSString*) urlString + params:(NSDictionary*) body + httpMethod:(NSString*) method; + +/*! + * @abstract adds the custom default headers + * + * @discussion + * This method adds custom default headers to the factory created MKNetworkOperation. + * This method can be over-ridden by subclasses to add more default headers if necessary. + * You would typically over-ride this method if you have over-ridden operationWithURLString:params:httpMethod:. + * @seealso + * operationWithURLString:params:httpMethod: + */ +-(void) prepareHeaders:(MKNetworkOperation*) operation; + +/*! + * @abstract Handy helper method for fetching images in the background + * + * @discussion + * Creates an operation with the given image URL. + * The hostname of the engine is *NOT* prefixed. + * The image is returned to the caller via MKNKImageBlock callback block. This image is resized as per the size and decompressed in background. + * @seealso + * imageAtUrl:onCompletion: + */ +- (MKNetworkOperation*)imageAtURL:(NSURL *)url completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock; + +#if TARGET_OS_IPHONE +/*! + * @abstract Handy helper method for fetching images asynchronously in the background + * + * @discussion + * Creates an operation with the given image URL. + * The hostname of the engine is *NOT* prefixed. + * The image is returned to the caller via MKNKImageBlock callback block. This image is resized as per the size and decompressed in background. + * @seealso + * imageAtUrl:onCompletion: + */ +- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size onCompletion:(MKNKImageBlock) imageFetchedBlock DEPRECATED_ATTRIBUTE; + +/*! + * @abstract Handy helper method for fetching images asynchronously in the background + * + * @discussion + * Creates an operation with the given image URL. + * The hostname of the engine is *NOT* prefixed. + * The image is returned to the caller via MKNKImageBlock callback block. This image is resized as per the size and decompressed in background. + * @seealso + * imageAtUrl:onCompletion: + */ +- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock; +#endif + +/*! + * @abstract Handy helper method for fetching images + * + * @discussion + * Creates an operation with the given image URL. + * The hostname of the engine is *NOT* prefixed. + * The image is returned to the caller via MKNKImageBlock callback block. + */ +- (MKNetworkOperation*)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock DEPRECATED_ATTRIBUTE; + +/*! + * @abstract Enqueues your operation into the shared queue + * + * @discussion + * The operation you created is enqueued to the shared queue. If the response for this operation was previously cached, the cached data will be returned. + * @seealso + * enqueueOperation:forceReload: + */ +-(void) enqueueOperation:(MKNetworkOperation*) request; + +/*! + * @abstract Enqueues your operation into the shared queue. + * + * @discussion + * The operation you created is enqueued to the shared queue. + * When forceReload is NO, this method behaves like enqueueOperation: + * When forceReload is YES, No cached data will be returned even if cached data is available. + * @seealso + * enqueueOperation: + */ +-(void) enqueueOperation:(MKNetworkOperation*) operation forceReload:(BOOL) forceReload; + +/*! + * @abstract Cancels operations matching a given string + * + * @discussion + * Cancels all operations in the shared queue that matches a given string. This string could be your host name or a path + * + */ ++(void) cancelOperationsContainingURLString:(NSString*) string; + +/*! + * @abstract Cancels operations matching the given block. + * + * @discussion + * Cancels all operations in the shared queue for which the given block returns YES. + * + */ ++(void) cancelOperationsMatchingBlock:(BOOL (^)(MKNetworkOperation*))block; + +/*! + * @abstract Cancels all operations created by this engine + * + * @discussion + * Cancels all operations that matches this engine's host name + * This method is a no-op if the engine's host name was not set. + * + */ +- (void) cancelAllOperations; + +/*! + * @abstract HostName of the engine + * @property readonlyHostName + * + * @discussion + * Returns the host name of the engine + * This property is readonly cannot be updated. + * You normally initialize an engine with its hostname using the initWithHostName:customHeaders: method + */ +@property (readonly, copy, nonatomic) NSString *readonlyHostName; + +/*! + * @abstract Port Number that should be used by URL creating factory methods + * @property portNumber + * + * @discussion + * Set a port number for your engine if your remote URL mandates it. + * This property is optional and you DON'T have to specify the default HTTP port 80 + */ +@property (assign, nonatomic) int portNumber; + +/*! + * @abstract WiFi only mode + * @property wifiOnlyMode + * + * @discussion + * When you set this property to YES, MKNetworkEngine will not run operations on mobile data network. + */ +@property (assign, nonatomic) BOOL wifiOnlyMode; + +/*! + * @abstract Sets an api path if it is different from root URL + * @property apiPath + * + * @discussion + * You can use this method to set a custom path to the API location if your server's API path is different from root (/) + * This property is optional + */ +@property (copy, nonatomic) NSString* apiPath; + +/*! + * @abstract Handler that you implement to monitor reachability changes + * @property reachabilityChangedHandler + * + * @discussion + * The framework calls this handler whenever the reachability of the host changes. + * The default implementation freezes the queued operations and stops network activity + * You normally don't have to implement this unless you need to show a HUD notifying the user of connectivity loss + */ +@property (copy, nonatomic) void (^reachabilityChangedHandler)(NetworkStatus ns); + +/*! + * @abstract Registers an associated operation subclass + * + * @discussion + * When you override both MKNetworkEngine and MKNetworkOperation, you might want the engine's factory method + * to prepare operations of your MKNetworkOperation subclass. To create your own MKNetworkOperation subclasses from the factory method, you can register your MKNetworkOperation subclass using this method. + * This method is optional. If you don't use, factory methods in MKNetworkEngine creates MKNetworkOperation objects. + */ +-(void) registerOperationSubclass:(Class) aClass; + +/*! + * @abstract Cache Directory Name + * + * @discussion + * This method can be over-ridden by subclasses to provide an alternative cache directory + * The default directory (MKNetworkKitCache) within the NSCaches directory will be used otherwise + * Overriding this method is optional + */ +-(NSString*) cacheDirectoryName; + +/*! + * @abstract Cache Directory In Memory Cost + * + * @discussion + * This method can be over-ridden by subclasses to provide an alternative in memory cache size. + * By default, MKNetworkKit caches 10 recent requests in memory + * The default size is 10 + * Overriding this method is optional + */ +-(int) cacheMemoryCost; + +/*! + * @abstract Enable Caching + * + * @discussion + * This method should be called explicitly to enable caching for this engine. + * By default, MKNetworkKit doens't cache your requests. + * The cacheMemoryCost and cacheDirectoryName will be used when you turn caching on using this method. + */ +-(void) useCache; + +/*! + * @abstract Empties previously cached data + * + * @discussion + * This method is a handy helper that you can use to clear cached data. + * By default, MKNetworkKit doens't cache your requests. Use this only when you enabled caching + * @seealso + * useCache + */ +-(void) emptyCache; + +/*! + * @abstract Checks current reachable status + * + * @discussion + * This method is a handy helper that you can use to check for network reachability. + */ +-(BOOL) isReachable; + +/*! + * @abstract Boolean variable that states whether the request should automatically include an Accept-Language header. + * @property shouldSendAcceptLanguageHeader + * + * @discussion + * The default value is YES. MKNetworkKit will generate an Accept-Language header using [NSLocale preferredLanguages] + "en-US". + */ +@property (nonatomic, assign) BOOL shouldSendAcceptLanguageHeader; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.m new file mode 100644 index 0000000..a238f97 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.m @@ -0,0 +1,766 @@ +// +// MKNetworkEngine.m +// MKNetworkKit +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "MKNetworkKit.h" +#define kFreezableOperationExtension @"mknetworkkitfrozenoperation" + +#ifdef __OBJC_GC__ +#error MKNetworkKit does not support Objective-C Garbage Collection +#endif + +#if TARGET_OS_IPHONE +#ifndef __IPHONE_5_0 +#error MKNetworkKit does not support iOS 4 and lower +#endif +#endif + +#if ! __has_feature(objc_arc) +#error MKNetworkKit is ARC only. Either turn on ARC for the project or use -fobjc-arc flag +#endif + +@interface MKNetworkEngine (/*Private Methods*/) + +@property (copy, nonatomic) NSString *hostName; +@property (strong, nonatomic) Reachability *reachability; +@property (copy, nonatomic) NSDictionary *customHeaders; +@property (assign, nonatomic) Class customOperationSubclass; + +@property (nonatomic, strong) NSMutableDictionary *memoryCache; +@property (nonatomic, strong) NSMutableArray *memoryCacheKeys; +@property (nonatomic, strong) NSMutableDictionary *cacheInvalidationParams; + +#if OS_OBJECT_USE_OBJC +@property (strong, nonatomic) dispatch_queue_t backgroundCacheQueue; +@property (strong, nonatomic) dispatch_queue_t operationQueue; +#else +@property (assign, nonatomic) dispatch_queue_t backgroundCacheQueue; +@property (assign, nonatomic) dispatch_queue_t operationQueue; +#endif + +@end + +static NSOperationQueue *_sharedNetworkQueue; + +@implementation MKNetworkEngine + +// Network Queue is a shared singleton object. +// no matter how many instances of MKNetworkEngine is created, there is one and only one network queue +// In theory an app should contain as many network engines as the number of domains it talks to + +#pragma mark - +#pragma mark Initialization + ++(void) initialize { + + if(!_sharedNetworkQueue) { + static dispatch_once_t oncePredicate; + dispatch_once(&oncePredicate, ^{ + _sharedNetworkQueue = [[NSOperationQueue alloc] init]; + [_sharedNetworkQueue addObserver:[self self] forKeyPath:@"operationCount" options:0 context:NULL]; + [_sharedNetworkQueue setMaxConcurrentOperationCount:6]; + + }); + } +} + +- (id) init { + + return [self initWithHostName:nil]; +} + +- (id) initWithHostName:(NSString*) hostName { + + return [self initWithHostName:hostName apiPath:nil customHeaderFields:nil]; +} + +- (id) initWithHostName:(NSString*) hostName apiPath:(NSString*) apiPath customHeaderFields:(NSDictionary*) headers { + + return [self initWithHostName:hostName portNumber:0 apiPath:apiPath customHeaderFields:headers]; +} + +- (id) initWithHostName:(NSString*) hostName portNumber:(int)portNumber apiPath:(NSString*) apiPath customHeaderFields:(NSDictionary*) headers { + if((self = [super init])) { + + self.portNumber = portNumber; + self.apiPath = apiPath; + self.backgroundCacheQueue = dispatch_queue_create("com.mknetworkkit.cachequeue", DISPATCH_QUEUE_SERIAL); + self.operationQueue = dispatch_queue_create("com.mknetworkkit.operationqueue", DISPATCH_QUEUE_SERIAL); + + if(hostName) { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(reachabilityChanged:) + name:kReachabilityChangedNotification + object:nil]; + + self.hostName = hostName; + self.reachability = [Reachability reachabilityWithHostname:self.hostName]; + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + + [self.reachability startNotifier]; + }); + } + + if(headers[@"User-Agent"] == nil) { + + NSMutableDictionary *newHeadersDict = [headers mutableCopy]; + NSString *userAgentString = [NSString stringWithFormat:@"%@/%@", + [[NSBundle mainBundle] infoDictionary][(NSString *)kCFBundleNameKey], + [[NSBundle mainBundle] infoDictionary][(NSString *)kCFBundleVersionKey]]; + newHeadersDict[@"User-Agent"] = userAgentString; + self.customHeaders = newHeadersDict; + } else { + self.customHeaders = [headers mutableCopy]; + } + + self.customOperationSubclass = [MKNetworkOperation class]; + self.shouldSendAcceptLanguageHeader = YES; + } + + return self; +} + +- (id) initWithHostName:(NSString*) hostName customHeaderFields:(NSDictionary*) headers { + + return [self initWithHostName:hostName apiPath:nil customHeaderFields:headers]; +} + +#pragma mark - +#pragma mark Memory Mangement + +-(void) dealloc { + +#if TARGET_OS_IPHONE +#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000 + dispatch_release(_backgroundCacheQueue); + dispatch_release(_operationQueue); +#endif + +#else + +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 + dispatch_release(_backgroundCacheQueue); + dispatch_release(_operationQueue); +#endif +#endif + + [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil]; +#if TARGET_OS_IPHONE + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil]; +#elif TARGET_OS_MAC + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillResignActiveNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil]; +#endif + +} + +#pragma mark - +#pragma mark KVO for network Queue + ++ (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object + change:(NSDictionary *)change context:(void *)context +{ + if (object == _sharedNetworkQueue && [keyPath isEqualToString:@"operationCount"]) { + + [[NSNotificationCenter defaultCenter] postNotificationName:kMKNetworkEngineOperationCountChanged + object:[NSNumber numberWithInteger:(NSInteger)[_sharedNetworkQueue operationCount]]]; +#if TARGET_OS_IPHONE + [UIApplication sharedApplication].networkActivityIndicatorVisible = + ([_sharedNetworkQueue.operations count] > 0); +#endif + } + else { + [super observeValueForKeyPath:keyPath ofObject:object + change:change context:context]; + } +} + +#pragma mark - +#pragma mark Reachability related + +-(void) reachabilityChanged:(NSNotification*) notification +{ + if([self.reachability currentReachabilityStatus] == ReachableViaWiFi) + { + DLog(@"Server [%@] is reachable via Wifi", self.hostName); + [_sharedNetworkQueue setMaxConcurrentOperationCount:6]; + + [self checkAndRestoreFrozenOperations]; + } + else if([self.reachability currentReachabilityStatus] == ReachableViaWWAN) + { + if(self.wifiOnlyMode) { + + DLog(@" Disabling engine as server [%@] is reachable only via cellular data.", self.hostName); + [_sharedNetworkQueue setMaxConcurrentOperationCount:0]; + } else { + DLog(@"Server [%@] is reachable only via cellular data", self.hostName); + [_sharedNetworkQueue setMaxConcurrentOperationCount:2]; + [self checkAndRestoreFrozenOperations]; + } + } + else if([self.reachability currentReachabilityStatus] == NotReachable) + { + DLog(@"Server [%@] is not reachable", self.hostName); + [self freezeOperations]; + } + + if(self.reachabilityChangedHandler) { + self.reachabilityChangedHandler([self.reachability currentReachabilityStatus]); + } +} + +#pragma mark Freezing operations (Called when network connectivity fails) +-(void) freezeOperations { + + if(![self isCacheEnabled]) return; + + for(MKNetworkOperation *operation in _sharedNetworkQueue.operations) { + + // freeze only freeable operations. + if(![operation freezable]) continue; + + if(!self.hostName) return; + + // freeze only operations that belong to this server + if([[operation url] rangeOfString:self.hostName].location == NSNotFound) continue; + + NSString *archivePath = [[[self cacheDirectoryName] stringByAppendingPathComponent:[operation uniqueIdentifier]] + stringByAppendingPathExtension:kFreezableOperationExtension]; + [NSKeyedArchiver archiveRootObject:operation toFile:archivePath]; + [operation cancel]; + } +} + ++(void) cancelOperationsContainingURLString:(NSString*) string { + + [self cancelOperationsMatchingBlock:^BOOL (MKNetworkOperation* op) { + return [[op.readonlyRequest.URL absoluteString] rangeOfString:string].location != NSNotFound; + }]; +} + ++(void) cancelOperationsMatchingBlock:(BOOL (^)(MKNetworkOperation* op))block { + + NSArray *runningOperations = _sharedNetworkQueue.operations; + [runningOperations enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + + MKNetworkOperation *thisOperation = obj; + if (block(thisOperation)) + [thisOperation cancel]; + }]; +} + +-(void) cancelAllOperations { + + if(self.hostName) { + [MKNetworkEngine cancelOperationsContainingURLString:self.hostName]; + } else { + DLog(@"Host name is not set. Cannot cancel operations."); + } +} + +-(void) checkAndRestoreFrozenOperations { + + if(![self isCacheEnabled]) return; + + NSError *error = nil; + NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self cacheDirectoryName] error:&error]; + if(error) + DLog(@"%@", error); + + NSArray *pendingOperations = [files filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { + + NSString *thisFile = (NSString*) evaluatedObject; + return ([thisFile rangeOfString:kFreezableOperationExtension].location != NSNotFound); + }]]; + + for(NSString *pendingOperationFile in pendingOperations) { + + NSString *archivePath = [[self cacheDirectoryName] stringByAppendingPathComponent:pendingOperationFile]; + MKNetworkOperation *pendingOperation = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath]; + [self enqueueOperation:pendingOperation]; + NSError *error2 = nil; + [[NSFileManager defaultManager] removeItemAtPath:archivePath error:&error2]; + if(error2) + DLog(@"%@", error2); + } +} + +-(NSString*) readonlyHostName { + + return [_hostName copy]; +} + +-(BOOL) isReachable { + + return ([self.reachability currentReachabilityStatus] != NotReachable); +} + +#pragma mark - +#pragma mark Create methods + +-(void) registerOperationSubclass:(Class) aClass { + + self.customOperationSubclass = aClass; +} + +-(MKNetworkOperation*) operationWithPath:(NSString*) path { + + return [self operationWithPath:path params:nil]; +} + +-(MKNetworkOperation*) operationWithPath:(NSString*) path + params:(NSDictionary*) body { + + return [self operationWithPath:path + params:body + httpMethod:@"GET"]; +} + +-(MKNetworkOperation*) operationWithPath:(NSString*) path + params:(NSDictionary*) body + httpMethod:(NSString*)method { + + return [self operationWithPath:path params:body httpMethod:method ssl:NO]; +} + +-(MKNetworkOperation*) operationWithPath:(NSString*) path + params:(NSDictionary*) body + httpMethod:(NSString*)method + ssl:(BOOL) useSSL { + + if(self.hostName == nil) { + + DLog(@"Hostname is nil, use operationWithURLString: method to create absolute URL operations"); + return nil; + } + + NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@://%@", useSSL ? @"https" : @"http", self.hostName]; + + if(self.portNumber != 0) + [urlString appendFormat:@":%d", self.portNumber]; + + if(self.apiPath) + [urlString appendFormat:@"/%@", self.apiPath]; + + if(![path isEqualToString:@"/"]) { // fetch for root? + + if(path.length > 0 && [path characterAtIndex:0] == '/') // if user passes /, don't prefix a slash + [urlString appendFormat:@"%@", path]; + else if (path != nil) + [urlString appendFormat:@"/%@", path]; + } + + + return [self operationWithURLString:urlString params:body httpMethod:method]; +} + +-(MKNetworkOperation*) operationWithURLString:(NSString*) urlString { + + return [self operationWithURLString:urlString params:nil httpMethod:@"GET"]; +} + +-(MKNetworkOperation*) operationWithURLString:(NSString*) urlString + params:(NSDictionary*) body { + + return [self operationWithURLString:urlString params:body httpMethod:@"GET"]; +} + + +-(MKNetworkOperation*) operationWithURLString:(NSString*) urlString + params:(NSDictionary*) body + httpMethod:(NSString*)method { + + MKNetworkOperation *operation = [[self.customOperationSubclass alloc] initWithURLString:urlString params:body httpMethod:method]; + operation.shouldSendAcceptLanguageHeader = self.shouldSendAcceptLanguageHeader; + + [self prepareHeaders:operation]; + return operation; +} + +-(void) prepareHeaders:(MKNetworkOperation*) operation { + + [operation addHeaders:self.customHeaders]; +} + +-(NSData*) cachedDataForOperation:(MKNetworkOperation*) operation { + + NSData *cachedData = (self.memoryCache)[[operation uniqueIdentifier]]; + if(cachedData) return cachedData; + + NSString *filePath = [[self cacheDirectoryName] stringByAppendingPathComponent:[operation uniqueIdentifier]]; + + if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { + + cachedData = [NSData dataWithContentsOfFile:filePath]; + [self saveCacheData:cachedData forKey:[operation uniqueIdentifier]]; // bring it back to the in-memory cache + return cachedData; + } + + return nil; +} + +-(void) enqueueOperation:(MKNetworkOperation*) operation { + + [self enqueueOperation:operation forceReload:NO]; +} + +-(void) enqueueOperation:(MKNetworkOperation*) operation forceReload:(BOOL) forceReload { + + NSParameterAssert(operation != nil); + if(operation == nil) return; + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + + + __weak id weakSelf = self; + + + [operation setCacheHandler:^(MKNetworkOperation* completedCacheableOperation) { + + // if this is not called, the request would have been a non cacheable request + //completedCacheableOperation.cacheHeaders; + NSString *uniqueId = [completedCacheableOperation uniqueIdentifier]; + [weakSelf saveCacheData:[completedCacheableOperation responseData] + forKey:uniqueId]; + + ([weakSelf cacheInvalidationParams])[uniqueId] = completedCacheableOperation.cacheHeaders; + }]; + + __block double expiryTimeInSeconds = 0.0f; + + if([operation isCacheable]) { + + NSData *cachedData = [self cachedDataForOperation:operation]; + if(cachedData) { + dispatch_async(dispatch_get_main_queue(), ^{ + // Jump back to the original thread here since setCachedData updates the main thread + [operation setCachedData:cachedData]; + }); + + if(!forceReload) { + + NSString *uniqueId = [operation uniqueIdentifier]; + NSMutableDictionary *savedCacheHeaders = (self.cacheInvalidationParams)[uniqueId]; + // there is a cached version. + // this means, the current operation is a "GET" + if(savedCacheHeaders) { + NSString *expiresOn = savedCacheHeaders[@"Expires"]; + + dispatch_sync(self.operationQueue, ^{ + NSDate *expiresOnDate = [NSDate dateFromRFC1123:expiresOn]; + expiryTimeInSeconds = [expiresOnDate timeIntervalSinceNow]; + }); + + dispatch_async(dispatch_get_main_queue(), ^{ + + [operation updateOperationBasedOnPreviousHeaders:savedCacheHeaders]; + }); + } + } + } + + dispatch_sync(self.operationQueue, ^{ + + NSArray *operations = _sharedNetworkQueue.operations; + NSUInteger index = [operations indexOfObject:operation]; + BOOL operationFinished = NO; + if(index != NSNotFound) { + + MKNetworkOperation *queuedOperation = (MKNetworkOperation*) (operations)[index]; + operationFinished = [queuedOperation isFinished]; + if(!operationFinished) { + dispatch_async(dispatch_get_main_queue(), ^{ + [queuedOperation updateHandlersFromOperation:operation]; + }); + } + } + + if(expiryTimeInSeconds <= 0 || forceReload || operationFinished) + [_sharedNetworkQueue addOperation:operation]; + // else don't do anything + }); + + } else { + + [_sharedNetworkQueue addOperation:operation]; + } + + if([self.reachability currentReachabilityStatus] == NotReachable) + [self freezeOperations]; + }); +} + +- (MKNetworkOperation*)imageAtURL:(NSURL *)url completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock { + +#ifdef DEBUG + // I could enable caching here, but that hits performance and inturn affects table view scrolling + // if imageAtURL is called for loading thumbnails. + if(![self isCacheEnabled]) DLog(@"imageAtURL:onCompletion: requires caching to be enabled.") +#endif + + if (url == nil) { + return nil; + } + + MKNetworkOperation *op = [self operationWithURLString:[url absoluteString]]; + op.shouldCacheResponseEvenIfProtocolIsHTTPS = YES; + + [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { + + if (imageFetchedBlock) + imageFetchedBlock([completedOperation responseImage], + url, + [completedOperation isCachedResponse]); + + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + if (errorBlock) + errorBlock(completedOperation, error); + }]; + + [self enqueueOperation:op]; + + return op; +} + +#if TARGET_OS_IPHONE + +- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock { + +#ifdef DEBUG + // I could enable caching here, but that hits performance and inturn affects table view scrolling + // if imageAtURL is called for loading thumbnails. + if(![self isCacheEnabled]) DLog(@"imageAtURL:size:onCompletion: requires caching to be enabled.") +#endif + + if (url == nil) { + return nil; + } + + MKNetworkOperation *op = [self operationWithURLString:[url absoluteString]]; + op.shouldCacheResponseEvenIfProtocolIsHTTPS = YES; + + [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { + [completedOperation decompressedResponseImageOfSize:size + completionHandler:^(UIImage *decompressedImage) { + if (imageFetchedBlock) + imageFetchedBlock(decompressedImage, + url, + [completedOperation isCachedResponse]); + }]; + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + if (errorBlock) + errorBlock(completedOperation, error); + DLog(@"%@", error); + }]; + + [self enqueueOperation:op]; + + return op; +} + +- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size onCompletion:(MKNKImageBlock) imageFetchedBlock { + + return [self imageAtURL:url size:size completionHandler:imageFetchedBlock errorHandler:^(MKNetworkOperation* op, NSError* error){}]; +} + +#endif + +- (MKNetworkOperation*)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock +{ + return [self imageAtURL:url completionHandler:imageFetchedBlock errorHandler:^(MKNetworkOperation* op, NSError* error){}]; +} + + +#pragma mark - +#pragma mark Cache related + +-(NSString*) cacheDirectoryName { + + static NSString *cacheDirectoryName = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + NSString *documentsDirectory = paths[0]; + cacheDirectoryName = [documentsDirectory stringByAppendingPathComponent:MKNETWORKCACHE_DEFAULT_DIRECTORY]; + }); + + return cacheDirectoryName; +} + +-(int) cacheMemoryCost { + + return MKNETWORKCACHE_DEFAULT_COST; +} + +-(void) saveCache { + + for(NSString *cacheKey in [self.memoryCache allKeys]) + { + NSString *filePath = [[self cacheDirectoryName] stringByAppendingPathComponent:cacheKey]; + if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { + + NSError *error = nil; + [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; + ELog(error); + } + + [(self.memoryCache)[cacheKey] writeToFile:filePath atomically:YES]; + } + + [self.memoryCache removeAllObjects]; + [self.memoryCacheKeys removeAllObjects]; + + NSString *cacheInvalidationPlistFilePath = [[self cacheDirectoryName] stringByAppendingPathExtension:@"plist"]; + [self.cacheInvalidationParams writeToFile:cacheInvalidationPlistFilePath atomically:YES]; +} + +-(void) saveCacheData:(NSData*) data forKey:(NSString*) cacheDataKey +{ + dispatch_async(self.backgroundCacheQueue, ^{ + + (self.memoryCache)[cacheDataKey] = data; + + NSUInteger index = [self.memoryCacheKeys indexOfObject:cacheDataKey]; + if(index != NSNotFound) + [self.memoryCacheKeys removeObjectAtIndex:index]; + + [self.memoryCacheKeys insertObject:cacheDataKey atIndex:0]; // remove it and insert it at start + + if([self.memoryCacheKeys count] >= (NSUInteger)[self cacheMemoryCost]) + { + NSString *lastKey = [self.memoryCacheKeys lastObject]; + NSData *data2 = (self.memoryCache)[lastKey]; + NSString *filePath = [[self cacheDirectoryName] stringByAppendingPathComponent:lastKey]; + + if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { + + NSError *error = nil; + [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; + ELog(error); + } + [data2 writeToFile:filePath atomically:YES]; + + [self.memoryCacheKeys removeLastObject]; + [self.memoryCache removeObjectForKey:lastKey]; + } + }); +} + +/* + - (BOOL) dataOldness:(NSString*) imagePath + { + NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:imagePath error:nil]; + NSDate *creationDate = [attributes valueForKey:NSFileCreationDate]; + + return abs([creationDate timeIntervalSinceNow]); + }*/ + +-(BOOL) isCacheEnabled { + + BOOL isDir = NO; + BOOL isCachingEnabled = [[NSFileManager defaultManager] fileExistsAtPath:[self cacheDirectoryName] isDirectory:&isDir]; + return isCachingEnabled; +} + +-(void) useCache { + + self.memoryCache = [NSMutableDictionary dictionaryWithCapacity:[self cacheMemoryCost]]; + self.memoryCacheKeys = [NSMutableArray arrayWithCapacity:[self cacheMemoryCost]]; + self.cacheInvalidationParams = [NSMutableDictionary dictionary]; + + NSString *cacheDirectory = [self cacheDirectoryName]; + BOOL isDirectory = YES; + BOOL folderExists = [[NSFileManager defaultManager] fileExistsAtPath:cacheDirectory isDirectory:&isDirectory] && isDirectory; + + if (!folderExists) + { + NSError *error = nil; + [[NSFileManager defaultManager] createDirectoryAtPath:cacheDirectory withIntermediateDirectories:YES attributes:nil error:&error]; + } + + NSString *cacheInvalidationPlistFilePath = [cacheDirectory stringByAppendingPathExtension:@"plist"]; + + BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:cacheInvalidationPlistFilePath]; + + if (fileExists) + { + self.cacheInvalidationParams = [NSMutableDictionary dictionaryWithContentsOfFile:cacheInvalidationPlistFilePath]; + } + +#if TARGET_OS_IPHONE + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) + name:UIApplicationDidReceiveMemoryWarningNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) + name:UIApplicationWillTerminateNotification + object:nil]; + +#elif TARGET_OS_MAC + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) + name:NSApplicationWillHideNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) + name:NSApplicationWillResignActiveNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) + name:NSApplicationWillTerminateNotification + object:nil]; + +#endif + + +} + +-(void) emptyCache { + + [self saveCache]; // ensures that invalidation params are written to disk properly + NSError *error = nil; + NSArray *directoryContents = [[NSFileManager defaultManager] + contentsOfDirectoryAtPath:[self cacheDirectoryName] error:&error]; + if(error) DLog(@"%@", error); + + error = nil; + for(NSString *fileName in directoryContents) { + + NSString *path = [[self cacheDirectoryName] stringByAppendingPathComponent:fileName]; + [[NSFileManager defaultManager] removeItemAtPath:path error:&error]; + if(error) DLog(@"%@", error); + } + + error = nil; + NSString *cacheInvalidationPlistFilePath = [[self cacheDirectoryName] stringByAppendingPathExtension:@"plist"]; + [[NSFileManager defaultManager] removeItemAtPath:cacheInvalidationPlistFilePath error:&error]; + if(error) DLog(@"%@", error); +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkKit.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkKit.h new file mode 100644 index 0000000..dc2cc4d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkKit.h @@ -0,0 +1,95 @@ +// +// MKNetworkKit.h +// MKNetworkKit +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#ifndef MKNetworkKit_MKNetworkKit_h +#define MKNetworkKit_MKNetworkKit_h + + +#if TARGET_OS_IPHONE +#import +#import +#elif TARGET_OS_MAC +#import +#import +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 +#define DO_GCD_RETAIN_RELEASE 0 +#else +#define DO_GCD_RETAIN_RELEASE 1 +#endif +#endif + +#ifdef DEBUG +#ifndef DLog +# define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);} +#endif +#ifndef ELog +# define ELog(err) {if(err) DLog(@"%@", err)} +#endif +#else +#ifndef DLog +# define DLog(...) +#endif +#ifndef ELog +# define ELog(err) +#endif +#endif + +// ALog always displays output regardless of the DEBUG setting +#ifndef ALog +#define ALog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}; +#endif + +#import "Categories/NSString+MKNetworkKitAdditions.h" +#import "Categories/NSDictionary+RequestEncoding.h" +#import "Categories/NSDate+RFC1123.h" +#import "Categories/NSData+MKBase64.h" +#if TARGET_OS_IPHONE +#import "Categories/UIImageView+MKNetworkKitAdditions.h" +#import "Categories/UIAlertView+MKNetworkKitAdditions.h" +#elif TARGET_OS_MAC +#import "Categories/NSImageView+MKNetworkKitAdditions.h" +#import "Categories/NSAlert+MKNetworkKitAdditions.h" +#endif + +#import "Reachability/Reachability.h" + +#import "MKNetworkOperation.h" +#import "MKNetworkEngine.h" + +#define kMKNetworkEngineOperationCountChanged @"kMKNetworkEngineOperationCountChanged" +#define MKNETWORKCACHE_DEFAULT_COST 10 +#define MKNETWORKCACHE_DEFAULT_DIRECTORY @"MKNetworkKitCache" +#define kMKNetworkKitDefaultCacheDuration 60 // 1 minute +#define kMKNetworkKitDefaultImageHeadRequestDuration 3600*24*1 // 1 day (HEAD requests with eTag are sent only after expiry of this. Not that these are not RFC compliant, but needed for performance tuning) +#define kMKNetworkKitDefaultImageCacheDuration 3600*24*7 // 1 day + +// if your server takes longer than 30 seconds to provide real data, +// you should hire a better server developer. +// on iOS (or any mobile device), 30 seconds is already considered high. + +#define kMKNetworkKitRequestTimeOutInSeconds 30 +#endif + + diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.h new file mode 100644 index 0000000..427b78d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.h @@ -0,0 +1,692 @@ +// +// MKNetwork.h +// MKNetworkKit +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +@class MKNetworkOperation; + +typedef enum { + MKNetworkOperationStateReady = 1, + MKNetworkOperationStateExecuting = 2, + MKNetworkOperationStateFinished = 3 +} MKNetworkOperationState; + +typedef void (^MKNKVoidBlock)(void); +typedef void (^MKNKIDBlock)(void); +typedef void (^MKNKProgressBlock)(double progress); +typedef void (^MKNKResponseBlock)(MKNetworkOperation* completedOperation); +#if TARGET_OS_IPHONE +typedef void (^MKNKImageBlock) (UIImage* fetchedImage, NSURL* url, BOOL isInCache); +#elif TARGET_OS_MAC +typedef void (^MKNKImageBlock) (NSImage* fetchedImage, NSURL* url, BOOL isInCache); +#endif +typedef void (^MKNKResponseErrorBlock)(MKNetworkOperation* completedOperation, NSError* error); +typedef void (^MKNKErrorBlock)(NSError* error); + +typedef void (^MKNKAuthBlock)(NSURLAuthenticationChallenge* challenge); + +typedef NSString* (^MKNKEncodingBlock) (NSDictionary* postDataDict); + +typedef enum { + + MKNKPostDataEncodingTypeURL = 0, // default + MKNKPostDataEncodingTypeJSON, + MKNKPostDataEncodingTypePlist, + MKNKPostDataEncodingTypeCustom +} MKNKPostDataEncodingType; +/*! + @header MKNetworkOperation.h + @abstract Represents a single unique network operation. + */ + +/*! + * @class MKNetworkOperation + * @abstract Represents a single unique network operation. + * + * @discussion + * You normally create an instance of this class using the methods exposed by MKNetworkEngine + * Created operations are enqueued into the shared queue on MKNetworkEngine + * MKNetworkOperation encapsulates both request and response + * Printing a MKNetworkOperation prints out a cURL command that can be copied and pasted directly on terminal + * Freezable operations are serialized when network connectivity is lost and performed when connection is restored + */ +@interface MKNetworkOperation : NSOperation { + +@private + int _state; + BOOL _freezable; + MKNKPostDataEncodingType _postDataEncoding; +} + +/*! + * @abstract Request URL Property + * @property url + * + * @discussion + * Returns the operation's URL + * This property is readonly cannot be updated. + * To create an operation with a specific URL, use the operationWithURLString:params:httpMethod: + */ +@property (nonatomic, copy, readonly) NSString *url; + +/*! + * @abstract The internal request object + * @property readonlyRequest + * + * @discussion + * Returns the operation's actual request object + * This property is readonly cannot be modified. + * To create an operation with a new request, use the operationWithURLString:params:httpMethod: + */ +@property (nonatomic, strong, readonly) NSURLRequest *readonlyRequest; + +/*! + * @abstract The internal HTTP Response Object + * @property readonlyResponse + * + * @discussion + * Returns the operation's actual response object + * This property is readonly cannot be updated. + */ +@property (nonatomic, strong, readonly) NSHTTPURLResponse *readonlyResponse; + +/*! + * @abstract The internal HTTP Post data values + * @property readonlyPostDictionary + * + * @discussion + * Returns the operation's post data dictionary + * This property is readonly cannot be updated. + * Rather, updating this post dictionary doesn't have any effect on the MKNetworkOperation. + * Use the addHeaders method to add post data parameters to the operation. + * + * @seealso + * addHeaders: + */ +@property (nonatomic, copy, readonly) NSDictionary *readonlyPostDictionary; + +/*! + * @abstract The internal request object's method type + * @property HTTPMethod + * + * @discussion + * Returns the operation's method type + * This property is readonly cannot be modified. + * To create an operation with a new method type, use the operationWithURLString:params:httpMethod: + */ +@property (nonatomic, copy, readonly) NSString *HTTPMethod; + +/*! + * @abstract The internal response object's status code + * @property HTTPStatusCode + * + * @discussion + * Returns the operation's response's status code. + * Returns 0 when the operation has not yet started and the response is not available. + * This property is readonly cannot be modified. + */ +@property (nonatomic, assign, readonly) NSInteger HTTPStatusCode; + +/*! + * @abstract Post Data Encoding Type Property + * @property postDataEncoding + * + * @discussion + * Specifies which type of encoding should be used to encode post data. + * MKNKPostDataEncodingTypeURL is the default which defaults to application/x-www-form-urlencoded + * MKNKPostDataEncodingTypeJSON uses JSON encoding. + * JSON Encoding is supported only in iOS 5 or Mac OS X 10.7 and above. + * On older operating systems, JSON Encoding reverts back to URL Encoding + * You can use the postDataEncodingHandler to provide a custom postDataEncoding + * For example, JSON encoding using a third party library. + * + * @seealso + * setCustomPostDataEncodingHandler:forType: + * + */ +@property (nonatomic, assign) MKNKPostDataEncodingType postDataEncoding; + +/*! + * @abstract Set a customized Post Data Encoding Handler for a given HTTP Content Type + * + * @discussion + * If you need customized post data encoding support, provide a block method here. + * This block method will be invoked only when your HTTP Method is POST or PUT + * For default URL encoding or JSON encoding, use the property postDataEncoding + * If you change the postData format, it's your responsiblity to provide a correct Content-Type. + * + * @seealso + * postDataEncoding + */ +-(void) setCustomPostDataEncodingHandler:(MKNKEncodingBlock) postDataEncodingHandler forType:(NSString*) contentType; + +/*! + * @abstract String Encoding Property + * @property stringEncoding + * + * @discussion + * Specifies which type of encoding should be used to encode URL strings + */ +@property (nonatomic, assign) NSStringEncoding stringEncoding; + +/*! + * @abstract Freezable request + * @property freezable + * + * @discussion + * Freezable operations are serialized when the network goes down and restored when the connectivity is up again. + * Only POST, PUT and DELETE operations are freezable. + * In short, any operation that changes the state of the server are freezable, creating a tweet, checking into a new location etc., Operations like fetching a list of tweets (think readonly GET operations) are not freezable. + * MKNetworkKit doesn't freeze (readonly) GET operations even if they are marked as freezable + */ +@property (nonatomic, assign) BOOL freezable; + +/*! + * @abstract Error object + * @property error + * + * @discussion + * If the network operation results in an error, this will hold the response error, otherwise it will be nil + */ +@property (nonatomic, readonly, strong) NSError *error; + +/*! + * @abstract Boolean variable that states whether the operation's response should be cached despite coming from a secured source + * @property shouldCacheEvenIfProtocolIsHTTPS + * + * @discussion + * If you set this property to YES, the operation's data will be cached even if the source is secure (HTTPS) + * The default value is NO. MKNetworkKit will not cache responses from secure servers + */ +@property (nonatomic, assign) BOOL shouldCacheResponseEvenIfProtocolIsHTTPS; + +/*! + * @abstract Boolean variable that states whether the operation's response should be cached + * @property shouldNotCacheResponse + * + * @discussion + * If you set this property to YES, the operation's data will not be cached even if the engine's useCache is enabled + * The default value is NO. MKNetworkKit will cache responses based on the engine setting. + * This property should be used sparingly if your backend isn't written adhering to HTTP 1.1 caching standards + */ +@property (nonatomic, assign) BOOL shouldNotCacheResponse; + +/*! + * @abstract Boolean variable that states whether the operation should continue if the certificate is invalid. + * @property shouldContinueWithInvalidCertificate + * + * @discussion + * If you set this property to YES, the operation will continue as if the certificate was valid (if you use Server Trust Auth) + * The default value is NO. MKNetworkKit will not run an operation with a server that is not trusted. + */ +@property (nonatomic, assign) BOOL shouldContinueWithInvalidCertificate; + +/*! + * @abstract Boolean variable that states whether the request should automatically include an Accept-Language header. + * @property shouldSendAcceptLanguageHeader + * + * @discussion + * If set to YES, then MKNetworkKit will generate an Accept-Language header using [NSLocale preferredLanguages] + "en-us". + * This is set by MKNetworkEngine when it creates the MKNetworkOperation instance, so it gets its default from there. + */ +@property (nonatomic, assign) BOOL shouldSendAcceptLanguageHeader; + +/*! + * @abstract Cache headers of the response + * @property cacheHeaders + * + * @discussion + * If the network operation is a GET, this dictionary will be populated with relevant cache related headers + * MKNetworkKit assumes a 7 day cache for images and 1 minute cache for all requests with no-cache set + * This property is internal to MKNetworkKit. Modifying this is not recommended and will result in unexpected behaviour + */ +@property (strong, nonatomic) NSMutableDictionary *cacheHeaders; + +/*! + * @abstract Authentication methods + * + * @discussion + * If your request needs to be authenticated, set your username and password using this method. + */ +-(void) setUsername:(NSString*) name password:(NSString*) password; + +/*! + * @abstract Authentication methods + * + * @discussion + * If your request needs to be authenticated using HTTP Basic, use this method to set your username and password. + * Calling this method with basicAuth:NO is same as calling setUserName:password: + * @seealso + * setUserName:password: + */ +-(void) setUsername:(NSString*) username password:(NSString*) password basicAuth:(BOOL) bYesOrNo; + +/*! + * @abstract Authentication methods (Client Certificate) + * @property clientCertificate + * + * @discussion + * If your request needs to be authenticated using a client certificate, set the certificate path here + */ +@property (copy, nonatomic) NSString *clientCertificate; + +/*! + * @abstract Authentication methods (Password for the Client Certificate) + * @property clientCertificatePassword + * + * @discussion + * If your client certificate is encrypted with a password, specify it here + */ +@property (copy, nonatomic) NSString *clientCertificatePassword; + +/*! + * @abstract Custom authentication handler + * @property authHandler + * + * @discussion + * If your request needs to be authenticated using a custom method (like a Web page/HTML Form), add a block method here + * and process the NSURLAuthenticationChallenge + */ +@property (nonatomic, copy) MKNKAuthBlock authHandler; + +/*! + * @abstract Handler that you implement to monitor reachability changes + * @property operationStateChangedHandler + * + * @discussion + * The framework calls this handler whenever the operation state changes + */ +@property (copy, nonatomic) void (^operationStateChangedHandler)(MKNetworkOperationState newState); + +/*! + * @abstract controls persistence of authentication credentials + * @property credentialPersistence + * + * @discussion + * The default value is set to NSURLCredentialPersistenceForSession, change it to NSURLCredentialPersistenceNone to avoid caching issues (isse #35) + */ +@property (nonatomic, assign) NSURLCredentialPersistence credentialPersistence; +#if TARGET_OS_IPHONE + +/*! + * @abstract notification that has to be shown when an error occurs and the app is in background + * @property localNotification + * + * @discussion + * The default value nil. No notification is shown when an error occurs. + * To show a notification when the app is in background and the network operation running in background fails, + * set this parameter to a UILocalNotification object + */ +@property (nonatomic, strong) UILocalNotification *localNotification; + +/*! + * @abstract Shows a local notification when an error occurs + * @property shouldShowLocalNotificationOnError + * + * @discussion + * The default value NO. No notification is shown when an error occurs. + * When set to YES, MKNetworkKit shows the NSError localizedDescription text as a notification when the app is in background and the network operation ended in error. + * To customize the local notification text, use the property localNotification + + * @seealso + * localNotification + */ +@property (nonatomic, assign) BOOL shouldShowLocalNotificationOnError; +#endif + +/*! + * @abstract Add additional POST/GET parameters to your request + * + * @discussion + * If you ever need to set additional params after creating your operation, you this method. + * You normally set default parameters to the params parameter when you create a operation. + * On specific cases where you need to add a new parameter for a call, you can use this + */ +-(void) addParams:(NSDictionary*) paramsDictionary; + +/*! + * @abstract Add additional header + * + * @discussion Add a single additional header. See addHeaders for a full discussion. + */ +-(void) addHeader:(NSString*)key withValue:(NSString*)value; + +/*! + * @abstract Add additional header parameters + * + * @discussion + * If you ever need to set additional headers after creating your operation, you this method. + * You normally set default headers to the engine and they get added to every request you create. + * On specific cases where you need to set a new header parameter for just a single API call, you can use this + */ +-(void) addHeaders:(NSDictionary*) headersDictionary; + +/*! + * @abstract Set a header, overwriting any value already set. + * + * @discussion addHeader will append the value to any header already set. If you want to overwrite + * that value, then use setHeader instead. + */ +-(void) setHeader:(NSString*)key withValue:(NSString*)value; + +/*! + * @abstract Sets the authorization header after prefixing it with a given auth type + * + * @discussion + * If you need to set the HTTP Authorization header, you can use this convinience method. + * This method internally calls addHeaders: + * The authType parameter is a string that you can prefix to your auth token to tell your server what kind of authentication scheme you want to use. HTTP Basic Authentication uses the string "Basic" for authType + * To use HTTP Basic Authentication, consider using the method setUsername:password:basicAuth: instead. + * + * Example + * [op setAuthorizationHeaderValue:@"abracadabra" forAuthType:@"Token"] will set the header value to + * "Authorization: Token abracadabra" + * + * @seealso + * setUsername:password:basicAuth: + * addHeaders: + */ +-(void) setAuthorizationHeaderValue:(NSString*) token forAuthType:(NSString*) authType; + +/*! + * @abstract Attaches a file to the request + * + * @discussion + * This method lets you attach a file to the request + * The method has a side effect. It changes the HTTPMethod to "POST" regardless of what it was before. + * It also changes the post format to multipart/form-data + * The mime-type is assumed to be application/octet-stream + */ +-(void) addFile:(NSString*) filePath forKey:(NSString*) key; + +/*! + * @abstract Attaches a file to the request and allows you to specify a mime-type + * + * @discussion + * This method lets you attach a file to the request + * The method has a side effect. It changes the HTTPMethod to "POST" regardless of what it was before. + * It also changes the post format to multipart/form-data + */ +-(void) addFile:(NSString*) filePath forKey:(NSString*) key mimeType:(NSString*) mimeType; + +/*! + * @abstract Attaches a resource to the request from a NSData pointer + * + * @discussion + * This method lets you attach a NSData object to the request. The behaviour is exactly similar to addFile:forKey: + * The method has a side effect. It changes the HTTPMethod to "POST" regardless of what it was before. + * It also changes the post format to multipart/form-data + * The mime-type is assumed to be application/octet-stream + */ +-(void) addData:(NSData*) data forKey:(NSString*) key; + +/*! + * @abstract Attaches a resource to the request from a NSData pointer and allows you to specify a mime-type + * + * @discussion + * This method lets you attach a NSData object to the request. The behaviour is exactly similar to addFile:forKey:mimeType: + * The method has a side effect. It changes the HTTPMethod to "POST" regardless of what it was before. + * It also changes the post format to multipart/form-data + */ +-(void) addData:(NSData*) data forKey:(NSString*) key mimeType:(NSString*) mimeType fileName:(NSString*) fileName; + +/*! + * @abstract Block Handler for completion and error + * + * @discussion + * This method sets your completion and error blocks. If your operation's response data was previously called, + * the completion block will be called almost immediately with the cached response. You can check if the completion + * handler was invoked with a cached data or with real data by calling the isCachedResponse method. + * This method is deprecated in favour of addCompletionHandler:errorHandler: that returns the completedOperation in the error block as well. + * While I will still continue to support this method, I'll remove it completely in a future release. + * + * @seealso + * isCachedResponse + * addCompletionHandler:errorHandler: + */ +-(void) onCompletion:(MKNKResponseBlock) response onError:(MKNKErrorBlock) error DEPRECATED_ATTRIBUTE; + +/*! + * @abstract adds a block Handler for completion and error + * + * @discussion + * This method sets your completion and error blocks. If your operation's response data was previously called, + * the completion block will be called almost immediately with the cached response. You can check if the completion + * handler was invoked with a cached data or with real data by calling the isCachedResponse method. + * + * @seealso + * onCompletion:onError: + */ +-(void) addCompletionHandler:(MKNKResponseBlock) response errorHandler:(MKNKResponseErrorBlock) error; + +/*! + * @abstract Block Handler for tracking 304 not modified state + * + * @discussion + * This method will be called if the server sends a 304 HTTP status for your request. + * + */ +-(void) onNotModified:(MKNKVoidBlock) notModifiedBlock; + +/*! + * @abstract Block Handler for tracking upload progress + * + * @discussion + * This method can be used to update your progress bars when an upload is in progress. + * The value range of the progress is 0 to 1. + * + */ +-(void) onUploadProgressChanged:(MKNKProgressBlock) uploadProgressBlock; + +/*! + * @abstract Block Handler for tracking download progress + * + * @discussion + * This method can be used to update your progress bars when a download is in progress. + * The value range of the progress is 0 to 1. + * + */ +-(void) onDownloadProgressChanged:(MKNKProgressBlock) downloadProgressBlock; + +/*! + * @abstract Uploads a resource from a stream + * + * @discussion + * This method can be used to upload a resource for a post body directly from a stream. + * + */ +-(void) setUploadStream:(NSInputStream*) inputStream; + +/*! + * @abstract Downloads a resource directly to a file or any output stream + * + * @discussion + * This method can be used to download a resource directly to a stream (It's normally a file in most cases). + * Calling this method multiple times adds new streams to the same operation. + * A stream cannot be removed after it is added. + * + */ +-(void) addDownloadStream:(NSOutputStream*) outputStream; + +/*! + * @abstract Helper method to check if the response is from cache + * + * @discussion + * This method should be used to check if your response is cached. + * When you enable caching on MKNetworkEngine, your completionHandler will be called with cached data first and then + * with real data, later after fetching. In your handler, you can call this method to check if it is from cache or not + * + */ +-(BOOL) isCachedResponse; + +/*! + * @abstract Helper method to retrieve the contents + * + * @discussion + * This method is used for accessing the downloaded data. If the operation is still in progress, the method returns nil instead of partial data. To access partial data, use a downloadStream. + * + * @seealso + * addDownloadStream: + */ +-(NSData*) responseData; + +/*! + * @abstract Helper method to retrieve the contents as a NSString + * + * @discussion + * This method is used for accessing the downloaded data. If the operation is still in progress, the method returns nil instead of partial data. To access partial data, use a downloadStream. The method also converts the responseData to a NSString using the stringEncoding specified in the operation + * + * @seealso + * addDownloadStream: + * stringEncoding + */ +-(NSString*)responseString; + +/*! + * @abstract Helper method to print the request as a cURL command + * + * @discussion + * This method is used for displaying the request you created as a cURL command + * + */ +-(NSString*) curlCommandLineString; + +/*! + * @abstract Helper method to retrieve the contents as a NSString encoded using a specific string encoding + * + * @discussion + * This method is used for accessing the downloaded data. If the operation is still in progress, the method returns nil instead of partial data. To access partial data, use a downloadStream. The method also converts the responseData to a NSString using the stringEncoding specified in the parameter + * + * @seealso + * addDownloadStream: + * stringEncoding + */ +-(NSString*) responseStringWithEncoding:(NSStringEncoding) encoding; + +/*! + * @abstract Helper method to retrieve the contents as a UIImage + * + * @discussion + * This method is used for accessing the downloaded data as a UIImage. If the operation is still in progress, the method returns nil instead of a partial image. To access partial data, use a downloadStream. If the response is not a valid image, this method returns nil. This method doesn't obey the response mime type property. If the server response with a proper image data but set the mime type incorrectly, this method will still be able access the response as an image. + * + * @seealso + * addDownloadStream: + */ +#if TARGET_OS_IPHONE +-(UIImage*) responseImage; +-(void) decompressedResponseImageOfSize:(CGSize) size completionHandler:(void (^)(UIImage *decompressedImage)) imageDecompressionHandler; +#elif TARGET_OS_MAC +-(NSImage*) responseImage; +-(NSXMLDocument*) responseXML; +#endif + +/*! + * @abstract Helper method to retrieve the contents as a NSDictionary or NSArray depending on the JSON contents + * + * @discussion + * This method is used for accessing the downloaded data as a NSDictionary or an NSArray. If the operation is still in progress, the method returns nil. If the response is not a valid JSON, this method returns nil. + * + * @seealso + * responseJSONWithCompletionHandler: + + * @availability + * iOS 5 and above or Mac OS 10.7 and above + */ +-(id) responseJSON; + +/*! + * @abstract Helper method to retrieve the contents as a NSDictionary or NSArray depending on the JSON contents in the background + * + * @discussion + * This method is used for accessing the downloaded data as a NSDictionary or an NSArray. If the operation is still in progress, the method returns nil. If the response is not a valid JSON, this method returns nil. The difference between this and responseJSON is that, this method decodes JSON in the background. + * + * @see also + * responseJSON + * responseJSONWithOptions:completionHandler: + * + * @availability + * iOS 5 and above or Mac OS 10.7 and above + */ +-(void) responseJSONWithCompletionHandler:(void (^)(id jsonObject)) jsonDecompressionHandler; + +/*! + * @abstract Helper method to retrieve the contents as a NSDictionary or NSArray depending on the JSON contents in the background + * + * @discussion + * This method is used for accessing the downloaded data as a NSDictionary or an NSArray. If the operation is still in progress, the method returns nil. If the response is not a valid JSON, this method returns nil. The difference between this and responseJSON is that, this method decodes JSON in the background and allows passing JSON reading options like parsing JSON fragments. + * + * @see also + * responseJSON + * responseJSONWithCompletionHandler: + * + * @availability + * iOS 5 and above or Mac OS 10.7 and above + */ +-(void) responseJSONWithOptions:(NSJSONReadingOptions) options completionHandler:(void (^)(id jsonObject)) jsonDecompressionHandler; + +/*! + * @abstract Overridable custom method where you can add your custom business logic error handling + * + * @discussion + * This optional method can be overridden to do custom error handling. Be sure to call [super operationSucceeded] at the last. + * For example, a valid HTTP response (200) like "Item not found in database" might have a custom business error code + * You can override this method and called [super failWithError:customError]; to notify that HTTP call was successful but the method + * ended as a failed call + * + */ +-(void) operationSucceeded; + +/*! + * @abstract Overridable custom method where you can add your custom business logic error handling + * + * @discussion + * This optional method can be overridden to do custom error handling. Be sure to call [super operationSucceeded] at the last. + * For example, a invalid HTTP response (401) like "Unauthorized" might be a valid case in your app. + * You can override this method and called [super operationSucceeded]; to notify that HTTP call failed but the method + * ended as a success call. For example, Facebook login failed, but to your business implementation, it's not a problem as you + * are going to try alternative login mechanisms. + * + */ +-(void) operationFailedWithError:(NSError*) error; + +/*! + * @abstract Copy this MKNetworkOperation, with the intention of retrying the call. + * + * @discussion This means that the request parameters and callbacks are all preserved, but anything related + * to an ongoing request is discarded, so that a new request with the same configuration can be made. + */ +-(instancetype) copyForRetry; + +// internal methods called by MKNetworkEngine only. +// Don't touch +-(BOOL) isCacheable; +-(void) setCachedData:(NSData*) cachedData; +-(void) setCacheHandler:(MKNKResponseBlock) cacheHandler; +-(void) updateHandlersFromOperation:(MKNetworkOperation*) operation; +-(void) updateOperationBasedOnPreviousHeaders:(NSMutableDictionary*) headers; +-(NSString*) uniqueIdentifier; + +- (instancetype)initWithURLString:(NSString *)aURLString + params:(NSDictionary *)params + httpMethod:(NSString *)method; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.m new file mode 100644 index 0000000..4932304 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.m @@ -0,0 +1,1518 @@ +// +// MKNetworkOperation.m +// MKNetworkKit +// +// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. +// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd + +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "MKNetworkKit.h" + +#import + +#ifdef __OBJC_GC__ +#error MKNetworkKit does not support Objective-C Garbage Collection +#endif + +#if TARGET_OS_IPHONE +#ifndef __IPHONE_5_0 +#error MKNetworkKit does not support iOS 4 and lower +#endif +#endif + +#if ! __has_feature(objc_arc) +#error MKNetworkKit is ARC only. Either turn on ARC for the project or use -fobjc-arc flag +#endif + +OSStatus extractIdentityAndTrust(CFDataRef inPKCS12Data, + SecIdentityRef *outIdentity, + SecTrustRef *outTrust, + CFStringRef keyPassword); + +@interface MKNetworkOperation (/*Private Methods*/) +@property (strong, nonatomic) NSURLConnection *connection; +@property (copy, nonatomic) NSString *uniqueId; +@property (strong, nonatomic) NSMutableURLRequest *request; +@property (strong, nonatomic) NSHTTPURLResponse *response; + +@property (strong, nonatomic) NSMutableDictionary *fieldsToBePosted; +@property (strong, nonatomic) NSMutableArray *filesToBePosted; +@property (strong, nonatomic) NSMutableArray *dataToBePosted; + +@property (copy, nonatomic) NSString *username; +@property (copy, nonatomic) NSString *password; + +@property (nonatomic, strong) NSMutableArray *responseBlocks; +@property (nonatomic, strong) NSMutableArray *errorBlocks; +@property (nonatomic, strong) NSMutableArray *errorBlocksType2; + +@property (nonatomic, assign) MKNetworkOperationState state; +@property (nonatomic, assign) BOOL isCancelled; + +@property (strong, nonatomic) NSMutableData *mutableData; +@property (assign, nonatomic) NSUInteger downloadedDataSize; + +@property (nonatomic, strong) NSMutableArray *notModifiedHandlers; + +@property (nonatomic, strong) NSMutableArray *uploadProgressChangedHandlers; +@property (nonatomic, strong) NSMutableArray *downloadProgressChangedHandlers; +@property (nonatomic, copy) MKNKEncodingBlock postDataEncodingHandler; + +@property (nonatomic, assign) NSInteger startPosition; + +@property (nonatomic, strong) NSMutableArray *downloadStreams; +@property (nonatomic, copy) NSData *cachedResponse; +@property (nonatomic, copy) MKNKResponseBlock cacheHandlingBlock; + +@property (nonatomic, assign) SecTrustRef serverTrust; + +#if TARGET_OS_IPHONE +@property (nonatomic, assign) UIBackgroundTaskIdentifier backgroundTaskId; +#endif + +@property (strong, nonatomic) NSError *error; + +- (instancetype)initWithURLString:(NSString *)aURLString + params:(NSDictionary *)body + httpMethod:(NSString *)method; + +-(NSData*) bodyData; + +-(NSString*) encodedPostDataString; +- (void) showLocalNotification; +- (void) endBackgroundTask; + +@end + +@implementation MKNetworkOperation + +@dynamic freezable; + +// A RESTful service should always return the same response for a given URL and it's parameters. +// this means if these values are correct, you can cache the responses +// This is another reason why we check only GET methods. +// even if URL and others are same, POST, DELETE, PUT methods should not be cached and should not be treated equal. + +-(BOOL) isCacheable { + + if(self.shouldNotCacheResponse) return NO; + if(self.username != nil) return NO; + if(self.password != nil) return NO; + if(self.clientCertificate != nil) return NO; + if(self.clientCertificatePassword != nil) return NO; + if(![self.request.HTTPMethod isEqualToString:@"GET"]) return NO; + if([self.request.URL.scheme.lowercaseString isEqualToString:@"https"]) return self.shouldCacheResponseEvenIfProtocolIsHTTPS; + if(self.downloadStreams.count > 0) return NO; // should not cache operations that have streams attached + return YES; +} + + +//=========================================================== +// + (BOOL)automaticallyNotifiesObserversForKey: +// +//=========================================================== ++ (BOOL)automaticallyNotifiesObserversForKey: (NSString *)theKey +{ + BOOL automatic; + + if ([theKey isEqualToString:@"postDataEncoding"]) { + automatic = NO; + } else { + automatic = [super automaticallyNotifiesObserversForKey:theKey]; + } + + return automatic; +} + +//=========================================================== +// postDataEncoding +//=========================================================== +- (MKNKPostDataEncodingType)postDataEncoding +{ + return _postDataEncoding; +} +- (void)setPostDataEncoding:(MKNKPostDataEncodingType)aPostDataEncoding +{ + _postDataEncoding = aPostDataEncoding; + + NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); + + switch (self.postDataEncoding) { + + case MKNKPostDataEncodingTypeURL: { + [self.request setValue: + [NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset] + forHTTPHeaderField:@"Content-Type"]; + } + break; + case MKNKPostDataEncodingTypeJSON: { + [self.request setValue: + [NSString stringWithFormat:@"application/json; charset=%@", charset] + forHTTPHeaderField:@"Content-Type"]; + } + break; + case MKNKPostDataEncodingTypePlist: { + [self.request setValue: + [NSString stringWithFormat:@"application/x-plist; charset=%@", charset] + forHTTPHeaderField:@"Content-Type"]; + } + + default: + break; + } +} + +-(NSString*) encodedPostDataString { + + NSString *returnValue = @""; + if(self.postDataEncodingHandler) + returnValue = self.postDataEncodingHandler(self.fieldsToBePosted); + else if(self.postDataEncoding == MKNKPostDataEncodingTypeURL) + returnValue = [self.fieldsToBePosted urlEncodedKeyValueString]; + else if(self.postDataEncoding == MKNKPostDataEncodingTypeJSON) + returnValue = [self.fieldsToBePosted jsonEncodedKeyValueString]; + else if(self.postDataEncoding == MKNKPostDataEncodingTypePlist) + returnValue = [self.fieldsToBePosted plistEncodedKeyValueString]; + return returnValue; +} + +-(void) setCustomPostDataEncodingHandler:(MKNKEncodingBlock) postDataEncodingHandler forType:(NSString*) contentType { + + NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); + self.postDataEncoding = MKNKPostDataEncodingTypeCustom; + self.postDataEncodingHandler = postDataEncodingHandler; + [self.request setValue: + [NSString stringWithFormat:@"%@; charset=%@", contentType, charset] + forHTTPHeaderField:@"Content-Type"]; +} +//=========================================================== +// freezable +//=========================================================== +- (BOOL)freezable +{ + return _freezable; +} + +-(NSString*) url { + + return [[self.request URL] absoluteString]; +} + +-(NSURLRequest*) readonlyRequest { + + return [self.request copy]; +} + +-(NSHTTPURLResponse*) readonlyResponse { + + return [self.response copy]; +} + +- (NSDictionary *) readonlyPostDictionary { + + return [self.fieldsToBePosted copy]; +} + +-(NSString*) HTTPMethod { + + return self.request.HTTPMethod; +} + +-(NSInteger) HTTPStatusCode { + + if(self.response) + return self.response.statusCode; + else + return 0; +} + +- (void)setFreezable:(BOOL)flag +{ + // get method cannot be frozen. + // No point in freezing a method that doesn't change server state. + if([self.request.HTTPMethod isEqualToString:@"GET"] && flag) return; + _freezable = flag; + + if(_freezable && self.uniqueId == nil) + self.uniqueId = [NSString uniqueString]; +} + + +-(BOOL) isEqual:(id)object { + if(object == self) + return YES; + if(!object || ![object isKindOfClass:[self class]]) + return NO; + if([self.request.HTTPMethod isEqualToString:@"GET"] || [self.request.HTTPMethod isEqualToString:@"HEAD"]) { + + MKNetworkOperation *anotherObject = (MKNetworkOperation*) object; + return ([[self uniqueIdentifier] isEqualToString:[anotherObject uniqueIdentifier]]); + } + + return NO; +} + +-(NSUInteger) hash { + return [[self uniqueIdentifier] hash]; +} + +-(NSString*) uniqueIdentifier { + + NSMutableString *str = [NSMutableString stringWithFormat:@"%@ %@", self.request.HTTPMethod, self.url]; + + if(self.username || self.password) { + + [str appendFormat:@" [%@:%@]", + self.username ? self.username : @"", + self.password ? self.password : @""]; + } + + if(self.freezable) { + + [str appendString:self.uniqueId]; + } + return [str md5]; +} + +-(BOOL) isCachedResponse { + + return self.cachedResponse != nil; +} + +-(void) notifyCache { + + if(![self isCacheable]) return; + if(!([self.response statusCode] >= 200 && [self.response statusCode] < 300)) return; + + if(![self isCancelled]) + self.cacheHandlingBlock(self); +} + +-(MKNetworkOperationState) state { + + return (MKNetworkOperationState)_state; +} + +-(void) setState:(MKNetworkOperationState)newState { + + switch (newState) { + case MKNetworkOperationStateReady: + [self willChangeValueForKey:@"isReady"]; + break; + case MKNetworkOperationStateExecuting: + [self willChangeValueForKey:@"isReady"]; + [self willChangeValueForKey:@"isExecuting"]; + break; + case MKNetworkOperationStateFinished: + [self willChangeValueForKey:@"isExecuting"]; + [self willChangeValueForKey:@"isFinished"]; + break; + } + + _state = newState; + + switch (newState) { + case MKNetworkOperationStateReady: + [self didChangeValueForKey:@"isReady"]; + break; + case MKNetworkOperationStateExecuting: + [self didChangeValueForKey:@"isReady"]; + [self didChangeValueForKey:@"isExecuting"]; + break; + case MKNetworkOperationStateFinished: + [self didChangeValueForKey:@"isExecuting"]; + [self didChangeValueForKey:@"isFinished"]; + break; + } + + if(self.operationStateChangedHandler) { + self.operationStateChangedHandler(newState); + } +} + +- (void)encodeWithCoder:(NSCoder *)encoder +{ + [encoder encodeInteger:(NSInteger)self.stringEncoding forKey:@"stringEncoding"]; + [encoder encodeInteger:_postDataEncoding forKey:@"postDataEncoding"]; + + [encoder encodeObject:self.uniqueId forKey:@"uniqueId"]; + [encoder encodeObject:self.request forKey:@"request"]; + [encoder encodeObject:self.response forKey:@"response"]; + [encoder encodeObject:self.fieldsToBePosted forKey:@"fieldsToBePosted"]; + [encoder encodeObject:self.filesToBePosted forKey:@"filesToBePosted"]; + [encoder encodeObject:self.dataToBePosted forKey:@"dataToBePosted"]; + [encoder encodeObject:self.username forKey:@"username"]; + [encoder encodeObject:self.password forKey:@"password"]; + [encoder encodeObject:self.clientCertificate forKey:@"clientCertificate"]; + [encoder encodeObject:self.clientCertificatePassword forKey:@"clientCertificatePassword"]; + [encoder encodeBool:self.shouldContinueWithInvalidCertificate forKey:@"shouldContinueWithInvalidCertificate"]; +#if TARGET_OS_IPHONE + [encoder encodeObject:self.localNotification forKey:@"localNotification"]; +#endif + self.state = MKNetworkOperationStateReady; + [encoder encodeInt32:_state forKey:@"state"]; + [encoder encodeBool:self.isCancelled forKey:@"isCancelled"]; + [encoder encodeObject:self.mutableData forKey:@"mutableData"]; + [encoder encodeInteger:(NSInteger)self.downloadedDataSize forKey:@"downloadedDataSize"]; + [encoder encodeObject:self.downloadStreams forKey:@"downloadStreams"]; + [encoder encodeInteger:self.startPosition forKey:@"startPosition"]; + [encoder encodeInteger:self.credentialPersistence forKey:@"credentialPersistence"]; +} + +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + self = [super init]; + if (self) { + [self setStringEncoding:(NSStringEncoding)[decoder decodeIntegerForKey:@"stringEncoding"]]; + _postDataEncoding = (MKNKPostDataEncodingType) [decoder decodeIntegerForKey:@"postDataEncoding"]; + self.request = [decoder decodeObjectForKey:@"request"]; + self.uniqueId = [decoder decodeObjectForKey:@"uniqueId"]; + + self.response = [decoder decodeObjectForKey:@"response"]; + self.fieldsToBePosted = [decoder decodeObjectForKey:@"fieldsToBePosted"]; + self.filesToBePosted = [decoder decodeObjectForKey:@"filesToBePosted"]; + self.dataToBePosted = [decoder decodeObjectForKey:@"dataToBePosted"]; + self.username = [decoder decodeObjectForKey:@"username"]; + self.password = [decoder decodeObjectForKey:@"password"]; + self.clientCertificate = [decoder decodeObjectForKey:@"clientCertificate"]; + self.clientCertificatePassword = [decoder decodeObjectForKey:@"clientCertificatePassword"]; +#if TARGET_OS_IPHONE + self.localNotification = [decoder decodeObjectForKey:@"localNotification"]; +#endif + [self setState:(MKNetworkOperationState)[decoder decodeInt32ForKey:@"state"]]; + self.isCancelled = [decoder decodeBoolForKey:@"isCancelled"]; + self.mutableData = [decoder decodeObjectForKey:@"mutableData"]; + self.downloadedDataSize = [decoder decodeIntegerForKey:@"downloadedDataSize"]; + self.downloadStreams = [decoder decodeObjectForKey:@"downloadStreams"]; + self.startPosition = [decoder decodeIntegerForKey:@"startPosition"]; + self.credentialPersistence = [decoder decodeIntegerForKey:@"credentialPersistence"]; + } + return self; +} + +- (instancetype)copyWithZone:(NSZone *)zone +{ + MKNetworkOperation *theCopy = [[[self class] allocWithZone:zone] init]; // use designated initializer + + theCopy.postDataEncoding = _postDataEncoding; + [theCopy setStringEncoding:self.stringEncoding]; + [theCopy setUniqueId:[self.uniqueId copy]]; + + [theCopy setConnection:[self.connection copy]]; + [theCopy setRequest:[self.request copy]]; + [theCopy setResponse:[self.response copy]]; + [theCopy setFieldsToBePosted:[self.fieldsToBePosted copy]]; + [theCopy setFilesToBePosted:[self.filesToBePosted copy]]; + [theCopy setDataToBePosted:[self.dataToBePosted copy]]; + [theCopy setUsername:[self.username copy]]; + [theCopy setPassword:[self.password copy]]; + [theCopy setClientCertificate:[self.clientCertificate copy]]; + [theCopy setClientCertificatePassword:[self.clientCertificatePassword copy]]; + [theCopy setResponseBlocks:[self.responseBlocks copy]]; + [theCopy setErrorBlocks:[self.errorBlocks copy]]; + [theCopy setErrorBlocksType2:[self.errorBlocksType2 copy]]; + [theCopy setState:self.state]; + [theCopy setIsCancelled:self.isCancelled]; + [theCopy setMutableData:[self.mutableData copy]]; + [theCopy setDownloadedDataSize:self.downloadedDataSize]; + [theCopy setNotModifiedHandlers:[self.notModifiedHandlers copy]]; + [theCopy setUploadProgressChangedHandlers:[self.uploadProgressChangedHandlers copy]]; + [theCopy setDownloadProgressChangedHandlers:[self.downloadProgressChangedHandlers copy]]; + [theCopy setDownloadStreams:[self.downloadStreams copy]]; + [theCopy setCachedResponse:[self.cachedResponse copy]]; + [theCopy setCacheHandlingBlock:self.cacheHandlingBlock]; + [theCopy setStartPosition:self.startPosition]; + [theCopy setCredentialPersistence:self.credentialPersistence]; + + return theCopy; +} + + +- (instancetype)mutableCopyWithZone:(NSZone *)zone +{ + MKNetworkOperation *theCopy = [[[self class] allocWithZone:zone] init]; // use designated initializer + + theCopy.postDataEncoding = _postDataEncoding; + [theCopy setStringEncoding:self.stringEncoding]; + [theCopy setUniqueId:[self.uniqueId copy]]; + + [theCopy setConnection:[self.connection mutableCopy]]; + [theCopy setRequest:[self.request mutableCopy]]; + [theCopy setResponse:[self.response mutableCopy]]; + [theCopy setFieldsToBePosted:[self.fieldsToBePosted mutableCopy]]; + [theCopy setFilesToBePosted:[self.filesToBePosted mutableCopy]]; + [theCopy setDataToBePosted:[self.dataToBePosted mutableCopy]]; + [theCopy setUsername:[self.username copy]]; + [theCopy setPassword:[self.password copy]]; + [theCopy setClientCertificate:[self.clientCertificate copy]]; + [theCopy setClientCertificatePassword:[self.clientCertificatePassword copy]]; + [theCopy setResponseBlocks:[self.responseBlocks mutableCopy]]; + [theCopy setErrorBlocks:[self.errorBlocks mutableCopy]]; + [theCopy setErrorBlocksType2:[self.errorBlocksType2 mutableCopy]]; + [theCopy setState:self.state]; + [theCopy setIsCancelled:self.isCancelled]; + [theCopy setMutableData:[self.mutableData mutableCopy]]; + [theCopy setDownloadedDataSize:self.downloadedDataSize]; + [theCopy setNotModifiedHandlers:[self.notModifiedHandlers mutableCopy]]; + [theCopy setUploadProgressChangedHandlers:[self.uploadProgressChangedHandlers mutableCopy]]; + [theCopy setDownloadProgressChangedHandlers:[self.downloadProgressChangedHandlers mutableCopy]]; + [theCopy setDownloadStreams:[self.downloadStreams mutableCopy]]; + [theCopy setCachedResponse:[self.cachedResponse mutableCopy]]; + [theCopy setCacheHandlingBlock:self.cacheHandlingBlock]; + [theCopy setStartPosition:self.startPosition]; + [theCopy setCredentialPersistence:self.credentialPersistence]; + + return theCopy; +} + +- (instancetype)copyForRetry +{ + MKNetworkOperation *theCopy = [[[self class] alloc] init]; + + [theCopy setConnection:nil]; + [theCopy setResponse:nil]; + [theCopy setState:MKNetworkOperationStateReady]; + [theCopy setIsCancelled:NO]; + [theCopy setDownloadedDataSize:0]; + [theCopy setStartPosition:0]; + + theCopy.postDataEncoding = _postDataEncoding; + [theCopy setStringEncoding:self.stringEncoding]; + [theCopy setUniqueId:[self.uniqueId copy]]; + [theCopy setRequest:[self.request copy]]; + [theCopy setFieldsToBePosted:[self.fieldsToBePosted mutableCopy]]; + [theCopy setFilesToBePosted:[self.filesToBePosted mutableCopy]]; + [theCopy setDataToBePosted:[self.dataToBePosted mutableCopy]]; + [theCopy setUsername:[self.username copy]]; + [theCopy setPassword:[self.password copy]]; + [theCopy setClientCertificate:[self.clientCertificate copy]]; + [theCopy setClientCertificatePassword:[self.clientCertificatePassword copy]]; + [theCopy setResponseBlocks:[self.responseBlocks mutableCopy]]; + [theCopy setErrorBlocks:[self.errorBlocks mutableCopy]]; + [theCopy setErrorBlocksType2:[self.errorBlocksType2 mutableCopy]]; + [theCopy setMutableData:[self.mutableData mutableCopy]]; + [theCopy setNotModifiedHandlers:[self.notModifiedHandlers mutableCopy]]; + [theCopy setUploadProgressChangedHandlers:[self.uploadProgressChangedHandlers mutableCopy]]; + [theCopy setDownloadProgressChangedHandlers:[self.downloadProgressChangedHandlers mutableCopy]]; + [theCopy setDownloadStreams:[self.downloadStreams mutableCopy]]; + [theCopy setCachedResponse:[self.cachedResponse mutableCopy]]; + [theCopy setCacheHandlingBlock:self.cacheHandlingBlock]; + [theCopy setCredentialPersistence:self.credentialPersistence]; + + return theCopy; +} + +-(void) dealloc { + + [_connection cancel]; + _connection = nil; +} + +-(void) updateHandlersFromOperation:(MKNetworkOperation*) operation { + + [self.responseBlocks addObjectsFromArray:operation.responseBlocks]; + [self.errorBlocks addObjectsFromArray:operation.errorBlocks]; + [self.errorBlocksType2 addObjectsFromArray:operation.errorBlocksType2]; + [self.notModifiedHandlers addObjectsFromArray:operation.notModifiedHandlers]; + [self.uploadProgressChangedHandlers addObjectsFromArray:operation.uploadProgressChangedHandlers]; + [self.downloadProgressChangedHandlers addObjectsFromArray:operation.downloadProgressChangedHandlers]; + [self.downloadStreams addObjectsFromArray:operation.downloadStreams]; +} + +-(void) setCachedData:(NSData*) cachedData { + + self.cachedResponse = cachedData; + [self operationSucceeded]; +} + +-(void) updateOperationBasedOnPreviousHeaders:(NSMutableDictionary*) headers { + + NSString *lastModified = headers[@"Last-Modified"]; + NSString *eTag = headers[@"ETag"]; + if(lastModified) { + [self.request setValue:lastModified forHTTPHeaderField:@"IF-MODIFIED-SINCE"]; + } + + if(eTag) { + [self.request setValue:eTag forHTTPHeaderField:@"IF-NONE-MATCH"]; + } +} + +-(void) setUsername:(NSString*) username password:(NSString*) password { + + self.username = username; + self.password = password; +} + +-(void) setUsername:(NSString*) username password:(NSString*) password basicAuth:(BOOL) bYesOrNo { + + [self setUsername:username password:password]; + NSString *base64EncodedString = [[[NSString stringWithFormat:@"%@:%@", self.username, self.password] dataUsingEncoding:NSUTF8StringEncoding] base64EncodedString]; + + [self setAuthorizationHeaderValue:base64EncodedString forAuthType:@"Basic"]; +} + +-(void) onCompletion:(MKNKResponseBlock) response onError:(MKNKErrorBlock) error { + + [self.responseBlocks addObject:[response copy]]; + [self.errorBlocks addObject:[error copy]]; +} + +-(void) addCompletionHandler:(MKNKResponseBlock)response errorHandler:(MKNKResponseErrorBlock)error { + + if(response) + [self.responseBlocks addObject:[response copy]]; + if(error) + [self.errorBlocksType2 addObject:[error copy]]; +} + +-(void) onNotModified:(MKNKVoidBlock)notModifiedBlock { + + [self.notModifiedHandlers addObject:[notModifiedBlock copy]]; +} + +-(void) onUploadProgressChanged:(MKNKProgressBlock) uploadProgressBlock { + + [self.uploadProgressChangedHandlers addObject:[uploadProgressBlock copy]]; +} + +-(void) onDownloadProgressChanged:(MKNKProgressBlock) downloadProgressBlock { + + [self.downloadProgressChangedHandlers addObject:[downloadProgressBlock copy]]; +} + +-(void) setUploadStream:(NSInputStream*) inputStream { + + self.request.HTTPBodyStream = inputStream; +} + +-(void) addDownloadStream:(NSOutputStream*) outputStream { + + [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; + [self.downloadStreams addObject:outputStream]; +} + +- (id)initWithURLString:(NSString *)aURLString + params:(NSDictionary *)params + httpMethod:(NSString *)method + +{ + if((self = [super init])) { + + self.responseBlocks = [NSMutableArray array]; + self.errorBlocks = [NSMutableArray array]; + self.errorBlocksType2 = [NSMutableArray array]; + self.filesToBePosted = [NSMutableArray array]; + self.dataToBePosted = [NSMutableArray array]; + self.fieldsToBePosted = [NSMutableDictionary dictionary]; + + self.notModifiedHandlers = [NSMutableArray array]; + self.uploadProgressChangedHandlers = [NSMutableArray array]; + self.downloadProgressChangedHandlers = [NSMutableArray array]; + self.downloadStreams = [NSMutableArray array]; + + self.credentialPersistence = NSURLCredentialPersistenceForSession; + + NSURL *finalURL = nil; + + if(params) + self.fieldsToBePosted = [params mutableCopy]; + + self.stringEncoding = NSUTF8StringEncoding; // use a delegate to get these values later + + if(!method) method = @"GET"; + + if ([method isEqualToString:@"GET"]) + self.cacheHeaders = [NSMutableDictionary dictionary]; + + if (([method isEqualToString:@"GET"] || + [method isEqualToString:@"DELETE"]) && (params && [params count] > 0)) { + + finalURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", aURLString, + [self.fieldsToBePosted urlEncodedKeyValueString]]]; + } else { + finalURL = [NSURL URLWithString:aURLString]; + } + + if(finalURL == nil) { + + DLog(@"Cannot create a URL with %@ and parameters %@ and method %@", aURLString, self.fieldsToBePosted, method); + return nil; + } + + self.request = [NSMutableURLRequest requestWithURL:finalURL + cachePolicy:NSURLRequestReloadIgnoringLocalCacheData + timeoutInterval:kMKNetworkKitRequestTimeOutInSeconds]; + + [self.request setHTTPMethod:method]; + + if (([method isEqualToString:@"POST"] || + [method isEqualToString:@"PUT"]) && (params && [params count] > 0)) { + + self.postDataEncoding = MKNKPostDataEncodingTypeURL; + } + + self.state = MKNetworkOperationStateReady; + } + + return self; +} + +-(void) addParams:(NSDictionary*) paramsDictionary { + + [self.fieldsToBePosted addEntriesFromDictionary:paramsDictionary]; +} + +-(void) addHeaders:(NSDictionary*) headersDictionary { + + [headersDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + [self.request addValue:obj forHTTPHeaderField:key]; + }]; +} + +-(void) addHeader:(NSString*)key withValue:(NSString*)value { + + [self.request addValue:value forHTTPHeaderField:key]; +} + +-(void) setHeader:(NSString*)key withValue:(NSString*)value { + + [self.request setValue:value forHTTPHeaderField:key]; +} + +-(void) setAuthorizationHeaderValue:(NSString*) token forAuthType:(NSString*) authType { + + [self.request setValue:[NSString stringWithFormat:@"%@ %@", authType, token] + forHTTPHeaderField:@"Authorization"]; +} +/* + Printing a MKNetworkOperation object is printed in curl syntax + */ + +-(NSString*) description { + + NSMutableString *displayString = [NSMutableString stringWithFormat:@"%@\nRequest\n-------\n%@", + [[NSDate date] descriptionWithLocale:[NSLocale currentLocale]], + [self curlCommandLineString]]; + + NSString *responseString = [self responseString]; + if([responseString length] > 0) { + [displayString appendFormat:@"\n--------\nResponse\n--------\n%@\n", responseString]; + } + + return displayString; +} + +-(NSString*) curlCommandLineString +{ + __block NSMutableString *displayString = [NSMutableString stringWithFormat:@"curl -X %@", self.request.HTTPMethod]; + + if([self.filesToBePosted count] == 0 && [self.dataToBePosted count] == 0) { + [[self.request allHTTPHeaderFields] enumerateKeysAndObjectsUsingBlock:^(id key, id val, BOOL *stop) + { + [displayString appendFormat:@" -H \'%@: %@\'", key, val]; + }]; + } + + [displayString appendFormat:@" \'%@\'", self.url]; + + if ([self.request.HTTPMethod isEqualToString:@"POST"] || + [self.request.HTTPMethod isEqualToString:@"PUT"] || + [self.request.HTTPMethod isEqualToString:@"PATCH"]) { + + NSString *option = [self.filesToBePosted count] == 0 ? @"-d" : @"-F"; + if(self.postDataEncoding == MKNKPostDataEncodingTypeURL) { + [self.fieldsToBePosted enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + + [displayString appendFormat:@" %@ \'%@=%@\'", option, key, obj]; + }]; + } else { + [displayString appendFormat:@" -d \'%@\'", [self encodedPostDataString]]; + } + + + [self.filesToBePosted enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + + NSDictionary *thisFile = (NSDictionary*) obj; + [displayString appendFormat:@" -F \'%@=@%@;type=%@\'", thisFile[@"name"], + thisFile[@"filepath"], thisFile[@"mimetype"]]; + }]; + + /* Not sure how to do this via curl + [self.dataToBePosted enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + + NSDictionary *thisData = (NSDictionary*) obj; + [displayString appendFormat:@" --data-binary \"%@\"", [thisData objectForKey:@"data"]]; + }];*/ + } + + return displayString; +} + + +-(void) addData:(NSData*) data forKey:(NSString*) key { + + [self addData:data forKey:key mimeType:@"application/octet-stream" fileName:@"file"]; +} + +-(void) addData:(NSData*) data forKey:(NSString*) key mimeType:(NSString*) mimeType fileName:(NSString*) fileName { + + if ([self.request.HTTPMethod isEqualToString:@"GET"]) { + [self.request setHTTPMethod:@"POST"]; + } + + NSDictionary *dict = @{@"data": data, + @"name": key, + @"mimetype": mimeType, + @"filename": fileName}; + + [self.dataToBePosted addObject:dict]; +} + +-(void) addFile:(NSString*) filePath forKey:(NSString*) key { + + [self addFile:filePath forKey:key mimeType:@"application/octet-stream"]; +} + +-(void) addFile:(NSString*) filePath forKey:(NSString*) key mimeType:(NSString*) mimeType { + + if ([self.request.HTTPMethod isEqualToString:@"GET"]) { + [self.request setHTTPMethod:@"POST"]; + } + + NSDictionary *dict = @{@"filepath": filePath, + @"name": key, + @"mimetype": mimeType}; + + [self.filesToBePosted addObject:dict]; +} + +-(NSData*) bodyData { + + if([self.filesToBePosted count] == 0 && [self.dataToBePosted count] == 0) { + + return [[self encodedPostDataString] dataUsingEncoding:self.stringEncoding]; + } + + NSString *boundary = @"0xKhTmLbOuNdArY"; + NSMutableData *body = [NSMutableData data]; + __block NSUInteger postLength = 0; + + [self.fieldsToBePosted enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + + NSString *thisFieldString = [NSString stringWithFormat: + @"--%@\r\nContent-Disposition: form-data; name=\"%@\"\r\n\r\n%@", + boundary, key, obj]; + + [body appendData:[thisFieldString dataUsingEncoding:[self stringEncoding]]]; + [body appendData:[@"\r\n" dataUsingEncoding:[self stringEncoding]]]; + }]; + + [self.filesToBePosted enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + + NSDictionary *thisFile = (NSDictionary*) obj; + NSString *thisFieldString = [NSString stringWithFormat: + @"--%@\r\nContent-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\nContent-Type: %@\r\nContent-Transfer-Encoding: binary\r\n\r\n", + boundary, + thisFile[@"name"], + [thisFile[@"filepath"] lastPathComponent], + thisFile[@"mimetype"]]; + + [body appendData:[thisFieldString dataUsingEncoding:[self stringEncoding]]]; + [body appendData: [NSData dataWithContentsOfFile:thisFile[@"filepath"]]]; + [body appendData:[@"\r\n" dataUsingEncoding:[self stringEncoding]]]; + }]; + + [self.dataToBePosted enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + + NSDictionary *thisDataObject = (NSDictionary*) obj; + NSString *thisFieldString = [NSString stringWithFormat: + @"--%@\r\nContent-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\nContent-Type: %@\r\nContent-Transfer-Encoding: binary\r\n\r\n", + boundary, + thisDataObject[@"name"], + thisDataObject[@"filename"], + thisDataObject[@"mimetype"]]; + + [body appendData:[thisFieldString dataUsingEncoding:[self stringEncoding]]]; + [body appendData:thisDataObject[@"data"]]; + [body appendData:[@"\r\n" dataUsingEncoding:[self stringEncoding]]]; + }]; + + if (postLength >= 1) + [self.request setValue:[NSString stringWithFormat:@"%lu", (unsigned long) postLength] forHTTPHeaderField:@"Content-Length"]; + + [body appendData: [[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:self.stringEncoding]]; + + NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); + + if(([self.filesToBePosted count] > 0) || ([self.dataToBePosted count] > 0)) { + [self.request setValue:[NSString stringWithFormat:@"multipart/form-data; charset=%@; boundary=%@", charset, boundary] + forHTTPHeaderField:@"Content-Type"]; + + [self.request setValue:[NSString stringWithFormat:@"%lu", (unsigned long) [body length]] forHTTPHeaderField:@"Content-Length"]; + } + + return body; +} + + +-(void) setCacheHandler:(MKNKResponseBlock) cacheHandler { + + self.cacheHandlingBlock = cacheHandler; +} + +#pragma mark - +#pragma Main method +-(void) main { + + @autoreleasepool { + [self start]; + } +} + +-(void) endBackgroundTask { + +#if TARGET_OS_IPHONE + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.backgroundTaskId != UIBackgroundTaskInvalid) { + [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId]; + self.backgroundTaskId = UIBackgroundTaskInvalid; + } + }); +#endif +} + +- (void) start +{ + +#if TARGET_OS_IPHONE + self.backgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.backgroundTaskId != UIBackgroundTaskInvalid) + { + [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId]; + self.backgroundTaskId = UIBackgroundTaskInvalid; + [self cancel]; + } + }); + }]; + +#endif + + if(!self.isCancelled) { + + if (([self.request.HTTPMethod isEqualToString:@"POST"] || + [self.request.HTTPMethod isEqualToString:@"PUT"] || + [self.request.HTTPMethod isEqualToString:@"PATCH"]) && !self.request.HTTPBodyStream) { + + [self.request setHTTPBody:[self bodyData]]; + } + + dispatch_async(dispatch_get_main_queue(), ^{ + self.connection = [[NSURLConnection alloc] initWithRequest:self.request + delegate:self + startImmediately:NO]; + + [self.connection scheduleInRunLoop:[NSRunLoop currentRunLoop] + forMode:NSRunLoopCommonModes]; + + [self.connection start]; + }); + + self.state = MKNetworkOperationStateExecuting; + } + else { + self.state = MKNetworkOperationStateFinished; + [self endBackgroundTask]; + } +} + +#pragma - +#pragma mark NSOperation stuff + +- (BOOL)isConcurrent +{ + return YES; +} + +- (BOOL)isReady { + + return (self.state == MKNetworkOperationStateReady && [super isReady]); +} + +- (BOOL)isFinished +{ + return (self.state == MKNetworkOperationStateFinished); +} + +- (BOOL)isExecuting { + + return (self.state == MKNetworkOperationStateExecuting); +} + +-(void) cancel { + + if([self isFinished]) + return; + + @synchronized(self) { + self.isCancelled = YES; + + [self.connection cancel]; + + [self.responseBlocks removeAllObjects]; + self.responseBlocks = nil; + + [self.errorBlocks removeAllObjects]; + self.errorBlocks = nil; + + [self.errorBlocksType2 removeAllObjects]; + self.errorBlocksType2 = nil; + + [self.notModifiedHandlers removeAllObjects]; + self.notModifiedHandlers = nil; + + [self.uploadProgressChangedHandlers removeAllObjects]; + self.uploadProgressChangedHandlers = nil; + + [self.downloadProgressChangedHandlers removeAllObjects]; + self.downloadProgressChangedHandlers = nil; + + for(NSOutputStream *stream in self.downloadStreams) + [stream close]; + + [self.downloadStreams removeAllObjects]; + self.downloadStreams = nil; + + self.authHandler = nil; + self.mutableData = nil; + self.downloadedDataSize = 0; + + self.cacheHandlingBlock = nil; + + if(self.state == MKNetworkOperationStateExecuting) + self.state = MKNetworkOperationStateFinished; // This notifies the queue and removes the operation. + // if the operation is not removed, the spinner continues to spin, not a good UX + + [self endBackgroundTask]; + } + [super cancel]; +} + +#pragma mark - +#pragma mark NSURLConnection delegates + +- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { + + self.state = MKNetworkOperationStateFinished; + self.mutableData = nil; + self.downloadedDataSize = 0; + for(NSOutputStream *stream in self.downloadStreams) + [stream close]; + + [self operationFailedWithError:error]; + [self endBackgroundTask]; +} + +// https://developer.apple.com/library/mac/#documentation/security/conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html +OSStatus extractIdentityAndTrust(CFDataRef inPKCS12Data, // 5 + SecIdentityRef *outIdentity, + SecTrustRef *outTrust, + CFStringRef keyPassword) +{ + OSStatus securityError = errSecSuccess; + + + const void *keys[] = { kSecImportExportPassphrase }; + const void *values[] = { keyPassword }; + CFDictionaryRef optionsDictionary = NULL; + + /* Create a dictionary containing the passphrase if one + was specified. Otherwise, create an empty dictionary. */ + optionsDictionary = CFDictionaryCreate( + NULL, keys, + values, (keyPassword ? 1 : 0), + NULL, NULL); // 6 + + CFArrayRef items = NULL; + securityError = SecPKCS12Import(inPKCS12Data, + optionsDictionary, + &items); // 7 + + + // + if (securityError == 0) { // 8 + CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0); + const void *tempIdentity = NULL; + tempIdentity = CFDictionaryGetValue (myIdentityAndTrust, + kSecImportItemIdentity); + CFRetain(tempIdentity); + *outIdentity = (SecIdentityRef)tempIdentity; + const void *tempTrust = NULL; + tempTrust = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemTrust); + + CFRetain(tempTrust); + *outTrust = (SecTrustRef)tempTrust; + } + + if (optionsDictionary) + CFRelease(optionsDictionary); // 9 + + if (items) + CFRelease(items); + + return securityError; +} + +- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { + + if (challenge.previousFailureCount == 0) { + + if (((challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodDefault) || + (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPBasic) || + (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPDigest) || + (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodNTLM)) && + (self.username && self.password)) + { + + // for NTLM, we will assume user name to be of the form "domain\\username" + NSURLCredential *credential = [NSURLCredential credentialWithUser:self.username + password:self.password + persistence:self.credentialPersistence]; + + [challenge.sender useCredential:credential forAuthenticationChallenge:challenge]; + } + else if ((challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate) && self.clientCertificate) { + + NSError *error = nil; + NSData *certData = [[NSData alloc] initWithContentsOfFile:self.clientCertificate options:0 error:&error]; + + SecIdentityRef identity; + SecTrustRef trust; + OSStatus status = extractIdentityAndTrust((__bridge CFDataRef) certData, &identity, &trust, (__bridge CFStringRef) self.clientCertificatePassword); + if(status == errSecSuccess) { + SecCertificateRef certificate; + SecIdentityCopyCertificate(identity, &certificate); + const void *certs[] = { certificate }; + CFArrayRef certsArray = CFArrayCreate(NULL, certs, 1, NULL); + NSArray *certificatesForCredential = (__bridge NSArray *)certsArray; + NSURLCredential *credential = [NSURLCredential credentialWithIdentity:identity + certificates:certificatesForCredential + persistence:NSURLCredentialPersistencePermanent]; + [challenge.sender useCredential:credential forAuthenticationChallenge:challenge]; + CFRelease(identity); + CFRelease(certificate); + CFRelease(certsArray); + } else { + [challenge.sender cancelAuthenticationChallenge:challenge]; + } + } + else if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) { + + if(challenge.previousFailureCount < 5) { + + self.serverTrust = challenge.protectionSpace.serverTrust; + SecTrustResultType result; + SecTrustEvaluate(self.serverTrust, &result); + + if(result == kSecTrustResultProceed || + result == kSecTrustResultUnspecified //The cert is valid, but user has not explicitly accepted/denied. Ok to proceed (Ch 15: iOS PTL :Pg 269) + ) { + + [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; + } else { + + // invalid or revoked certificate + if(self.shouldContinueWithInvalidCertificate) { + DLog(@"Certificate is invalid, but self.shouldContinueWithInvalidCertificate is YES"); + [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; + } else { + DLog(@"Certificate is invalid, continuing without credentials. Might result in 401 Unauthorized"); + [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; + } + } + } else { + + [challenge.sender cancelAuthenticationChallenge:challenge]; + } + } + else if (self.authHandler) { + + // forward the authentication to the view controller that created this operation + // If this happens for NSURLAuthenticationMethodHTMLForm, you have to + // do some shit work like showing a modal webview controller and close it after authentication. + // I HATE THIS. + self.authHandler(challenge); + } + else { + [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; + } + } else { + // apple proposes to cancel authentication, which results in NSURLErrorDomain error -1012, but we prefer to trigger a 401 + // [[challenge sender] cancelAuthenticationChallenge:challenge]; + [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; + } +} + +- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { + + NSUInteger size = [self.response expectedContentLength] < 0 ? 0 : (NSUInteger)[self.response expectedContentLength]; + self.response = (NSHTTPURLResponse*) response; + + // dont' save data if the operation was created to download directly to a stream. + if([self.downloadStreams count] == 0) + self.mutableData = [NSMutableData dataWithCapacity:size]; + else + self.mutableData = nil; + + for(NSOutputStream *stream in self.downloadStreams) + [stream open]; + + NSDictionary *httpHeaders = [self.response allHeaderFields]; + + // if you attach a stream to the operation, MKNetworkKit will not cache the response. + // Streams are usually "big data chunks" that doesn't need caching anyways. + + if([self.request.HTTPMethod isEqualToString:@"GET"] && [self.downloadStreams count] == 0) { + + // We have all this complicated cache handling since NSURLRequestReloadRevalidatingCacheData is not implemented + // do cache processing only if the request is a "GET" method + NSString *lastModified = httpHeaders[@"Last-Modified"]; + NSString *eTag = httpHeaders[@"ETag"]; + NSString *expiresOn = httpHeaders[@"Expires"]; + + NSString *contentType = httpHeaders[@"Content-Type"]; + // if contentType is image, + + NSDate *expiresOnDate = nil; + + if([contentType rangeOfString:@"image"].location != NSNotFound) { + + // For images let's assume a expiry date of 7 days if there is no eTag or Last Modified. + if(!eTag && !lastModified) + expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultImageCacheDuration]; + else + expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultImageHeadRequestDuration]; + } + + NSString *cacheControl = httpHeaders[@"Cache-Control"]; // max-age, must-revalidate, no-cache + NSArray *cacheControlEntities = [cacheControl componentsSeparatedByString:@","]; + + for(NSString *substring in cacheControlEntities) { + + if([substring rangeOfString:@"max-age"].location != NSNotFound) { + + // do some processing to calculate expiresOn + NSString *maxAge = nil; + NSArray *array = [substring componentsSeparatedByString:@"="]; + if([array count] > 1) + maxAge = array[1]; + + expiresOnDate = [[NSDate date] dateByAddingTimeInterval:[maxAge intValue]]; + } + if([substring rangeOfString:@"no-cache"].location != NSNotFound) { + + // Don't cache this request + expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultCacheDuration]; + } + } + + // if there was a cacheControl entity, we would have a expiresOnDate that is not nil. + // "Cache-Control" headers take precedence over "Expires" headers + + if(expiresOnDate) + expiresOn = [expiresOnDate rfc1123String]; + + // now remember lastModified, eTag and expires for this request in cache + if(expiresOn) + (self.cacheHeaders)[@"Expires"] = expiresOn; + if(lastModified) + (self.cacheHeaders)[@"Last-Modified"] = lastModified; + if(eTag) + (self.cacheHeaders)[@"ETag"] = eTag; + } +} + +- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { + + if (self.downloadedDataSize == 0) { + // This is the first batch of data + // Check for a range header and make changes as neccesary + NSString *rangeString = [[self request] valueForHTTPHeaderField:@"Range"]; + if ([rangeString hasPrefix:@"bytes="] && [rangeString hasSuffix:@"-"]) { + NSString *bytesText = [rangeString substringWithRange:NSMakeRange(6, [rangeString length] - 7)]; + self.startPosition = [bytesText integerValue]; + self.downloadedDataSize = self.startPosition; + DLog(@"Resuming at %lu bytes", (unsigned long) self.startPosition); + } + } + + if([self.downloadStreams count] == 0) + [self.mutableData appendData:data]; + + for(NSOutputStream *stream in self.downloadStreams) { + + if ([stream hasSpaceAvailable]) { + const uint8_t *dataBuffer = [data bytes]; + [stream write:&dataBuffer[0] maxLength:[data length]]; + } + } + + self.downloadedDataSize += [data length]; + + for(MKNKProgressBlock downloadProgressBlock in self.downloadProgressChangedHandlers) { + + if([self.response expectedContentLength] > 0) { + + double progress = (double)(self.downloadedDataSize) / (double)(self.startPosition + [self.response expectedContentLength]); + downloadProgressBlock(progress); + } + } +} + +- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten + totalBytesWritten:(NSInteger)totalBytesWritten +totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite { + + for(MKNKProgressBlock uploadProgressBlock in self.uploadProgressChangedHandlers) { + + if(totalBytesExpectedToWrite > 0) { + uploadProgressBlock(((double)totalBytesWritten/(double)totalBytesExpectedToWrite)); + } + } +} + +// http://stackoverflow.com/questions/1446509/handling-redirects-correctly-with-nsurlconnection +- (NSURLRequest *)connection: (NSURLConnection *)inConnection + willSendRequest: (NSURLRequest *)inRequest + redirectResponse: (NSURLResponse *)inRedirectResponse; +{ + NSMutableURLRequest *r = [self.request mutableCopy]; + if (inRedirectResponse) { + [r setURL: [inRequest URL]]; + } else { + // Note that we need to configure the Accept-Language header this late in processing + // because NSURLRequest adds a default Accept-Language header late in the day, so we + // have to undo that here. + // For discussion see: + // http://lists.apple.com/archives/macnetworkprog/2009/Sep/msg00022.html + // http://stackoverflow.com/questions/5695914/nsurlrequest-where-an-app-can-find-the-default-headers-for-http-request + NSString* accept_language = self.shouldSendAcceptLanguageHeader ? [self languagesFromLocale] : nil; + [r setValue:accept_language forHTTPHeaderField:@"Accept-Language"]; + } + return r; +} + +- (NSString*)languagesFromLocale { + return [NSString stringWithFormat:@"%@, en-us", [[NSLocale preferredLanguages] componentsJoinedByString:@", "]]; +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)connection { + + if([self isCancelled]) + return; + + self.state = MKNetworkOperationStateFinished; + + for(NSOutputStream *stream in self.downloadStreams) + [stream close]; + + if (self.response.statusCode >= 200 && self.response.statusCode < 300 && ![self isCancelled]) { + + self.cachedResponse = nil; // remove cached data + + [self notifyCache]; + [self operationSucceeded]; + + } + if (self.response.statusCode >= 300 && self.response.statusCode < 400) { + + if(self.response.statusCode == 301) { + DLog(@"%@ has moved to %@", self.url, [self.response.URL absoluteString]); + } + else if(self.response.statusCode == 304) { + + for(MKNKVoidBlock notModifiedBlock in self.notModifiedHandlers) { + + notModifiedBlock(); + } + } + else if(self.response.statusCode == 307) { + DLog(@"%@ temporarily redirected", self.url); + } + else { + DLog(@"%@ returned status %d", self.url, (int) self.response.statusCode); + } + + } else if (self.response.statusCode >= 400 && self.response.statusCode < 600 && ![self isCancelled]) { + + [self operationFailedWithError:[NSError errorWithDomain:NSURLErrorDomain + code:self.response.statusCode + userInfo:self.response.allHeaderFields]]; + } + [self endBackgroundTask]; + +} + +#pragma mark - +#pragma mark Our methods to get data + +-(NSData*) responseData { + + if([self isFinished]) + return self.mutableData; + else if(self.cachedResponse) + return self.cachedResponse; + else + return nil; +} + +-(NSString*)responseString { + + return [self responseStringWithEncoding:self.stringEncoding]; +} + +-(NSString*) responseStringWithEncoding:(NSStringEncoding) encoding { + + return [[NSString alloc] initWithData:[self responseData] encoding:encoding]; +} + +#if TARGET_OS_IPHONE +-(UIImage*) responseImage { + + return [UIImage imageWithData:[self responseData]]; +} + +-(void) decompressedResponseImageOfSize:(CGSize) size completionHandler:(void (^)(UIImage *decompressedImage)) imageDecompressionHandler { + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + + CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)([self responseData]), NULL); + CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, (__bridge CFDictionaryRef)(@{(id)kCGImageSourceShouldCache:@(YES)})); + UIImage *decompressedImage = [UIImage imageWithCGImage:cgImage]; + if(source) + CFRelease(source); + if(cgImage) + CGImageRelease(cgImage); + + dispatch_async(dispatch_get_main_queue(), ^{ + imageDecompressionHandler(decompressedImage); + }); + }); +} + +#elif TARGET_OS_MAC +-(NSImage*) responseImage { + + return [[NSImage alloc] initWithData:[self responseData]]; +} + +-(NSXMLDocument*) responseXML { + + return [[NSXMLDocument alloc] initWithData:[self responseData] options:0 error:nil]; +} +#endif + +-(id) responseJSON { + + if([self responseData] == nil) return nil; + NSError *error = nil; + id returnValue = [NSJSONSerialization JSONObjectWithData:[self responseData] options:0 error:&error]; + if(error) DLog(@"JSON Parsing Error: %@", error); + return returnValue; +} + +-(void) responseJSONWithCompletionHandler:(void (^)(id jsonObject)) jsonDecompressionHandler { + + [self responseJSONWithOptions:0 completionHandler:jsonDecompressionHandler]; +} + +-(void) responseJSONWithOptions:(NSJSONReadingOptions) options completionHandler:(void (^)(id jsonObject)) jsonDecompressionHandler { + + if([self responseData] == nil) { + + jsonDecompressionHandler(nil); + return; + } + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ + + NSError *error = nil; + id returnValue = [NSJSONSerialization JSONObjectWithData:[self responseData] options:options error:&error]; + if(error) { + + DLog(@"JSON Parsing Error: %@", error); + jsonDecompressionHandler(nil); + return; + } + + dispatch_async(dispatch_get_main_queue(), ^{ + + jsonDecompressionHandler(returnValue); + }); + }); +} + +#pragma mark - +#pragma mark Overridable methods + +-(void) operationSucceeded { + + for(MKNKResponseBlock responseBlock in self.responseBlocks) + responseBlock(self); +} + +-(void) showLocalNotification { +#if TARGET_OS_IPHONE + + if(self.localNotification) { + + [[UIApplication sharedApplication] presentLocalNotificationNow:self.localNotification]; + } else if(self.shouldShowLocalNotificationOnError) { + + UILocalNotification *localNotification = [[UILocalNotification alloc] init]; + + localNotification.alertBody = [self.error localizedDescription]; + localNotification.alertAction = NSLocalizedString(@"Dismiss", @""); + + [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification]; + } +#endif +} + +-(void) operationFailedWithError:(NSError*) error { + + self.error = error; + DLog(@"%@, [%@]", self, [self.error localizedDescription]); + for(MKNKErrorBlock errorBlock in self.errorBlocks) + errorBlock(error); + + for(MKNKResponseErrorBlock errorBlock in self.errorBlocksType2) + errorBlock(self, error); + +#if TARGET_OS_IPHONE + if([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) + [self showLocalNotification]; +#endif + +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.h new file mode 100644 index 0000000..c6570d8 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.h @@ -0,0 +1,21 @@ +// +// CLLocation+Testing.h +// UXRX +// +// Created by Rex St John on 2/8/13. +// Copyright (c) 2013 UXRX. All rights reserved. +// + +#import + +@interface CLLocation (Testing) + ++(CLLocation*)locationInSeattle; ++(CLLocation*)locationInNewYork; ++(CLLocation*)locationInSanFransisco; ++(CLLocation*)locationInBoston; ++(CLLocation*)locationInMiami; ++(CLLocation*)locationInLondon; ++(CLLocation*)randomMajorCity; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.m new file mode 100644 index 0000000..8f2f2c3 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.m @@ -0,0 +1,63 @@ +// +// CLLocation+Testing.m +// UXRX +// +// Created by Rex St John on 2/8/13. +// Copyright (c) 2013 UXRX. All rights reserved. +// + +#import "CLLocation+Testing.h" + +@implementation CLLocation (Testing) + ++(CLLocation*)locationInSeattle{ + CLLocationDegrees lat = 47.6097; + CLLocationDegrees lon = -122.3331; + CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; + return someLocation; +} + ++(CLLocation*)locationInNewYork{ + CLLocationDegrees lat = 40.7142; + CLLocationDegrees lon = -74.0064; + CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; + return someLocation; +} + ++(CLLocation*)locationInSanFransisco{ + CLLocationDegrees lat = 37.7750; + CLLocationDegrees lon = -122.4183; + CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; + return someLocation; +} + ++(CLLocation*)locationInBoston{ + CLLocationDegrees lat = 42.3583; + CLLocationDegrees lon = -71.0603; + CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; + return someLocation; +} + ++(CLLocation*)locationInMiami{ + CLLocationDegrees lat = 25.4716; + CLLocationDegrees lon = -80.1327; + CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; + return someLocation; +} + ++(CLLocation*)locationInLondon{ + CLLocationDegrees lat = 51.5171; + CLLocationDegrees lon = -0.1062; + CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; + return someLocation; +} + ++(CLLocation*)randomMajorCity{ + //RSJ: Not yet implemented. + CLLocationDegrees lat = 47.6097; + CLLocationDegrees lon = -122.3331; + CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; + return someLocation; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.h new file mode 100644 index 0000000..8c3a4a6 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.h @@ -0,0 +1,13 @@ +// +// CLLocation+isEmpty.h +// UXRX +// +// Created by JASON CROSS on 3/21/13. +// Copyright (c) 2013 UXRX. All rights reserved. +// + +#import + +@interface CLLocation (isEmpty) ++ (BOOL) isEmpty:(CLLocation*)thing; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.m new file mode 100644 index 0000000..220005e --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.m @@ -0,0 +1,17 @@ +// +// CLLocation+isEmpty.m +// UXRX +// +// Created by JASON CROSS on 3/21/13. +// Copyright (c) 2013 UXRX. All rights reserved. +// + +#import "CLLocation+isEmpty.h" + +@implementation CLLocation (isEmpty) + ++ (BOOL) isEmpty:(CLLocation*)thing; { + return (nil == thing) || (thing.coordinate.latitude == 0) || (thing.coordinate.longitude == 0); +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.h new file mode 100644 index 0000000..3d6587e --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.h @@ -0,0 +1,15 @@ +// +// NSDictionary+PList.h +// UXRX +// +// Created by Rex St John on 6/7/13. +// Copyright (c) 2013 UXRX. All rights reserved. +// + +#import + +@interface NSDictionary (PList) + ++(NSDictionary*)dictionaryFromPlistWithName:(NSString*)plistName; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.m new file mode 100644 index 0000000..62b8559 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.m @@ -0,0 +1,21 @@ +// +// NSDictionary+PList.m +// UXRX +// +// Created by Rex St John on 6/7/13. +// Copyright (c) 2013 UXRX. All rights reserved. +// + +#import "NSDictionary+PList.h" + +@implementation NSDictionary (PList) + ++(NSDictionary*)dictionaryFromPlistWithName:(NSString*)plistName{ + // Path to the plist (in the application bundle) + NSString *path = [[NSBundle mainBundle] pathForResource: + plistName ofType:@"plist"]; + + return [[NSDictionary alloc] initWithContentsOfFile:path]; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.h new file mode 100644 index 0000000..6020b6f --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.h @@ -0,0 +1,24 @@ +// +// NSString+Location.h +// UXRX +// +// Category methods for producing stringified location data. +// +// Created by Rex St John on 10/18/12. +// Copyright (c) 2012 UXRX. All rights reserved. +// + +#import + +@class CLLocation; + +@interface NSString (Location) + +// Produces a string from a location e.g. latitude and longitude in string format. ++ (NSString *)stringFromLocation:(CLLocation *)location; + ++ (NSString *) milesToString:(float) miles inCountry:(NSString *)country; + ++ (CLLocation *)locationFromString:(NSString *)locString; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.m new file mode 100644 index 0000000..ef0880c --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.m @@ -0,0 +1,48 @@ +// +// NSString+Location.m +// UXRX +// +// Created by Rex St John on 10/18/12. +// Copyright (c) 2012 UXRX. All rights reserved. +// + +#import "NSString+Location.h" +#import +#import "NSString+Utils.h" + +@implementation NSString (Location) + ++ (NSString *)stringFromLocation:(CLLocation *)location { + return [NSString stringWithFormat:@"%.6f,%.6f", location.coordinate.latitude, location.coordinate.longitude]; +} + ++ (NSString *) milesToString:(float) miles inCountry:(NSString *)country { + BOOL mi = [country isEqual:@"UK"] || [country isEqual:@"US"]; + if (mi) { + return [NSString stringWithFormat:@"%.2fmi", miles]; + } + else { + return [NSString stringWithFormat:@"%.2fkm", miles * 1.609344]; + } +} + ++ (CLLocation *)locationFromString:(NSString *)locString { + if (!locString) { + return nil; + } + + int comma = [NSString indexOf:locString andSubString: @","]; + if (comma == -1) { + return nil; + } + CLLocation *location = [[CLLocation alloc] initWithLatitude:[[locString substringToIndex:comma] doubleValue] + longitude:[[locString substringFromIndex:comma + 1] doubleValue]]; + return location; +} + +NSString *stringFromLocation(CLLocation *location) { + return [NSString stringWithFormat:@"%.6f,%.6f", location.coordinate.latitude, location.coordinate.longitude]; +} + + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.h new file mode 100644 index 0000000..cfca90c --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.h @@ -0,0 +1,19 @@ +// +// NSString+Utils.h +// UXRX +// +// Created by Rex St John on 1/10/13. +// Copyright (c) 2013 UXRX. All rights reserved. +// + +#import + +@interface NSString (Utils) + ++(NSString *)join:(NSArray *)strings andSeperator:( NSString *)separator; ++(NSArray *)split:(NSString *)s andSeperator:(NSString *)separator; ++(int) indexOf:(NSString *)haystack andSubString:(NSString *)needle; ++(BOOL) contains:(NSString *)haystack andSubString:(NSString *)needle; ++(BOOL) startsWith:(NSString *)haystack andSubString:( NSString *)needle; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.m new file mode 100644 index 0000000..42e4241 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.m @@ -0,0 +1,49 @@ +// +// NSString+Utils.m +// UXRX +// +// Created by Rex St John on 1/10/13. +// Copyright (c) 2013 UXRX. All rights reserved. +// + +#import "NSString+Utils.h" + +@implementation NSString (Utils) + ++(NSString *)join:(NSArray *)strings andSeperator:( NSString *)separator { + if (strings.count == 0) { + return @""; + } + + NSString *result = nil; + for (NSString *i in strings) { + if (result == nil) { + result = i; + } + else { + result = [result stringByAppendingFormat:@"%@%@", separator, i]; + } + } + return result; +} + ++(NSArray *)split:(NSString *)s andSeperator:(NSString *)separator{ + if (s.length == 0) { + return [NSMutableArray arrayWithCapacity:0]; + } + return [s componentsSeparatedByString:separator]; +} + ++(int) indexOf:(NSString *)haystack andSubString:(NSString *)needle{ + NSUInteger location = [haystack rangeOfString:needle].location; + return (location != NSNotFound) ? location : -1; +} + ++(BOOL) contains:(NSString *)haystack andSubString:(NSString *)needle { + return [NSString indexOf:haystack andSubString: needle] != -1; +} + ++(BOOL) startsWith:(NSString *)haystack andSubString:( NSString *)needle{ + return [NSString indexOf:haystack andSubString: needle] == 0; +} +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.h new file mode 100644 index 0000000..09d6283 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.h @@ -0,0 +1,13 @@ +// +// UXRBaseModel.h +// FourSquareKit +// +// Created by Rex St. John on 12/19/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRJSONDeserializableObject.h" + +@interface UXRBaseModel : UXRJSONDeserializableObject + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.m new file mode 100644 index 0000000..8ce98b0 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.m @@ -0,0 +1,17 @@ +// +// UXRBaseModel.m +// FourSquareKit +// +// Created by Rex St. John on 12/19/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@implementation UXRBaseModel + + +-(void)setId:(id)someId{ + // prevent trying to set our Id again +} +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.h new file mode 100644 index 0000000..906f0c3 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.h @@ -0,0 +1,21 @@ +// +// UXRExploreQueryBaseModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/26/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" +#import "UXRFourSquareGeoCodeModel.h" + +@interface UXRExploreQueryBaseModel : UXRBaseModel +@property(nonatomic,strong) UXRFourSquareGeoCodeModel *geocode; +@property(nonatomic,strong) NSString *headerLocation; +@property(nonatomic,strong) NSString *headerFullLocation; +@property(nonatomic,strong) NSString *headerLocationGranularity; +@property(nonatomic,strong) NSString *query; +@property(nonatomic,strong) NSNumber *totalResults; +@property(nonatomic,strong) NSArray *groups; +@property(nonatomic,strong) NSArray *venues; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.m new file mode 100644 index 0000000..87bd646 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.m @@ -0,0 +1,52 @@ +// +// UXRExploreQueryBaseModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/26/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRExploreQueryBaseModel.h" +#import "UXRFourSquareExploreResultsModel.h" + +@implementation UXRExploreQueryBaseModel + +- (void) setGeocode:(id)geocode{ + if (nil == geocode) { + _geocode = nil; + } + else if ([geocode isKindOfClass:[UXRFourSquareGeoCodeModel class]]) { + _geocode = geocode; + } + else if ([geocode isKindOfClass:[NSDictionary class]]) { + _geocode = [[UXRFourSquareGeoCodeModel alloc] initWithDictionary:geocode]; + } +} + +-(void)setGroups:(id)groups{ + if (nil == groups) { + _groups = nil; + } + else if ([groups isKindOfClass:[NSArray class]]) { + + NSMutableArray *resultsArray = [[NSMutableArray alloc] init]; + NSMutableArray *venuesArray =[[NSMutableArray alloc] init]; + + for(id group in groups){ + + NSArray *items = (NSArray*)[group objectForKey:@"items"]; + + for(id entry in items){ + if([entry isKindOfClass:[NSDictionary class]]){ + UXRFourSquareExploreResultsModel *result = [[UXRFourSquareExploreResultsModel alloc] initWithDictionary:entry]; + [resultsArray addObject:result]; + [venuesArray addObject:result.venue]; + } + } + } + _venues = venuesArray; + _groups = (NSArray*)resultsArray; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.h new file mode 100644 index 0000000..2496782 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.h @@ -0,0 +1,13 @@ +// +// UXRFourSquareAttributesModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/28/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareAttributesModel : UXRBaseModel + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.m new file mode 100644 index 0000000..3f185b5 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.m @@ -0,0 +1,65 @@ +// +// UXRFourSquareAttributesModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/28/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +/* + attributes = { + groups = ( + { + count = 1; + items = ( + { + displayName = Price; + displayValue = "$$ (from category)"; + priceTier = 2; + } + ); + name = Price; + summary = "$$"; + type = price; + }, + { + count = 6; + items = ( + { + displayName = "Credit Cards"; + displayValue = Yes; + } + ); + name = "Credit Cards"; + summary = "Credit Cards"; + type = payments; + }, + { + count = 8; + items = ( + { + displayName = Breakfast; + displayValue = Breakfast; + }, + { + displayName = Brunch; + displayValue = Brunch; + }, + { + displayName = Dinner; + displayValue = Dinner; + } + ); + name = Menus; + summary = "Dinner, Brunch & more"; + type = serves; + } + ); + }; + */ + +#import "UXRFourSquareAttributesModel.h" + +@implementation UXRFourSquareAttributesModel + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.h new file mode 100644 index 0000000..b63a86b --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.h @@ -0,0 +1,20 @@ +// +// UXRFourSquareCategoryModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" +#import "UXRFourSquarePhotoModel.h" + +@interface UXRFourSquareCategoryModel : UXRBaseModel + +@property(nonatomic,strong) NSString *name; +@property(nonatomic,strong) UXRFourSquarePhotoModel *icon; +@property(nonatomic,strong) NSString *pluralName; +@property(nonatomic,strong) NSNumber *primary; +@property(nonatomic,strong) NSString *shortName; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.m new file mode 100644 index 0000000..870a614 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.m @@ -0,0 +1,25 @@ +// +// UXRFourSquareCategoryModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareCategoryModel.h" + +@implementation UXRFourSquareCategoryModel + +- (void) setIcon:(id)icon{ + if (nil == icon) { + _icon = nil; + } + else if ([icon isKindOfClass:[UXRFourSquarePhotoModel class]]) { + _icon = icon; + } + else if ([icon isKindOfClass:[NSDictionary class]]) { + _icon = [[UXRFourSquarePhotoModel alloc ] initWithDictionary:icon]; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.h new file mode 100644 index 0000000..feb8e65 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.h @@ -0,0 +1,15 @@ +// +// UXRFourSquareContactModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareContactModel : UXRBaseModel +@property(nonatomic,strong) NSString *phone; +@property(nonatomic,strong) NSString *formattedPhone; +@property(nonatomic,strong) NSString *twitter; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.m new file mode 100644 index 0000000..5165149 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.m @@ -0,0 +1,13 @@ +// +// UXRFourSquareContactModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareContactModel.h" + +@implementation UXRFourSquareContactModel + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.h new file mode 100644 index 0000000..d10bf73 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.h @@ -0,0 +1,17 @@ +// +// UXRFourSquareReasonsModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/26/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" +#import "UXRFourSquareRestaurantModel.h" + +@interface UXRFourSquareExploreResultsModel : UXRBaseModel +@property(nonatomic,strong) NSArray *tips; +@property(nonatomic,strong) NSArray *reasons; +@property(nonatomic,strong) NSString *referralId; +@property(nonatomic,strong) UXRFourSquareRestaurantModel *venue; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.m new file mode 100644 index 0000000..f28cf96 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.m @@ -0,0 +1,42 @@ +// +// UXRFourSquareReasonsModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/26/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareExploreResultsModel.h" +#import "UXRFourSquareTipModel.h" +#import "UXRFourSquareRestaurantModel.h" + +@implementation UXRFourSquareExploreResultsModel + +- (void) setTips:(id)tips { + if (nil == tips) { + _tips = nil; + } else if ([tips isKindOfClass:[NSArray class]]){ + NSMutableArray *resultsMutableArray = [[NSMutableArray alloc] initWithCapacity:((NSArray*)tips).count]; + for(id entry in tips){ + if([entry isKindOfClass:[NSDictionary class]]){ + UXRFourSquareTipModel *tip = [[UXRFourSquareTipModel alloc] initWithDictionary:entry]; + [resultsMutableArray addObject:tip]; + } + } + _tips = (NSArray*)resultsMutableArray; + } +} + +- (void) setVenue:(id)venue{ + if (nil == venue) { + _venue = nil; + } + else if ([venue isKindOfClass:[UXRFourSquareContactModel class]]) { + _venue = venue; + } + else if ([venue isKindOfClass:[NSDictionary class]]) { + _venue = [[UXRFourSquareRestaurantModel alloc ] initWithDictionary:venue]; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.h new file mode 100644 index 0000000..59881b7 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.h @@ -0,0 +1,18 @@ +// +// UXRGeoCodeModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/26/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareGeoCodeModel : UXRBaseModel +@property(nonatomic,strong) NSNumber *longId; +@property(nonatomic,strong) NSString *displayString; +@property(nonatomic,strong) NSString *slug; +@property(nonatomic,strong) NSString *cc; +@property(nonatomic,strong) NSString *what; +@property(nonatomic,strong) NSString *where; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.m new file mode 100644 index 0000000..722e4c0 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.m @@ -0,0 +1,13 @@ +// +// UXRGeoCodeModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/26/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareGeoCodeModel.h" + +@implementation UXRFourSquareGeoCodeModel + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.h new file mode 100644 index 0000000..78e0f3d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.h @@ -0,0 +1,15 @@ +// +// UXRFourSquareHoursModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareHoursModel : UXRBaseModel +@property(nonatomic,assign) BOOL isOpen; +@property(nonatomic,strong) NSString *status; +@property(nonatomic,strong) NSArray *timeframes; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.m new file mode 100644 index 0000000..7999120 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.m @@ -0,0 +1,31 @@ +// +// UXRFourSquareHoursModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareHoursModel.h" +#import "UXRFourSquareTimeFramesModel.h" + +@implementation UXRFourSquareHoursModel + +- (void) setTimeframes:(id)timeframes { + if (nil == timeframes) { + _timeframes = nil; + } + else if ([timeframes isKindOfClass:[NSArray class]]) { + NSArray *categoriesArray = (NSArray*)timeframes; + NSMutableArray *mutableCategories = [[NSMutableArray alloc] initWithCapacity:categoriesArray.count]; + for(id entry in categoriesArray){ + if([entry isKindOfClass:[NSDictionary class]]){ + UXRFourSquareTimeFramesModel *category = [[UXRFourSquareTimeFramesModel alloc] initWithDictionary:entry]; + [mutableCategories addObject:category]; + } + } + _timeframes = (NSArray*)mutableCategories; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.h new file mode 100644 index 0000000..1d43cbe --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.h @@ -0,0 +1,15 @@ +// +// UXRFourSquareLikesModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareLikesModel : UXRBaseModel +@property(nonatomic,strong) NSNumber *count; +@property(nonatomic,strong) NSString *summary; +@property(nonatomic,strong) NSArray *groups; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.m new file mode 100644 index 0000000..43024fc --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.m @@ -0,0 +1,13 @@ +// +// UXRFourSquareLikesModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareLikesModel.h" + +@implementation UXRFourSquareLikesModel + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.h new file mode 100644 index 0000000..d89624f --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.h @@ -0,0 +1,21 @@ +// +// UXRFourSquareLocationModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareLocationModel : UXRBaseModel +@property(nonatomic,strong) NSString *address; +@property(nonatomic,strong) NSString *cc; +@property(nonatomic,strong) NSString *city; +@property(nonatomic,strong) NSString *country; +@property(nonatomic,strong) NSString *crossStreet; +@property(nonatomic,strong) NSNumber *lat; +@property(nonatomic,strong) NSNumber *lng; +@property(nonatomic,strong) NSNumber *postalCode; +@property(nonatomic,strong) NSString *state; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.m new file mode 100644 index 0000000..9ff3a7e --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.m @@ -0,0 +1,14 @@ +// +// UXRFourSquareLocationModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareLocationModel.h" + +@implementation UXRFourSquareLocationModel + + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.h new file mode 100644 index 0000000..04166a7 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.h @@ -0,0 +1,17 @@ +// +// UXRFourSquareMenuModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareMenuModel : UXRBaseModel +@property(nonatomic,strong) NSString *type; +@property(nonatomic,strong) NSString *label; +@property(nonatomic,strong) NSString *anchor; +@property(nonatomic,strong) NSURL *url; +@property(nonatomic,strong) NSURL *mobileUrl; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.m new file mode 100644 index 0000000..fbbee5d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.m @@ -0,0 +1,36 @@ +// +// UXRFourSquareMenuModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareMenuModel.h" + +@implementation UXRFourSquareMenuModel + +- (void) setUrl:(id)url { + if (nil == url) { + _url = nil; + } + else if ([url isKindOfClass:[NSURL class]]) { + _url = url; + } + else if ([url isKindOfClass:[NSString class]]) { + _url = [NSURL URLWithString:url]; + } +} + +- (void) setMobileUrl:(id)url { + if (nil == url) { + _mobileUrl = nil; + } + else if ([url isKindOfClass:[NSURL class]]) { + _mobileUrl = url; + } + else if ([url isKindOfClass:[NSString class]]) { + _mobileUrl = [NSURL URLWithString:url]; + } +} +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.h new file mode 100644 index 0000000..8b4ab52 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.h @@ -0,0 +1,13 @@ +// +// UXRFourSquareOpenTime.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/26/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareOpenTime : UXRBaseModel +@property(nonatomic,strong) NSString *renderedTime; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.m new file mode 100644 index 0000000..6d6ad41 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.m @@ -0,0 +1,12 @@ +// +// UXRFourSquareOpenTime.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/26/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareOpenTime.h" + +@implementation UXRFourSquareOpenTime +@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.h new file mode 100644 index 0000000..2ac5818 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.h @@ -0,0 +1,22 @@ +// +// UXRFourSquarePhotoModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" +@class UXRFourSquareUserModel; + +@interface UXRFourSquarePhotoModel : UXRBaseModel +@property(nonatomic,strong) NSNumber *createdAt; +@property(nonatomic,strong) NSNumber *height; +@property(nonatomic,strong) NSNumber *width; +@property(nonatomic,strong) NSURL *prefix; +@property(nonatomic,assign) BOOL containsFace; +@property(nonatomic,strong) NSString *suffix; +@property(nonatomic,strong) UXRFourSquareUserModel *user; +@property(nonatomic,strong) NSString *visibility; +-(NSURL*)fullPhotoURL; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.m new file mode 100644 index 0000000..b5b99cc --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.m @@ -0,0 +1,63 @@ +// +// UXRFourSquarePhotoModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquarePhotoModel.h" +#import "UXRFourSquareUserModel.h" + +@implementation UXRFourSquarePhotoModel + +- (void) setPrefix:(id)url { + if (nil == url) { + _prefix = nil; + } + else if ([url isKindOfClass:[NSURL class]]) { + _prefix = url; + } + else if ([url isKindOfClass:[NSString class]]) { + _prefix = [NSURL URLWithString:url]; + } +} + +- (void) setUser:(id)user { + if (nil == user) { + _user = nil; + } + else if ([user isKindOfClass:[UXRFourSquareUserModel class]]) { + _user = user; + } + else if ([user isKindOfClass:[NSDictionary class]]) { + _user = [[UXRFourSquareUserModel alloc ] initWithDictionary:user]; + } +} + +-(NSURL*)fullPhotoURL{ + /* + Ending of the URL for this photo. + + To assemble a resolvable photo URL, take prefix + size + suffix, e.g. https://irs0.4sqi.net/img/general/300x500/2341723_vt1Kr-SfmRmdge-M7b4KNgX2_PHElyVbYL65pMnxEQw.jpg. + + size can be one of the following, where XX or YY is one of 36, 100, 300, or 500. + XXxYY + original: the original photo's size + capXX: cap the photo with a width or height of XX (whichever is larger). Scales the other, smaller dimension proportionally + widthXX: forces the width to be XX and scales the height proportionally + heightYY: forces the height to be YY and scales the width proportionally + */ + //https://developer.foursquare.com/docs/responses/photo + NSString *size = @"500x500"; + NSString *fullUrl = [NSString stringWithFormat:@"%@%@%@", [self.prefix absoluteString],size,self.suffix ]; + return [NSURL URLWithString:fullUrl]; +} + +#pragma mark - Photo Delegate Methods + +-(NSURL*)photoDownloadURL{ + return [self fullPhotoURL]; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.h new file mode 100644 index 0000000..99aecd5 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.h @@ -0,0 +1,14 @@ +// +// UXRFourSquarePriceModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquarePriceModel : UXRBaseModel +@property(nonatomic,strong) NSNumber *tier; +@property(nonatomic,strong) NSString *message; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.m new file mode 100644 index 0000000..aad3b49 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.m @@ -0,0 +1,13 @@ +// +// UXRFourSquarePriceModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquarePriceModel.h" + +@implementation UXRFourSquarePriceModel + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.h new file mode 100644 index 0000000..155bdb7 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.h @@ -0,0 +1,13 @@ +// +// UXRFourSquareReservationsModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareReservationsModel : UXRBaseModel +@property(nonatomic,strong) NSURL *url; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.m new file mode 100644 index 0000000..3a7a6fe --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.m @@ -0,0 +1,25 @@ +// +// UXRFourSquareReservationsModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareReservationsModel.h" + +@implementation UXRFourSquareReservationsModel + +- (void) setUrl:(id)url { + if (nil == url) { + _url = nil; + } + else if ([url isKindOfClass:[NSURL class]]) { + _url = url; + } + else if ([url isKindOfClass:[NSString class]]) { + _url = [NSURL URLWithString:url]; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.h new file mode 100644 index 0000000..98cc6ea --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.h @@ -0,0 +1,42 @@ +// +// UXRFourSquareRestaurantModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +#import "UXRFourSquareLocationModel.h" +#import "UXRFourSquareStatsModel.h" +#import "UXRFourSquareHoursModel.h" +#import "UXRFourSquarePriceModel.h" +#import "UXRFourSquareMenuModel.h" +#import "UXRFourSquareReservationsModel.h" +#import "UXRFourSquareContactModel.h" + +@interface UXRFourSquareRestaurantModel : UXRBaseModel +@property(nonatomic,strong) NSArray *categories; +@property(nonatomic,strong) NSArray *photos; +@property(nonatomic,strong) UXRFourSquareLocationModel *location; +@property(nonatomic,strong) NSString *name; +@property(nonatomic,strong) NSString *description; +@property(nonatomic,strong) NSString *timeZone; +@property(nonatomic,strong) NSNumber *dislike; +@property(nonatomic,strong) NSNumber *rating; +@property(nonatomic,strong) NSArray *specials; +@property(nonatomic,strong) NSArray *tips; +@property(nonatomic,strong) UXRFourSquareStatsModel *stats; +@property(nonatomic,strong) NSURL *url; +@property(nonatomic,strong) NSURL *canonicalUrl; +@property(nonatomic,strong) NSURL *shortUrl; +@property(nonatomic,strong) UXRFourSquareHoursModel *hours; +@property(nonatomic,strong) UXRFourSquareMenuModel *menu; +@property(nonatomic,assign) BOOL verified; +@property(nonatomic,assign) BOOL restricted; +@property(nonatomic,strong) UXRFourSquarePriceModel* price; +@property(nonatomic,strong) UXRFourSquareReservationsModel* reservations; +@property(nonatomic,strong) UXRFourSquareContactModel *contact; +@property(nonatomic,strong) NSString *restaurantId; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.m new file mode 100644 index 0000000..c8c659b --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.m @@ -0,0 +1,221 @@ +// +// UXRFourSquareRestaurantModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareRestaurantModel.h" +#import "UXRFourSquareCategoryModel.h" +#import "UXRFourSquarePhotoModel.h" +#import +#import "UXRFourSquareTipModel.h" + +@implementation UXRFourSquareRestaurantModel + +- (void) setCategories:(id)categories { + if (nil == categories) { + _categories = nil; + } + else if ([categories isKindOfClass:[NSArray class]]) { + NSArray *categoriesArray = (NSArray*)categories; + NSMutableArray *mutableCategories = [[NSMutableArray alloc] initWithCapacity:categoriesArray.count]; + for(id entry in categoriesArray){ + if([entry isKindOfClass:[NSDictionary class]]){ + UXRFourSquareCategoryModel *category = [[UXRFourSquareCategoryModel alloc] initWithDictionary:entry]; + [mutableCategories addObject:category]; + } + } + _categories = (NSArray*)mutableCategories; + } +} + +- (void) setPhotos:(id)photos { + if (nil == photos) { + _photos = nil; + } else if ([photos isKindOfClass:[NSArray class]]){ + _photos = photos; + } + else if ([photos isKindOfClass:[NSDictionary class]]) { + + NSArray *photoGroups = (NSArray*)[photos objectForKey:@"groups"]; + NSMutableArray *photosMutableArray = [[NSMutableArray alloc] init]; + + for(NSDictionary *group in photoGroups){ + NSArray *itemPhotos = (NSArray*)[group objectForKey:@"items"]; + for(id itemPhoto in itemPhotos){ + [photosMutableArray addObject:itemPhoto]; + } + } + + NSMutableArray *photosResultsArray = [[NSMutableArray alloc] initWithCapacity:photosMutableArray.count]; + for(id entry in photosMutableArray){ + if([entry isKindOfClass:[NSDictionary class]]){ + UXRFourSquarePhotoModel *photo = [[UXRFourSquarePhotoModel alloc] initWithDictionary:entry]; + [photosResultsArray addObject:photo]; + } + } + _photos = (NSArray*)photosResultsArray; + } +} + +- (void) setTips:(id)tips { + if (nil == tips) { + _tips = nil; + } else if ([tips isKindOfClass:[NSArray class]]){ + _tips = tips; + } + else if ([tips isKindOfClass:[NSDictionary class]]) { + + NSArray *groups = (NSArray*)[tips objectForKey:@"groups"]; + NSMutableArray *groupsMutableArray = [[NSMutableArray alloc] init]; + + for(NSDictionary *group in groups){ + NSArray *items = (NSArray*)[group objectForKey:@"items"]; + for(id item in items){ + [groupsMutableArray addObject:item]; + } + } + + NSMutableArray *resultsMutableArray = [[NSMutableArray alloc] initWithCapacity:groupsMutableArray.count]; + for(id entry in groupsMutableArray){ + if([entry isKindOfClass:[NSDictionary class]]){ + UXRFourSquareTipModel *tip = [[UXRFourSquareTipModel alloc] initWithDictionary:entry]; + [resultsMutableArray addObject:tip]; + } + } + _tips = (NSArray*)resultsMutableArray; + } +} + +- (void) setContact:(id)contact{ + if (nil == contact) { + _contact = nil; + } + else if ([contact isKindOfClass:[UXRFourSquareContactModel class]]) { + _contact = contact; + } + else if ([contact isKindOfClass:[NSDictionary class]]) { + _contact = [[UXRFourSquareContactModel alloc ] initWithDictionary:contact]; + } +} + +- (void) setStats:(id)stats{ + if (nil == stats) { + _stats = nil; + } + else if ([stats isKindOfClass:[UXRFourSquareStatsModel class]]) { + _stats = stats; + } + else if ([stats isKindOfClass:[NSDictionary class]]) { + _stats = [[UXRFourSquareStatsModel alloc ] initWithDictionary:stats]; + } +} + +- (void) setLocation:(id)location { + if (nil == location) { + _location = nil; + } + else if ([location isKindOfClass:[UXRFourSquareLocationModel class]]) { + _location = location; + } + else if ([location isKindOfClass:[NSDictionary class]]) { + _location = [[UXRFourSquareLocationModel alloc ] initWithDictionary:location]; + } +} + +- (void) setMenu:(id)menu { + if (nil == menu) { + _menu = nil; + } + else if ([menu isKindOfClass:[UXRFourSquareMenuModel class]]) { + _menu = menu; + } + else if ([menu isKindOfClass:[NSDictionary class]]) { + _menu = [[UXRFourSquareMenuModel alloc ] initWithDictionary:menu]; + } +} + +- (void) setReservations:(id)reservations { + if (nil == reservations) { + _reservations = nil; + } + else if ([reservations isKindOfClass:[UXRFourSquareReservationsModel class]]) { + _reservations = reservations; + } + else if ([reservations isKindOfClass:[NSDictionary class]]) { + _reservations = [[UXRFourSquareReservationsModel alloc ] initWithDictionary:reservations]; + } +} + +- (void) setHours:(id)hours { + if (nil == hours) { + _hours = nil; + } + else if ([hours isKindOfClass:[UXRFourSquareHoursModel class]]) { + _hours = hours; + } + else if ([hours isKindOfClass:[NSDictionary class]]) { + _hours = [[UXRFourSquareHoursModel alloc ] initWithDictionary:hours]; + } +} + +- (void) setPrice:(id)price { + if (nil == price) { + _price = nil; + } + else if ([price isKindOfClass:[UXRFourSquarePriceModel class]]) { + _price = price; + } + else if ([price isKindOfClass:[NSDictionary class]]) { + _price = [[UXRFourSquarePriceModel alloc ] initWithDictionary:price]; + } +} + +- (void) setShortUrl:(id)url { + if (nil == url) { + _shortUrl = nil; + } + else if ([url isKindOfClass:[NSURL class]]) { + _shortUrl = url; + } + else if ([url isKindOfClass:[NSString class]]) { + _shortUrl = [NSURL URLWithString:url]; + } +} + +- (void) setUrl:(id)url { + if (nil == url) { + _url = nil; + } + else if ([url isKindOfClass:[NSURL class]]) { + _url = url; + } + else if ([url isKindOfClass:[NSString class]]) { + _url = [NSURL URLWithString:url]; + } +} + +- (void) setCanonicalUrl:(id)url { + if (nil == url) { + _canonicalUrl = nil; + } + else if ([url isKindOfClass:[NSURL class]]) { + _canonicalUrl = url; + } + else if ([url isKindOfClass:[NSString class]]) { + _canonicalUrl = [NSURL URLWithString:url]; + } +} + +-(void)setId:(id)possibleId{ + if (nil == possibleId) { + _restaurantId = nil; + } + else if ([possibleId isKindOfClass:[NSString class]]) { + _restaurantId = possibleId; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.h new file mode 100644 index 0000000..64fa170 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.h @@ -0,0 +1,17 @@ +// +// UXRFourSquareStatsModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareStatsModel : UXRBaseModel + +@property(nonatomic,strong) NSNumber *usersCount; +@property(nonatomic,strong) NSNumber *checkinsCount; +@property(nonatomic,strong) NSNumber *tipCount; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.m new file mode 100644 index 0000000..c3be7e9 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.m @@ -0,0 +1,12 @@ +// +// UXRFourSquareStatsModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareStatsModel.h" + +@implementation UXRFourSquareStatsModel +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.h new file mode 100644 index 0000000..b01b267 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.h @@ -0,0 +1,16 @@ +// +// UXRFourSquareTimeFramesModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" + +@interface UXRFourSquareTimeFramesModel : UXRBaseModel +@property(nonatomic,strong) NSString *days; +@property(nonatomic,assign) BOOL includesToday; +@property(nonatomic,strong) NSArray *open; +@property(nonatomic,strong) NSArray *segments; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.m new file mode 100644 index 0000000..a1dc15d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.m @@ -0,0 +1,31 @@ +// +// UXRFourSquareTimeFramesModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareTimeFramesModel.h" +#import "UXRFourSquareOpenTime.h" + +@implementation UXRFourSquareTimeFramesModel + +- (void) setOpen:(id)open{ + if (nil == open) { + _open = nil; + } + else if ([open isKindOfClass:[NSArray class]]) { + NSArray *resultsArray = (NSArray*)open; + NSMutableArray *mutableOpens = [[NSMutableArray alloc] initWithCapacity:resultsArray.count]; + for(id entry in resultsArray){ + if([entry isKindOfClass:[NSDictionary class]]){ + UXRFourSquareOpenTime *opentime = [[UXRFourSquareOpenTime alloc] initWithDictionary:entry]; + [mutableOpens addObject:opentime]; + } + } + _open = (NSArray*)mutableOpens; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.h new file mode 100644 index 0000000..ff01edf --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.h @@ -0,0 +1,19 @@ +// +// UXRFourSquareCommentModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" +#import "UXRFourSquareUserModel.h" +#import "UXRFourSquareLikesModel.h" + +@interface UXRFourSquareTipModel : UXRBaseModel +@property(nonatomic,strong) NSNumber *createdAt; +@property(nonatomic,strong) NSString *text; +@property(nonatomic,strong) NSURL *canonicalUrl; +@property(nonatomic,strong) UXRFourSquareUserModel *user; +@property(nonatomic,strong) UXRFourSquareLikesModel *likes; +@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.m new file mode 100644 index 0000000..d338bb8 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.m @@ -0,0 +1,50 @@ +// +// UXRFourSquareCommentModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/23/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareTipModel.h" + +@implementation UXRFourSquareTipModel + + +- (void) setUser:(id)user { + if (nil == user) { + _user = nil; + } + else if ([user isKindOfClass:[UXRFourSquareUserModel class]]) { + _user = user; + } + else if ([user isKindOfClass:[NSDictionary class]]) { + _user = [[UXRFourSquareUserModel alloc ] initWithDictionary:user]; + } +} + +- (void) setCanonicalUrl:(id)url { + if (nil == url) { + _canonicalUrl = nil; + } + else if ([url isKindOfClass:[NSURL class]]) { + _canonicalUrl = url; + } + else if ([url isKindOfClass:[NSString class]]) { + _canonicalUrl = [NSURL URLWithString:url]; + } +} + +- (void) setLikes:(id)likes { + if (nil == likes) { + _likes = nil; + } + else if ([likes isKindOfClass:[NSURL class]]) { + _likes = likes; + } + else if ([likes isKindOfClass:[NSDictionary class]]) { + _likes = [[UXRFourSquareLikesModel alloc] initWithDictionary:likes]; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.h new file mode 100644 index 0000000..fdb3faa --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.h @@ -0,0 +1,17 @@ +// +// UXRFourSquareUserModel.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseModel.h" +@class UXRFourSquarePhotoModel; + +@interface UXRFourSquareUserModel : UXRBaseModel +@property(nonatomic,strong) NSString *firstName; +@property(nonatomic,strong) NSString *gender; +@property(nonatomic,strong) NSString *lastName; +@property(nonatomic,strong) UXRFourSquarePhotoModel *photo; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.m new file mode 100644 index 0000000..9e4cc53 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.m @@ -0,0 +1,26 @@ +// +// UXRFourSquareUserModel.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/20/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareUserModel.h" +#import "UXRFourSquarePhotoModel.h" + +@implementation UXRFourSquareUserModel + +- (void) setPhoto:(id)photo { + if (nil == photo) { + _photo = nil; + } + else if ([photo isKindOfClass:[UXRFourSquarePhotoModel class]]) { + _photo = photo; + } + else if ([photo isKindOfClass:[NSDictionary class]]) { + _photo = [[UXRFourSquarePhotoModel alloc] initWithDictionary:photo]; + } +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.h new file mode 100644 index 0000000..cd0bd2d --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.h @@ -0,0 +1,66 @@ +// +// UXRDeserializableObject.h +// FourSquareKit +// +// Created by Rex St. John on 12/15/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import + +@interface UXRJSONDeserializableObject : NSObject + +- (id) initWithDictionary: (NSDictionary*) dictionary; + +/*! + @property identifier + the id of the object. The json uses the name 'id', which is a reserverd word in Objective-C + so instead we use the name 'identifier' to mean the same thing. + */ +@property (nonatomic, assign) NSUInteger identifier; + +/*! + @method + dateFromJSONDateString: + Dates will be converted to match the format expected by UrbanSpoon's API: + Time (UTC). ISO 8601 format YYYY-MM-DDThh:mm:ssZ, which is JSON standard + @param + jsonDate + the JSON-serialized string representation of a date + */ ++ (NSDate *) dateFromJSONDateString: (NSString *) jsonDate; + + +#pragma mark - convert from Objective-C to JSON + +/*! + @method convertToJsonSerializableDictionary: + converts each of the objects contained in the dictionary to NSDictionary objects, + so that the original dictionary (passed in) can be serialized to JSON + */ +- (NSDictionary *) convertToJsonSerializableDictionary: (NSDictionary*) dictionary; + +/*! + @method convertToJsonSerializableArray: + converts each of the objects contained in the array to NSDictionary objects, + so that the original array (passed in) can be serialized to JSON + */ +- (NSArray *) convertToJsonSerializableArray: (NSArray *) array; + +/*! + @method convertDateToJsonFormat: + Dates will be converted to match the format expected by Yapta's API: + Time (UTC). ISO 8601 format YYYY-MM-DDThh:mm:ssZ, which is JSON standard + */ ++ (NSString *) convertDateToJsonFormat: (NSDate *) date; + +/*! + @method convertZuluDateToJsonFormat: + Dates will be converted to match the format expected by Yapta's API: + Time (UTC). ISO 8601 format YYYY-MM-DDThh:mm:ssZ, which is JSON standard + This method will let us keep GMT times on dates + */ ++ (NSString *) convertZuluDateToJsonFormat: (NSDate *) zuluDate; + + +@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.m new file mode 100644 index 0000000..37e826b --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.m @@ -0,0 +1,178 @@ +// +// UXRDeserializableObject.m +// FourSquareKit +// +// Created by Rex St. John on 12/15/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRJSONDeserializableObject.h" +#import "UXRJSONSerializableObject.h" + +static NSDateFormatter *longDateFormatter = nil; +static NSDateFormatter *longZuluDateFormatter = nil; +static NSDateFormatter *shortDateFormatter = nil; +static NSDateFormatter *longZuluDateReFormatter = nil; + +@implementation UXRJSONDeserializableObject + +#pragma mark - initialization + ++ (void) initialize { + // we expect the short date to be in this format: + // 2011-12-02 + shortDateFormatter = [[NSDateFormatter alloc] init]; + [shortDateFormatter setDateFormat:@"yyyy-MM-dd"]; + + // we expect the 'long' date to be in this format: + // 2011-01-12T06:10:00 + longDateFormatter = [[NSDateFormatter alloc] init]; + [longDateFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ss"]; + + // we expect the 'long' date to sometimes have a 'Z' on the end: + // 2008-11-25T14:34:01Z + longZuluDateFormatter = [[NSDateFormatter alloc] init]; + [longZuluDateFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ssZ"]; + [longZuluDateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; + + //Zulu dates are GMT times and as such need a specific reformatter + longZuluDateReFormatter = [[NSDateFormatter alloc] init]; + [longZuluDateReFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; + [longZuluDateReFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; + +} + +- (id) initWithDictionary: (NSDictionary*) dictionary; { + self = [super init]; + if (self) { + [self setValuesForKeysWithDictionary:dictionary]; + } + return self; +} + +#pragma mark - override equality + +- (BOOL) isEqual:(id)object { + if (![object isKindOfClass:[self class]]) { + return NO; + } + + NSUInteger otherId = [(UXRJSONDeserializableObject*)object identifier]; + NSUInteger thisId = self.identifier; + return (otherId == thisId); +} + +- (NSUInteger) hash { + return [self identifier]; +} + +#pragma mark - convert from JSON to Objective-C + +- (void) setNilValueForKey:(NSString *)key { + // this blank override prevents an Exception + + // *very* noisy logs as city_states calls this method 5000 times + if (![key isEqualToString:@"major"]) { + NSLog(@"attempting to set nil value for key: %@", key); + } +} + + +- (void) setValue:(id)value forUndefinedKey:(NSString *)key { + // this blank override prevents an NSUndefinedKeyException +#ifdef TEST + // NSAssert(0, @"undefined key during testing"); +#endif + return; +} + +- (void) setId:(NSUInteger)identifier { + [self setIdentifier:identifier]; +} + +// dealing with dates from JSON being passed in as strings +// Time (UTC). ISO 8601 format YYYY-MM-DDThh:mm:ssZ, which is JSON standard ++ (NSDate *) dateFromJSONDateString: (NSString *) jsonDate; { + + NSDate * returnDate = [[NSDate alloc] init]; + if ([jsonDate length] == 10) { + returnDate = [shortDateFormatter dateFromString:jsonDate]; + } + else if ([jsonDate length] == 19) { + returnDate = [longDateFormatter dateFromString:jsonDate]; + } + else if ([jsonDate length] == 20) { + // Z stands for "Zulu", or GMT minus 0 hours + // this offset information is important; we don't want to lose it + // therefore must replace the Z with an offset, -0000 + returnDate = [longZuluDateFormatter dateFromString: + [jsonDate stringByReplacingOccurrencesOfString:@"Z" withString:@"+0000"]]; + } + + return returnDate; +} + + +#pragma mark - convert from Objective-C to JSON + +- (NSDictionary *) convertToJsonSerializableDictionary: (NSDictionary*) originalDictionary; { + NSMutableDictionary * outDictionary = [[NSMutableDictionary alloc] init]; + NSArray * keys = [originalDictionary allKeys]; + for(int i = 0; i < [keys count]; i++) { + NSString * key = [keys objectAtIndex:i]; + id valueToBeConverted = [originalDictionary valueForKey:key]; + if([valueToBeConverted respondsToSelector:@selector(convertToDictionaryOrArray)]) { + id serializableValue = valueToBeConverted; + NSDictionary * convertedValue = (NSDictionary*)[serializableValue convertToDictionaryOrArray]; + if(convertedValue) { + [originalDictionary setValue:convertedValue + forKey:key]; + } + } + } + return outDictionary; +} + + +- (NSArray *) convertToJsonSerializableArray: (NSArray *) array; { + NSMutableArray * outArray = [[NSMutableArray alloc] init]; + // convert all the array members + for (int i = 0; i < [array count]; i++) { + id valueToBeConverted = [array objectAtIndex:i]; + if([valueToBeConverted respondsToSelector:@selector(convertToDictionaryOrArray)]) { + id serializableValue = valueToBeConverted; + NSDictionary * convertedValue = (NSDictionary*)[serializableValue convertToDictionaryOrArray]; + [outArray addObject:convertedValue]; + } + } + return outArray; +} + ++ (NSString *) convertDateToJsonFormat: (NSDate *) date; { + + //TODO: fix formatter to deal with Zulu times + + if (longDateFormatter == nil) { + longDateFormatter = [[NSDateFormatter alloc] init]; + [longDateFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ss"]; + } + + NSString *dateString = [longDateFormatter stringFromDate:date]; + return dateString; +} + ++ (NSString *) convertZuluDateToJsonFormat: (NSDate *) zuluDate; { + + //Zulu dates are GMT times and as such need a specific reformatter + if (longZuluDateReFormatter == nil) { + longZuluDateReFormatter = [[NSDateFormatter alloc] init]; + [longZuluDateReFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; + [longZuluDateReFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; + } + + NSString *dateString = [longZuluDateReFormatter stringFromDate:zuluDate]; + return dateString; +} + +@end + diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONSerializableObject.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONSerializableObject.h new file mode 100644 index 0000000..ab73214 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONSerializableObject.h @@ -0,0 +1,22 @@ +// +// UXRJSONSerializableObject.h +// FourSquareKit +// +// Created by Rex St. John on 12/15/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import + +/*! + @protocol USPJsonSerializableObject + Objects conforming to this protocol guarantee that they will be able to + be converted to a Dictionary, which in turn is used to serialize the object + (as its dicitonary representation) to JSON. + */ +@protocol UXRJSONSerializableObject + +@required +- (id ) convertToDictionaryOrArray; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.h new file mode 100644 index 0000000..937fae2 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.h @@ -0,0 +1,17 @@ +// +// UXRBaseNetworkingEngine.h +// FourSquareKit +// +// This is largely used for downloading images. +// +// Created by Rex St. John on 12/19/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "MKNetworkEngine.h" + +@interface UXRBaseNetworkingEngine : MKNetworkEngine + ++(UXRBaseNetworkingEngine*) sharedInstance; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.m new file mode 100644 index 0000000..dc08caf --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.m @@ -0,0 +1,34 @@ +// +// UXRBaseNetworkingEngine.m +// FourSquareKit +// +// Created by Rex St. John on 12/19/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRBaseNetworkingEngine.h" + +@implementation UXRBaseNetworkingEngine + +- (id) init { + static BOOL alreadyInitialized = NO; + if (alreadyInitialized) { + return self; + } + alreadyInitialized = YES; + + self = [super init]; + [self useCache]; + if (self) { + } + return self; +} + ++(UXRBaseNetworkingEngine*) sharedInstance; { + static dispatch_once_t onceQueue; + static UXRBaseNetworkingEngine* _sharedInstance; + dispatch_once(&onceQueue, ^{ _sharedInstance = [[self alloc] init]; }); + return _sharedInstance; +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.h new file mode 100644 index 0000000..ab40f49 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.h @@ -0,0 +1,60 @@ +// +// UXRFourSquareNetworkingEngine.h +// FourSquareKit iOS +// +// Created by Rex St. John on 12/16/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// +#import "MKNetworkKit.h" +#import "UXRFourSquareRestaurantModel.h" +#import + +// Common response blocks. +typedef void (^UXRFourSquareEngineRestaurantsCompletionBlock)(NSArray *restaurants); +typedef void (^UXRFourSquareEnginePhotosCompletionBlock)(NSArray *photos); +typedef void (^UXRFourSquareEngineRestaurantCompletionBlock)(UXRFourSquareRestaurantModel *restaurant); +typedef void (^UXRFourSquareEngineErrorBlock)(NSError *error); + +@interface UXRFourSquareNetworkingEngine : MKNetworkEngine + +// Set these on startup. +@property(nonatomic,strong,readonly) NSString *clientId; +@property(nonatomic,strong,readonly) NSString *clientSecret; +@property(nonatomic,strong,readonly) NSString *callBackURL; + +// Singleton. ++(UXRFourSquareNetworkingEngine*) sharedInstance; + +// Use to bootstrap the engine for first time use. ++(void)registerFourSquareEngineWithClientId:(NSString*)client andSecret:(NSString*)secret andCallBackURL:(NSString*)callback; + +// Get alist of restaurants generically. +- (void)getRestaurantsWithCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; + +// Fetch restaurant stubs nearby, you will need to look up full restaurants individually if you want all the details. +- (void)getRestaurantsNearLocation:(CLLocation*)location + withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; + +// Returns a complex object containing many details about your surrounding area. +- (void)exploreRestaurantsNearLocation:(NSString*)location + withQuery:(NSString*)query + withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; + +// Returns a complex object containing many details about your surrounding area. +- (void)exploreRestaurantsNearLatLong:(CLLocationCoordinate2D)coordinate + withQuery:(NSString*)query + withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; + +// Get a specific restaurant, returns a full restaurant model with lot of data in it. +- (void)getRestaurantWithId:(NSString*)restaurantId withCompletionBlock:(UXRFourSquareEngineRestaurantCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; + +// Featch all photo models associated with a specific restaurant Id. +- (void)getPhotosForRestaurantWithId:(NSString*)restaurantId + withCompletionBlock:(UXRFourSquareEnginePhotosCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; +@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.m new file mode 100644 index 0000000..c957721 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.m @@ -0,0 +1,375 @@ +// +// UXRFourSquareNetworkingEngine.m +// FourSquareKit iOS +// +// Created by Rex St. John on 12/16/13. +// Copyright (c) 2013 UX-RX. All rights reserved. +// + +#import "UXRFourSquareNetworkingEngine.h" +#import "UXRFourSquarePhotoModel.h" +#import "UXRFourSquareExploreResultsModel.h" +#import "UXRExploreQueryBaseModel.h" +#import + +// Static paths. +static const NSString* FOURSQUARE_HOSTNAME = @"api.foursquare.com"; +static const NSString* FOURSQUARE_API = @"v2"; +static const NSString* FOURSQUARE_SEARCH_PATH = @"venues/search"; +static const NSString* FOURSQUARE_EXPLORE_PATH = @"venues/explore"; +static const NSString* FOURSQUARE_VENUE_PATH = @"venue"; +static const NSString* FOURSQUARE_VENUES_PATH = @"venues"; +static const NSString* FOURSQUARE_VENUE_PHOTOS_PATH = @"photos"; +static const NSInteger DEFAULT_RANGE_METERS = 800; +static const NSString* DEFAULT_SECTION = @"food"; + +@interface UXRFourSquareNetworkingEngine() +@property(nonatomic,strong,readwrite) NSString *clientId; +@property(nonatomic,strong,readwrite) NSString *clientSecret; +@property(nonatomic,strong,readwrite) NSString *callBackURL; +@end + +@implementation UXRFourSquareNetworkingEngine + +#pragma mark - Initialization + +- (id) init { + static BOOL alreadyInitialized = NO; + if (alreadyInitialized) { + return self; + } + alreadyInitialized = YES; + + self = [super initWithHostName:[FOURSQUARE_HOSTNAME copy] apiPath:[FOURSQUARE_API copy] customHeaderFields:nil]; + [self useCache]; + + if (self) { + } + return self; +} + ++(UXRFourSquareNetworkingEngine*) sharedInstance; { + static dispatch_once_t onceQueue; + static UXRFourSquareNetworkingEngine* _sharedInstance; + dispatch_once(&onceQueue, ^{ _sharedInstance = [[self alloc] init]; }); + return _sharedInstance; +} + ++(void)registerFourSquareEngineWithClientId:(NSString*)client + andSecret:(NSString*)secret + andCallBackURL:(NSString*)callback{ + // Some basic validation. + if(client.length < 48 || [client isEqualToString:@""] == YES){ + [NSException raise:@"Invalid FourSquare Client Id" format:@""]; + } + if(secret.length < 48 || [secret isEqualToString:@""] == YES){ + [NSException raise:@"Invalid FourSquare secret" format:@""]; + } + if([callback isEqualToString:@""] == YES){ + [NSException raise:@"Invalid FourSquare secret" format:@""]; + } + + UXRFourSquareNetworkingEngine *instance = UXRFourSquareNetworkingEngine.sharedInstance; + instance.clientSecret = secret; + instance.clientId = client; + instance.callBackURL = callback; +} + +#pragma mark - Rendering models + +-(NSArray*)renderJSONToFourSquareRestaurantModels:(NSArray*)models{ + + NSMutableArray *restaurantModels = [[NSMutableArray alloc] initWithCapacity:models.count]; + + for(NSDictionary *business in models){ + UXRFourSquareRestaurantModel *restaurantModel = [[UXRFourSquareRestaurantModel alloc] initWithDictionary:business]; + [restaurantModels addObject:restaurantModel]; + } + + return (NSArray*)restaurantModels; +} + +-(NSArray*)renderJSONToFourSquarePhotoModels:(NSArray*)models{ + + NSMutableArray *photoModels = [[NSMutableArray alloc] initWithCapacity:models.count]; + + for(NSDictionary *photo in models){ + UXRFourSquarePhotoModel *photoModel = [[UXRFourSquarePhotoModel alloc] initWithDictionary:photo]; + [photoModels addObject:photoModel]; + } + + return (NSArray*)photoModels; +} + +#pragma mark - Private Methods. + +- (NSDictionary*)dictionaryWithAuthFromDictionary:(NSDictionary*)dictionary{ + //https://api.foursquare.com/v2/venues/search?ll=40.7,-74&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&v=YYYYMMDD + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; + [formatter setDateFormat:@"YYYYMMDD"]; + NSDate *now = [NSDate date]; + NSString *stringFromDate = [formatter stringFromDate:now]; + NSMutableDictionary *authDict = [NSMutableDictionary dictionaryWithDictionary: @{@"client_id":self.clientId, @"client_secret":self.clientSecret, @"v":stringFromDate}]; + [authDict addEntriesFromDictionary:dictionary]; + return [NSDictionary dictionaryWithDictionary:authDict]; +} + +#pragma mark - Public Methods + +- (void)getRestaurantsWithCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock +{ + [self checkRegistration]; + // Fill the post body with the tweet + NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: + @"restaurants", @"query", + @"San Francisco", @"near", + nil]; + + MKNetworkOperation *op = [self operationWithPath:[FOURSQUARE_SEARCH_PATH copy] + params:[self dictionaryWithAuthFromDictionary:postParams] + httpMethod:@"GET" + ssl:YES]; + + [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { + + NSError* error = nil; + NSDictionary* json = [NSJSONSerialization + JSONObjectWithData:[completedOperation responseData] + options:kNilOptions + error:&error]; + if(error != nil){ + errorBlock(error); + } + + NSDictionary *response = [json objectForKey:@"response"]; + NSArray* businesses = [response objectForKey:@"venues"]; + NSArray* models =[self renderJSONToFourSquareRestaurantModels:businesses]; + completionBlock(models); + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + errorBlock(error); + }]; + + [self enqueueOperation:op]; +} + +- (void)getRestaurantsNearLocation:(CLLocation*)location + withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ + [self checkRegistration]; + + CLLocationCoordinate2D coordinate = location.coordinate; + NSString *latLonString = [NSString stringWithFormat:@"%f,%f",coordinate.latitude,coordinate.longitude]; + NSNumber *rangeMeters = [NSNumber numberWithInt:DEFAULT_RANGE_METERS]; + + // Fill the post body with the tweet + //https://developer.foursquare.com/docs/venues/explore + NSDictionary *postParams = @{ + @"query" : @"restaurants", + @"ll": latLonString, + @"radius" : [rangeMeters stringValue] + }; + + MKNetworkOperation *op = [self operationWithPath:[FOURSQUARE_SEARCH_PATH copy] + params:[self dictionaryWithAuthFromDictionary:postParams] + httpMethod:@"GET" + ssl:YES]; + + [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { + + NSError* error = nil; + NSDictionary* json = [NSJSONSerialization + JSONObjectWithData:[completedOperation responseData] + options:kNilOptions + error:&error]; + if(error != nil){ + errorBlock(error); + } + + NSDictionary *response = [json objectForKey:@"response"]; + NSArray* businesses = [response objectForKey:@"venues"]; + NSArray* models =[self renderJSONToFourSquareRestaurantModels:businesses]; + completionBlock(models); + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + errorBlock(error); + }]; + + [self enqueueOperation:op]; +} + +- (void)exploreRestaurantsNearLocation:(NSString*)location + withQuery:(NSString*)query + withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ + [self checkRegistration]; + + NSNumber *rangeMeters = [NSNumber numberWithInt:DEFAULT_RANGE_METERS]; + // Section needs to be nil or it will override any incoming query. + NSString *section = (query==nil || [query isEqualToString:@""] == YES)?[DEFAULT_SECTION copy]:@""; + + // Fill the post body with the tweet + //https://developer.foursquare.com/docs/venues/explore + NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: + section, @"section", + query, @"query", + location, @"near", + @"1", @"sortByDistance", + @"1", @"venuePhotos", + [rangeMeters stringValue],@"radius", + nil]; + + MKNetworkOperation *op = [self operationWithPath:[FOURSQUARE_EXPLORE_PATH copy] + params:[self dictionaryWithAuthFromDictionary:postParams ] + httpMethod:@"GET" + ssl:YES]; + [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { + + NSError* error = nil; + NSDictionary* json = [NSJSONSerialization + JSONObjectWithData:[completedOperation responseData] + options:kNilOptions + error:&error]; + if(error != nil){ + errorBlock(error); + } + + NSDictionary *response = [json objectForKey:@"response"]; + UXRExploreQueryBaseModel* result =[[UXRExploreQueryBaseModel alloc] initWithDictionary:response]; + completionBlock(result.venues); + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + errorBlock(error); + }]; + + [self enqueueOperation:op]; +} + + +- (void)exploreRestaurantsNearLatLong:(CLLocationCoordinate2D)coordinate + withQuery:(NSString*)query + withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ + [self checkRegistration]; + + NSNumber *rangeMeters = [NSNumber numberWithInt:DEFAULT_RANGE_METERS]; + NSString *latLonString = [NSString stringWithFormat:@"%f,%f", coordinate.latitude, coordinate.longitude]; + + // Section needs to be nil or it will override any incoming query. + NSString *section = (query==nil || [query isEqualToString:@""] == YES)?[DEFAULT_SECTION copy]:@""; + + // Fill the post body with the tweet + //https://developer.foursquare.com/docs/venues/explore + NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: + section, @"section", + query, @"query", + latLonString, @"ll", + @"1", @"sortByDistance", + @"1", @"venuePhotos", + [rangeMeters stringValue],@"radius", + nil]; + + MKNetworkOperation *op = [self operationWithPath:[FOURSQUARE_EXPLORE_PATH copy] + params:[self dictionaryWithAuthFromDictionary:postParams ] + httpMethod:@"GET" + ssl:YES]; + [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { + + NSError* error = nil; + NSDictionary* json = [NSJSONSerialization + JSONObjectWithData:[completedOperation responseData] + options:kNilOptions + error:&error]; + if(error != nil){ + errorBlock(error); + } + + NSDictionary *response = [json objectForKey:@"response"]; + UXRExploreQueryBaseModel* result =[[UXRExploreQueryBaseModel alloc] initWithDictionary:response]; + completionBlock(result.venues); + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + errorBlock(error); + }]; + + [self enqueueOperation:op]; +} + +- (void)getRestaurantWithId:(NSString*)restaurantId + withCompletionBlock:(UXRFourSquareEngineRestaurantCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ + [self checkRegistration]; + + // Fill the post body with the tweet + NSString *venuePath = [NSString stringWithFormat:@"%@/%@",[FOURSQUARE_VENUES_PATH copy],restaurantId]; + + MKNetworkOperation *op = [self operationWithPath:venuePath + params:[self dictionaryWithAuthFromDictionary:nil] + httpMethod:@"GET" + ssl:YES]; + + [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { + + NSError* error = nil; + NSDictionary* json = [NSJSONSerialization + JSONObjectWithData:[completedOperation responseData] + options:kNilOptions + error:&error]; + if(error != nil){ + errorBlock(error); + } + + NSDictionary *response = [json objectForKey:@"response"]; + NSDictionary *venue = [response objectForKey:@"venue"]; + UXRFourSquareRestaurantModel *restuarant = [[UXRFourSquareRestaurantModel alloc] initWithDictionary:venue]; + completionBlock(restuarant); + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + errorBlock(error); + }]; + + [self enqueueOperation:op]; +} + +- (void)getPhotosForRestaurantWithId:(NSString*)restaurantId + withCompletionBlock:(UXRFourSquareEnginePhotosCompletionBlock)completionBlock + failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ + [self checkRegistration]; + // Fill the post body with the tweet + NSString *venuePath = [NSString stringWithFormat:@"%@/%@/%@",[FOURSQUARE_VENUES_PATH copy],restaurantId, [FOURSQUARE_VENUE_PHOTOS_PATH copy]]; + + MKNetworkOperation *op = [self operationWithPath:venuePath + params:[self dictionaryWithAuthFromDictionary:nil] + httpMethod:@"GET" + ssl:YES]; + + [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { + + NSError* error = nil; + NSDictionary* json = [NSJSONSerialization + JSONObjectWithData:[completedOperation responseData] + options:kNilOptions + error:&error]; + if(error != nil){ + errorBlock(error); + } + + NSDictionary* response = [json objectForKey:@"response"]; + NSDictionary* photos = [response objectForKey:@"photos"]; + NSArray *models = [self renderJSONToFourSquarePhotoModels:[photos objectForKey:@"items"]]; + completionBlock(models); + } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { + errorBlock(error); + }]; + + [self enqueueOperation:op]; +} + +#pragma mark - Verify registration status + +-(void)checkRegistration{ + BOOL isRegistered = NO; + isRegistered = self.clientId != nil; + isRegistered = self.clientSecret != nil; + isRegistered = self.callBackURL != nil; + if(isRegistered == NO){ + [NSException raise:@"FourSquare Client Not Registered, use registerFourSquareEngineWithClientId" format:@""]; + } +} +@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/ViewController.m b/TalkinToTheNet/TalkinToTheNet/ViewController.m index cbefa29..224f03a 100644 --- a/TalkinToTheNet/TalkinToTheNet/ViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/ViewController.m @@ -19,9 +19,4 @@ - (void)viewDidLoad { // Do any additional setup after loading the view, typically from a nib. } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - @end From 459986bce8546b08e2b708950d2559d41eef09e2 Mon Sep 17 00:00:00 2001 From: Derek316x Date: Mon, 21 Sep 2015 23:42:01 -0400 Subject: [PATCH 2/5] fixed Reachability.m in MKNetworkKit --- .../TalkinToTheNet.xcodeproj/project.pbxproj | 149 +++--- .../NSAlert+MKNetworkKitAdditions.h | 0 .../NSAlert+MKNetworkKitAdditions.m | 0 .../MKNetworkKit/Categories/NSData+MKBase64.h | 0 .../MKNetworkKit/Categories/NSData+MKBase64.m | 0 .../MKNetworkKit/Categories/NSDate+RFC1123.h | 0 .../MKNetworkKit/Categories/NSDate+RFC1123.m | 0 .../Categories/NSDictionary+RequestEncoding.h | 0 .../Categories/NSDictionary+RequestEncoding.m | 0 .../NSImageView+MKNetworkKitAdditions.h | 0 .../NSImageView+MKNetworkKitAdditions.m | 0 .../NSString+MKNetworkKitAdditions.h | 0 .../NSString+MKNetworkKitAdditions.m | 0 .../UIAlertView+MKNetworkKitAdditions.h | 0 .../UIAlertView+MKNetworkKitAdditions.m | 0 .../UIImageView+MKNetworkKitAdditions.h | 0 .../UIImageView+MKNetworkKitAdditions.m | 0 .../MKNetworkKit/MKNetworkEngine.h | 0 .../MKNetworkKit/MKNetworkEngine.m | 0 .../MKNetworkKit/MKNetworkKit.h | 0 .../MKNetworkKit/MKNetworkOperation.h | 0 .../MKNetworkKit/MKNetworkOperation.m | 0 .../MKNetworkKit/Reachability/Reachability.h | 115 ++++ .../MKNetworkKit/Reachability/Reachability.m | 492 ++++++++++++++++++ .../TalkinToTheNet/ViewController.m | 28 +- 25 files changed, 715 insertions(+), 69 deletions(-) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSData+MKBase64.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSData+MKBase64.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSDate+RFC1123.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSDate+RFC1123.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/MKNetworkEngine.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/MKNetworkEngine.m (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/MKNetworkKit.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/MKNetworkOperation.h (100%) rename TalkinToTheNet/TalkinToTheNet/{FourSquareKit => }/MKNetworkKit/MKNetworkOperation.m (100%) create mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.h create mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.m diff --git a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj index b367b79..9ee2b34 100644 --- a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj +++ b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj @@ -36,16 +36,17 @@ 69E41FCD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FAD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m */; settings = {ASSET_TAGS = (); }; }; 69E41FCE1BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FB11BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m */; settings = {ASSET_TAGS = (); }; }; 69E41FCF1BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FB31BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FE71BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FD31BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FE81BB0FFDD00D7324C /* NSData+MKBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FD51BB0FFDD00D7324C /* NSData+MKBase64.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FE91BB0FFDD00D7324C /* NSDate+RFC1123.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FD71BB0FFDD00D7324C /* NSDate+RFC1123.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FEA1BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FD91BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FEB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FDB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FEC1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FDD1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FED1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FDF1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FEE1BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FE11BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FEF1BB0FFDD00D7324C /* MKNetworkEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FE31BB0FFDD00D7324C /* MKNetworkEngine.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FF01BB0FFDD00D7324C /* MKNetworkOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FE61BB0FFDD00D7324C /* MKNetworkOperation.m */; settings = {ASSET_TAGS = (); }; }; + 69E420081BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FF41BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E420091BB1041E00D7324C /* NSData+MKBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FF61BB1041E00D7324C /* NSData+MKBase64.m */; settings = {ASSET_TAGS = (); }; }; + 69E4200A1BB1041E00D7324C /* NSDate+RFC1123.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FF81BB1041E00D7324C /* NSDate+RFC1123.m */; settings = {ASSET_TAGS = (); }; }; + 69E4200B1BB1041E00D7324C /* NSDictionary+RequestEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FFA1BB1041E00D7324C /* NSDictionary+RequestEncoding.m */; settings = {ASSET_TAGS = (); }; }; + 69E4200C1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FFC1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E4200D1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FFE1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E4200E1BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420001BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E4200F1BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420021BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; + 69E420101BB1041E00D7324C /* MKNetworkEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420041BB1041E00D7324C /* MKNetworkEngine.m */; settings = {ASSET_TAGS = (); }; }; + 69E420111BB1041E00D7324C /* MKNetworkOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420071BB1041E00D7324C /* MKNetworkOperation.m */; settings = {ASSET_TAGS = (); }; }; + 69E420151BB1053D00D7324C /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420141BB1053D00D7324C /* Reachability.m */; settings = {ASSET_TAGS = (); }; }; 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4A1BAF859400A92AD2 /* main.m */; }; 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */; }; 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD501BAF859400A92AD2 /* ViewController.m */; }; @@ -115,27 +116,29 @@ 69E41FB11BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRBaseNetworkingEngine.m; sourceTree = ""; }; 69E41FB21BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareNetworkingEngine.h; sourceTree = ""; }; 69E41FB31BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareNetworkingEngine.m; sourceTree = ""; }; - 69E41FD21BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAlert+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E41FD31BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSAlert+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E41FD41BB0FFDD00D7324C /* NSData+MKBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+MKBase64.h"; sourceTree = ""; }; - 69E41FD51BB0FFDD00D7324C /* NSData+MKBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+MKBase64.m"; sourceTree = ""; }; - 69E41FD61BB0FFDD00D7324C /* NSDate+RFC1123.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+RFC1123.h"; sourceTree = ""; }; - 69E41FD71BB0FFDD00D7324C /* NSDate+RFC1123.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+RFC1123.m"; sourceTree = ""; }; - 69E41FD81BB0FFDD00D7324C /* NSDictionary+RequestEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+RequestEncoding.h"; sourceTree = ""; }; - 69E41FD91BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+RequestEncoding.m"; sourceTree = ""; }; - 69E41FDA1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImageView+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E41FDB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImageView+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E41FDC1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E41FDD1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E41FDE1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertView+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E41FDF1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertView+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E41FE01BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E41FE11BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E41FE21BB0FFDD00D7324C /* MKNetworkEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkEngine.h; sourceTree = ""; }; - 69E41FE31BB0FFDD00D7324C /* MKNetworkEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKNetworkEngine.m; sourceTree = ""; }; - 69E41FE41BB0FFDD00D7324C /* MKNetworkKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkKit.h; sourceTree = ""; }; - 69E41FE51BB0FFDD00D7324C /* MKNetworkOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkOperation.h; sourceTree = ""; }; - 69E41FE61BB0FFDD00D7324C /* MKNetworkOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKNetworkOperation.m; sourceTree = ""; }; + 69E41FF31BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAlert+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E41FF41BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSAlert+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E41FF51BB1041E00D7324C /* NSData+MKBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+MKBase64.h"; sourceTree = ""; }; + 69E41FF61BB1041E00D7324C /* NSData+MKBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+MKBase64.m"; sourceTree = ""; }; + 69E41FF71BB1041E00D7324C /* NSDate+RFC1123.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+RFC1123.h"; sourceTree = ""; }; + 69E41FF81BB1041E00D7324C /* NSDate+RFC1123.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+RFC1123.m"; sourceTree = ""; }; + 69E41FF91BB1041E00D7324C /* NSDictionary+RequestEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+RequestEncoding.h"; sourceTree = ""; }; + 69E41FFA1BB1041E00D7324C /* NSDictionary+RequestEncoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+RequestEncoding.m"; sourceTree = ""; }; + 69E41FFB1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImageView+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E41FFC1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImageView+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E41FFD1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E41FFE1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E41FFF1BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertView+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E420001BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertView+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E420011BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+MKNetworkKitAdditions.h"; sourceTree = ""; }; + 69E420021BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+MKNetworkKitAdditions.m"; sourceTree = ""; }; + 69E420031BB1041E00D7324C /* MKNetworkEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkEngine.h; sourceTree = ""; }; + 69E420041BB1041E00D7324C /* MKNetworkEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKNetworkEngine.m; sourceTree = ""; }; + 69E420051BB1041E00D7324C /* MKNetworkKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkKit.h; sourceTree = ""; }; + 69E420061BB1041E00D7324C /* MKNetworkOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkOperation.h; sourceTree = ""; }; + 69E420071BB1041E00D7324C /* MKNetworkOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKNetworkOperation.m; sourceTree = ""; }; + 69E420131BB1053D00D7324C /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = ""; }; + 69E420141BB1053D00D7324C /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = ""; }; 8D7DCD461BAF859400A92AD2 /* TalkinToTheNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TalkinToTheNet.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D7DCD4A1BAF859400A92AD2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -248,43 +251,52 @@ path = networking; sourceTree = ""; }; - 69E41FD01BB0FFDD00D7324C /* MKNetworkKit */ = { + 69E41FF11BB1041E00D7324C /* MKNetworkKit */ = { isa = PBXGroup; children = ( - 69E41FD11BB0FFDD00D7324C /* Categories */, - 69E41FE21BB0FFDD00D7324C /* MKNetworkEngine.h */, - 69E41FE31BB0FFDD00D7324C /* MKNetworkEngine.m */, - 69E41FE41BB0FFDD00D7324C /* MKNetworkKit.h */, - 69E41FE51BB0FFDD00D7324C /* MKNetworkOperation.h */, - 69E41FE61BB0FFDD00D7324C /* MKNetworkOperation.m */, + 69E420121BB1053D00D7324C /* Reachability */, + 69E41FF21BB1041E00D7324C /* Categories */, + 69E420031BB1041E00D7324C /* MKNetworkEngine.h */, + 69E420041BB1041E00D7324C /* MKNetworkEngine.m */, + 69E420051BB1041E00D7324C /* MKNetworkKit.h */, + 69E420061BB1041E00D7324C /* MKNetworkOperation.h */, + 69E420071BB1041E00D7324C /* MKNetworkOperation.m */, ); - name = MKNetworkKit; - path = FourSquareKit/MKNetworkKit; + path = MKNetworkKit; sourceTree = ""; }; - 69E41FD11BB0FFDD00D7324C /* Categories */ = { + 69E41FF21BB1041E00D7324C /* Categories */ = { isa = PBXGroup; children = ( - 69E41FD21BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.h */, - 69E41FD31BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m */, - 69E41FD41BB0FFDD00D7324C /* NSData+MKBase64.h */, - 69E41FD51BB0FFDD00D7324C /* NSData+MKBase64.m */, - 69E41FD61BB0FFDD00D7324C /* NSDate+RFC1123.h */, - 69E41FD71BB0FFDD00D7324C /* NSDate+RFC1123.m */, - 69E41FD81BB0FFDD00D7324C /* NSDictionary+RequestEncoding.h */, - 69E41FD91BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m */, - 69E41FDA1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.h */, - 69E41FDB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m */, - 69E41FDC1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.h */, - 69E41FDD1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m */, - 69E41FDE1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.h */, - 69E41FDF1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m */, - 69E41FE01BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.h */, - 69E41FE11BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m */, + 69E41FF31BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.h */, + 69E41FF41BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m */, + 69E41FF51BB1041E00D7324C /* NSData+MKBase64.h */, + 69E41FF61BB1041E00D7324C /* NSData+MKBase64.m */, + 69E41FF71BB1041E00D7324C /* NSDate+RFC1123.h */, + 69E41FF81BB1041E00D7324C /* NSDate+RFC1123.m */, + 69E41FF91BB1041E00D7324C /* NSDictionary+RequestEncoding.h */, + 69E41FFA1BB1041E00D7324C /* NSDictionary+RequestEncoding.m */, + 69E41FFB1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.h */, + 69E41FFC1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m */, + 69E41FFD1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.h */, + 69E41FFE1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m */, + 69E41FFF1BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.h */, + 69E420001BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m */, + 69E420011BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.h */, + 69E420021BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m */, ); path = Categories; sourceTree = ""; }; + 69E420121BB1053D00D7324C /* Reachability */ = { + isa = PBXGroup; + children = ( + 69E420131BB1053D00D7324C /* Reachability.h */, + 69E420141BB1053D00D7324C /* Reachability.m */, + ); + path = Reachability; + sourceTree = ""; + }; 8D7DCD3D1BAF859400A92AD2 = { isa = PBXGroup; children = ( @@ -304,7 +316,7 @@ 8D7DCD481BAF859400A92AD2 /* TalkinToTheNet */ = { isa = PBXGroup; children = ( - 69E41FD01BB0FFDD00D7324C /* MKNetworkKit */, + 69E41FF11BB1041E00D7324C /* MKNetworkKit */, 69E41F761BB0FFCF00D7324C /* FourSquareKit */, 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */, 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */, @@ -405,31 +417,32 @@ 69E41FC51BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m in Sources */, 69E41FCF1BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m in Sources */, 69E41EF71BB0F5F600D7324C /* APIManager.m in Sources */, - 69E41FEE1BB0FFDD00D7324C /* UIImageView+MKNetworkKitAdditions.m in Sources */, - 69E41FEC1BB0FFDD00D7324C /* NSString+MKNetworkKitAdditions.m in Sources */, + 69E4200F1BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m in Sources */, + 69E4200D1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m in Sources */, 69E41FB91BB0FFCF00D7324C /* UXRBaseModel.m in Sources */, - 69E41FED1BB0FFDD00D7324C /* UIAlertView+MKNetworkKitAdditions.m in Sources */, + 69E4200E1BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m in Sources */, 69E41FCD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m in Sources */, 69E41FC41BB0FFCF00D7324C /* UXRFourSquareOpenTime.m in Sources */, - 69E41FEF1BB0FFDD00D7324C /* MKNetworkEngine.m in Sources */, + 69E420101BB1041E00D7324C /* MKNetworkEngine.m in Sources */, 69E41FC01BB0FFCF00D7324C /* UXRFourSquareHoursModel.m in Sources */, - 69E41FEB1BB0FFDD00D7324C /* NSImageView+MKNetworkKitAdditions.m in Sources */, + 69E4200C1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m in Sources */, 69E41FCB1BB0FFCF00D7324C /* UXRFourSquareTipModel.m in Sources */, 69E41FCE1BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m in Sources */, 69E41FB71BB0FFCF00D7324C /* NSString+Location.m in Sources */, 69E41FC21BB0FFCF00D7324C /* UXRFourSquareLocationModel.m in Sources */, 69E41FC71BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m in Sources */, - 69E41FE81BB0FFDD00D7324C /* NSData+MKBase64.m in Sources */, + 69E420091BB1041E00D7324C /* NSData+MKBase64.m in Sources */, 69E41FCA1BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m in Sources */, 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */, 69E41FC91BB0FFCF00D7324C /* UXRFourSquareStatsModel.m in Sources */, - 69E41FF01BB0FFDD00D7324C /* MKNetworkOperation.m in Sources */, - 69E41FEA1BB0FFDD00D7324C /* NSDictionary+RequestEncoding.m in Sources */, - 69E41FE71BB0FFDD00D7324C /* NSAlert+MKNetworkKitAdditions.m in Sources */, + 69E420111BB1041E00D7324C /* MKNetworkOperation.m in Sources */, + 69E4200B1BB1041E00D7324C /* NSDictionary+RequestEncoding.m in Sources */, + 69E420081BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m in Sources */, 69E41FBB1BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m in Sources */, 69E41FCC1BB0FFCF00D7324C /* UXRFourSquareUserModel.m in Sources */, + 69E420151BB1053D00D7324C /* Reachability.m in Sources */, 69E41FC61BB0FFCF00D7324C /* UXRFourSquarePriceModel.m in Sources */, - 69E41FE91BB0FFDD00D7324C /* NSDate+RFC1123.m in Sources */, + 69E4200A1BB1041E00D7324C /* NSDate+RFC1123.m in Sources */, 69E41FC81BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m in Sources */, 69E41FB81BB0FFCF00D7324C /* NSString+Utils.m in Sources */, 69E41FB61BB0FFCF00D7324C /* NSDictionary+PList.m in Sources */, diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSData+MKBase64.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDate+RFC1123.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkEngine.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.m diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkKit.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkKit.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkKit.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkKit.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.h similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.h rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.h diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.m similarity index 100% rename from TalkinToTheNet/TalkinToTheNet/FourSquareKit/MKNetworkKit/MKNetworkOperation.m rename to TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.m diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.h new file mode 100644 index 0000000..7e5c889 --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.h @@ -0,0 +1,115 @@ +/* + Copyright (c) 2011, Tony Million. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + 2. 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. + + 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 +#import +#import +#import +#import + +/** + * Does ARC support support GCD objects? + * It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ + **/ +#if TARGET_OS_IPHONE + +// Compiling for iOS + +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later +#define NEEDS_DISPATCH_RETAIN_RELEASE 0 +#else // iOS 5.X or earlier +#define NEEDS_DISPATCH_RETAIN_RELEASE 1 +#endif + +#else + +// Compiling for Mac OS X + +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later +#define NEEDS_DISPATCH_RETAIN_RELEASE 0 +#else +#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier +#endif + +#endif + + +extern NSString *const kReachabilityChangedNotification; + +typedef enum +{ + // Apple NetworkStatus Compatible Names. + NotReachable = 0, + ReachableViaWiFi = 2, + ReachableViaWWAN = 1 +} NetworkStatus; + +@class Reachability; + +typedef void (^NetworkReachable)(Reachability * reachability); +typedef void (^NetworkUnreachable)(Reachability * reachability); + +@interface Reachability : NSObject + +@property (nonatomic, copy) NetworkReachable reachableBlock; +@property (nonatomic, copy) NetworkUnreachable unreachableBlock; + + +@property (nonatomic, assign) BOOL reachableOnWWAN; + ++(Reachability*)reachabilityWithHostname:(NSString*)hostname; ++(Reachability*)reachabilityForInternetConnection; ++(Reachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress; ++(Reachability*)reachabilityForLocalWiFi; + +-(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref; + +-(BOOL)startNotifier; +-(void)stopNotifier; + +-(BOOL)isReachable; +-(BOOL)isReachableViaWWAN; +-(BOOL)isReachableViaWiFi; + +// WWAN may be available, but not active until a connection has been established. +// WiFi may require a connection for VPN on Demand. +-(BOOL)isConnectionRequired; // Identical DDG variant. +-(BOOL)connectionRequired; // Apple's routine. +// Dynamic, on demand connection? +-(BOOL)isConnectionOnDemand; +// Is user intervention required? +-(BOOL)isInterventionRequired; + +-(NetworkStatus)currentReachabilityStatus; +-(SCNetworkReachabilityFlags)reachabilityFlags; +-(NSString*)currentReachabilityString; +-(NSString*)currentReachabilityFlags; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.m new file mode 100644 index 0000000..c423c9b --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.m @@ -0,0 +1,492 @@ +/* + Copyright (c) 2011, Tony Million. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + 2. 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. + + 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 "Reachability.h" + + +NSString *const kReachabilityChangedNotification = @"kReachabilityChangedNotification"; + +@interface Reachability () + +@property (nonatomic, assign) SCNetworkReachabilityRef reachabilityRef; + + +#if NEEDS_DISPATCH_RETAIN_RELEASE +@property (nonatomic, assign) dispatch_queue_t reachabilitySerialQueue; +#else +@property (nonatomic, strong) dispatch_queue_t reachabilitySerialQueue; +#endif + + +@property (nonatomic, strong) id reachabilityObject; + +-(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags; +-(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags; + +@end + +static NSString *reachabilityFlags(SCNetworkReachabilityFlags flags) +{ + return [NSString stringWithFormat:@"%c%c %c%c%c%c%c%c%c", +#if TARGET_OS_IPHONE + (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', +#else + 'X', +#endif + (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', + (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', + (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', + (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', + (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', + (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-']; +} + +//Start listening for reachability notifications on the current run loop +static void TMReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) +{ +#pragma unused (target) + Reachability *reachability = ((__bridge Reachability*)info); + + // we probably dont need an autoreleasepool here as GCD docs state each queue has its own autorelease pool + // but what the heck eh? + @autoreleasepool + { + [reachability reachabilityChanged:flags]; + } +} + + +@implementation Reachability + +#pragma mark - class constructor methods ++(Reachability*)reachabilityWithHostname:(NSString*)hostname +{ + SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]); + if (ref) + { + id reachability = [[self alloc] initWithReachabilityRef:ref]; + +#if __has_feature(objc_arc) + return reachability; +#else + return [reachability autorelease]; +#endif + + } + + return nil; +} + ++(Reachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress +{ + SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress); + if (ref) + { + id reachability = [[self alloc] initWithReachabilityRef:ref]; + +#if __has_feature(objc_arc) + return reachability; +#else + return [reachability autorelease]; +#endif + } + + return nil; +} + ++(Reachability *)reachabilityForInternetConnection +{ + struct sockaddr_in zeroAddress; + bzero(&zeroAddress, sizeof(zeroAddress)); + zeroAddress.sin_len = sizeof(zeroAddress); + zeroAddress.sin_family = AF_INET; + + return [self reachabilityWithAddress:&zeroAddress]; +} + ++(Reachability*)reachabilityForLocalWiFi +{ + struct sockaddr_in localWifiAddress; + bzero(&localWifiAddress, sizeof(localWifiAddress)); + localWifiAddress.sin_len = sizeof(localWifiAddress); + localWifiAddress.sin_family = AF_INET; + // IN_LINKLOCALNETNUM is defined in as 169.254.0.0 + localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); + + return [self reachabilityWithAddress:&localWifiAddress]; +} + + +// initialization methods + +-(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref +{ + self = [super init]; + if (self != nil) + { + self.reachableOnWWAN = YES; + self.reachabilityRef = ref; + } + + return self; +} + +-(void)dealloc +{ + [self stopNotifier]; + + if(self.reachabilityRef) + { + CFRelease(self.reachabilityRef); + self.reachabilityRef = nil; + } + +#if !(__has_feature(objc_arc)) + [super dealloc]; +#endif + + +} + +#pragma mark - notifier methods + +// Notifier +// NOTE: this uses GCD to trigger the blocks - they *WILL NOT* be called on THE MAIN THREAD +// - In other words DO NOT DO ANY UI UPDATES IN THE BLOCKS. +// INSTEAD USE dispatch_async(dispatch_get_main_queue(), ^{UISTUFF}) (or dispatch_sync if you want) + +-(BOOL)startNotifier +{ + SCNetworkReachabilityContext context = { 0, NULL, NULL, NULL, NULL }; + + // this should do a retain on ourself, so as long as we're in notifier mode we shouldn't disappear out from under ourselves + // woah + self.reachabilityObject = self; + + + + // first we need to create a serial queue + // we allocate this once for the lifetime of the notifier + self.reachabilitySerialQueue = dispatch_queue_create("com.tonymillion.reachability", NULL); + if(!self.reachabilitySerialQueue) + { + return NO; + } + + + context.info = (__bridge void *)self; + + if (!SCNetworkReachabilitySetCallback(self.reachabilityRef, TMReachabilityCallback, &context)) + { +#ifdef DEBUG + NSLog(@"SCNetworkReachabilitySetCallback() failed: %s", SCErrorString(SCError())); +#endif + + //clear out the dispatch queue + if(self.reachabilitySerialQueue) + { +#if NEEDS_DISPATCH_RETAIN_RELEASE + dispatch_release(self.reachabilitySerialQueue); +#endif + self.reachabilitySerialQueue = nil; + } + + self.reachabilityObject = nil; + + return NO; + } + + // set it as our reachability queue which will retain the queue + if(!SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, self.reachabilitySerialQueue)) + { +#ifdef DEBUG + NSLog(@"SCNetworkReachabilitySetDispatchQueue() failed: %s", SCErrorString(SCError())); +#endif + + //UH OH - FAILURE! + + // first stop any callbacks! + SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL); + + // then clear out the dispatch queue + if(self.reachabilitySerialQueue) + { +#if NEEDS_DISPATCH_RETAIN_RELEASE + dispatch_release(self.reachabilitySerialQueue); +#endif + self.reachabilitySerialQueue = nil; + } + + self.reachabilityObject = nil; + + return NO; + } + + return YES; +} + +-(void)stopNotifier +{ + // first stop any callbacks! + SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL); + + // unregister target from the GCD serial dispatch queue + SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, NULL); + + if(self.reachabilitySerialQueue) + { +#if NEEDS_DISPATCH_RETAIN_RELEASE + dispatch_release(self.reachabilitySerialQueue); +#endif + self.reachabilitySerialQueue = nil; + } + + self.reachabilityObject = nil; +} + +#pragma mark - reachability tests + +// this is for the case where you flick the airplane mode +// you end up getting something like this: +//Reachability: WR ct----- +//Reachability: -- ------- +//Reachability: WR ct----- +//Reachability: -- ------- +// we treat this as 4 UNREACHABLE triggers - really apple should do better than this + +#define testcase (kSCNetworkReachabilityFlagsConnectionRequired | kSCNetworkReachabilityFlagsTransientConnection) + +-(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags +{ + BOOL connectionUP = YES; + + if(!(flags & kSCNetworkReachabilityFlagsReachable)) + connectionUP = NO; + + if( (flags & testcase) == testcase ) + connectionUP = NO; + +#if TARGET_OS_IPHONE + if(flags & kSCNetworkReachabilityFlagsIsWWAN) + { + // we're on 3G + if(!self.reachableOnWWAN) + { + // we dont want to connect when on 3G + connectionUP = NO; + } + } +#endif + + return connectionUP; +} + +-(BOOL)isReachable +{ + SCNetworkReachabilityFlags flags; + + if(!SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) + return NO; + + return [self isReachableWithFlags:flags]; +} + +-(BOOL)isReachableViaWWAN +{ +#if TARGET_OS_IPHONE + + SCNetworkReachabilityFlags flags = 0; + + if(SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) + { + // check we're REACHABLE + if(flags & kSCNetworkReachabilityFlagsReachable) + { + // now, check we're on WWAN + if(flags & kSCNetworkReachabilityFlagsIsWWAN) + { + return YES; + } + } + } +#endif + + return NO; +} + +-(BOOL)isReachableViaWiFi +{ + SCNetworkReachabilityFlags flags = 0; + + if(SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) + { + // check we're reachable + if((flags & kSCNetworkReachabilityFlagsReachable)) + { +#if TARGET_OS_IPHONE + // check we're NOT on WWAN + if((flags & kSCNetworkReachabilityFlagsIsWWAN)) + { + return NO; + } +#endif + return YES; + } + } + + return NO; +} + + +// WWAN may be available, but not active until a connection has been established. +// WiFi may require a connection for VPN on Demand. +-(BOOL)isConnectionRequired +{ + return [self connectionRequired]; +} + +-(BOOL)connectionRequired +{ + SCNetworkReachabilityFlags flags; + + if(SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) + { + return (flags & kSCNetworkReachabilityFlagsConnectionRequired); + } + + return NO; +} + +// Dynamic, on demand connection? +-(BOOL)isConnectionOnDemand +{ + SCNetworkReachabilityFlags flags; + + if (SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) + { + return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && + (flags & (kSCNetworkReachabilityFlagsConnectionOnTraffic | kSCNetworkReachabilityFlagsConnectionOnDemand))); + } + + return NO; +} + +// Is user intervention required? +-(BOOL)isInterventionRequired +{ + SCNetworkReachabilityFlags flags; + + if (SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) + { + return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && + (flags & kSCNetworkReachabilityFlagsInterventionRequired)); + } + + return NO; +} + + +#pragma mark - reachability status stuff + +-(NetworkStatus)currentReachabilityStatus +{ + if([self isReachable]) + { + if([self isReachableViaWiFi]) + return ReachableViaWiFi; + +#if TARGET_OS_IPHONE + return ReachableViaWWAN; +#endif + } + + return NotReachable; +} + +-(SCNetworkReachabilityFlags)reachabilityFlags +{ + SCNetworkReachabilityFlags flags = 0; + + if(SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) + { + return flags; + } + + return 0; +} + +-(NSString*)currentReachabilityString +{ + NetworkStatus temp = [self currentReachabilityStatus]; + + if(temp == self.reachableOnWWAN) + { + // updated for the fact we have CDMA phones now! + return NSLocalizedString(@"Cellular", @""); + } + if (temp == ReachableViaWiFi) + { + return NSLocalizedString(@"WiFi", @""); + } + + return NSLocalizedString(@"No Connection", @""); +} + +-(NSString*)currentReachabilityFlags +{ + return reachabilityFlags([self reachabilityFlags]); +} + +#pragma mark - callback function calls this method + +-(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags +{ + if([self isReachableWithFlags:flags]) + { + if(self.reachableBlock) + { + self.reachableBlock(self); + } + } + else + { + if(self.unreachableBlock) + { + self.unreachableBlock(self); + } + } + + // this makes sure the change notification happens on the MAIN THREAD + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification + object:self]; + }); +} + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/ViewController.m b/TalkinToTheNet/TalkinToTheNet/ViewController.m index 224f03a..945792d 100644 --- a/TalkinToTheNet/TalkinToTheNet/ViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/ViewController.m @@ -7,8 +7,12 @@ // #import "ViewController.h" +#import "FourSquareKit.h" +#import "MKNetworkKit.h" + @interface ViewController () +@property (nonatomic) UXRFourSquareNetworkingEngine *fourSquareEngine; @end @@ -16,7 +20,29 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. + [self registerNetworkingEngine]; + [self getNearbyTacoRestaurants]; +} + +-(void)registerNetworkingEngine{ + NSString *yourClientId = @"RCPNIN1V5V5GCZ0F3RSFCNFIOD2K2240ZIW2ZANAOFIJWV1O"; + NSString *yourClientSecret = @"4YZZKIM1UUUXTVG4K3RX2Y4BV3TIG2RZDIB1KUTJJJPCTK5G"; + NSString *yourCallbackURl = @"http://google.com"; + [UXRFourSquareNetworkingEngine registerFourSquareEngineWithClientId:yourClientId andSecret:yourClientSecret andCallBackURL:yourCallbackURl]; + self.fourSquareEngine = [UXRFourSquareNetworkingEngine sharedInstance]; +} + +-(void)getNearbyTacoRestaurants{ + NSString *locationString = @"Seattle"; + NSString *query = @"tacos"; + [self.fourSquareEngine exploreRestaurantsNearLocation:locationString + withQuery:query + withCompletionBlock:^(NSArray *restaurants) { + UXRFourSquareRestaurantModel *restaurantModel = (UXRFourSquareRestaurantModel *)restaurants[0]; + NSLog(@"%@",restaurantModel); + } failureBlock:^(NSError *error) { + // Error + }]; } @end From bd93d914d731ad8130b49d66a5857048f5316eda Mon Sep 17 00:00:00 2001 From: Derek316x Date: Tue, 22 Sep 2015 01:04:15 -0400 Subject: [PATCH 3/5] got coordinates from CLLocationManager --- .../TalkinToTheNet.xcodeproj/project.pbxproj | 300 +--- .../TalkinToTheNet/Base.lproj/Main.storyboard | 7 +- .../FourSquareKit/FourSquareKit.h | 42 - .../categories/CLLocation+Testing.h | 21 - .../categories/CLLocation+Testing.m | 63 - .../categories/CLLocation+isEmpty.h | 13 - .../categories/CLLocation+isEmpty.m | 17 - .../categories/NSDictionary+PList.h | 15 - .../categories/NSDictionary+PList.m | 21 - .../categories/NSString+Location.h | 24 - .../categories/NSString+Location.m | 48 - .../FourSquareKit/categories/NSString+Utils.h | 19 - .../FourSquareKit/categories/NSString+Utils.m | 49 - .../FourSquareKit/models/UXRBaseModel.h | 13 - .../FourSquareKit/models/UXRBaseModel.m | 17 - .../models/UXRExploreQueryBaseModel.h | 21 - .../models/UXRExploreQueryBaseModel.m | 52 - .../models/UXRFourSquareAttributesModel.h | 13 - .../models/UXRFourSquareAttributesModel.m | 65 - .../models/UXRFourSquareCategoryModel.h | 20 - .../models/UXRFourSquareCategoryModel.m | 25 - .../models/UXRFourSquareContactModel.h | 15 - .../models/UXRFourSquareContactModel.m | 13 - .../models/UXRFourSquareExploreResultsModel.h | 17 - .../models/UXRFourSquareExploreResultsModel.m | 42 - .../models/UXRFourSquareGeoCodeModel.h | 18 - .../models/UXRFourSquareGeoCodeModel.m | 13 - .../models/UXRFourSquareHoursModel.h | 15 - .../models/UXRFourSquareHoursModel.m | 31 - .../models/UXRFourSquareLikesModel.h | 15 - .../models/UXRFourSquareLikesModel.m | 13 - .../models/UXRFourSquareLocationModel.h | 21 - .../models/UXRFourSquareLocationModel.m | 14 - .../models/UXRFourSquareMenuModel.h | 17 - .../models/UXRFourSquareMenuModel.m | 36 - .../models/UXRFourSquareOpenTime.h | 13 - .../models/UXRFourSquareOpenTime.m | 12 - .../models/UXRFourSquarePhotoModel.h | 22 - .../models/UXRFourSquarePhotoModel.m | 63 - .../models/UXRFourSquarePriceModel.h | 14 - .../models/UXRFourSquarePriceModel.m | 13 - .../models/UXRFourSquareReservationsModel.h | 13 - .../models/UXRFourSquareReservationsModel.m | 25 - .../models/UXRFourSquareRestaurantModel.h | 42 - .../models/UXRFourSquareRestaurantModel.m | 221 --- .../models/UXRFourSquareStatsModel.h | 17 - .../models/UXRFourSquareStatsModel.m | 12 - .../models/UXRFourSquareTimeFramesModel.h | 16 - .../models/UXRFourSquareTimeFramesModel.m | 31 - .../models/UXRFourSquareTipModel.h | 19 - .../models/UXRFourSquareTipModel.m | 50 - .../models/UXRFourSquareUserModel.h | 17 - .../models/UXRFourSquareUserModel.m | 26 - .../models/UXRJSONDeserializableObject.h | 66 - .../models/UXRJSONDeserializableObject.m | 178 -- .../models/UXRJSONSerializableObject.h | 22 - .../networking/UXRBaseNetworkingEngine.h | 17 - .../networking/UXRBaseNetworkingEngine.m | 34 - .../UXRFourSquareNetworkingEngine.h | 60 - .../UXRFourSquareNetworkingEngine.m | 375 ---- TalkinToTheNet/TalkinToTheNet/Info.plist | 2 + .../NSAlert+MKNetworkKitAdditions.h | 15 - .../NSAlert+MKNetworkKitAdditions.m | 20 - .../MKNetworkKit/Categories/NSData+MKBase64.h | 42 - .../MKNetworkKit/Categories/NSData+MKBase64.m | 312 ---- .../MKNetworkKit/Categories/NSDate+RFC1123.h | 27 - .../MKNetworkKit/Categories/NSDate+RFC1123.m | 76 - .../Categories/NSDictionary+RequestEncoding.h | 33 - .../Categories/NSDictionary+RequestEncoding.m | 74 - .../NSImageView+MKNetworkKitAdditions.h | 45 - .../NSImageView+MKNetworkKitAdditions.m | 99 -- .../NSString+MKNetworkKitAdditions.h | 34 - .../NSString+MKNetworkKitAdditions.m | 81 - .../UIAlertView+MKNetworkKitAdditions.h | 31 - .../UIAlertView+MKNetworkKitAdditions.m | 41 - .../UIImageView+MKNetworkKitAdditions.h | 42 - .../UIImageView+MKNetworkKitAdditions.m | 109 -- .../MKNetworkKit/MKNetworkEngine.h | 425 ----- .../MKNetworkKit/MKNetworkEngine.m | 766 --------- .../MKNetworkKit/MKNetworkKit.h | 95 -- .../MKNetworkKit/MKNetworkOperation.h | 692 -------- .../MKNetworkKit/MKNetworkOperation.m | 1518 ----------------- .../MKNetworkKit/Reachability/Reachability.h | 115 -- .../MKNetworkKit/Reachability/Reachability.m | 492 ------ .../TalkinToTheNet/ViewController.m | 66 +- 85 files changed, 52 insertions(+), 7723 deletions(-) delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/FourSquareKit.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONSerializableObject.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkKit.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.m delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.h delete mode 100644 TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.m diff --git a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj index 9ee2b34..579a249 100644 --- a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj +++ b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj @@ -8,45 +8,7 @@ /* Begin PBXBuildFile section */ 69E41EF71BB0F5F600D7324C /* APIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41EF61BB0F5F600D7324C /* APIManager.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FB41BB0FFCF00D7324C /* CLLocation+isEmpty.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F791BB0FFCF00D7324C /* CLLocation+isEmpty.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FB51BB0FFCF00D7324C /* CLLocation+Testing.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F7B1BB0FFCF00D7324C /* CLLocation+Testing.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FB61BB0FFCF00D7324C /* NSDictionary+PList.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F7D1BB0FFCF00D7324C /* NSDictionary+PList.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FB71BB0FFCF00D7324C /* NSString+Location.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F7F1BB0FFCF00D7324C /* NSString+Location.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FB81BB0FFCF00D7324C /* NSString+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F811BB0FFCF00D7324C /* NSString+Utils.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FB91BB0FFCF00D7324C /* UXRBaseModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F851BB0FFCF00D7324C /* UXRBaseModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FBA1BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F871BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FBB1BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F891BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FBC1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F8B1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FBD1BB0FFCF00D7324C /* UXRFourSquareContactModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F8D1BB0FFCF00D7324C /* UXRFourSquareContactModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FBE1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F8F1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FBF1BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F911BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC01BB0FFCF00D7324C /* UXRFourSquareHoursModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F931BB0FFCF00D7324C /* UXRFourSquareHoursModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC11BB0FFCF00D7324C /* UXRFourSquareLikesModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F951BB0FFCF00D7324C /* UXRFourSquareLikesModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC21BB0FFCF00D7324C /* UXRFourSquareLocationModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F971BB0FFCF00D7324C /* UXRFourSquareLocationModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC31BB0FFCF00D7324C /* UXRFourSquareMenuModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F991BB0FFCF00D7324C /* UXRFourSquareMenuModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC41BB0FFCF00D7324C /* UXRFourSquareOpenTime.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F9B1BB0FFCF00D7324C /* UXRFourSquareOpenTime.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC51BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F9D1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC61BB0FFCF00D7324C /* UXRFourSquarePriceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41F9F1BB0FFCF00D7324C /* UXRFourSquarePriceModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC71BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA11BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC81BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA31BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FC91BB0FFCF00D7324C /* UXRFourSquareStatsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA51BB0FFCF00D7324C /* UXRFourSquareStatsModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FCA1BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA71BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FCB1BB0FFCF00D7324C /* UXRFourSquareTipModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FA91BB0FFCF00D7324C /* UXRFourSquareTipModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FCC1BB0FFCF00D7324C /* UXRFourSquareUserModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FAB1BB0FFCF00D7324C /* UXRFourSquareUserModel.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FCD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FAD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FCE1BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FB11BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m */; settings = {ASSET_TAGS = (); }; }; - 69E41FCF1BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FB31BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m */; settings = {ASSET_TAGS = (); }; }; - 69E420081BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FF41BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E420091BB1041E00D7324C /* NSData+MKBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FF61BB1041E00D7324C /* NSData+MKBase64.m */; settings = {ASSET_TAGS = (); }; }; - 69E4200A1BB1041E00D7324C /* NSDate+RFC1123.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FF81BB1041E00D7324C /* NSDate+RFC1123.m */; settings = {ASSET_TAGS = (); }; }; - 69E4200B1BB1041E00D7324C /* NSDictionary+RequestEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FFA1BB1041E00D7324C /* NSDictionary+RequestEncoding.m */; settings = {ASSET_TAGS = (); }; }; - 69E4200C1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FFC1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E4200D1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41FFE1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E4200E1BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420001BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E4200F1BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420021BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m */; settings = {ASSET_TAGS = (); }; }; - 69E420101BB1041E00D7324C /* MKNetworkEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420041BB1041E00D7324C /* MKNetworkEngine.m */; settings = {ASSET_TAGS = (); }; }; - 69E420111BB1041E00D7324C /* MKNetworkOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420071BB1041E00D7324C /* MKNetworkOperation.m */; settings = {ASSET_TAGS = (); }; }; - 69E420151BB1053D00D7324C /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420141BB1053D00D7324C /* Reachability.m */; settings = {ASSET_TAGS = (); }; }; + 69E420171BB10B3D00D7324C /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 69E420161BB10B3D00D7324C /* CoreLocation.framework */; }; 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4A1BAF859400A92AD2 /* main.m */; }; 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */; }; 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD501BAF859400A92AD2 /* ViewController.m */; }; @@ -58,87 +20,7 @@ /* Begin PBXFileReference section */ 69E41EF51BB0F5F600D7324C /* APIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIManager.h; sourceTree = ""; }; 69E41EF61BB0F5F600D7324C /* APIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIManager.m; sourceTree = ""; }; - 69E41F781BB0FFCF00D7324C /* CLLocation+isEmpty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CLLocation+isEmpty.h"; sourceTree = ""; }; - 69E41F791BB0FFCF00D7324C /* CLLocation+isEmpty.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CLLocation+isEmpty.m"; sourceTree = ""; }; - 69E41F7A1BB0FFCF00D7324C /* CLLocation+Testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CLLocation+Testing.h"; sourceTree = ""; }; - 69E41F7B1BB0FFCF00D7324C /* CLLocation+Testing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "CLLocation+Testing.m"; sourceTree = ""; }; - 69E41F7C1BB0FFCF00D7324C /* NSDictionary+PList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+PList.h"; sourceTree = ""; }; - 69E41F7D1BB0FFCF00D7324C /* NSDictionary+PList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+PList.m"; sourceTree = ""; }; - 69E41F7E1BB0FFCF00D7324C /* NSString+Location.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Location.h"; sourceTree = ""; }; - 69E41F7F1BB0FFCF00D7324C /* NSString+Location.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Location.m"; sourceTree = ""; }; - 69E41F801BB0FFCF00D7324C /* NSString+Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Utils.h"; sourceTree = ""; }; - 69E41F811BB0FFCF00D7324C /* NSString+Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Utils.m"; sourceTree = ""; }; - 69E41F821BB0FFCF00D7324C /* FourSquareKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FourSquareKit.h; sourceTree = ""; }; - 69E41F841BB0FFCF00D7324C /* UXRBaseModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRBaseModel.h; sourceTree = ""; }; - 69E41F851BB0FFCF00D7324C /* UXRBaseModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRBaseModel.m; sourceTree = ""; }; - 69E41F861BB0FFCF00D7324C /* UXRExploreQueryBaseModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRExploreQueryBaseModel.h; sourceTree = ""; }; - 69E41F871BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRExploreQueryBaseModel.m; sourceTree = ""; }; - 69E41F881BB0FFCF00D7324C /* UXRFourSquareAttributesModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareAttributesModel.h; sourceTree = ""; }; - 69E41F891BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareAttributesModel.m; sourceTree = ""; }; - 69E41F8A1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareCategoryModel.h; sourceTree = ""; }; - 69E41F8B1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareCategoryModel.m; sourceTree = ""; }; - 69E41F8C1BB0FFCF00D7324C /* UXRFourSquareContactModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareContactModel.h; sourceTree = ""; }; - 69E41F8D1BB0FFCF00D7324C /* UXRFourSquareContactModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareContactModel.m; sourceTree = ""; }; - 69E41F8E1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareExploreResultsModel.h; sourceTree = ""; }; - 69E41F8F1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareExploreResultsModel.m; sourceTree = ""; }; - 69E41F901BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareGeoCodeModel.h; sourceTree = ""; }; - 69E41F911BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareGeoCodeModel.m; sourceTree = ""; }; - 69E41F921BB0FFCF00D7324C /* UXRFourSquareHoursModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareHoursModel.h; sourceTree = ""; }; - 69E41F931BB0FFCF00D7324C /* UXRFourSquareHoursModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareHoursModel.m; sourceTree = ""; }; - 69E41F941BB0FFCF00D7324C /* UXRFourSquareLikesModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareLikesModel.h; sourceTree = ""; }; - 69E41F951BB0FFCF00D7324C /* UXRFourSquareLikesModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareLikesModel.m; sourceTree = ""; }; - 69E41F961BB0FFCF00D7324C /* UXRFourSquareLocationModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareLocationModel.h; sourceTree = ""; }; - 69E41F971BB0FFCF00D7324C /* UXRFourSquareLocationModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareLocationModel.m; sourceTree = ""; }; - 69E41F981BB0FFCF00D7324C /* UXRFourSquareMenuModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareMenuModel.h; sourceTree = ""; }; - 69E41F991BB0FFCF00D7324C /* UXRFourSquareMenuModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareMenuModel.m; sourceTree = ""; }; - 69E41F9A1BB0FFCF00D7324C /* UXRFourSquareOpenTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareOpenTime.h; sourceTree = ""; }; - 69E41F9B1BB0FFCF00D7324C /* UXRFourSquareOpenTime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareOpenTime.m; sourceTree = ""; }; - 69E41F9C1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquarePhotoModel.h; sourceTree = ""; }; - 69E41F9D1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquarePhotoModel.m; sourceTree = ""; }; - 69E41F9E1BB0FFCF00D7324C /* UXRFourSquarePriceModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquarePriceModel.h; sourceTree = ""; }; - 69E41F9F1BB0FFCF00D7324C /* UXRFourSquarePriceModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquarePriceModel.m; sourceTree = ""; }; - 69E41FA01BB0FFCF00D7324C /* UXRFourSquareReservationsModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareReservationsModel.h; sourceTree = ""; }; - 69E41FA11BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareReservationsModel.m; sourceTree = ""; }; - 69E41FA21BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareRestaurantModel.h; sourceTree = ""; }; - 69E41FA31BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareRestaurantModel.m; sourceTree = ""; }; - 69E41FA41BB0FFCF00D7324C /* UXRFourSquareStatsModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareStatsModel.h; sourceTree = ""; }; - 69E41FA51BB0FFCF00D7324C /* UXRFourSquareStatsModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareStatsModel.m; sourceTree = ""; }; - 69E41FA61BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareTimeFramesModel.h; sourceTree = ""; }; - 69E41FA71BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareTimeFramesModel.m; sourceTree = ""; }; - 69E41FA81BB0FFCF00D7324C /* UXRFourSquareTipModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareTipModel.h; sourceTree = ""; }; - 69E41FA91BB0FFCF00D7324C /* UXRFourSquareTipModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareTipModel.m; sourceTree = ""; }; - 69E41FAA1BB0FFCF00D7324C /* UXRFourSquareUserModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareUserModel.h; sourceTree = ""; }; - 69E41FAB1BB0FFCF00D7324C /* UXRFourSquareUserModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareUserModel.m; sourceTree = ""; }; - 69E41FAC1BB0FFCF00D7324C /* UXRJSONDeserializableObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRJSONDeserializableObject.h; sourceTree = ""; }; - 69E41FAD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRJSONDeserializableObject.m; sourceTree = ""; }; - 69E41FAE1BB0FFCF00D7324C /* UXRJSONSerializableObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRJSONSerializableObject.h; sourceTree = ""; }; - 69E41FB01BB0FFCF00D7324C /* UXRBaseNetworkingEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRBaseNetworkingEngine.h; sourceTree = ""; }; - 69E41FB11BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRBaseNetworkingEngine.m; sourceTree = ""; }; - 69E41FB21BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UXRFourSquareNetworkingEngine.h; sourceTree = ""; }; - 69E41FB31BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UXRFourSquareNetworkingEngine.m; sourceTree = ""; }; - 69E41FF31BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSAlert+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E41FF41BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSAlert+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E41FF51BB1041E00D7324C /* NSData+MKBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+MKBase64.h"; sourceTree = ""; }; - 69E41FF61BB1041E00D7324C /* NSData+MKBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+MKBase64.m"; sourceTree = ""; }; - 69E41FF71BB1041E00D7324C /* NSDate+RFC1123.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+RFC1123.h"; sourceTree = ""; }; - 69E41FF81BB1041E00D7324C /* NSDate+RFC1123.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+RFC1123.m"; sourceTree = ""; }; - 69E41FF91BB1041E00D7324C /* NSDictionary+RequestEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+RequestEncoding.h"; sourceTree = ""; }; - 69E41FFA1BB1041E00D7324C /* NSDictionary+RequestEncoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+RequestEncoding.m"; sourceTree = ""; }; - 69E41FFB1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImageView+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E41FFC1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImageView+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E41FFD1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E41FFE1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E41FFF1BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIAlertView+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E420001BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIAlertView+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E420011BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+MKNetworkKitAdditions.h"; sourceTree = ""; }; - 69E420021BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+MKNetworkKitAdditions.m"; sourceTree = ""; }; - 69E420031BB1041E00D7324C /* MKNetworkEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkEngine.h; sourceTree = ""; }; - 69E420041BB1041E00D7324C /* MKNetworkEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKNetworkEngine.m; sourceTree = ""; }; - 69E420051BB1041E00D7324C /* MKNetworkKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkKit.h; sourceTree = ""; }; - 69E420061BB1041E00D7324C /* MKNetworkOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MKNetworkOperation.h; sourceTree = ""; }; - 69E420071BB1041E00D7324C /* MKNetworkOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MKNetworkOperation.m; sourceTree = ""; }; - 69E420131BB1053D00D7324C /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = ""; }; - 69E420141BB1053D00D7324C /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = ""; }; + 69E420161BB10B3D00D7324C /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; 8D7DCD461BAF859400A92AD2 /* TalkinToTheNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TalkinToTheNet.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D7DCD4A1BAF859400A92AD2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -156,150 +38,17 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 69E420171BB10B3D00D7324C /* CoreLocation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 69E41F761BB0FFCF00D7324C /* FourSquareKit */ = { - isa = PBXGroup; - children = ( - 69E41F771BB0FFCF00D7324C /* categories */, - 69E41F821BB0FFCF00D7324C /* FourSquareKit.h */, - 69E41F831BB0FFCF00D7324C /* models */, - 69E41FAF1BB0FFCF00D7324C /* networking */, - ); - path = FourSquareKit; - sourceTree = ""; - }; - 69E41F771BB0FFCF00D7324C /* categories */ = { - isa = PBXGroup; - children = ( - 69E41F781BB0FFCF00D7324C /* CLLocation+isEmpty.h */, - 69E41F791BB0FFCF00D7324C /* CLLocation+isEmpty.m */, - 69E41F7A1BB0FFCF00D7324C /* CLLocation+Testing.h */, - 69E41F7B1BB0FFCF00D7324C /* CLLocation+Testing.m */, - 69E41F7C1BB0FFCF00D7324C /* NSDictionary+PList.h */, - 69E41F7D1BB0FFCF00D7324C /* NSDictionary+PList.m */, - 69E41F7E1BB0FFCF00D7324C /* NSString+Location.h */, - 69E41F7F1BB0FFCF00D7324C /* NSString+Location.m */, - 69E41F801BB0FFCF00D7324C /* NSString+Utils.h */, - 69E41F811BB0FFCF00D7324C /* NSString+Utils.m */, - ); - path = categories; - sourceTree = ""; - }; - 69E41F831BB0FFCF00D7324C /* models */ = { - isa = PBXGroup; - children = ( - 69E41F841BB0FFCF00D7324C /* UXRBaseModel.h */, - 69E41F851BB0FFCF00D7324C /* UXRBaseModel.m */, - 69E41F861BB0FFCF00D7324C /* UXRExploreQueryBaseModel.h */, - 69E41F871BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m */, - 69E41F881BB0FFCF00D7324C /* UXRFourSquareAttributesModel.h */, - 69E41F891BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m */, - 69E41F8A1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.h */, - 69E41F8B1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m */, - 69E41F8C1BB0FFCF00D7324C /* UXRFourSquareContactModel.h */, - 69E41F8D1BB0FFCF00D7324C /* UXRFourSquareContactModel.m */, - 69E41F8E1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.h */, - 69E41F8F1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m */, - 69E41F901BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.h */, - 69E41F911BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m */, - 69E41F921BB0FFCF00D7324C /* UXRFourSquareHoursModel.h */, - 69E41F931BB0FFCF00D7324C /* UXRFourSquareHoursModel.m */, - 69E41F941BB0FFCF00D7324C /* UXRFourSquareLikesModel.h */, - 69E41F951BB0FFCF00D7324C /* UXRFourSquareLikesModel.m */, - 69E41F961BB0FFCF00D7324C /* UXRFourSquareLocationModel.h */, - 69E41F971BB0FFCF00D7324C /* UXRFourSquareLocationModel.m */, - 69E41F981BB0FFCF00D7324C /* UXRFourSquareMenuModel.h */, - 69E41F991BB0FFCF00D7324C /* UXRFourSquareMenuModel.m */, - 69E41F9A1BB0FFCF00D7324C /* UXRFourSquareOpenTime.h */, - 69E41F9B1BB0FFCF00D7324C /* UXRFourSquareOpenTime.m */, - 69E41F9C1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.h */, - 69E41F9D1BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m */, - 69E41F9E1BB0FFCF00D7324C /* UXRFourSquarePriceModel.h */, - 69E41F9F1BB0FFCF00D7324C /* UXRFourSquarePriceModel.m */, - 69E41FA01BB0FFCF00D7324C /* UXRFourSquareReservationsModel.h */, - 69E41FA11BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m */, - 69E41FA21BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.h */, - 69E41FA31BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m */, - 69E41FA41BB0FFCF00D7324C /* UXRFourSquareStatsModel.h */, - 69E41FA51BB0FFCF00D7324C /* UXRFourSquareStatsModel.m */, - 69E41FA61BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.h */, - 69E41FA71BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m */, - 69E41FA81BB0FFCF00D7324C /* UXRFourSquareTipModel.h */, - 69E41FA91BB0FFCF00D7324C /* UXRFourSquareTipModel.m */, - 69E41FAA1BB0FFCF00D7324C /* UXRFourSquareUserModel.h */, - 69E41FAB1BB0FFCF00D7324C /* UXRFourSquareUserModel.m */, - 69E41FAC1BB0FFCF00D7324C /* UXRJSONDeserializableObject.h */, - 69E41FAD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m */, - 69E41FAE1BB0FFCF00D7324C /* UXRJSONSerializableObject.h */, - ); - path = models; - sourceTree = ""; - }; - 69E41FAF1BB0FFCF00D7324C /* networking */ = { - isa = PBXGroup; - children = ( - 69E41FB01BB0FFCF00D7324C /* UXRBaseNetworkingEngine.h */, - 69E41FB11BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m */, - 69E41FB21BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.h */, - 69E41FB31BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m */, - ); - path = networking; - sourceTree = ""; - }; - 69E41FF11BB1041E00D7324C /* MKNetworkKit */ = { - isa = PBXGroup; - children = ( - 69E420121BB1053D00D7324C /* Reachability */, - 69E41FF21BB1041E00D7324C /* Categories */, - 69E420031BB1041E00D7324C /* MKNetworkEngine.h */, - 69E420041BB1041E00D7324C /* MKNetworkEngine.m */, - 69E420051BB1041E00D7324C /* MKNetworkKit.h */, - 69E420061BB1041E00D7324C /* MKNetworkOperation.h */, - 69E420071BB1041E00D7324C /* MKNetworkOperation.m */, - ); - path = MKNetworkKit; - sourceTree = ""; - }; - 69E41FF21BB1041E00D7324C /* Categories */ = { - isa = PBXGroup; - children = ( - 69E41FF31BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.h */, - 69E41FF41BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m */, - 69E41FF51BB1041E00D7324C /* NSData+MKBase64.h */, - 69E41FF61BB1041E00D7324C /* NSData+MKBase64.m */, - 69E41FF71BB1041E00D7324C /* NSDate+RFC1123.h */, - 69E41FF81BB1041E00D7324C /* NSDate+RFC1123.m */, - 69E41FF91BB1041E00D7324C /* NSDictionary+RequestEncoding.h */, - 69E41FFA1BB1041E00D7324C /* NSDictionary+RequestEncoding.m */, - 69E41FFB1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.h */, - 69E41FFC1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m */, - 69E41FFD1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.h */, - 69E41FFE1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m */, - 69E41FFF1BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.h */, - 69E420001BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m */, - 69E420011BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.h */, - 69E420021BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m */, - ); - path = Categories; - sourceTree = ""; - }; - 69E420121BB1053D00D7324C /* Reachability */ = { - isa = PBXGroup; - children = ( - 69E420131BB1053D00D7324C /* Reachability.h */, - 69E420141BB1053D00D7324C /* Reachability.m */, - ); - path = Reachability; - sourceTree = ""; - }; 8D7DCD3D1BAF859400A92AD2 = { isa = PBXGroup; children = ( + 69E420161BB10B3D00D7324C /* CoreLocation.framework */, 8D7DCD481BAF859400A92AD2 /* TalkinToTheNet */, 8D7DCD471BAF859400A92AD2 /* Products */, ); @@ -316,8 +65,6 @@ 8D7DCD481BAF859400A92AD2 /* TalkinToTheNet */ = { isa = PBXGroup; children = ( - 69E41FF11BB1041E00D7324C /* MKNetworkKit */, - 69E41F761BB0FFCF00D7324C /* FourSquareKit */, 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */, 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */, 69E41EF51BB0F5F600D7324C /* APIManager.h */, @@ -411,49 +158,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 69E41FBE1BB0FFCF00D7324C /* UXRFourSquareExploreResultsModel.m in Sources */, - 69E41FC11BB0FFCF00D7324C /* UXRFourSquareLikesModel.m in Sources */, - 69E41FB51BB0FFCF00D7324C /* CLLocation+Testing.m in Sources */, - 69E41FC51BB0FFCF00D7324C /* UXRFourSquarePhotoModel.m in Sources */, - 69E41FCF1BB0FFCF00D7324C /* UXRFourSquareNetworkingEngine.m in Sources */, 69E41EF71BB0F5F600D7324C /* APIManager.m in Sources */, - 69E4200F1BB1041E00D7324C /* UIImageView+MKNetworkKitAdditions.m in Sources */, - 69E4200D1BB1041E00D7324C /* NSString+MKNetworkKitAdditions.m in Sources */, - 69E41FB91BB0FFCF00D7324C /* UXRBaseModel.m in Sources */, - 69E4200E1BB1041E00D7324C /* UIAlertView+MKNetworkKitAdditions.m in Sources */, - 69E41FCD1BB0FFCF00D7324C /* UXRJSONDeserializableObject.m in Sources */, - 69E41FC41BB0FFCF00D7324C /* UXRFourSquareOpenTime.m in Sources */, - 69E420101BB1041E00D7324C /* MKNetworkEngine.m in Sources */, - 69E41FC01BB0FFCF00D7324C /* UXRFourSquareHoursModel.m in Sources */, - 69E4200C1BB1041E00D7324C /* NSImageView+MKNetworkKitAdditions.m in Sources */, - 69E41FCB1BB0FFCF00D7324C /* UXRFourSquareTipModel.m in Sources */, - 69E41FCE1BB0FFCF00D7324C /* UXRBaseNetworkingEngine.m in Sources */, - 69E41FB71BB0FFCF00D7324C /* NSString+Location.m in Sources */, - 69E41FC21BB0FFCF00D7324C /* UXRFourSquareLocationModel.m in Sources */, - 69E41FC71BB0FFCF00D7324C /* UXRFourSquareReservationsModel.m in Sources */, - 69E420091BB1041E00D7324C /* NSData+MKBase64.m in Sources */, - 69E41FCA1BB0FFCF00D7324C /* UXRFourSquareTimeFramesModel.m in Sources */, 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */, - 69E41FC91BB0FFCF00D7324C /* UXRFourSquareStatsModel.m in Sources */, - 69E420111BB1041E00D7324C /* MKNetworkOperation.m in Sources */, - 69E4200B1BB1041E00D7324C /* NSDictionary+RequestEncoding.m in Sources */, - 69E420081BB1041E00D7324C /* NSAlert+MKNetworkKitAdditions.m in Sources */, - 69E41FBB1BB0FFCF00D7324C /* UXRFourSquareAttributesModel.m in Sources */, - 69E41FCC1BB0FFCF00D7324C /* UXRFourSquareUserModel.m in Sources */, - 69E420151BB1053D00D7324C /* Reachability.m in Sources */, - 69E41FC61BB0FFCF00D7324C /* UXRFourSquarePriceModel.m in Sources */, - 69E4200A1BB1041E00D7324C /* NSDate+RFC1123.m in Sources */, - 69E41FC81BB0FFCF00D7324C /* UXRFourSquareRestaurantModel.m in Sources */, - 69E41FB81BB0FFCF00D7324C /* NSString+Utils.m in Sources */, - 69E41FB61BB0FFCF00D7324C /* NSDictionary+PList.m in Sources */, - 69E41FBF1BB0FFCF00D7324C /* UXRFourSquareGeoCodeModel.m in Sources */, 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */, 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */, - 69E41FB41BB0FFCF00D7324C /* CLLocation+isEmpty.m in Sources */, - 69E41FBC1BB0FFCF00D7324C /* UXRFourSquareCategoryModel.m in Sources */, - 69E41FC31BB0FFCF00D7324C /* UXRFourSquareMenuModel.m in Sources */, - 69E41FBA1BB0FFCF00D7324C /* UXRExploreQueryBaseModel.m in Sources */, - 69E41FBD1BB0FFCF00D7324C /* UXRFourSquareContactModel.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard index f56d2f3..f9440a8 100644 --- a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard +++ b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard @@ -1,13 +1,14 @@ - + - + + - + diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/FourSquareKit.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/FourSquareKit.h deleted file mode 100644 index d73bcfa..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/FourSquareKit.h +++ /dev/null @@ -1,42 +0,0 @@ - // -// FourSquareKit.h -// FourSquareKit -// -// Created by Rex St. John on 3/9/14. -// Copyright (c) 2014 UX-RX. All rights reserved. -// - -// Engines -#import "UXRFourSquareNetworkingEngine.h" -#import "UXRBaseNetworkingEngine.h" - -// Models -#import "UXRBaseModel.h" -#import "UXRExploreQueryBaseModel.h" -#import "UXRFourSquareAttributesModel.h" -#import "UXRFourSquareCategoryModel.h" -#import "UXRFourSquareContactModel.h" -#import "UXRFourSquareExploreResultsModel.h" -#import "UXRFourSquareGeoCodeModel.h" -#import "UXRFourSquareHoursModel.h" -#import "UXRFourSquareLikesModel.h" -#import "UXRFourSquareLocationModel.h" -#import "UXRFourSquareMenuModel.h" -#import "UXRFourSquareOpenTime.h" -#import "UXRFourSquarePhotoModel.h" -#import "UXRFourSquarePriceModel.h" -#import "UXRFourSquareReservationsModel.h" -#import "UXRFourSquareRestaurantModel.h" -#import "UXRFourSquareStatsModel.h" -#import "UXRFourSquareTimeFramesModel.h" -#import "UXRFourSquareTipModel.h" -#import "UXRFourSquareUserModel.h" -#import "UXRJSONDeserializableObject.h" -#import "UXRJSONSerializableObject.h" - -// Categories. -#import "CLLocation+isEmpty.h" -#import "CLLocation+Testing.h" -#import "NSDictionary+PList.h" -#import "NSString+Location.h" -#import "NSString+Utils.h" \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.h deleted file mode 100644 index c6570d8..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// CLLocation+Testing.h -// UXRX -// -// Created by Rex St John on 2/8/13. -// Copyright (c) 2013 UXRX. All rights reserved. -// - -#import - -@interface CLLocation (Testing) - -+(CLLocation*)locationInSeattle; -+(CLLocation*)locationInNewYork; -+(CLLocation*)locationInSanFransisco; -+(CLLocation*)locationInBoston; -+(CLLocation*)locationInMiami; -+(CLLocation*)locationInLondon; -+(CLLocation*)randomMajorCity; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.m deleted file mode 100644 index 8f2f2c3..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+Testing.m +++ /dev/null @@ -1,63 +0,0 @@ -// -// CLLocation+Testing.m -// UXRX -// -// Created by Rex St John on 2/8/13. -// Copyright (c) 2013 UXRX. All rights reserved. -// - -#import "CLLocation+Testing.h" - -@implementation CLLocation (Testing) - -+(CLLocation*)locationInSeattle{ - CLLocationDegrees lat = 47.6097; - CLLocationDegrees lon = -122.3331; - CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; - return someLocation; -} - -+(CLLocation*)locationInNewYork{ - CLLocationDegrees lat = 40.7142; - CLLocationDegrees lon = -74.0064; - CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; - return someLocation; -} - -+(CLLocation*)locationInSanFransisco{ - CLLocationDegrees lat = 37.7750; - CLLocationDegrees lon = -122.4183; - CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; - return someLocation; -} - -+(CLLocation*)locationInBoston{ - CLLocationDegrees lat = 42.3583; - CLLocationDegrees lon = -71.0603; - CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; - return someLocation; -} - -+(CLLocation*)locationInMiami{ - CLLocationDegrees lat = 25.4716; - CLLocationDegrees lon = -80.1327; - CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; - return someLocation; -} - -+(CLLocation*)locationInLondon{ - CLLocationDegrees lat = 51.5171; - CLLocationDegrees lon = -0.1062; - CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; - return someLocation; -} - -+(CLLocation*)randomMajorCity{ - //RSJ: Not yet implemented. - CLLocationDegrees lat = 47.6097; - CLLocationDegrees lon = -122.3331; - CLLocation *someLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; - return someLocation; -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.h deleted file mode 100644 index 8c3a4a6..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// CLLocation+isEmpty.h -// UXRX -// -// Created by JASON CROSS on 3/21/13. -// Copyright (c) 2013 UXRX. All rights reserved. -// - -#import - -@interface CLLocation (isEmpty) -+ (BOOL) isEmpty:(CLLocation*)thing; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.m deleted file mode 100644 index 220005e..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/CLLocation+isEmpty.m +++ /dev/null @@ -1,17 +0,0 @@ -// -// CLLocation+isEmpty.m -// UXRX -// -// Created by JASON CROSS on 3/21/13. -// Copyright (c) 2013 UXRX. All rights reserved. -// - -#import "CLLocation+isEmpty.h" - -@implementation CLLocation (isEmpty) - -+ (BOOL) isEmpty:(CLLocation*)thing; { - return (nil == thing) || (thing.coordinate.latitude == 0) || (thing.coordinate.longitude == 0); -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.h deleted file mode 100644 index 3d6587e..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// NSDictionary+PList.h -// UXRX -// -// Created by Rex St John on 6/7/13. -// Copyright (c) 2013 UXRX. All rights reserved. -// - -#import - -@interface NSDictionary (PList) - -+(NSDictionary*)dictionaryFromPlistWithName:(NSString*)plistName; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.m deleted file mode 100644 index 62b8559..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSDictionary+PList.m +++ /dev/null @@ -1,21 +0,0 @@ -// -// NSDictionary+PList.m -// UXRX -// -// Created by Rex St John on 6/7/13. -// Copyright (c) 2013 UXRX. All rights reserved. -// - -#import "NSDictionary+PList.h" - -@implementation NSDictionary (PList) - -+(NSDictionary*)dictionaryFromPlistWithName:(NSString*)plistName{ - // Path to the plist (in the application bundle) - NSString *path = [[NSBundle mainBundle] pathForResource: - plistName ofType:@"plist"]; - - return [[NSDictionary alloc] initWithContentsOfFile:path]; -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.h deleted file mode 100644 index 6020b6f..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// NSString+Location.h -// UXRX -// -// Category methods for producing stringified location data. -// -// Created by Rex St John on 10/18/12. -// Copyright (c) 2012 UXRX. All rights reserved. -// - -#import - -@class CLLocation; - -@interface NSString (Location) - -// Produces a string from a location e.g. latitude and longitude in string format. -+ (NSString *)stringFromLocation:(CLLocation *)location; - -+ (NSString *) milesToString:(float) miles inCountry:(NSString *)country; - -+ (CLLocation *)locationFromString:(NSString *)locString; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.m deleted file mode 100644 index ef0880c..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Location.m +++ /dev/null @@ -1,48 +0,0 @@ -// -// NSString+Location.m -// UXRX -// -// Created by Rex St John on 10/18/12. -// Copyright (c) 2012 UXRX. All rights reserved. -// - -#import "NSString+Location.h" -#import -#import "NSString+Utils.h" - -@implementation NSString (Location) - -+ (NSString *)stringFromLocation:(CLLocation *)location { - return [NSString stringWithFormat:@"%.6f,%.6f", location.coordinate.latitude, location.coordinate.longitude]; -} - -+ (NSString *) milesToString:(float) miles inCountry:(NSString *)country { - BOOL mi = [country isEqual:@"UK"] || [country isEqual:@"US"]; - if (mi) { - return [NSString stringWithFormat:@"%.2fmi", miles]; - } - else { - return [NSString stringWithFormat:@"%.2fkm", miles * 1.609344]; - } -} - -+ (CLLocation *)locationFromString:(NSString *)locString { - if (!locString) { - return nil; - } - - int comma = [NSString indexOf:locString andSubString: @","]; - if (comma == -1) { - return nil; - } - CLLocation *location = [[CLLocation alloc] initWithLatitude:[[locString substringToIndex:comma] doubleValue] - longitude:[[locString substringFromIndex:comma + 1] doubleValue]]; - return location; -} - -NSString *stringFromLocation(CLLocation *location) { - return [NSString stringWithFormat:@"%.6f,%.6f", location.coordinate.latitude, location.coordinate.longitude]; -} - - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.h deleted file mode 100644 index cfca90c..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// NSString+Utils.h -// UXRX -// -// Created by Rex St John on 1/10/13. -// Copyright (c) 2013 UXRX. All rights reserved. -// - -#import - -@interface NSString (Utils) - -+(NSString *)join:(NSArray *)strings andSeperator:( NSString *)separator; -+(NSArray *)split:(NSString *)s andSeperator:(NSString *)separator; -+(int) indexOf:(NSString *)haystack andSubString:(NSString *)needle; -+(BOOL) contains:(NSString *)haystack andSubString:(NSString *)needle; -+(BOOL) startsWith:(NSString *)haystack andSubString:( NSString *)needle; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.m deleted file mode 100644 index 42e4241..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/categories/NSString+Utils.m +++ /dev/null @@ -1,49 +0,0 @@ -// -// NSString+Utils.m -// UXRX -// -// Created by Rex St John on 1/10/13. -// Copyright (c) 2013 UXRX. All rights reserved. -// - -#import "NSString+Utils.h" - -@implementation NSString (Utils) - -+(NSString *)join:(NSArray *)strings andSeperator:( NSString *)separator { - if (strings.count == 0) { - return @""; - } - - NSString *result = nil; - for (NSString *i in strings) { - if (result == nil) { - result = i; - } - else { - result = [result stringByAppendingFormat:@"%@%@", separator, i]; - } - } - return result; -} - -+(NSArray *)split:(NSString *)s andSeperator:(NSString *)separator{ - if (s.length == 0) { - return [NSMutableArray arrayWithCapacity:0]; - } - return [s componentsSeparatedByString:separator]; -} - -+(int) indexOf:(NSString *)haystack andSubString:(NSString *)needle{ - NSUInteger location = [haystack rangeOfString:needle].location; - return (location != NSNotFound) ? location : -1; -} - -+(BOOL) contains:(NSString *)haystack andSubString:(NSString *)needle { - return [NSString indexOf:haystack andSubString: needle] != -1; -} - -+(BOOL) startsWith:(NSString *)haystack andSubString:( NSString *)needle{ - return [NSString indexOf:haystack andSubString: needle] == 0; -} -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.h deleted file mode 100644 index 09d6283..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// UXRBaseModel.h -// FourSquareKit -// -// Created by Rex St. John on 12/19/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRJSONDeserializableObject.h" - -@interface UXRBaseModel : UXRJSONDeserializableObject - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.m deleted file mode 100644 index 8ce98b0..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRBaseModel.m +++ /dev/null @@ -1,17 +0,0 @@ -// -// UXRBaseModel.m -// FourSquareKit -// -// Created by Rex St. John on 12/19/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@implementation UXRBaseModel - - --(void)setId:(id)someId{ - // prevent trying to set our Id again -} -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.h deleted file mode 100644 index 906f0c3..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// UXRExploreQueryBaseModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/26/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" -#import "UXRFourSquareGeoCodeModel.h" - -@interface UXRExploreQueryBaseModel : UXRBaseModel -@property(nonatomic,strong) UXRFourSquareGeoCodeModel *geocode; -@property(nonatomic,strong) NSString *headerLocation; -@property(nonatomic,strong) NSString *headerFullLocation; -@property(nonatomic,strong) NSString *headerLocationGranularity; -@property(nonatomic,strong) NSString *query; -@property(nonatomic,strong) NSNumber *totalResults; -@property(nonatomic,strong) NSArray *groups; -@property(nonatomic,strong) NSArray *venues; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.m deleted file mode 100644 index 87bd646..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRExploreQueryBaseModel.m +++ /dev/null @@ -1,52 +0,0 @@ -// -// UXRExploreQueryBaseModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/26/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRExploreQueryBaseModel.h" -#import "UXRFourSquareExploreResultsModel.h" - -@implementation UXRExploreQueryBaseModel - -- (void) setGeocode:(id)geocode{ - if (nil == geocode) { - _geocode = nil; - } - else if ([geocode isKindOfClass:[UXRFourSquareGeoCodeModel class]]) { - _geocode = geocode; - } - else if ([geocode isKindOfClass:[NSDictionary class]]) { - _geocode = [[UXRFourSquareGeoCodeModel alloc] initWithDictionary:geocode]; - } -} - --(void)setGroups:(id)groups{ - if (nil == groups) { - _groups = nil; - } - else if ([groups isKindOfClass:[NSArray class]]) { - - NSMutableArray *resultsArray = [[NSMutableArray alloc] init]; - NSMutableArray *venuesArray =[[NSMutableArray alloc] init]; - - for(id group in groups){ - - NSArray *items = (NSArray*)[group objectForKey:@"items"]; - - for(id entry in items){ - if([entry isKindOfClass:[NSDictionary class]]){ - UXRFourSquareExploreResultsModel *result = [[UXRFourSquareExploreResultsModel alloc] initWithDictionary:entry]; - [resultsArray addObject:result]; - [venuesArray addObject:result.venue]; - } - } - } - _venues = venuesArray; - _groups = (NSArray*)resultsArray; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.h deleted file mode 100644 index 2496782..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// UXRFourSquareAttributesModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/28/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareAttributesModel : UXRBaseModel - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.m deleted file mode 100644 index 3f185b5..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareAttributesModel.m +++ /dev/null @@ -1,65 +0,0 @@ -// -// UXRFourSquareAttributesModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/28/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -/* - attributes = { - groups = ( - { - count = 1; - items = ( - { - displayName = Price; - displayValue = "$$ (from category)"; - priceTier = 2; - } - ); - name = Price; - summary = "$$"; - type = price; - }, - { - count = 6; - items = ( - { - displayName = "Credit Cards"; - displayValue = Yes; - } - ); - name = "Credit Cards"; - summary = "Credit Cards"; - type = payments; - }, - { - count = 8; - items = ( - { - displayName = Breakfast; - displayValue = Breakfast; - }, - { - displayName = Brunch; - displayValue = Brunch; - }, - { - displayName = Dinner; - displayValue = Dinner; - } - ); - name = Menus; - summary = "Dinner, Brunch & more"; - type = serves; - } - ); - }; - */ - -#import "UXRFourSquareAttributesModel.h" - -@implementation UXRFourSquareAttributesModel - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.h deleted file mode 100644 index b63a86b..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// UXRFourSquareCategoryModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" -#import "UXRFourSquarePhotoModel.h" - -@interface UXRFourSquareCategoryModel : UXRBaseModel - -@property(nonatomic,strong) NSString *name; -@property(nonatomic,strong) UXRFourSquarePhotoModel *icon; -@property(nonatomic,strong) NSString *pluralName; -@property(nonatomic,strong) NSNumber *primary; -@property(nonatomic,strong) NSString *shortName; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.m deleted file mode 100644 index 870a614..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareCategoryModel.m +++ /dev/null @@ -1,25 +0,0 @@ -// -// UXRFourSquareCategoryModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareCategoryModel.h" - -@implementation UXRFourSquareCategoryModel - -- (void) setIcon:(id)icon{ - if (nil == icon) { - _icon = nil; - } - else if ([icon isKindOfClass:[UXRFourSquarePhotoModel class]]) { - _icon = icon; - } - else if ([icon isKindOfClass:[NSDictionary class]]) { - _icon = [[UXRFourSquarePhotoModel alloc ] initWithDictionary:icon]; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.h deleted file mode 100644 index feb8e65..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// UXRFourSquareContactModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareContactModel : UXRBaseModel -@property(nonatomic,strong) NSString *phone; -@property(nonatomic,strong) NSString *formattedPhone; -@property(nonatomic,strong) NSString *twitter; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.m deleted file mode 100644 index 5165149..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareContactModel.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// UXRFourSquareContactModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareContactModel.h" - -@implementation UXRFourSquareContactModel - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.h deleted file mode 100644 index d10bf73..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// UXRFourSquareReasonsModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/26/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" -#import "UXRFourSquareRestaurantModel.h" - -@interface UXRFourSquareExploreResultsModel : UXRBaseModel -@property(nonatomic,strong) NSArray *tips; -@property(nonatomic,strong) NSArray *reasons; -@property(nonatomic,strong) NSString *referralId; -@property(nonatomic,strong) UXRFourSquareRestaurantModel *venue; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.m deleted file mode 100644 index f28cf96..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareExploreResultsModel.m +++ /dev/null @@ -1,42 +0,0 @@ -// -// UXRFourSquareReasonsModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/26/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareExploreResultsModel.h" -#import "UXRFourSquareTipModel.h" -#import "UXRFourSquareRestaurantModel.h" - -@implementation UXRFourSquareExploreResultsModel - -- (void) setTips:(id)tips { - if (nil == tips) { - _tips = nil; - } else if ([tips isKindOfClass:[NSArray class]]){ - NSMutableArray *resultsMutableArray = [[NSMutableArray alloc] initWithCapacity:((NSArray*)tips).count]; - for(id entry in tips){ - if([entry isKindOfClass:[NSDictionary class]]){ - UXRFourSquareTipModel *tip = [[UXRFourSquareTipModel alloc] initWithDictionary:entry]; - [resultsMutableArray addObject:tip]; - } - } - _tips = (NSArray*)resultsMutableArray; - } -} - -- (void) setVenue:(id)venue{ - if (nil == venue) { - _venue = nil; - } - else if ([venue isKindOfClass:[UXRFourSquareContactModel class]]) { - _venue = venue; - } - else if ([venue isKindOfClass:[NSDictionary class]]) { - _venue = [[UXRFourSquareRestaurantModel alloc ] initWithDictionary:venue]; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.h deleted file mode 100644 index 59881b7..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// UXRGeoCodeModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/26/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareGeoCodeModel : UXRBaseModel -@property(nonatomic,strong) NSNumber *longId; -@property(nonatomic,strong) NSString *displayString; -@property(nonatomic,strong) NSString *slug; -@property(nonatomic,strong) NSString *cc; -@property(nonatomic,strong) NSString *what; -@property(nonatomic,strong) NSString *where; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.m deleted file mode 100644 index 722e4c0..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareGeoCodeModel.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// UXRGeoCodeModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/26/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareGeoCodeModel.h" - -@implementation UXRFourSquareGeoCodeModel - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.h deleted file mode 100644 index 78e0f3d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// UXRFourSquareHoursModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareHoursModel : UXRBaseModel -@property(nonatomic,assign) BOOL isOpen; -@property(nonatomic,strong) NSString *status; -@property(nonatomic,strong) NSArray *timeframes; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.m deleted file mode 100644 index 7999120..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareHoursModel.m +++ /dev/null @@ -1,31 +0,0 @@ -// -// UXRFourSquareHoursModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareHoursModel.h" -#import "UXRFourSquareTimeFramesModel.h" - -@implementation UXRFourSquareHoursModel - -- (void) setTimeframes:(id)timeframes { - if (nil == timeframes) { - _timeframes = nil; - } - else if ([timeframes isKindOfClass:[NSArray class]]) { - NSArray *categoriesArray = (NSArray*)timeframes; - NSMutableArray *mutableCategories = [[NSMutableArray alloc] initWithCapacity:categoriesArray.count]; - for(id entry in categoriesArray){ - if([entry isKindOfClass:[NSDictionary class]]){ - UXRFourSquareTimeFramesModel *category = [[UXRFourSquareTimeFramesModel alloc] initWithDictionary:entry]; - [mutableCategories addObject:category]; - } - } - _timeframes = (NSArray*)mutableCategories; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.h deleted file mode 100644 index 1d43cbe..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// UXRFourSquareLikesModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareLikesModel : UXRBaseModel -@property(nonatomic,strong) NSNumber *count; -@property(nonatomic,strong) NSString *summary; -@property(nonatomic,strong) NSArray *groups; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.m deleted file mode 100644 index 43024fc..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLikesModel.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// UXRFourSquareLikesModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareLikesModel.h" - -@implementation UXRFourSquareLikesModel - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.h deleted file mode 100644 index d89624f..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// UXRFourSquareLocationModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareLocationModel : UXRBaseModel -@property(nonatomic,strong) NSString *address; -@property(nonatomic,strong) NSString *cc; -@property(nonatomic,strong) NSString *city; -@property(nonatomic,strong) NSString *country; -@property(nonatomic,strong) NSString *crossStreet; -@property(nonatomic,strong) NSNumber *lat; -@property(nonatomic,strong) NSNumber *lng; -@property(nonatomic,strong) NSNumber *postalCode; -@property(nonatomic,strong) NSString *state; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.m deleted file mode 100644 index 9ff3a7e..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareLocationModel.m +++ /dev/null @@ -1,14 +0,0 @@ -// -// UXRFourSquareLocationModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareLocationModel.h" - -@implementation UXRFourSquareLocationModel - - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.h deleted file mode 100644 index 04166a7..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// UXRFourSquareMenuModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareMenuModel : UXRBaseModel -@property(nonatomic,strong) NSString *type; -@property(nonatomic,strong) NSString *label; -@property(nonatomic,strong) NSString *anchor; -@property(nonatomic,strong) NSURL *url; -@property(nonatomic,strong) NSURL *mobileUrl; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.m deleted file mode 100644 index fbbee5d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareMenuModel.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// UXRFourSquareMenuModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareMenuModel.h" - -@implementation UXRFourSquareMenuModel - -- (void) setUrl:(id)url { - if (nil == url) { - _url = nil; - } - else if ([url isKindOfClass:[NSURL class]]) { - _url = url; - } - else if ([url isKindOfClass:[NSString class]]) { - _url = [NSURL URLWithString:url]; - } -} - -- (void) setMobileUrl:(id)url { - if (nil == url) { - _mobileUrl = nil; - } - else if ([url isKindOfClass:[NSURL class]]) { - _mobileUrl = url; - } - else if ([url isKindOfClass:[NSString class]]) { - _mobileUrl = [NSURL URLWithString:url]; - } -} -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.h deleted file mode 100644 index 8b4ab52..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// UXRFourSquareOpenTime.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/26/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareOpenTime : UXRBaseModel -@property(nonatomic,strong) NSString *renderedTime; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.m deleted file mode 100644 index 6d6ad41..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareOpenTime.m +++ /dev/null @@ -1,12 +0,0 @@ -// -// UXRFourSquareOpenTime.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/26/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareOpenTime.h" - -@implementation UXRFourSquareOpenTime -@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.h deleted file mode 100644 index 2ac5818..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// UXRFourSquarePhotoModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" -@class UXRFourSquareUserModel; - -@interface UXRFourSquarePhotoModel : UXRBaseModel -@property(nonatomic,strong) NSNumber *createdAt; -@property(nonatomic,strong) NSNumber *height; -@property(nonatomic,strong) NSNumber *width; -@property(nonatomic,strong) NSURL *prefix; -@property(nonatomic,assign) BOOL containsFace; -@property(nonatomic,strong) NSString *suffix; -@property(nonatomic,strong) UXRFourSquareUserModel *user; -@property(nonatomic,strong) NSString *visibility; --(NSURL*)fullPhotoURL; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.m deleted file mode 100644 index b5b99cc..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePhotoModel.m +++ /dev/null @@ -1,63 +0,0 @@ -// -// UXRFourSquarePhotoModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquarePhotoModel.h" -#import "UXRFourSquareUserModel.h" - -@implementation UXRFourSquarePhotoModel - -- (void) setPrefix:(id)url { - if (nil == url) { - _prefix = nil; - } - else if ([url isKindOfClass:[NSURL class]]) { - _prefix = url; - } - else if ([url isKindOfClass:[NSString class]]) { - _prefix = [NSURL URLWithString:url]; - } -} - -- (void) setUser:(id)user { - if (nil == user) { - _user = nil; - } - else if ([user isKindOfClass:[UXRFourSquareUserModel class]]) { - _user = user; - } - else if ([user isKindOfClass:[NSDictionary class]]) { - _user = [[UXRFourSquareUserModel alloc ] initWithDictionary:user]; - } -} - --(NSURL*)fullPhotoURL{ - /* - Ending of the URL for this photo. - - To assemble a resolvable photo URL, take prefix + size + suffix, e.g. https://irs0.4sqi.net/img/general/300x500/2341723_vt1Kr-SfmRmdge-M7b4KNgX2_PHElyVbYL65pMnxEQw.jpg. - - size can be one of the following, where XX or YY is one of 36, 100, 300, or 500. - XXxYY - original: the original photo's size - capXX: cap the photo with a width or height of XX (whichever is larger). Scales the other, smaller dimension proportionally - widthXX: forces the width to be XX and scales the height proportionally - heightYY: forces the height to be YY and scales the width proportionally - */ - //https://developer.foursquare.com/docs/responses/photo - NSString *size = @"500x500"; - NSString *fullUrl = [NSString stringWithFormat:@"%@%@%@", [self.prefix absoluteString],size,self.suffix ]; - return [NSURL URLWithString:fullUrl]; -} - -#pragma mark - Photo Delegate Methods - --(NSURL*)photoDownloadURL{ - return [self fullPhotoURL]; -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.h deleted file mode 100644 index 99aecd5..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// UXRFourSquarePriceModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquarePriceModel : UXRBaseModel -@property(nonatomic,strong) NSNumber *tier; -@property(nonatomic,strong) NSString *message; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.m deleted file mode 100644 index aad3b49..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquarePriceModel.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// UXRFourSquarePriceModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquarePriceModel.h" - -@implementation UXRFourSquarePriceModel - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.h deleted file mode 100644 index 155bdb7..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// UXRFourSquareReservationsModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareReservationsModel : UXRBaseModel -@property(nonatomic,strong) NSURL *url; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.m deleted file mode 100644 index 3a7a6fe..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareReservationsModel.m +++ /dev/null @@ -1,25 +0,0 @@ -// -// UXRFourSquareReservationsModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareReservationsModel.h" - -@implementation UXRFourSquareReservationsModel - -- (void) setUrl:(id)url { - if (nil == url) { - _url = nil; - } - else if ([url isKindOfClass:[NSURL class]]) { - _url = url; - } - else if ([url isKindOfClass:[NSString class]]) { - _url = [NSURL URLWithString:url]; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.h deleted file mode 100644 index 98cc6ea..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// UXRFourSquareRestaurantModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -#import "UXRFourSquareLocationModel.h" -#import "UXRFourSquareStatsModel.h" -#import "UXRFourSquareHoursModel.h" -#import "UXRFourSquarePriceModel.h" -#import "UXRFourSquareMenuModel.h" -#import "UXRFourSquareReservationsModel.h" -#import "UXRFourSquareContactModel.h" - -@interface UXRFourSquareRestaurantModel : UXRBaseModel -@property(nonatomic,strong) NSArray *categories; -@property(nonatomic,strong) NSArray *photos; -@property(nonatomic,strong) UXRFourSquareLocationModel *location; -@property(nonatomic,strong) NSString *name; -@property(nonatomic,strong) NSString *description; -@property(nonatomic,strong) NSString *timeZone; -@property(nonatomic,strong) NSNumber *dislike; -@property(nonatomic,strong) NSNumber *rating; -@property(nonatomic,strong) NSArray *specials; -@property(nonatomic,strong) NSArray *tips; -@property(nonatomic,strong) UXRFourSquareStatsModel *stats; -@property(nonatomic,strong) NSURL *url; -@property(nonatomic,strong) NSURL *canonicalUrl; -@property(nonatomic,strong) NSURL *shortUrl; -@property(nonatomic,strong) UXRFourSquareHoursModel *hours; -@property(nonatomic,strong) UXRFourSquareMenuModel *menu; -@property(nonatomic,assign) BOOL verified; -@property(nonatomic,assign) BOOL restricted; -@property(nonatomic,strong) UXRFourSquarePriceModel* price; -@property(nonatomic,strong) UXRFourSquareReservationsModel* reservations; -@property(nonatomic,strong) UXRFourSquareContactModel *contact; -@property(nonatomic,strong) NSString *restaurantId; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.m deleted file mode 100644 index c8c659b..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareRestaurantModel.m +++ /dev/null @@ -1,221 +0,0 @@ -// -// UXRFourSquareRestaurantModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareRestaurantModel.h" -#import "UXRFourSquareCategoryModel.h" -#import "UXRFourSquarePhotoModel.h" -#import -#import "UXRFourSquareTipModel.h" - -@implementation UXRFourSquareRestaurantModel - -- (void) setCategories:(id)categories { - if (nil == categories) { - _categories = nil; - } - else if ([categories isKindOfClass:[NSArray class]]) { - NSArray *categoriesArray = (NSArray*)categories; - NSMutableArray *mutableCategories = [[NSMutableArray alloc] initWithCapacity:categoriesArray.count]; - for(id entry in categoriesArray){ - if([entry isKindOfClass:[NSDictionary class]]){ - UXRFourSquareCategoryModel *category = [[UXRFourSquareCategoryModel alloc] initWithDictionary:entry]; - [mutableCategories addObject:category]; - } - } - _categories = (NSArray*)mutableCategories; - } -} - -- (void) setPhotos:(id)photos { - if (nil == photos) { - _photos = nil; - } else if ([photos isKindOfClass:[NSArray class]]){ - _photos = photos; - } - else if ([photos isKindOfClass:[NSDictionary class]]) { - - NSArray *photoGroups = (NSArray*)[photos objectForKey:@"groups"]; - NSMutableArray *photosMutableArray = [[NSMutableArray alloc] init]; - - for(NSDictionary *group in photoGroups){ - NSArray *itemPhotos = (NSArray*)[group objectForKey:@"items"]; - for(id itemPhoto in itemPhotos){ - [photosMutableArray addObject:itemPhoto]; - } - } - - NSMutableArray *photosResultsArray = [[NSMutableArray alloc] initWithCapacity:photosMutableArray.count]; - for(id entry in photosMutableArray){ - if([entry isKindOfClass:[NSDictionary class]]){ - UXRFourSquarePhotoModel *photo = [[UXRFourSquarePhotoModel alloc] initWithDictionary:entry]; - [photosResultsArray addObject:photo]; - } - } - _photos = (NSArray*)photosResultsArray; - } -} - -- (void) setTips:(id)tips { - if (nil == tips) { - _tips = nil; - } else if ([tips isKindOfClass:[NSArray class]]){ - _tips = tips; - } - else if ([tips isKindOfClass:[NSDictionary class]]) { - - NSArray *groups = (NSArray*)[tips objectForKey:@"groups"]; - NSMutableArray *groupsMutableArray = [[NSMutableArray alloc] init]; - - for(NSDictionary *group in groups){ - NSArray *items = (NSArray*)[group objectForKey:@"items"]; - for(id item in items){ - [groupsMutableArray addObject:item]; - } - } - - NSMutableArray *resultsMutableArray = [[NSMutableArray alloc] initWithCapacity:groupsMutableArray.count]; - for(id entry in groupsMutableArray){ - if([entry isKindOfClass:[NSDictionary class]]){ - UXRFourSquareTipModel *tip = [[UXRFourSquareTipModel alloc] initWithDictionary:entry]; - [resultsMutableArray addObject:tip]; - } - } - _tips = (NSArray*)resultsMutableArray; - } -} - -- (void) setContact:(id)contact{ - if (nil == contact) { - _contact = nil; - } - else if ([contact isKindOfClass:[UXRFourSquareContactModel class]]) { - _contact = contact; - } - else if ([contact isKindOfClass:[NSDictionary class]]) { - _contact = [[UXRFourSquareContactModel alloc ] initWithDictionary:contact]; - } -} - -- (void) setStats:(id)stats{ - if (nil == stats) { - _stats = nil; - } - else if ([stats isKindOfClass:[UXRFourSquareStatsModel class]]) { - _stats = stats; - } - else if ([stats isKindOfClass:[NSDictionary class]]) { - _stats = [[UXRFourSquareStatsModel alloc ] initWithDictionary:stats]; - } -} - -- (void) setLocation:(id)location { - if (nil == location) { - _location = nil; - } - else if ([location isKindOfClass:[UXRFourSquareLocationModel class]]) { - _location = location; - } - else if ([location isKindOfClass:[NSDictionary class]]) { - _location = [[UXRFourSquareLocationModel alloc ] initWithDictionary:location]; - } -} - -- (void) setMenu:(id)menu { - if (nil == menu) { - _menu = nil; - } - else if ([menu isKindOfClass:[UXRFourSquareMenuModel class]]) { - _menu = menu; - } - else if ([menu isKindOfClass:[NSDictionary class]]) { - _menu = [[UXRFourSquareMenuModel alloc ] initWithDictionary:menu]; - } -} - -- (void) setReservations:(id)reservations { - if (nil == reservations) { - _reservations = nil; - } - else if ([reservations isKindOfClass:[UXRFourSquareReservationsModel class]]) { - _reservations = reservations; - } - else if ([reservations isKindOfClass:[NSDictionary class]]) { - _reservations = [[UXRFourSquareReservationsModel alloc ] initWithDictionary:reservations]; - } -} - -- (void) setHours:(id)hours { - if (nil == hours) { - _hours = nil; - } - else if ([hours isKindOfClass:[UXRFourSquareHoursModel class]]) { - _hours = hours; - } - else if ([hours isKindOfClass:[NSDictionary class]]) { - _hours = [[UXRFourSquareHoursModel alloc ] initWithDictionary:hours]; - } -} - -- (void) setPrice:(id)price { - if (nil == price) { - _price = nil; - } - else if ([price isKindOfClass:[UXRFourSquarePriceModel class]]) { - _price = price; - } - else if ([price isKindOfClass:[NSDictionary class]]) { - _price = [[UXRFourSquarePriceModel alloc ] initWithDictionary:price]; - } -} - -- (void) setShortUrl:(id)url { - if (nil == url) { - _shortUrl = nil; - } - else if ([url isKindOfClass:[NSURL class]]) { - _shortUrl = url; - } - else if ([url isKindOfClass:[NSString class]]) { - _shortUrl = [NSURL URLWithString:url]; - } -} - -- (void) setUrl:(id)url { - if (nil == url) { - _url = nil; - } - else if ([url isKindOfClass:[NSURL class]]) { - _url = url; - } - else if ([url isKindOfClass:[NSString class]]) { - _url = [NSURL URLWithString:url]; - } -} - -- (void) setCanonicalUrl:(id)url { - if (nil == url) { - _canonicalUrl = nil; - } - else if ([url isKindOfClass:[NSURL class]]) { - _canonicalUrl = url; - } - else if ([url isKindOfClass:[NSString class]]) { - _canonicalUrl = [NSURL URLWithString:url]; - } -} - --(void)setId:(id)possibleId{ - if (nil == possibleId) { - _restaurantId = nil; - } - else if ([possibleId isKindOfClass:[NSString class]]) { - _restaurantId = possibleId; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.h deleted file mode 100644 index 64fa170..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// UXRFourSquareStatsModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareStatsModel : UXRBaseModel - -@property(nonatomic,strong) NSNumber *usersCount; -@property(nonatomic,strong) NSNumber *checkinsCount; -@property(nonatomic,strong) NSNumber *tipCount; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.m deleted file mode 100644 index c3be7e9..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareStatsModel.m +++ /dev/null @@ -1,12 +0,0 @@ -// -// UXRFourSquareStatsModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareStatsModel.h" - -@implementation UXRFourSquareStatsModel -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.h deleted file mode 100644 index b01b267..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// UXRFourSquareTimeFramesModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" - -@interface UXRFourSquareTimeFramesModel : UXRBaseModel -@property(nonatomic,strong) NSString *days; -@property(nonatomic,assign) BOOL includesToday; -@property(nonatomic,strong) NSArray *open; -@property(nonatomic,strong) NSArray *segments; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.m deleted file mode 100644 index a1dc15d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTimeFramesModel.m +++ /dev/null @@ -1,31 +0,0 @@ -// -// UXRFourSquareTimeFramesModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareTimeFramesModel.h" -#import "UXRFourSquareOpenTime.h" - -@implementation UXRFourSquareTimeFramesModel - -- (void) setOpen:(id)open{ - if (nil == open) { - _open = nil; - } - else if ([open isKindOfClass:[NSArray class]]) { - NSArray *resultsArray = (NSArray*)open; - NSMutableArray *mutableOpens = [[NSMutableArray alloc] initWithCapacity:resultsArray.count]; - for(id entry in resultsArray){ - if([entry isKindOfClass:[NSDictionary class]]){ - UXRFourSquareOpenTime *opentime = [[UXRFourSquareOpenTime alloc] initWithDictionary:entry]; - [mutableOpens addObject:opentime]; - } - } - _open = (NSArray*)mutableOpens; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.h deleted file mode 100644 index ff01edf..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// UXRFourSquareCommentModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" -#import "UXRFourSquareUserModel.h" -#import "UXRFourSquareLikesModel.h" - -@interface UXRFourSquareTipModel : UXRBaseModel -@property(nonatomic,strong) NSNumber *createdAt; -@property(nonatomic,strong) NSString *text; -@property(nonatomic,strong) NSURL *canonicalUrl; -@property(nonatomic,strong) UXRFourSquareUserModel *user; -@property(nonatomic,strong) UXRFourSquareLikesModel *likes; -@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.m deleted file mode 100644 index d338bb8..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareTipModel.m +++ /dev/null @@ -1,50 +0,0 @@ -// -// UXRFourSquareCommentModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/23/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareTipModel.h" - -@implementation UXRFourSquareTipModel - - -- (void) setUser:(id)user { - if (nil == user) { - _user = nil; - } - else if ([user isKindOfClass:[UXRFourSquareUserModel class]]) { - _user = user; - } - else if ([user isKindOfClass:[NSDictionary class]]) { - _user = [[UXRFourSquareUserModel alloc ] initWithDictionary:user]; - } -} - -- (void) setCanonicalUrl:(id)url { - if (nil == url) { - _canonicalUrl = nil; - } - else if ([url isKindOfClass:[NSURL class]]) { - _canonicalUrl = url; - } - else if ([url isKindOfClass:[NSString class]]) { - _canonicalUrl = [NSURL URLWithString:url]; - } -} - -- (void) setLikes:(id)likes { - if (nil == likes) { - _likes = nil; - } - else if ([likes isKindOfClass:[NSURL class]]) { - _likes = likes; - } - else if ([likes isKindOfClass:[NSDictionary class]]) { - _likes = [[UXRFourSquareLikesModel alloc] initWithDictionary:likes]; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.h deleted file mode 100644 index fdb3faa..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// UXRFourSquareUserModel.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseModel.h" -@class UXRFourSquarePhotoModel; - -@interface UXRFourSquareUserModel : UXRBaseModel -@property(nonatomic,strong) NSString *firstName; -@property(nonatomic,strong) NSString *gender; -@property(nonatomic,strong) NSString *lastName; -@property(nonatomic,strong) UXRFourSquarePhotoModel *photo; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.m deleted file mode 100644 index 9e4cc53..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRFourSquareUserModel.m +++ /dev/null @@ -1,26 +0,0 @@ -// -// UXRFourSquareUserModel.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/20/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareUserModel.h" -#import "UXRFourSquarePhotoModel.h" - -@implementation UXRFourSquareUserModel - -- (void) setPhoto:(id)photo { - if (nil == photo) { - _photo = nil; - } - else if ([photo isKindOfClass:[UXRFourSquarePhotoModel class]]) { - _photo = photo; - } - else if ([photo isKindOfClass:[NSDictionary class]]) { - _photo = [[UXRFourSquarePhotoModel alloc] initWithDictionary:photo]; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.h deleted file mode 100644 index cd0bd2d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.h +++ /dev/null @@ -1,66 +0,0 @@ -// -// UXRDeserializableObject.h -// FourSquareKit -// -// Created by Rex St. John on 12/15/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import - -@interface UXRJSONDeserializableObject : NSObject - -- (id) initWithDictionary: (NSDictionary*) dictionary; - -/*! - @property identifier - the id of the object. The json uses the name 'id', which is a reserverd word in Objective-C - so instead we use the name 'identifier' to mean the same thing. - */ -@property (nonatomic, assign) NSUInteger identifier; - -/*! - @method - dateFromJSONDateString: - Dates will be converted to match the format expected by UrbanSpoon's API: - Time (UTC). ISO 8601 format YYYY-MM-DDThh:mm:ssZ, which is JSON standard - @param - jsonDate - the JSON-serialized string representation of a date - */ -+ (NSDate *) dateFromJSONDateString: (NSString *) jsonDate; - - -#pragma mark - convert from Objective-C to JSON - -/*! - @method convertToJsonSerializableDictionary: - converts each of the objects contained in the dictionary to NSDictionary objects, - so that the original dictionary (passed in) can be serialized to JSON - */ -- (NSDictionary *) convertToJsonSerializableDictionary: (NSDictionary*) dictionary; - -/*! - @method convertToJsonSerializableArray: - converts each of the objects contained in the array to NSDictionary objects, - so that the original array (passed in) can be serialized to JSON - */ -- (NSArray *) convertToJsonSerializableArray: (NSArray *) array; - -/*! - @method convertDateToJsonFormat: - Dates will be converted to match the format expected by Yapta's API: - Time (UTC). ISO 8601 format YYYY-MM-DDThh:mm:ssZ, which is JSON standard - */ -+ (NSString *) convertDateToJsonFormat: (NSDate *) date; - -/*! - @method convertZuluDateToJsonFormat: - Dates will be converted to match the format expected by Yapta's API: - Time (UTC). ISO 8601 format YYYY-MM-DDThh:mm:ssZ, which is JSON standard - This method will let us keep GMT times on dates - */ -+ (NSString *) convertZuluDateToJsonFormat: (NSDate *) zuluDate; - - -@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.m deleted file mode 100644 index 37e826b..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONDeserializableObject.m +++ /dev/null @@ -1,178 +0,0 @@ -// -// UXRDeserializableObject.m -// FourSquareKit -// -// Created by Rex St. John on 12/15/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRJSONDeserializableObject.h" -#import "UXRJSONSerializableObject.h" - -static NSDateFormatter *longDateFormatter = nil; -static NSDateFormatter *longZuluDateFormatter = nil; -static NSDateFormatter *shortDateFormatter = nil; -static NSDateFormatter *longZuluDateReFormatter = nil; - -@implementation UXRJSONDeserializableObject - -#pragma mark - initialization - -+ (void) initialize { - // we expect the short date to be in this format: - // 2011-12-02 - shortDateFormatter = [[NSDateFormatter alloc] init]; - [shortDateFormatter setDateFormat:@"yyyy-MM-dd"]; - - // we expect the 'long' date to be in this format: - // 2011-01-12T06:10:00 - longDateFormatter = [[NSDateFormatter alloc] init]; - [longDateFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ss"]; - - // we expect the 'long' date to sometimes have a 'Z' on the end: - // 2008-11-25T14:34:01Z - longZuluDateFormatter = [[NSDateFormatter alloc] init]; - [longZuluDateFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ssZ"]; - [longZuluDateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; - - //Zulu dates are GMT times and as such need a specific reformatter - longZuluDateReFormatter = [[NSDateFormatter alloc] init]; - [longZuluDateReFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; - [longZuluDateReFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; - -} - -- (id) initWithDictionary: (NSDictionary*) dictionary; { - self = [super init]; - if (self) { - [self setValuesForKeysWithDictionary:dictionary]; - } - return self; -} - -#pragma mark - override equality - -- (BOOL) isEqual:(id)object { - if (![object isKindOfClass:[self class]]) { - return NO; - } - - NSUInteger otherId = [(UXRJSONDeserializableObject*)object identifier]; - NSUInteger thisId = self.identifier; - return (otherId == thisId); -} - -- (NSUInteger) hash { - return [self identifier]; -} - -#pragma mark - convert from JSON to Objective-C - -- (void) setNilValueForKey:(NSString *)key { - // this blank override prevents an Exception - - // *very* noisy logs as city_states calls this method 5000 times - if (![key isEqualToString:@"major"]) { - NSLog(@"attempting to set nil value for key: %@", key); - } -} - - -- (void) setValue:(id)value forUndefinedKey:(NSString *)key { - // this blank override prevents an NSUndefinedKeyException -#ifdef TEST - // NSAssert(0, @"undefined key during testing"); -#endif - return; -} - -- (void) setId:(NSUInteger)identifier { - [self setIdentifier:identifier]; -} - -// dealing with dates from JSON being passed in as strings -// Time (UTC). ISO 8601 format YYYY-MM-DDThh:mm:ssZ, which is JSON standard -+ (NSDate *) dateFromJSONDateString: (NSString *) jsonDate; { - - NSDate * returnDate = [[NSDate alloc] init]; - if ([jsonDate length] == 10) { - returnDate = [shortDateFormatter dateFromString:jsonDate]; - } - else if ([jsonDate length] == 19) { - returnDate = [longDateFormatter dateFromString:jsonDate]; - } - else if ([jsonDate length] == 20) { - // Z stands for "Zulu", or GMT minus 0 hours - // this offset information is important; we don't want to lose it - // therefore must replace the Z with an offset, -0000 - returnDate = [longZuluDateFormatter dateFromString: - [jsonDate stringByReplacingOccurrencesOfString:@"Z" withString:@"+0000"]]; - } - - return returnDate; -} - - -#pragma mark - convert from Objective-C to JSON - -- (NSDictionary *) convertToJsonSerializableDictionary: (NSDictionary*) originalDictionary; { - NSMutableDictionary * outDictionary = [[NSMutableDictionary alloc] init]; - NSArray * keys = [originalDictionary allKeys]; - for(int i = 0; i < [keys count]; i++) { - NSString * key = [keys objectAtIndex:i]; - id valueToBeConverted = [originalDictionary valueForKey:key]; - if([valueToBeConverted respondsToSelector:@selector(convertToDictionaryOrArray)]) { - id serializableValue = valueToBeConverted; - NSDictionary * convertedValue = (NSDictionary*)[serializableValue convertToDictionaryOrArray]; - if(convertedValue) { - [originalDictionary setValue:convertedValue - forKey:key]; - } - } - } - return outDictionary; -} - - -- (NSArray *) convertToJsonSerializableArray: (NSArray *) array; { - NSMutableArray * outArray = [[NSMutableArray alloc] init]; - // convert all the array members - for (int i = 0; i < [array count]; i++) { - id valueToBeConverted = [array objectAtIndex:i]; - if([valueToBeConverted respondsToSelector:@selector(convertToDictionaryOrArray)]) { - id serializableValue = valueToBeConverted; - NSDictionary * convertedValue = (NSDictionary*)[serializableValue convertToDictionaryOrArray]; - [outArray addObject:convertedValue]; - } - } - return outArray; -} - -+ (NSString *) convertDateToJsonFormat: (NSDate *) date; { - - //TODO: fix formatter to deal with Zulu times - - if (longDateFormatter == nil) { - longDateFormatter = [[NSDateFormatter alloc] init]; - [longDateFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ss"]; - } - - NSString *dateString = [longDateFormatter stringFromDate:date]; - return dateString; -} - -+ (NSString *) convertZuluDateToJsonFormat: (NSDate *) zuluDate; { - - //Zulu dates are GMT times and as such need a specific reformatter - if (longZuluDateReFormatter == nil) { - longZuluDateReFormatter = [[NSDateFormatter alloc] init]; - [longZuluDateReFormatter setDateFormat:@"YYYY'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; - [longZuluDateReFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; - } - - NSString *dateString = [longZuluDateReFormatter stringFromDate:zuluDate]; - return dateString; -} - -@end - diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONSerializableObject.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONSerializableObject.h deleted file mode 100644 index ab73214..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/models/UXRJSONSerializableObject.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// UXRJSONSerializableObject.h -// FourSquareKit -// -// Created by Rex St. John on 12/15/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import - -/*! - @protocol USPJsonSerializableObject - Objects conforming to this protocol guarantee that they will be able to - be converted to a Dictionary, which in turn is used to serialize the object - (as its dicitonary representation) to JSON. - */ -@protocol UXRJSONSerializableObject - -@required -- (id ) convertToDictionaryOrArray; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.h deleted file mode 100644 index 937fae2..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// UXRBaseNetworkingEngine.h -// FourSquareKit -// -// This is largely used for downloading images. -// -// Created by Rex St. John on 12/19/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "MKNetworkEngine.h" - -@interface UXRBaseNetworkingEngine : MKNetworkEngine - -+(UXRBaseNetworkingEngine*) sharedInstance; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.m deleted file mode 100644 index dc08caf..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRBaseNetworkingEngine.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// UXRBaseNetworkingEngine.m -// FourSquareKit -// -// Created by Rex St. John on 12/19/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRBaseNetworkingEngine.h" - -@implementation UXRBaseNetworkingEngine - -- (id) init { - static BOOL alreadyInitialized = NO; - if (alreadyInitialized) { - return self; - } - alreadyInitialized = YES; - - self = [super init]; - [self useCache]; - if (self) { - } - return self; -} - -+(UXRBaseNetworkingEngine*) sharedInstance; { - static dispatch_once_t onceQueue; - static UXRBaseNetworkingEngine* _sharedInstance; - dispatch_once(&onceQueue, ^{ _sharedInstance = [[self alloc] init]; }); - return _sharedInstance; -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.h b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.h deleted file mode 100644 index ab40f49..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// UXRFourSquareNetworkingEngine.h -// FourSquareKit iOS -// -// Created by Rex St. John on 12/16/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// -#import "MKNetworkKit.h" -#import "UXRFourSquareRestaurantModel.h" -#import - -// Common response blocks. -typedef void (^UXRFourSquareEngineRestaurantsCompletionBlock)(NSArray *restaurants); -typedef void (^UXRFourSquareEnginePhotosCompletionBlock)(NSArray *photos); -typedef void (^UXRFourSquareEngineRestaurantCompletionBlock)(UXRFourSquareRestaurantModel *restaurant); -typedef void (^UXRFourSquareEngineErrorBlock)(NSError *error); - -@interface UXRFourSquareNetworkingEngine : MKNetworkEngine - -// Set these on startup. -@property(nonatomic,strong,readonly) NSString *clientId; -@property(nonatomic,strong,readonly) NSString *clientSecret; -@property(nonatomic,strong,readonly) NSString *callBackURL; - -// Singleton. -+(UXRFourSquareNetworkingEngine*) sharedInstance; - -// Use to bootstrap the engine for first time use. -+(void)registerFourSquareEngineWithClientId:(NSString*)client andSecret:(NSString*)secret andCallBackURL:(NSString*)callback; - -// Get alist of restaurants generically. -- (void)getRestaurantsWithCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; - -// Fetch restaurant stubs nearby, you will need to look up full restaurants individually if you want all the details. -- (void)getRestaurantsNearLocation:(CLLocation*)location - withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; - -// Returns a complex object containing many details about your surrounding area. -- (void)exploreRestaurantsNearLocation:(NSString*)location - withQuery:(NSString*)query - withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; - -// Returns a complex object containing many details about your surrounding area. -- (void)exploreRestaurantsNearLatLong:(CLLocationCoordinate2D)coordinate - withQuery:(NSString*)query - withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; - -// Get a specific restaurant, returns a full restaurant model with lot of data in it. -- (void)getRestaurantWithId:(NSString*)restaurantId withCompletionBlock:(UXRFourSquareEngineRestaurantCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; - -// Featch all photo models associated with a specific restaurant Id. -- (void)getPhotosForRestaurantWithId:(NSString*)restaurantId - withCompletionBlock:(UXRFourSquareEnginePhotosCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.m b/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.m deleted file mode 100644 index c957721..0000000 --- a/TalkinToTheNet/TalkinToTheNet/FourSquareKit/networking/UXRFourSquareNetworkingEngine.m +++ /dev/null @@ -1,375 +0,0 @@ -// -// UXRFourSquareNetworkingEngine.m -// FourSquareKit iOS -// -// Created by Rex St. John on 12/16/13. -// Copyright (c) 2013 UX-RX. All rights reserved. -// - -#import "UXRFourSquareNetworkingEngine.h" -#import "UXRFourSquarePhotoModel.h" -#import "UXRFourSquareExploreResultsModel.h" -#import "UXRExploreQueryBaseModel.h" -#import - -// Static paths. -static const NSString* FOURSQUARE_HOSTNAME = @"api.foursquare.com"; -static const NSString* FOURSQUARE_API = @"v2"; -static const NSString* FOURSQUARE_SEARCH_PATH = @"venues/search"; -static const NSString* FOURSQUARE_EXPLORE_PATH = @"venues/explore"; -static const NSString* FOURSQUARE_VENUE_PATH = @"venue"; -static const NSString* FOURSQUARE_VENUES_PATH = @"venues"; -static const NSString* FOURSQUARE_VENUE_PHOTOS_PATH = @"photos"; -static const NSInteger DEFAULT_RANGE_METERS = 800; -static const NSString* DEFAULT_SECTION = @"food"; - -@interface UXRFourSquareNetworkingEngine() -@property(nonatomic,strong,readwrite) NSString *clientId; -@property(nonatomic,strong,readwrite) NSString *clientSecret; -@property(nonatomic,strong,readwrite) NSString *callBackURL; -@end - -@implementation UXRFourSquareNetworkingEngine - -#pragma mark - Initialization - -- (id) init { - static BOOL alreadyInitialized = NO; - if (alreadyInitialized) { - return self; - } - alreadyInitialized = YES; - - self = [super initWithHostName:[FOURSQUARE_HOSTNAME copy] apiPath:[FOURSQUARE_API copy] customHeaderFields:nil]; - [self useCache]; - - if (self) { - } - return self; -} - -+(UXRFourSquareNetworkingEngine*) sharedInstance; { - static dispatch_once_t onceQueue; - static UXRFourSquareNetworkingEngine* _sharedInstance; - dispatch_once(&onceQueue, ^{ _sharedInstance = [[self alloc] init]; }); - return _sharedInstance; -} - -+(void)registerFourSquareEngineWithClientId:(NSString*)client - andSecret:(NSString*)secret - andCallBackURL:(NSString*)callback{ - // Some basic validation. - if(client.length < 48 || [client isEqualToString:@""] == YES){ - [NSException raise:@"Invalid FourSquare Client Id" format:@""]; - } - if(secret.length < 48 || [secret isEqualToString:@""] == YES){ - [NSException raise:@"Invalid FourSquare secret" format:@""]; - } - if([callback isEqualToString:@""] == YES){ - [NSException raise:@"Invalid FourSquare secret" format:@""]; - } - - UXRFourSquareNetworkingEngine *instance = UXRFourSquareNetworkingEngine.sharedInstance; - instance.clientSecret = secret; - instance.clientId = client; - instance.callBackURL = callback; -} - -#pragma mark - Rendering models - --(NSArray*)renderJSONToFourSquareRestaurantModels:(NSArray*)models{ - - NSMutableArray *restaurantModels = [[NSMutableArray alloc] initWithCapacity:models.count]; - - for(NSDictionary *business in models){ - UXRFourSquareRestaurantModel *restaurantModel = [[UXRFourSquareRestaurantModel alloc] initWithDictionary:business]; - [restaurantModels addObject:restaurantModel]; - } - - return (NSArray*)restaurantModels; -} - --(NSArray*)renderJSONToFourSquarePhotoModels:(NSArray*)models{ - - NSMutableArray *photoModels = [[NSMutableArray alloc] initWithCapacity:models.count]; - - for(NSDictionary *photo in models){ - UXRFourSquarePhotoModel *photoModel = [[UXRFourSquarePhotoModel alloc] initWithDictionary:photo]; - [photoModels addObject:photoModel]; - } - - return (NSArray*)photoModels; -} - -#pragma mark - Private Methods. - -- (NSDictionary*)dictionaryWithAuthFromDictionary:(NSDictionary*)dictionary{ - //https://api.foursquare.com/v2/venues/search?ll=40.7,-74&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&v=YYYYMMDD - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateFormat:@"YYYYMMDD"]; - NSDate *now = [NSDate date]; - NSString *stringFromDate = [formatter stringFromDate:now]; - NSMutableDictionary *authDict = [NSMutableDictionary dictionaryWithDictionary: @{@"client_id":self.clientId, @"client_secret":self.clientSecret, @"v":stringFromDate}]; - [authDict addEntriesFromDictionary:dictionary]; - return [NSDictionary dictionaryWithDictionary:authDict]; -} - -#pragma mark - Public Methods - -- (void)getRestaurantsWithCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock -{ - [self checkRegistration]; - // Fill the post body with the tweet - NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: - @"restaurants", @"query", - @"San Francisco", @"near", - nil]; - - MKNetworkOperation *op = [self operationWithPath:[FOURSQUARE_SEARCH_PATH copy] - params:[self dictionaryWithAuthFromDictionary:postParams] - httpMethod:@"GET" - ssl:YES]; - - [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { - - NSError* error = nil; - NSDictionary* json = [NSJSONSerialization - JSONObjectWithData:[completedOperation responseData] - options:kNilOptions - error:&error]; - if(error != nil){ - errorBlock(error); - } - - NSDictionary *response = [json objectForKey:@"response"]; - NSArray* businesses = [response objectForKey:@"venues"]; - NSArray* models =[self renderJSONToFourSquareRestaurantModels:businesses]; - completionBlock(models); - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - errorBlock(error); - }]; - - [self enqueueOperation:op]; -} - -- (void)getRestaurantsNearLocation:(CLLocation*)location - withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ - [self checkRegistration]; - - CLLocationCoordinate2D coordinate = location.coordinate; - NSString *latLonString = [NSString stringWithFormat:@"%f,%f",coordinate.latitude,coordinate.longitude]; - NSNumber *rangeMeters = [NSNumber numberWithInt:DEFAULT_RANGE_METERS]; - - // Fill the post body with the tweet - //https://developer.foursquare.com/docs/venues/explore - NSDictionary *postParams = @{ - @"query" : @"restaurants", - @"ll": latLonString, - @"radius" : [rangeMeters stringValue] - }; - - MKNetworkOperation *op = [self operationWithPath:[FOURSQUARE_SEARCH_PATH copy] - params:[self dictionaryWithAuthFromDictionary:postParams] - httpMethod:@"GET" - ssl:YES]; - - [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { - - NSError* error = nil; - NSDictionary* json = [NSJSONSerialization - JSONObjectWithData:[completedOperation responseData] - options:kNilOptions - error:&error]; - if(error != nil){ - errorBlock(error); - } - - NSDictionary *response = [json objectForKey:@"response"]; - NSArray* businesses = [response objectForKey:@"venues"]; - NSArray* models =[self renderJSONToFourSquareRestaurantModels:businesses]; - completionBlock(models); - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - errorBlock(error); - }]; - - [self enqueueOperation:op]; -} - -- (void)exploreRestaurantsNearLocation:(NSString*)location - withQuery:(NSString*)query - withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ - [self checkRegistration]; - - NSNumber *rangeMeters = [NSNumber numberWithInt:DEFAULT_RANGE_METERS]; - // Section needs to be nil or it will override any incoming query. - NSString *section = (query==nil || [query isEqualToString:@""] == YES)?[DEFAULT_SECTION copy]:@""; - - // Fill the post body with the tweet - //https://developer.foursquare.com/docs/venues/explore - NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: - section, @"section", - query, @"query", - location, @"near", - @"1", @"sortByDistance", - @"1", @"venuePhotos", - [rangeMeters stringValue],@"radius", - nil]; - - MKNetworkOperation *op = [self operationWithPath:[FOURSQUARE_EXPLORE_PATH copy] - params:[self dictionaryWithAuthFromDictionary:postParams ] - httpMethod:@"GET" - ssl:YES]; - [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { - - NSError* error = nil; - NSDictionary* json = [NSJSONSerialization - JSONObjectWithData:[completedOperation responseData] - options:kNilOptions - error:&error]; - if(error != nil){ - errorBlock(error); - } - - NSDictionary *response = [json objectForKey:@"response"]; - UXRExploreQueryBaseModel* result =[[UXRExploreQueryBaseModel alloc] initWithDictionary:response]; - completionBlock(result.venues); - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - errorBlock(error); - }]; - - [self enqueueOperation:op]; -} - - -- (void)exploreRestaurantsNearLatLong:(CLLocationCoordinate2D)coordinate - withQuery:(NSString*)query - withCompletionBlock:(UXRFourSquareEngineRestaurantsCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ - [self checkRegistration]; - - NSNumber *rangeMeters = [NSNumber numberWithInt:DEFAULT_RANGE_METERS]; - NSString *latLonString = [NSString stringWithFormat:@"%f,%f", coordinate.latitude, coordinate.longitude]; - - // Section needs to be nil or it will override any incoming query. - NSString *section = (query==nil || [query isEqualToString:@""] == YES)?[DEFAULT_SECTION copy]:@""; - - // Fill the post body with the tweet - //https://developer.foursquare.com/docs/venues/explore - NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: - section, @"section", - query, @"query", - latLonString, @"ll", - @"1", @"sortByDistance", - @"1", @"venuePhotos", - [rangeMeters stringValue],@"radius", - nil]; - - MKNetworkOperation *op = [self operationWithPath:[FOURSQUARE_EXPLORE_PATH copy] - params:[self dictionaryWithAuthFromDictionary:postParams ] - httpMethod:@"GET" - ssl:YES]; - [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { - - NSError* error = nil; - NSDictionary* json = [NSJSONSerialization - JSONObjectWithData:[completedOperation responseData] - options:kNilOptions - error:&error]; - if(error != nil){ - errorBlock(error); - } - - NSDictionary *response = [json objectForKey:@"response"]; - UXRExploreQueryBaseModel* result =[[UXRExploreQueryBaseModel alloc] initWithDictionary:response]; - completionBlock(result.venues); - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - errorBlock(error); - }]; - - [self enqueueOperation:op]; -} - -- (void)getRestaurantWithId:(NSString*)restaurantId - withCompletionBlock:(UXRFourSquareEngineRestaurantCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ - [self checkRegistration]; - - // Fill the post body with the tweet - NSString *venuePath = [NSString stringWithFormat:@"%@/%@",[FOURSQUARE_VENUES_PATH copy],restaurantId]; - - MKNetworkOperation *op = [self operationWithPath:venuePath - params:[self dictionaryWithAuthFromDictionary:nil] - httpMethod:@"GET" - ssl:YES]; - - [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { - - NSError* error = nil; - NSDictionary* json = [NSJSONSerialization - JSONObjectWithData:[completedOperation responseData] - options:kNilOptions - error:&error]; - if(error != nil){ - errorBlock(error); - } - - NSDictionary *response = [json objectForKey:@"response"]; - NSDictionary *venue = [response objectForKey:@"venue"]; - UXRFourSquareRestaurantModel *restuarant = [[UXRFourSquareRestaurantModel alloc] initWithDictionary:venue]; - completionBlock(restuarant); - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - errorBlock(error); - }]; - - [self enqueueOperation:op]; -} - -- (void)getPhotosForRestaurantWithId:(NSString*)restaurantId - withCompletionBlock:(UXRFourSquareEnginePhotosCompletionBlock)completionBlock - failureBlock:(UXRFourSquareEngineErrorBlock)errorBlock{ - [self checkRegistration]; - // Fill the post body with the tweet - NSString *venuePath = [NSString stringWithFormat:@"%@/%@/%@",[FOURSQUARE_VENUES_PATH copy],restaurantId, [FOURSQUARE_VENUE_PHOTOS_PATH copy]]; - - MKNetworkOperation *op = [self operationWithPath:venuePath - params:[self dictionaryWithAuthFromDictionary:nil] - httpMethod:@"GET" - ssl:YES]; - - [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { - - NSError* error = nil; - NSDictionary* json = [NSJSONSerialization - JSONObjectWithData:[completedOperation responseData] - options:kNilOptions - error:&error]; - if(error != nil){ - errorBlock(error); - } - - NSDictionary* response = [json objectForKey:@"response"]; - NSDictionary* photos = [response objectForKey:@"photos"]; - NSArray *models = [self renderJSONToFourSquarePhotoModels:[photos objectForKey:@"items"]]; - completionBlock(models); - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - errorBlock(error); - }]; - - [self enqueueOperation:op]; -} - -#pragma mark - Verify registration status - --(void)checkRegistration{ - BOOL isRegistered = NO; - isRegistered = self.clientId != nil; - isRegistered = self.clientSecret != nil; - isRegistered = self.callBackURL != nil; - if(isRegistered == NO){ - [NSException raise:@"FourSquare Client Not Registered, use registerFourSquareEngineWithClientId" format:@""]; - } -} -@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/Info.plist b/TalkinToTheNet/TalkinToTheNet/Info.plist index 6905cc6..dc007cb 100644 --- a/TalkinToTheNet/TalkinToTheNet/Info.plist +++ b/TalkinToTheNet/TalkinToTheNet/Info.plist @@ -2,6 +2,8 @@ + NSLocationWhenInUseUsageDescription + Location is required to find out where you are CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h deleted file mode 100644 index c2ec0db..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// NSAlert+MKNetworkKitAdditions.h -// FourSquareKit-OSX -// -// Created by JASON CROSS on 3/6/15. -// Copyright (c) 2015 UX RX. All rights reserved. -// - -#if TARGET_OS_MAC -#import - -@interface NSAlert (MKNetworkKitAdditions) -+(NSAlert*) showWithError:(NSError*) networkError; -@end -#endif \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m deleted file mode 100644 index 80ff6e4..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSAlert+MKNetworkKitAdditions.m +++ /dev/null @@ -1,20 +0,0 @@ -// -// NSAlert+MKNetworkKitAdditions.m -// FourSquareKit-OSX -// -// Created by JASON CROSS on 3/6/15. -// Copyright (c) 2015 UX RX. All rights reserved. -// - -#if TARGET_OS_MAC -#import "NSAlert+MKNetworkKitAdditions.h" - -@implementation NSAlert (MKNetworkKitAdditions) - -+(NSAlert*) showWithError:(NSError*) networkError; { - - NSAlert * alert = [NSAlert alertWithError:networkError]; - [alert show]; -} -@end -#endif \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.h deleted file mode 100644 index ec8147d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// NSData+MKNKBase64.h -// base64 -// -// Created by Matt Gallagher on 2009/06/03. -// Copyright 2009 Matt Gallagher. All rights reserved. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. Permission is granted to anyone to -// use this software for any purpose, including commercial applications, and to -// alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source -// distribution. -// - -#import - -void *mk_NewBase64Decode( - const char *inputBuffer, - size_t length, - size_t *outputLength); - -char *mk_NewBase64Encode( - const void *inputBuffer, - size_t length, - bool separateLines, - size_t *outputLength); - -@interface NSData (MKNKBase64) - -+ (NSData *)dataFromBase64String:(NSString *)aString; -- (NSString *)base64EncodedString; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.m deleted file mode 100644 index 5802fac..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSData+MKBase64.m +++ /dev/null @@ -1,312 +0,0 @@ -// -// NSData+MKNKBase64.m -// base64 -// -// Created by Matt Gallagher on 2009/06/03. -// Copyright 2009 Matt Gallagher. All rights reserved. -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. Permission is granted to anyone to -// use this software for any purpose, including commercial applications, and to -// alter it and redistribute it freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// 3. This notice may not be removed or altered from any source -// distribution. -// - -#import "NSData+MKBase64.h" - -// -// Mapping from 6 bit pattern to ASCII character. -// -static unsigned char mk_base64EncodeLookup[65] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -// -// Definition for "masked-out" areas of the base64DecodeLookup mapping -// -#define xx 65 - -// -// Mapping from ASCII character to 6 bit pattern. -// -static unsigned char mk_base64DecodeLookup[256] = -{ - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 62, xx, xx, xx, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, xx, xx, xx, xx, xx, xx, - xx, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, xx, xx, xx, xx, xx, - xx, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, - xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, -}; - -// -// Fundamental sizes of the binary and base64 encode/decode units in bytes -// -#define BINARY_UNIT_SIZE 3 -#define BASE64_UNIT_SIZE 4 - -// -// NewBase64Decode -// -// Decodes the base64 ASCII string in the inputBuffer to a newly malloced -// output buffer. -// -// inputBuffer - the source ASCII string for the decode -// length - the length of the string or -1 (to specify strlen should be used) -// outputLength - if not-NULL, on output will contain the decoded length -// -// returns the decoded buffer. Must be free'd by caller. Length is given by -// outputLength. -// -void *mk_NewBase64Decode( - const char *inputBuffer, - size_t length, - size_t *outputLength) -{ - if (length == (size_t)-1) - { - length = strlen(inputBuffer); - } - - size_t outputBufferSize = - ((length+BASE64_UNIT_SIZE-1) / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE; - unsigned char *outputBuffer = (unsigned char *)malloc(outputBufferSize); - - size_t i = 0; - size_t j = 0; - while (i < length) - { - // - // Accumulate 4 valid characters (ignore everything else) - // - unsigned char accumulated[BASE64_UNIT_SIZE]; - size_t accumulateIndex = 0; - while (i < length) - { - unsigned char decode = mk_base64DecodeLookup[inputBuffer[i++]]; - if (decode != xx) - { - accumulated[accumulateIndex] = decode; - accumulateIndex++; - - if (accumulateIndex == BASE64_UNIT_SIZE) - { - break; - } - } - } - - // - // Store the 6 bits from each of the 4 characters as 3 bytes - // - // (Uses improved bounds checking suggested by Alexandre Colucci) - // - if(accumulateIndex >= 2) - outputBuffer[j] = (unsigned char)(accumulated[0] << 2) | (accumulated[1] >> 4); - if(accumulateIndex >= 3) - outputBuffer[j + 1] = (unsigned char)(accumulated[1] << 4) | (accumulated[2] >> 2); - if(accumulateIndex >= 4) - outputBuffer[j + 2] = (unsigned char)(accumulated[2] << 6) | accumulated[3]; - j += accumulateIndex - 1; - } - - if (outputLength) - { - *outputLength = j; - } - return outputBuffer; -} - -// -// NewBase64Encode -// -// Encodes the arbitrary data in the inputBuffer as base64 into a newly malloced -// output buffer. -// -// inputBuffer - the source data for the encode -// length - the length of the input in bytes -// separateLines - if zero, no CR/LF characters will be added. Otherwise -// a CR/LF pair will be added every 64 encoded chars. -// outputLength - if not-NULL, on output will contain the encoded length -// (not including terminating 0 char) -// -// returns the encoded buffer. Must be free'd by caller. Length is given by -// outputLength. -// -char *mk_NewBase64Encode( - const void *buffer, - size_t length, - bool separateLines, - size_t *outputLength) -{ - const unsigned char *inputBuffer = (const unsigned char *)buffer; - - #define MAX_NUM_PADDING_CHARS 2 - #define OUTPUT_LINE_LENGTH 64 - #define INPUT_LINE_LENGTH ((OUTPUT_LINE_LENGTH / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE) - #define CR_LF_SIZE 2 - - // - // Byte accurate calculation of final buffer size - // - size_t outputBufferSize = - ((length / BINARY_UNIT_SIZE) - + ((length % BINARY_UNIT_SIZE) ? 1 : 0)) - * BASE64_UNIT_SIZE; - if (separateLines) - { - outputBufferSize += - (outputBufferSize / OUTPUT_LINE_LENGTH) * CR_LF_SIZE; - } - - // - // Include space for a terminating zero - // - outputBufferSize += 1; - - // - // Allocate the output buffer - // - char *outputBuffer = (char *)malloc(outputBufferSize); - if (!outputBuffer) - { - return NULL; - } - - size_t i = 0; - size_t j = 0; - const size_t lineLength = separateLines ? INPUT_LINE_LENGTH : length; - size_t lineEnd = lineLength; - - while (true) - { - if (lineEnd > length) - { - lineEnd = length; - } - - for (; i + BINARY_UNIT_SIZE - 1 < lineEnd; i += BINARY_UNIT_SIZE) - { - // - // Inner loop: turn 48 bytes into 64 base64 characters - // - outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; - outputBuffer[j++] = (char)mk_base64EncodeLookup[((inputBuffer[i] & 0x03) << 4) - | ((inputBuffer[i + 1] & 0xF0) >> 4)]; - outputBuffer[j++] = (char)mk_base64EncodeLookup[((inputBuffer[i + 1] & 0x0F) << 2) - | ((inputBuffer[i + 2] & 0xC0) >> 6)]; - outputBuffer[j++] = (char)mk_base64EncodeLookup[inputBuffer[i + 2] & 0x3F]; - } - - if (lineEnd == length) - { - break; - } - - // - // Add the newline - // - outputBuffer[j++] = '\r'; - outputBuffer[j++] = '\n'; - lineEnd += lineLength; - } - - if (i + 1 < length) - { - // - // Handle the single '=' case - // - outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; - outputBuffer[j++] = (char)mk_base64EncodeLookup[((inputBuffer[i] & 0x03) << 4) - | ((inputBuffer[i + 1] & 0xF0) >> 4)]; - outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i + 1] & 0x0F) << 2]; - outputBuffer[j++] = '='; - } - else if (i < length) - { - // - // Handle the double '=' case - // - outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2]; - outputBuffer[j++] = (char)mk_base64EncodeLookup[(inputBuffer[i] & 0x03) << 4]; - outputBuffer[j++] = '='; - outputBuffer[j++] = '='; - } - outputBuffer[j] = 0; - - // - // Set the output length and return the buffer - // - if (outputLength) - { - *outputLength = j; - } - return outputBuffer; -} - -@implementation NSData (MKNKBase64) - -// -// dataFromBase64String: -// -// Creates an NSData object containing the base64 decoded representation of -// the base64 string 'aString' -// -// Parameters: -// aString - the base64 string to decode -// -// returns the autoreleased NSData representation of the base64 string -// -+ (NSData *)dataFromBase64String:(NSString *)aString -{ - NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding]; - size_t outputLength; - void *outputBuffer = mk_NewBase64Decode([data bytes], [data length], &outputLength); - NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength]; - free(outputBuffer); - return result; -} - -// -// base64EncodedString -// -// Creates an NSString object that contains the base 64 encoding of the -// receiver's data. Lines are broken at 64 characters long. -// -// returns an autoreleased NSString being the base 64 representation of the -// receiver. -// -- (NSString *)base64EncodedString -{ - size_t outputLength = 0; - char *outputBuffer = - mk_NewBase64Encode([self bytes], [self length], false, &outputLength); - - NSString *result = - [[NSString alloc] - initWithBytes:outputBuffer - length:outputLength - encoding:NSASCIIStringEncoding]; - free(outputBuffer); - return result; -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.h deleted file mode 100644 index 12b3f2e..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// NSDate+RFC1123.h -// MKNetworkKit -// -// Created by Marcus Rohrmoser -// http://blog.mro.name/2009/08/nsdateformatter-http-header/ -// http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 - -// No obvious license attached - -#import - -@interface NSDate (RFC1123) -/** - Convert a RFC1123 'Full-Date' string - (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1) - into NSDate. - */ -+(NSDate*)dateFromRFC1123:(NSString*)value_; - -/** - Convert NSDate into a RFC1123 'Full-Date' string - (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1). - */ --(NSString*)rfc1123String; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.m deleted file mode 100644 index 261e467..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDate+RFC1123.m +++ /dev/null @@ -1,76 +0,0 @@ -// -// NSDate+RFC1123.m -// MKNetworkKit -// -// Originally created by Marcus Rohrmoser -// http://blog.mro.name/2009/08/nsdateformatter-http-header/ -// Updated with strptime methods by Bo98 -// -// No obvious license attached - -#import "NSDate+RFC1123.h" -#import -#import - -@implementation NSDate (RFC1123) - -+(NSDate*)dateFromRFC1123:(NSString*)value_ -{ - if(value_ == nil) - return nil; - - const char *str = [value_ UTF8String]; - const char *fmt; - NSDate *retDate; - char *ret; - - fmt = "%a, %d %b %Y %H:%M:%S %Z"; - struct tm rfc1123timeinfo; - memset(&rfc1123timeinfo, 0, sizeof(rfc1123timeinfo)); - ret = strptime_l(str, fmt, &rfc1123timeinfo, NULL); - if (ret) { - time_t rfc1123time = mktime(&rfc1123timeinfo); - retDate = [NSDate dateWithTimeIntervalSince1970:rfc1123time]; - if (retDate != nil) - return retDate; - } - - - fmt = "%A, %d-%b-%y %H:%M:%S %Z"; - struct tm rfc850timeinfo; - memset(&rfc850timeinfo, 0, sizeof(rfc850timeinfo)); - ret = strptime_l(str, fmt, &rfc850timeinfo, NULL); - if (ret) { - time_t rfc850time = mktime(&rfc850timeinfo); - retDate = [NSDate dateWithTimeIntervalSince1970:rfc850time]; - if (retDate != nil) - return retDate; - } - - fmt = "%a %b %e %H:%M:%S %Y"; - struct tm asctimeinfo; - memset(&asctimeinfo, 0, sizeof(asctimeinfo)); - ret = strptime_l(str, fmt, &asctimeinfo, NULL); - if (ret) { - time_t asctime = mktime(&asctimeinfo); - return [NSDate dateWithTimeIntervalSince1970:asctime]; - } - - return nil; -} - --(NSString*)rfc1123String -{ - time_t date = (time_t)[self timeIntervalSince1970]; - struct tm timeinfo; - gmtime_r(&date, &timeinfo); - char buffer[32]; - size_t ret = strftime_l(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S GMT", &timeinfo, NULL); - if (ret) { - return @(buffer); - } else { - return nil; - } -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h deleted file mode 100644 index 1f2593e..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// NSDictionary+RequestEncoding.h -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import - -@interface NSDictionary (RequestEncoding) - --(NSString*) urlEncodedKeyValueString; --(NSString*) jsonEncodedKeyValueString; --(NSString*) plistEncodedKeyValueString; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m deleted file mode 100644 index a8fac4b..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSDictionary+RequestEncoding.m +++ /dev/null @@ -1,74 +0,0 @@ -// -// NSDictionary+RequestEncoding.m -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import "MKNetworkKit.h" - -@implementation NSDictionary (RequestEncoding) - --(NSString*) urlEncodedKeyValueString { - - NSMutableString *string = [NSMutableString string]; - for (NSString *key in self) { - - NSObject *value = [self valueForKey:key]; - if([value isKindOfClass:[NSString class]]) - [string appendFormat:@"%@=%@&", [key mk_urlEncodedString], [((NSString*)value) mk_urlEncodedString]]; - else - [string appendFormat:@"%@=%@&", [key mk_urlEncodedString], value]; - } - - if([string length] > 0) - [string deleteCharactersInRange:NSMakeRange([string length] - 1, 1)]; - - return string; -} - - --(NSString*) jsonEncodedKeyValueString { - - NSError *error = nil; - NSData *data = [NSJSONSerialization dataWithJSONObject:self - options:0 // non-pretty printing - error:&error]; - if(error) - DLog(@"JSON Parsing Error: %@", error); - - return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; -} - - --(NSString*) plistEncodedKeyValueString { - - NSError *error = nil; - NSData *data = [NSPropertyListSerialization dataWithPropertyList:self - format:NSPropertyListXMLFormat_v1_0 - options:0 error:&error]; - if(error) - DLog(@"JSON Parsing Error: %@", error); - - return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h deleted file mode 100644 index 098cff0..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// NSImageView+MKNetworkKitAdditions.h -// FourSquareKit-OSX -// -// Created by JASON CROSS on 3/6/15. -// Copyright (c) 2015 UX RX. All rights reserved. -// -// Originally Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#if TARGET_OS_MAC -#import - -extern const float kFromCacheAnimationDuration; -extern const float kFreshLoadAnimationDuration; - -@class MKNetworkEngine; -@class MKNetworkOperation; - -@interface NSImageView (MKNetworkKitAdditions) -+(void) setDefaultEngine:(MKNetworkEngine*) engine; --(MKNetworkOperation*) setImageFromURL:(NSURL*) url; --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image; --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image animation:(BOOL) yesOrNo; --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) yesOrNo; -@end -#endif \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m deleted file mode 100644 index 5a532ac..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSImageView+MKNetworkKitAdditions.m +++ /dev/null @@ -1,99 +0,0 @@ -// -// NSImageView+MKNetworkKitAdditions.m -// FourSquareKit-OSX -// -// Created by JASON CROSS on 3/6/15. -// Copyright (c) 2015 UX RX. All rights reserved. -// -// Originally Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - - -#import "NSImageView+MKNetworkKitAdditions.h" - -#import "MKNetworkEngine.h" - -#import - -static MKNetworkEngine *DefaultEngine; -static char imageFetchOperationKey; - -const float kFromCacheAnimationDuration = 0.1f; -const float kFreshLoadAnimationDuration = 0.35f; - -@interface NSImageView (/*Private Methods*/) -@property (strong, nonatomic) MKNetworkOperation *imageFetchOperation; -@end - -@implementation NSImageView (MKNetworkKitAdditions) - --(MKNetworkOperation*) imageFetchOperation { - - return (MKNetworkOperation*) objc_getAssociatedObject(self, &imageFetchOperationKey); -} - --(void) setImageFetchOperation:(MKNetworkOperation *)imageFetchOperation { - - objc_setAssociatedObject(self, &imageFetchOperationKey, imageFetchOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -+(void) setDefaultEngine:(MKNetworkEngine*) engine; { - - DefaultEngine = engine; -} - --(MKNetworkOperation*) setImageFromURL:(NSURL*) url; { - - return [self setImageFromURL:url placeHolderImage:nil]; -} - --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image; { - - return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:YES]; -} - --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image animation:(BOOL) yesOrNo; { - - return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:yesOrNo]; -} - --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(NSImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) yesOrNo; { - - if(image) self.image = image; - [self.imageFetchOperation cancel]; - if(!imageCacheEngine) imageCacheEngine = DefaultEngine; - - if(imageCacheEngine) { - self.imageFetchOperation = [imageCacheEngine imageAtURL:url completionHandler:^(NSImage *fetchedImage, NSURL *url, BOOL isInCache) { - self.image = fetchedImage; - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - DLog(@"%@", error); - }]; - } else { - - DLog(@"No default engine found and imageCacheEngine parameter is null") - } - - return self.imageFetchOperation; - -} - -@end \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h deleted file mode 100644 index 99514c8..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// NSString+MKNetworkKitAdditions.h -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import - -@interface NSString (MKNetworkKitAdditions) - -- (NSString *) md5; -+ (NSString*) uniqueString; -- (NSString*) mk_urlEncodedString; -- (NSString*) urlDecodedString; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m deleted file mode 100644 index adf2e3d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/NSString+MKNetworkKitAdditions.m +++ /dev/null @@ -1,81 +0,0 @@ -// -// NSString+MKNetworkKitAdditions.m -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import "NSString+MKNetworkKitAdditions.h" -#import - -@implementation NSString (MKNetworkKitAdditions) - -- (NSString *) md5 -{ - const char *cStr = [self UTF8String]; - unsigned char result[16]; - CC_MD5( cStr, (unsigned int) strlen(cStr), result); - return [NSString stringWithFormat: - @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - result[0], result[1], result[2], result[3], - result[4], result[5], result[6], result[7], - result[8], result[9], result[10], result[11], - result[12], result[13], result[14], result[15] - ]; -} - -+ (NSString*) uniqueString -{ - CFUUIDRef uuidObj = CFUUIDCreate(nil); - NSString *uuidString = (__bridge_transfer NSString*)CFUUIDCreateString(nil, uuidObj); - CFRelease(uuidObj); - return uuidString; -} - -- (NSString*) mk_urlEncodedString { // mk_ prefix prevents a clash with a private api - - CFStringRef encodedCFString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, - (__bridge CFStringRef) self, - nil, - CFSTR("?!@#$^&%*+,:;='\"`<>()[]{}/\\| "), - kCFStringEncodingUTF8); - - NSString *encodedString = [[NSString alloc] initWithString:(__bridge_transfer NSString*) encodedCFString]; - - if(!encodedString) - encodedString = @""; - - return encodedString; -} - -- (NSString*) urlDecodedString { - - CFStringRef decodedCFString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, - (__bridge CFStringRef) self, - CFSTR(""), - kCFStringEncodingUTF8); - - // We need to replace "+" with " " because the CF method above doesn't do it - NSString *decodedString = [[NSString alloc] initWithString:(__bridge_transfer NSString*) decodedCFString]; - return (!decodedString) ? @"" : [decodedString stringByReplacingOccurrencesOfString:@"+" withString:@" "]; -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h deleted file mode 100644 index 89c9205..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// UIAlertView+MKNetworkKitAdditions.h -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -#if TARGET_OS_IPHONE -#import - -@interface UIAlertView (MKNetworkKitAdditions) -+(UIAlertView*) showWithError:(NSError*) networkError; -@end -#endif diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m deleted file mode 100644 index 887deba..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIAlertView+MKNetworkKitAdditions.m +++ /dev/null @@ -1,41 +0,0 @@ -// -// UIAlertView+MKNetworkKitAdditions.m -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -#if TARGET_OS_IPHONE -#import "UIAlertView+MKNetworkKitAdditions.h" - -@implementation UIAlertView (MKNetworkKitAdditions) - -+(UIAlertView*) showWithError:(NSError*) networkError { - - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[networkError localizedDescription] - message:[networkError localizedRecoverySuggestion] - delegate:nil - cancelButtonTitle:NSLocalizedString(@"Dismiss", @"") - otherButtonTitles:nil]; - [alert show]; - return alert; -} -@end -#endif diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h deleted file mode 100644 index 46f343d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// UIImageView+MKNetworkKitAdditions.h -// MKNetworkKit-iOS -// -// Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#if TARGET_OS_IPHONE -#import - -extern const float kFromCacheAnimationDuration; -extern const float kFreshLoadAnimationDuration; - -@class MKNetworkEngine; -@class MKNetworkOperation; - -@interface UIImageView (MKNetworkKitAdditions) -+(void) setDefaultEngine:(MKNetworkEngine*) engine; --(MKNetworkOperation*) setImageFromURL:(NSURL*) url; --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image; --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image animation:(BOOL) yesOrNo; --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) yesOrNo; -@end -#endif \ No newline at end of file diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m deleted file mode 100644 index 77f4054..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Categories/UIImageView+MKNetworkKitAdditions.m +++ /dev/null @@ -1,109 +0,0 @@ -// -// UIImageView+MKNetworkKitAdditions.m -// MKNetworkKitDemo -// -// Created by Mugunth Kumar (@mugunthkumar) on 18/01/13. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#if TARGET_OS_IPHONE -#import "UIImageView+MKNetworkKitAdditions.h" - -#import "MKNetworkEngine.h" - -#import - -static MKNetworkEngine *DefaultEngine; -static char imageFetchOperationKey; - -const float kFromCacheAnimationDuration = 0.1f; -const float kFreshLoadAnimationDuration = 0.35f; - -@interface UIImageView (/*Private Methods*/) -@property (strong, nonatomic) MKNetworkOperation *imageFetchOperation; -@end - -@implementation UIImageView (MKNetworkKitAdditions) - --(MKNetworkOperation*) imageFetchOperation { - - return (MKNetworkOperation*) objc_getAssociatedObject(self, &imageFetchOperationKey); -} - --(void) setImageFetchOperation:(MKNetworkOperation *)imageFetchOperation { - - objc_setAssociatedObject(self, &imageFetchOperationKey, imageFetchOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -+(void) setDefaultEngine:(MKNetworkEngine*) engine { - - DefaultEngine = engine; -} - --(MKNetworkOperation*) setImageFromURL:(NSURL*) url { - - return [self setImageFromURL:url placeHolderImage:nil]; -} - --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image { - - return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:YES]; -} - --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image animation:(BOOL) yesOrNo { - - return [self setImageFromURL:url placeHolderImage:image usingEngine:DefaultEngine animation:yesOrNo]; -} - --(MKNetworkOperation*) setImageFromURL:(NSURL*) url placeHolderImage:(UIImage*) image usingEngine:(MKNetworkEngine*) imageCacheEngine animation:(BOOL) animation { - - if(image) self.image = image; - [self.imageFetchOperation cancel]; - if(!imageCacheEngine) imageCacheEngine = DefaultEngine; - - if(imageCacheEngine) { - self.imageFetchOperation = [imageCacheEngine imageAtURL:url - size:self.frame.size - completionHandler:^(UIImage *fetchedImage, NSURL *url, BOOL isInCache) { - - if(animation) { - [UIView transitionWithView:self.superview - duration:isInCache?kFromCacheAnimationDuration:kFreshLoadAnimationDuration - options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction - animations:^{ - self.image = fetchedImage; - } completion:nil]; - } else { - self.image = fetchedImage; - } - - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - - DLog(@"%@", error); - }]; - } else { - - DLog(@"No default engine found and imageCacheEngine parameter is null") - } - - return self.imageFetchOperation; -} -@end -#endif diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.h deleted file mode 100644 index 5f67587..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.h +++ /dev/null @@ -1,425 +0,0 @@ -// -// MKNetworkEngine.h -// MKNetworkKit -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import "MKNetworkKit.h" -/*! - @header MKNetworkEngine.h - @abstract Represents a subclassable Network Engine for your app - */ - -/*! - * @class MKNetworkEngine - * @abstract Represents a subclassable Network Engine for your app - * - * @discussion - * This class is the heart of MKNetworkEngine - * You create network operations and enqueue them here - * MKNetworkEngine encapsulates a Reachability object that relieves you of managing network connectivity losses - * MKNetworkEngine also allows you to provide custom header fields that gets appended automatically to every request - */ -@interface MKNetworkEngine : NSObject -/*! - * @abstract Initializes your network engine with a hostname - * - * @discussion - * Creates an engine for a given host name - * The hostname parameter is optional - * The hostname, if not null, initializes a Reachability notifier. - * Network reachability notifications are automatically taken care of by MKNetworkEngine - * - */ -- (id) initWithHostName:(NSString*) hostName; - -/*! - * @abstract Initializes your network engine with a hostname and custom header fields - * - * @discussion - * Creates an engine for a given host name - * The default headers you specify here will be appened to every operation created in this engine - * The hostname, if not null, initializes a Reachability notifier. - * Network reachability notifications are automatically taken care of by MKNetworkEngine - * Both parameters are optional - * - */ -- (id) initWithHostName:(NSString*) hostName customHeaderFields:(NSDictionary*) headers; - -/*! - * @abstract Initializes your network engine with a hostname - * - * @discussion - * Creates an engine for a given host name - * The hostname parameter is optional - * The apiPath paramter is optional - * The apiPath is prefixed to every call to operationWithPath: You can use this method if your server's API location is not at the root (/) - * The hostname, if not null, initializes a Reachability notifier. - * Network reachability notifications are automatically taken care of by MKNetworkEngine - * - */ -- (id) initWithHostName:(NSString*) hostName apiPath:(NSString*) apiPath customHeaderFields:(NSDictionary*) headers; - -/*! - * @abstract Initializes your network engine with a hostname, port, path, and headers. - * - * @discussion - * Creates an engine for a given host name - * The hostname parameter is optional - * The port parameter can be 0, which means to use the appropriate default port (80 or 443 for HTTP or HTTPS respectively). - * The apiPath paramter is optional - * The apiPath is prefixed to every call to operationWithPath: You can use this method if your server's API location is not at the root (/) - * The hostname, if not null, initializes a Reachability notifier. - * Network reachability notifications are automatically taken care of by MKNetworkEngine - * - */ -- (id) initWithHostName:(NSString*) hostName portNumber:(int)portNumber apiPath:(NSString*) apiPath customHeaderFields:(NSDictionary*) headers; - -/*! - * @abstract Creates a simple GET Operation with a request URL - * - * @discussion - * Creates an operation with the given URL path. - * The default headers you specified in your MKNetworkEngine subclass gets added to the headers - * The HTTP Method is implicitly assumed to be GET - * - */ - --(MKNetworkOperation*) operationWithPath:(NSString*) path; - -/*! - * @abstract Creates a simple GET Operation with a request URL and parameters - * - * @discussion - * Creates an operation with the given URL path. - * The default headers you specified in your MKNetworkEngine subclass gets added to the headers - * The body dictionary in this method gets attached to the URL as query parameters - * The HTTP Method is implicitly assumed to be GET - * - */ --(MKNetworkOperation*) operationWithPath:(NSString*) path - params:(NSDictionary*) body; - -/*! - * @abstract Creates a simple GET Operation with a request URL, parameters and HTTP Method - * - * @discussion - * Creates an operation with the given URL path. - * The default headers you specified in your MKNetworkEngine subclass gets added to the headers - * The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE - * The params dictionary is attached to the body if the HTTP Method is POST/PUT - * The HTTP Method is implicitly assumed to be GET - */ --(MKNetworkOperation*) operationWithPath:(NSString*) path - params:(NSDictionary*) body - httpMethod:(NSString*)method; - -/*! - * @abstract Creates a simple GET Operation with a request URL, parameters, HTTP Method and the SSL switch - * - * @discussion - * Creates an operation with the given URL path. - * The ssl option when true changes the URL to https. - * The ssl option when false changes the URL to http. - * The default headers you specified in your MKNetworkEngine subclass gets added to the headers - * The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE - * The params dictionary is attached to the body if the HTTP Method is POST/PUT - * The previously mentioned methods operationWithPath: and operationWithPath:params: call this internally - */ --(MKNetworkOperation*) operationWithPath:(NSString*) path - params:(NSDictionary*) body - httpMethod:(NSString*)method - ssl:(BOOL) useSSL; - -/*! - * @abstract Creates a simple GET Operation with a request URL - * - * @discussion - * Creates an operation with the given absolute URL. - * The hostname of the engine is *NOT* prefixed - * The default headers you specified in your MKNetworkEngine subclass gets added to the headers - * The HTTP method is implicitly assumed to be GET. - */ --(MKNetworkOperation*) operationWithURLString:(NSString*) urlString; - -/*! - * @abstract Creates a simple GET Operation with a request URL and parameters - * - * @discussion - * Creates an operation with the given absolute URL. - * The hostname of the engine is *NOT* prefixed - * The default headers you specified in your MKNetworkEngine subclass gets added to the headers - * The body dictionary in this method gets attached to the URL as query parameters - * The HTTP method is implicitly assumed to be GET. - */ --(MKNetworkOperation*) operationWithURLString:(NSString*) urlString - params:(NSDictionary*) body; - -/*! - * @abstract Creates a simple Operation with a request URL, parameters and HTTP Method - * - * @discussion - * Creates an operation with the given absolute URL. - * The hostname of the engine is *NOT* prefixed - * The default headers you specified in your MKNetworkEngine subclass gets added to the headers - * The params dictionary in this method gets attached to the URL as query parameters if the HTTP Method is GET/DELETE - * The params dictionary is attached to the body if the HTTP Method is POST/PUT - * This method can be over-ridden by subclasses to tweak the operation creation mechanism. - * You would typically over-ride this method to create a subclass of MKNetworkOperation (if you have one). After you create it, you should call [super prepareHeaders:operation] to attach any custom headers from super class. - * @seealso - * prepareHeaders: - */ --(MKNetworkOperation*) operationWithURLString:(NSString*) urlString - params:(NSDictionary*) body - httpMethod:(NSString*) method; - -/*! - * @abstract adds the custom default headers - * - * @discussion - * This method adds custom default headers to the factory created MKNetworkOperation. - * This method can be over-ridden by subclasses to add more default headers if necessary. - * You would typically over-ride this method if you have over-ridden operationWithURLString:params:httpMethod:. - * @seealso - * operationWithURLString:params:httpMethod: - */ --(void) prepareHeaders:(MKNetworkOperation*) operation; - -/*! - * @abstract Handy helper method for fetching images in the background - * - * @discussion - * Creates an operation with the given image URL. - * The hostname of the engine is *NOT* prefixed. - * The image is returned to the caller via MKNKImageBlock callback block. This image is resized as per the size and decompressed in background. - * @seealso - * imageAtUrl:onCompletion: - */ -- (MKNetworkOperation*)imageAtURL:(NSURL *)url completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock; - -#if TARGET_OS_IPHONE -/*! - * @abstract Handy helper method for fetching images asynchronously in the background - * - * @discussion - * Creates an operation with the given image URL. - * The hostname of the engine is *NOT* prefixed. - * The image is returned to the caller via MKNKImageBlock callback block. This image is resized as per the size and decompressed in background. - * @seealso - * imageAtUrl:onCompletion: - */ -- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size onCompletion:(MKNKImageBlock) imageFetchedBlock DEPRECATED_ATTRIBUTE; - -/*! - * @abstract Handy helper method for fetching images asynchronously in the background - * - * @discussion - * Creates an operation with the given image URL. - * The hostname of the engine is *NOT* prefixed. - * The image is returned to the caller via MKNKImageBlock callback block. This image is resized as per the size and decompressed in background. - * @seealso - * imageAtUrl:onCompletion: - */ -- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock; -#endif - -/*! - * @abstract Handy helper method for fetching images - * - * @discussion - * Creates an operation with the given image URL. - * The hostname of the engine is *NOT* prefixed. - * The image is returned to the caller via MKNKImageBlock callback block. - */ -- (MKNetworkOperation*)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock DEPRECATED_ATTRIBUTE; - -/*! - * @abstract Enqueues your operation into the shared queue - * - * @discussion - * The operation you created is enqueued to the shared queue. If the response for this operation was previously cached, the cached data will be returned. - * @seealso - * enqueueOperation:forceReload: - */ --(void) enqueueOperation:(MKNetworkOperation*) request; - -/*! - * @abstract Enqueues your operation into the shared queue. - * - * @discussion - * The operation you created is enqueued to the shared queue. - * When forceReload is NO, this method behaves like enqueueOperation: - * When forceReload is YES, No cached data will be returned even if cached data is available. - * @seealso - * enqueueOperation: - */ --(void) enqueueOperation:(MKNetworkOperation*) operation forceReload:(BOOL) forceReload; - -/*! - * @abstract Cancels operations matching a given string - * - * @discussion - * Cancels all operations in the shared queue that matches a given string. This string could be your host name or a path - * - */ -+(void) cancelOperationsContainingURLString:(NSString*) string; - -/*! - * @abstract Cancels operations matching the given block. - * - * @discussion - * Cancels all operations in the shared queue for which the given block returns YES. - * - */ -+(void) cancelOperationsMatchingBlock:(BOOL (^)(MKNetworkOperation*))block; - -/*! - * @abstract Cancels all operations created by this engine - * - * @discussion - * Cancels all operations that matches this engine's host name - * This method is a no-op if the engine's host name was not set. - * - */ -- (void) cancelAllOperations; - -/*! - * @abstract HostName of the engine - * @property readonlyHostName - * - * @discussion - * Returns the host name of the engine - * This property is readonly cannot be updated. - * You normally initialize an engine with its hostname using the initWithHostName:customHeaders: method - */ -@property (readonly, copy, nonatomic) NSString *readonlyHostName; - -/*! - * @abstract Port Number that should be used by URL creating factory methods - * @property portNumber - * - * @discussion - * Set a port number for your engine if your remote URL mandates it. - * This property is optional and you DON'T have to specify the default HTTP port 80 - */ -@property (assign, nonatomic) int portNumber; - -/*! - * @abstract WiFi only mode - * @property wifiOnlyMode - * - * @discussion - * When you set this property to YES, MKNetworkEngine will not run operations on mobile data network. - */ -@property (assign, nonatomic) BOOL wifiOnlyMode; - -/*! - * @abstract Sets an api path if it is different from root URL - * @property apiPath - * - * @discussion - * You can use this method to set a custom path to the API location if your server's API path is different from root (/) - * This property is optional - */ -@property (copy, nonatomic) NSString* apiPath; - -/*! - * @abstract Handler that you implement to monitor reachability changes - * @property reachabilityChangedHandler - * - * @discussion - * The framework calls this handler whenever the reachability of the host changes. - * The default implementation freezes the queued operations and stops network activity - * You normally don't have to implement this unless you need to show a HUD notifying the user of connectivity loss - */ -@property (copy, nonatomic) void (^reachabilityChangedHandler)(NetworkStatus ns); - -/*! - * @abstract Registers an associated operation subclass - * - * @discussion - * When you override both MKNetworkEngine and MKNetworkOperation, you might want the engine's factory method - * to prepare operations of your MKNetworkOperation subclass. To create your own MKNetworkOperation subclasses from the factory method, you can register your MKNetworkOperation subclass using this method. - * This method is optional. If you don't use, factory methods in MKNetworkEngine creates MKNetworkOperation objects. - */ --(void) registerOperationSubclass:(Class) aClass; - -/*! - * @abstract Cache Directory Name - * - * @discussion - * This method can be over-ridden by subclasses to provide an alternative cache directory - * The default directory (MKNetworkKitCache) within the NSCaches directory will be used otherwise - * Overriding this method is optional - */ --(NSString*) cacheDirectoryName; - -/*! - * @abstract Cache Directory In Memory Cost - * - * @discussion - * This method can be over-ridden by subclasses to provide an alternative in memory cache size. - * By default, MKNetworkKit caches 10 recent requests in memory - * The default size is 10 - * Overriding this method is optional - */ --(int) cacheMemoryCost; - -/*! - * @abstract Enable Caching - * - * @discussion - * This method should be called explicitly to enable caching for this engine. - * By default, MKNetworkKit doens't cache your requests. - * The cacheMemoryCost and cacheDirectoryName will be used when you turn caching on using this method. - */ --(void) useCache; - -/*! - * @abstract Empties previously cached data - * - * @discussion - * This method is a handy helper that you can use to clear cached data. - * By default, MKNetworkKit doens't cache your requests. Use this only when you enabled caching - * @seealso - * useCache - */ --(void) emptyCache; - -/*! - * @abstract Checks current reachable status - * - * @discussion - * This method is a handy helper that you can use to check for network reachability. - */ --(BOOL) isReachable; - -/*! - * @abstract Boolean variable that states whether the request should automatically include an Accept-Language header. - * @property shouldSendAcceptLanguageHeader - * - * @discussion - * The default value is YES. MKNetworkKit will generate an Accept-Language header using [NSLocale preferredLanguages] + "en-US". - */ -@property (nonatomic, assign) BOOL shouldSendAcceptLanguageHeader; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.m deleted file mode 100644 index a238f97..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkEngine.m +++ /dev/null @@ -1,766 +0,0 @@ -// -// MKNetworkEngine.m -// MKNetworkKit -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import "MKNetworkKit.h" -#define kFreezableOperationExtension @"mknetworkkitfrozenoperation" - -#ifdef __OBJC_GC__ -#error MKNetworkKit does not support Objective-C Garbage Collection -#endif - -#if TARGET_OS_IPHONE -#ifndef __IPHONE_5_0 -#error MKNetworkKit does not support iOS 4 and lower -#endif -#endif - -#if ! __has_feature(objc_arc) -#error MKNetworkKit is ARC only. Either turn on ARC for the project or use -fobjc-arc flag -#endif - -@interface MKNetworkEngine (/*Private Methods*/) - -@property (copy, nonatomic) NSString *hostName; -@property (strong, nonatomic) Reachability *reachability; -@property (copy, nonatomic) NSDictionary *customHeaders; -@property (assign, nonatomic) Class customOperationSubclass; - -@property (nonatomic, strong) NSMutableDictionary *memoryCache; -@property (nonatomic, strong) NSMutableArray *memoryCacheKeys; -@property (nonatomic, strong) NSMutableDictionary *cacheInvalidationParams; - -#if OS_OBJECT_USE_OBJC -@property (strong, nonatomic) dispatch_queue_t backgroundCacheQueue; -@property (strong, nonatomic) dispatch_queue_t operationQueue; -#else -@property (assign, nonatomic) dispatch_queue_t backgroundCacheQueue; -@property (assign, nonatomic) dispatch_queue_t operationQueue; -#endif - -@end - -static NSOperationQueue *_sharedNetworkQueue; - -@implementation MKNetworkEngine - -// Network Queue is a shared singleton object. -// no matter how many instances of MKNetworkEngine is created, there is one and only one network queue -// In theory an app should contain as many network engines as the number of domains it talks to - -#pragma mark - -#pragma mark Initialization - -+(void) initialize { - - if(!_sharedNetworkQueue) { - static dispatch_once_t oncePredicate; - dispatch_once(&oncePredicate, ^{ - _sharedNetworkQueue = [[NSOperationQueue alloc] init]; - [_sharedNetworkQueue addObserver:[self self] forKeyPath:@"operationCount" options:0 context:NULL]; - [_sharedNetworkQueue setMaxConcurrentOperationCount:6]; - - }); - } -} - -- (id) init { - - return [self initWithHostName:nil]; -} - -- (id) initWithHostName:(NSString*) hostName { - - return [self initWithHostName:hostName apiPath:nil customHeaderFields:nil]; -} - -- (id) initWithHostName:(NSString*) hostName apiPath:(NSString*) apiPath customHeaderFields:(NSDictionary*) headers { - - return [self initWithHostName:hostName portNumber:0 apiPath:apiPath customHeaderFields:headers]; -} - -- (id) initWithHostName:(NSString*) hostName portNumber:(int)portNumber apiPath:(NSString*) apiPath customHeaderFields:(NSDictionary*) headers { - if((self = [super init])) { - - self.portNumber = portNumber; - self.apiPath = apiPath; - self.backgroundCacheQueue = dispatch_queue_create("com.mknetworkkit.cachequeue", DISPATCH_QUEUE_SERIAL); - self.operationQueue = dispatch_queue_create("com.mknetworkkit.operationqueue", DISPATCH_QUEUE_SERIAL); - - if(hostName) { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(reachabilityChanged:) - name:kReachabilityChangedNotification - object:nil]; - - self.hostName = hostName; - self.reachability = [Reachability reachabilityWithHostname:self.hostName]; - - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - - [self.reachability startNotifier]; - }); - } - - if(headers[@"User-Agent"] == nil) { - - NSMutableDictionary *newHeadersDict = [headers mutableCopy]; - NSString *userAgentString = [NSString stringWithFormat:@"%@/%@", - [[NSBundle mainBundle] infoDictionary][(NSString *)kCFBundleNameKey], - [[NSBundle mainBundle] infoDictionary][(NSString *)kCFBundleVersionKey]]; - newHeadersDict[@"User-Agent"] = userAgentString; - self.customHeaders = newHeadersDict; - } else { - self.customHeaders = [headers mutableCopy]; - } - - self.customOperationSubclass = [MKNetworkOperation class]; - self.shouldSendAcceptLanguageHeader = YES; - } - - return self; -} - -- (id) initWithHostName:(NSString*) hostName customHeaderFields:(NSDictionary*) headers { - - return [self initWithHostName:hostName apiPath:nil customHeaderFields:headers]; -} - -#pragma mark - -#pragma mark Memory Mangement - --(void) dealloc { - -#if TARGET_OS_IPHONE -#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000 - dispatch_release(_backgroundCacheQueue); - dispatch_release(_operationQueue); -#endif - -#else - -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 - dispatch_release(_backgroundCacheQueue); - dispatch_release(_operationQueue); -#endif -#endif - - [[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil]; -#if TARGET_OS_IPHONE - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil]; -#elif TARGET_OS_MAC - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillHideNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillResignActiveNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil]; -#endif - -} - -#pragma mark - -#pragma mark KVO for network Queue - -+ (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object - change:(NSDictionary *)change context:(void *)context -{ - if (object == _sharedNetworkQueue && [keyPath isEqualToString:@"operationCount"]) { - - [[NSNotificationCenter defaultCenter] postNotificationName:kMKNetworkEngineOperationCountChanged - object:[NSNumber numberWithInteger:(NSInteger)[_sharedNetworkQueue operationCount]]]; -#if TARGET_OS_IPHONE - [UIApplication sharedApplication].networkActivityIndicatorVisible = - ([_sharedNetworkQueue.operations count] > 0); -#endif - } - else { - [super observeValueForKeyPath:keyPath ofObject:object - change:change context:context]; - } -} - -#pragma mark - -#pragma mark Reachability related - --(void) reachabilityChanged:(NSNotification*) notification -{ - if([self.reachability currentReachabilityStatus] == ReachableViaWiFi) - { - DLog(@"Server [%@] is reachable via Wifi", self.hostName); - [_sharedNetworkQueue setMaxConcurrentOperationCount:6]; - - [self checkAndRestoreFrozenOperations]; - } - else if([self.reachability currentReachabilityStatus] == ReachableViaWWAN) - { - if(self.wifiOnlyMode) { - - DLog(@" Disabling engine as server [%@] is reachable only via cellular data.", self.hostName); - [_sharedNetworkQueue setMaxConcurrentOperationCount:0]; - } else { - DLog(@"Server [%@] is reachable only via cellular data", self.hostName); - [_sharedNetworkQueue setMaxConcurrentOperationCount:2]; - [self checkAndRestoreFrozenOperations]; - } - } - else if([self.reachability currentReachabilityStatus] == NotReachable) - { - DLog(@"Server [%@] is not reachable", self.hostName); - [self freezeOperations]; - } - - if(self.reachabilityChangedHandler) { - self.reachabilityChangedHandler([self.reachability currentReachabilityStatus]); - } -} - -#pragma mark Freezing operations (Called when network connectivity fails) --(void) freezeOperations { - - if(![self isCacheEnabled]) return; - - for(MKNetworkOperation *operation in _sharedNetworkQueue.operations) { - - // freeze only freeable operations. - if(![operation freezable]) continue; - - if(!self.hostName) return; - - // freeze only operations that belong to this server - if([[operation url] rangeOfString:self.hostName].location == NSNotFound) continue; - - NSString *archivePath = [[[self cacheDirectoryName] stringByAppendingPathComponent:[operation uniqueIdentifier]] - stringByAppendingPathExtension:kFreezableOperationExtension]; - [NSKeyedArchiver archiveRootObject:operation toFile:archivePath]; - [operation cancel]; - } -} - -+(void) cancelOperationsContainingURLString:(NSString*) string { - - [self cancelOperationsMatchingBlock:^BOOL (MKNetworkOperation* op) { - return [[op.readonlyRequest.URL absoluteString] rangeOfString:string].location != NSNotFound; - }]; -} - -+(void) cancelOperationsMatchingBlock:(BOOL (^)(MKNetworkOperation* op))block { - - NSArray *runningOperations = _sharedNetworkQueue.operations; - [runningOperations enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - - MKNetworkOperation *thisOperation = obj; - if (block(thisOperation)) - [thisOperation cancel]; - }]; -} - --(void) cancelAllOperations { - - if(self.hostName) { - [MKNetworkEngine cancelOperationsContainingURLString:self.hostName]; - } else { - DLog(@"Host name is not set. Cannot cancel operations."); - } -} - --(void) checkAndRestoreFrozenOperations { - - if(![self isCacheEnabled]) return; - - NSError *error = nil; - NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self cacheDirectoryName] error:&error]; - if(error) - DLog(@"%@", error); - - NSArray *pendingOperations = [files filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { - - NSString *thisFile = (NSString*) evaluatedObject; - return ([thisFile rangeOfString:kFreezableOperationExtension].location != NSNotFound); - }]]; - - for(NSString *pendingOperationFile in pendingOperations) { - - NSString *archivePath = [[self cacheDirectoryName] stringByAppendingPathComponent:pendingOperationFile]; - MKNetworkOperation *pendingOperation = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath]; - [self enqueueOperation:pendingOperation]; - NSError *error2 = nil; - [[NSFileManager defaultManager] removeItemAtPath:archivePath error:&error2]; - if(error2) - DLog(@"%@", error2); - } -} - --(NSString*) readonlyHostName { - - return [_hostName copy]; -} - --(BOOL) isReachable { - - return ([self.reachability currentReachabilityStatus] != NotReachable); -} - -#pragma mark - -#pragma mark Create methods - --(void) registerOperationSubclass:(Class) aClass { - - self.customOperationSubclass = aClass; -} - --(MKNetworkOperation*) operationWithPath:(NSString*) path { - - return [self operationWithPath:path params:nil]; -} - --(MKNetworkOperation*) operationWithPath:(NSString*) path - params:(NSDictionary*) body { - - return [self operationWithPath:path - params:body - httpMethod:@"GET"]; -} - --(MKNetworkOperation*) operationWithPath:(NSString*) path - params:(NSDictionary*) body - httpMethod:(NSString*)method { - - return [self operationWithPath:path params:body httpMethod:method ssl:NO]; -} - --(MKNetworkOperation*) operationWithPath:(NSString*) path - params:(NSDictionary*) body - httpMethod:(NSString*)method - ssl:(BOOL) useSSL { - - if(self.hostName == nil) { - - DLog(@"Hostname is nil, use operationWithURLString: method to create absolute URL operations"); - return nil; - } - - NSMutableString *urlString = [NSMutableString stringWithFormat:@"%@://%@", useSSL ? @"https" : @"http", self.hostName]; - - if(self.portNumber != 0) - [urlString appendFormat:@":%d", self.portNumber]; - - if(self.apiPath) - [urlString appendFormat:@"/%@", self.apiPath]; - - if(![path isEqualToString:@"/"]) { // fetch for root? - - if(path.length > 0 && [path characterAtIndex:0] == '/') // if user passes /, don't prefix a slash - [urlString appendFormat:@"%@", path]; - else if (path != nil) - [urlString appendFormat:@"/%@", path]; - } - - - return [self operationWithURLString:urlString params:body httpMethod:method]; -} - --(MKNetworkOperation*) operationWithURLString:(NSString*) urlString { - - return [self operationWithURLString:urlString params:nil httpMethod:@"GET"]; -} - --(MKNetworkOperation*) operationWithURLString:(NSString*) urlString - params:(NSDictionary*) body { - - return [self operationWithURLString:urlString params:body httpMethod:@"GET"]; -} - - --(MKNetworkOperation*) operationWithURLString:(NSString*) urlString - params:(NSDictionary*) body - httpMethod:(NSString*)method { - - MKNetworkOperation *operation = [[self.customOperationSubclass alloc] initWithURLString:urlString params:body httpMethod:method]; - operation.shouldSendAcceptLanguageHeader = self.shouldSendAcceptLanguageHeader; - - [self prepareHeaders:operation]; - return operation; -} - --(void) prepareHeaders:(MKNetworkOperation*) operation { - - [operation addHeaders:self.customHeaders]; -} - --(NSData*) cachedDataForOperation:(MKNetworkOperation*) operation { - - NSData *cachedData = (self.memoryCache)[[operation uniqueIdentifier]]; - if(cachedData) return cachedData; - - NSString *filePath = [[self cacheDirectoryName] stringByAppendingPathComponent:[operation uniqueIdentifier]]; - - if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { - - cachedData = [NSData dataWithContentsOfFile:filePath]; - [self saveCacheData:cachedData forKey:[operation uniqueIdentifier]]; // bring it back to the in-memory cache - return cachedData; - } - - return nil; -} - --(void) enqueueOperation:(MKNetworkOperation*) operation { - - [self enqueueOperation:operation forceReload:NO]; -} - --(void) enqueueOperation:(MKNetworkOperation*) operation forceReload:(BOOL) forceReload { - - NSParameterAssert(operation != nil); - if(operation == nil) return; - - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - - - __weak id weakSelf = self; - - - [operation setCacheHandler:^(MKNetworkOperation* completedCacheableOperation) { - - // if this is not called, the request would have been a non cacheable request - //completedCacheableOperation.cacheHeaders; - NSString *uniqueId = [completedCacheableOperation uniqueIdentifier]; - [weakSelf saveCacheData:[completedCacheableOperation responseData] - forKey:uniqueId]; - - ([weakSelf cacheInvalidationParams])[uniqueId] = completedCacheableOperation.cacheHeaders; - }]; - - __block double expiryTimeInSeconds = 0.0f; - - if([operation isCacheable]) { - - NSData *cachedData = [self cachedDataForOperation:operation]; - if(cachedData) { - dispatch_async(dispatch_get_main_queue(), ^{ - // Jump back to the original thread here since setCachedData updates the main thread - [operation setCachedData:cachedData]; - }); - - if(!forceReload) { - - NSString *uniqueId = [operation uniqueIdentifier]; - NSMutableDictionary *savedCacheHeaders = (self.cacheInvalidationParams)[uniqueId]; - // there is a cached version. - // this means, the current operation is a "GET" - if(savedCacheHeaders) { - NSString *expiresOn = savedCacheHeaders[@"Expires"]; - - dispatch_sync(self.operationQueue, ^{ - NSDate *expiresOnDate = [NSDate dateFromRFC1123:expiresOn]; - expiryTimeInSeconds = [expiresOnDate timeIntervalSinceNow]; - }); - - dispatch_async(dispatch_get_main_queue(), ^{ - - [operation updateOperationBasedOnPreviousHeaders:savedCacheHeaders]; - }); - } - } - } - - dispatch_sync(self.operationQueue, ^{ - - NSArray *operations = _sharedNetworkQueue.operations; - NSUInteger index = [operations indexOfObject:operation]; - BOOL operationFinished = NO; - if(index != NSNotFound) { - - MKNetworkOperation *queuedOperation = (MKNetworkOperation*) (operations)[index]; - operationFinished = [queuedOperation isFinished]; - if(!operationFinished) { - dispatch_async(dispatch_get_main_queue(), ^{ - [queuedOperation updateHandlersFromOperation:operation]; - }); - } - } - - if(expiryTimeInSeconds <= 0 || forceReload || operationFinished) - [_sharedNetworkQueue addOperation:operation]; - // else don't do anything - }); - - } else { - - [_sharedNetworkQueue addOperation:operation]; - } - - if([self.reachability currentReachabilityStatus] == NotReachable) - [self freezeOperations]; - }); -} - -- (MKNetworkOperation*)imageAtURL:(NSURL *)url completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock { - -#ifdef DEBUG - // I could enable caching here, but that hits performance and inturn affects table view scrolling - // if imageAtURL is called for loading thumbnails. - if(![self isCacheEnabled]) DLog(@"imageAtURL:onCompletion: requires caching to be enabled.") -#endif - - if (url == nil) { - return nil; - } - - MKNetworkOperation *op = [self operationWithURLString:[url absoluteString]]; - op.shouldCacheResponseEvenIfProtocolIsHTTPS = YES; - - [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { - - if (imageFetchedBlock) - imageFetchedBlock([completedOperation responseImage], - url, - [completedOperation isCachedResponse]); - - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - if (errorBlock) - errorBlock(completedOperation, error); - }]; - - [self enqueueOperation:op]; - - return op; -} - -#if TARGET_OS_IPHONE - -- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock { - -#ifdef DEBUG - // I could enable caching here, but that hits performance and inturn affects table view scrolling - // if imageAtURL is called for loading thumbnails. - if(![self isCacheEnabled]) DLog(@"imageAtURL:size:onCompletion: requires caching to be enabled.") -#endif - - if (url == nil) { - return nil; - } - - MKNetworkOperation *op = [self operationWithURLString:[url absoluteString]]; - op.shouldCacheResponseEvenIfProtocolIsHTTPS = YES; - - [op addCompletionHandler:^(MKNetworkOperation *completedOperation) { - [completedOperation decompressedResponseImageOfSize:size - completionHandler:^(UIImage *decompressedImage) { - if (imageFetchedBlock) - imageFetchedBlock(decompressedImage, - url, - [completedOperation isCachedResponse]); - }]; - } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) { - if (errorBlock) - errorBlock(completedOperation, error); - DLog(@"%@", error); - }]; - - [self enqueueOperation:op]; - - return op; -} - -- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size onCompletion:(MKNKImageBlock) imageFetchedBlock { - - return [self imageAtURL:url size:size completionHandler:imageFetchedBlock errorHandler:^(MKNetworkOperation* op, NSError* error){}]; -} - -#endif - -- (MKNetworkOperation*)imageAtURL:(NSURL *)url onCompletion:(MKNKImageBlock) imageFetchedBlock -{ - return [self imageAtURL:url completionHandler:imageFetchedBlock errorHandler:^(MKNetworkOperation* op, NSError* error){}]; -} - - -#pragma mark - -#pragma mark Cache related - --(NSString*) cacheDirectoryName { - - static NSString *cacheDirectoryName = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); - NSString *documentsDirectory = paths[0]; - cacheDirectoryName = [documentsDirectory stringByAppendingPathComponent:MKNETWORKCACHE_DEFAULT_DIRECTORY]; - }); - - return cacheDirectoryName; -} - --(int) cacheMemoryCost { - - return MKNETWORKCACHE_DEFAULT_COST; -} - --(void) saveCache { - - for(NSString *cacheKey in [self.memoryCache allKeys]) - { - NSString *filePath = [[self cacheDirectoryName] stringByAppendingPathComponent:cacheKey]; - if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { - - NSError *error = nil; - [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; - ELog(error); - } - - [(self.memoryCache)[cacheKey] writeToFile:filePath atomically:YES]; - } - - [self.memoryCache removeAllObjects]; - [self.memoryCacheKeys removeAllObjects]; - - NSString *cacheInvalidationPlistFilePath = [[self cacheDirectoryName] stringByAppendingPathExtension:@"plist"]; - [self.cacheInvalidationParams writeToFile:cacheInvalidationPlistFilePath atomically:YES]; -} - --(void) saveCacheData:(NSData*) data forKey:(NSString*) cacheDataKey -{ - dispatch_async(self.backgroundCacheQueue, ^{ - - (self.memoryCache)[cacheDataKey] = data; - - NSUInteger index = [self.memoryCacheKeys indexOfObject:cacheDataKey]; - if(index != NSNotFound) - [self.memoryCacheKeys removeObjectAtIndex:index]; - - [self.memoryCacheKeys insertObject:cacheDataKey atIndex:0]; // remove it and insert it at start - - if([self.memoryCacheKeys count] >= (NSUInteger)[self cacheMemoryCost]) - { - NSString *lastKey = [self.memoryCacheKeys lastObject]; - NSData *data2 = (self.memoryCache)[lastKey]; - NSString *filePath = [[self cacheDirectoryName] stringByAppendingPathComponent:lastKey]; - - if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { - - NSError *error = nil; - [[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]; - ELog(error); - } - [data2 writeToFile:filePath atomically:YES]; - - [self.memoryCacheKeys removeLastObject]; - [self.memoryCache removeObjectForKey:lastKey]; - } - }); -} - -/* - - (BOOL) dataOldness:(NSString*) imagePath - { - NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:imagePath error:nil]; - NSDate *creationDate = [attributes valueForKey:NSFileCreationDate]; - - return abs([creationDate timeIntervalSinceNow]); - }*/ - --(BOOL) isCacheEnabled { - - BOOL isDir = NO; - BOOL isCachingEnabled = [[NSFileManager defaultManager] fileExistsAtPath:[self cacheDirectoryName] isDirectory:&isDir]; - return isCachingEnabled; -} - --(void) useCache { - - self.memoryCache = [NSMutableDictionary dictionaryWithCapacity:[self cacheMemoryCost]]; - self.memoryCacheKeys = [NSMutableArray arrayWithCapacity:[self cacheMemoryCost]]; - self.cacheInvalidationParams = [NSMutableDictionary dictionary]; - - NSString *cacheDirectory = [self cacheDirectoryName]; - BOOL isDirectory = YES; - BOOL folderExists = [[NSFileManager defaultManager] fileExistsAtPath:cacheDirectory isDirectory:&isDirectory] && isDirectory; - - if (!folderExists) - { - NSError *error = nil; - [[NSFileManager defaultManager] createDirectoryAtPath:cacheDirectory withIntermediateDirectories:YES attributes:nil error:&error]; - } - - NSString *cacheInvalidationPlistFilePath = [cacheDirectory stringByAppendingPathExtension:@"plist"]; - - BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:cacheInvalidationPlistFilePath]; - - if (fileExists) - { - self.cacheInvalidationParams = [NSMutableDictionary dictionaryWithContentsOfFile:cacheInvalidationPlistFilePath]; - } - -#if TARGET_OS_IPHONE - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) - name:UIApplicationDidReceiveMemoryWarningNotification - object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) - name:UIApplicationDidEnterBackgroundNotification - object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) - name:UIApplicationWillTerminateNotification - object:nil]; - -#elif TARGET_OS_MAC - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) - name:NSApplicationWillHideNotification - object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) - name:NSApplicationWillResignActiveNotification - object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveCache) - name:NSApplicationWillTerminateNotification - object:nil]; - -#endif - - -} - --(void) emptyCache { - - [self saveCache]; // ensures that invalidation params are written to disk properly - NSError *error = nil; - NSArray *directoryContents = [[NSFileManager defaultManager] - contentsOfDirectoryAtPath:[self cacheDirectoryName] error:&error]; - if(error) DLog(@"%@", error); - - error = nil; - for(NSString *fileName in directoryContents) { - - NSString *path = [[self cacheDirectoryName] stringByAppendingPathComponent:fileName]; - [[NSFileManager defaultManager] removeItemAtPath:path error:&error]; - if(error) DLog(@"%@", error); - } - - error = nil; - NSString *cacheInvalidationPlistFilePath = [[self cacheDirectoryName] stringByAppendingPathExtension:@"plist"]; - [[NSFileManager defaultManager] removeItemAtPath:cacheInvalidationPlistFilePath error:&error]; - if(error) DLog(@"%@", error); -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkKit.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkKit.h deleted file mode 100644 index dc2cc4d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkKit.h +++ /dev/null @@ -1,95 +0,0 @@ -// -// MKNetworkKit.h -// MKNetworkKit -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#ifndef MKNetworkKit_MKNetworkKit_h -#define MKNetworkKit_MKNetworkKit_h - - -#if TARGET_OS_IPHONE -#import -#import -#elif TARGET_OS_MAC -#import -#import -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 -#define DO_GCD_RETAIN_RELEASE 0 -#else -#define DO_GCD_RETAIN_RELEASE 1 -#endif -#endif - -#ifdef DEBUG -#ifndef DLog -# define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);} -#endif -#ifndef ELog -# define ELog(err) {if(err) DLog(@"%@", err)} -#endif -#else -#ifndef DLog -# define DLog(...) -#endif -#ifndef ELog -# define ELog(err) -#endif -#endif - -// ALog always displays output regardless of the DEBUG setting -#ifndef ALog -#define ALog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}; -#endif - -#import "Categories/NSString+MKNetworkKitAdditions.h" -#import "Categories/NSDictionary+RequestEncoding.h" -#import "Categories/NSDate+RFC1123.h" -#import "Categories/NSData+MKBase64.h" -#if TARGET_OS_IPHONE -#import "Categories/UIImageView+MKNetworkKitAdditions.h" -#import "Categories/UIAlertView+MKNetworkKitAdditions.h" -#elif TARGET_OS_MAC -#import "Categories/NSImageView+MKNetworkKitAdditions.h" -#import "Categories/NSAlert+MKNetworkKitAdditions.h" -#endif - -#import "Reachability/Reachability.h" - -#import "MKNetworkOperation.h" -#import "MKNetworkEngine.h" - -#define kMKNetworkEngineOperationCountChanged @"kMKNetworkEngineOperationCountChanged" -#define MKNETWORKCACHE_DEFAULT_COST 10 -#define MKNETWORKCACHE_DEFAULT_DIRECTORY @"MKNetworkKitCache" -#define kMKNetworkKitDefaultCacheDuration 60 // 1 minute -#define kMKNetworkKitDefaultImageHeadRequestDuration 3600*24*1 // 1 day (HEAD requests with eTag are sent only after expiry of this. Not that these are not RFC compliant, but needed for performance tuning) -#define kMKNetworkKitDefaultImageCacheDuration 3600*24*7 // 1 day - -// if your server takes longer than 30 seconds to provide real data, -// you should hire a better server developer. -// on iOS (or any mobile device), 30 seconds is already considered high. - -#define kMKNetworkKitRequestTimeOutInSeconds 30 -#endif - - diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.h deleted file mode 100644 index 427b78d..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.h +++ /dev/null @@ -1,692 +0,0 @@ -// -// MKNetwork.h -// MKNetworkKit -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -@class MKNetworkOperation; - -typedef enum { - MKNetworkOperationStateReady = 1, - MKNetworkOperationStateExecuting = 2, - MKNetworkOperationStateFinished = 3 -} MKNetworkOperationState; - -typedef void (^MKNKVoidBlock)(void); -typedef void (^MKNKIDBlock)(void); -typedef void (^MKNKProgressBlock)(double progress); -typedef void (^MKNKResponseBlock)(MKNetworkOperation* completedOperation); -#if TARGET_OS_IPHONE -typedef void (^MKNKImageBlock) (UIImage* fetchedImage, NSURL* url, BOOL isInCache); -#elif TARGET_OS_MAC -typedef void (^MKNKImageBlock) (NSImage* fetchedImage, NSURL* url, BOOL isInCache); -#endif -typedef void (^MKNKResponseErrorBlock)(MKNetworkOperation* completedOperation, NSError* error); -typedef void (^MKNKErrorBlock)(NSError* error); - -typedef void (^MKNKAuthBlock)(NSURLAuthenticationChallenge* challenge); - -typedef NSString* (^MKNKEncodingBlock) (NSDictionary* postDataDict); - -typedef enum { - - MKNKPostDataEncodingTypeURL = 0, // default - MKNKPostDataEncodingTypeJSON, - MKNKPostDataEncodingTypePlist, - MKNKPostDataEncodingTypeCustom -} MKNKPostDataEncodingType; -/*! - @header MKNetworkOperation.h - @abstract Represents a single unique network operation. - */ - -/*! - * @class MKNetworkOperation - * @abstract Represents a single unique network operation. - * - * @discussion - * You normally create an instance of this class using the methods exposed by MKNetworkEngine - * Created operations are enqueued into the shared queue on MKNetworkEngine - * MKNetworkOperation encapsulates both request and response - * Printing a MKNetworkOperation prints out a cURL command that can be copied and pasted directly on terminal - * Freezable operations are serialized when network connectivity is lost and performed when connection is restored - */ -@interface MKNetworkOperation : NSOperation { - -@private - int _state; - BOOL _freezable; - MKNKPostDataEncodingType _postDataEncoding; -} - -/*! - * @abstract Request URL Property - * @property url - * - * @discussion - * Returns the operation's URL - * This property is readonly cannot be updated. - * To create an operation with a specific URL, use the operationWithURLString:params:httpMethod: - */ -@property (nonatomic, copy, readonly) NSString *url; - -/*! - * @abstract The internal request object - * @property readonlyRequest - * - * @discussion - * Returns the operation's actual request object - * This property is readonly cannot be modified. - * To create an operation with a new request, use the operationWithURLString:params:httpMethod: - */ -@property (nonatomic, strong, readonly) NSURLRequest *readonlyRequest; - -/*! - * @abstract The internal HTTP Response Object - * @property readonlyResponse - * - * @discussion - * Returns the operation's actual response object - * This property is readonly cannot be updated. - */ -@property (nonatomic, strong, readonly) NSHTTPURLResponse *readonlyResponse; - -/*! - * @abstract The internal HTTP Post data values - * @property readonlyPostDictionary - * - * @discussion - * Returns the operation's post data dictionary - * This property is readonly cannot be updated. - * Rather, updating this post dictionary doesn't have any effect on the MKNetworkOperation. - * Use the addHeaders method to add post data parameters to the operation. - * - * @seealso - * addHeaders: - */ -@property (nonatomic, copy, readonly) NSDictionary *readonlyPostDictionary; - -/*! - * @abstract The internal request object's method type - * @property HTTPMethod - * - * @discussion - * Returns the operation's method type - * This property is readonly cannot be modified. - * To create an operation with a new method type, use the operationWithURLString:params:httpMethod: - */ -@property (nonatomic, copy, readonly) NSString *HTTPMethod; - -/*! - * @abstract The internal response object's status code - * @property HTTPStatusCode - * - * @discussion - * Returns the operation's response's status code. - * Returns 0 when the operation has not yet started and the response is not available. - * This property is readonly cannot be modified. - */ -@property (nonatomic, assign, readonly) NSInteger HTTPStatusCode; - -/*! - * @abstract Post Data Encoding Type Property - * @property postDataEncoding - * - * @discussion - * Specifies which type of encoding should be used to encode post data. - * MKNKPostDataEncodingTypeURL is the default which defaults to application/x-www-form-urlencoded - * MKNKPostDataEncodingTypeJSON uses JSON encoding. - * JSON Encoding is supported only in iOS 5 or Mac OS X 10.7 and above. - * On older operating systems, JSON Encoding reverts back to URL Encoding - * You can use the postDataEncodingHandler to provide a custom postDataEncoding - * For example, JSON encoding using a third party library. - * - * @seealso - * setCustomPostDataEncodingHandler:forType: - * - */ -@property (nonatomic, assign) MKNKPostDataEncodingType postDataEncoding; - -/*! - * @abstract Set a customized Post Data Encoding Handler for a given HTTP Content Type - * - * @discussion - * If you need customized post data encoding support, provide a block method here. - * This block method will be invoked only when your HTTP Method is POST or PUT - * For default URL encoding or JSON encoding, use the property postDataEncoding - * If you change the postData format, it's your responsiblity to provide a correct Content-Type. - * - * @seealso - * postDataEncoding - */ --(void) setCustomPostDataEncodingHandler:(MKNKEncodingBlock) postDataEncodingHandler forType:(NSString*) contentType; - -/*! - * @abstract String Encoding Property - * @property stringEncoding - * - * @discussion - * Specifies which type of encoding should be used to encode URL strings - */ -@property (nonatomic, assign) NSStringEncoding stringEncoding; - -/*! - * @abstract Freezable request - * @property freezable - * - * @discussion - * Freezable operations are serialized when the network goes down and restored when the connectivity is up again. - * Only POST, PUT and DELETE operations are freezable. - * In short, any operation that changes the state of the server are freezable, creating a tweet, checking into a new location etc., Operations like fetching a list of tweets (think readonly GET operations) are not freezable. - * MKNetworkKit doesn't freeze (readonly) GET operations even if they are marked as freezable - */ -@property (nonatomic, assign) BOOL freezable; - -/*! - * @abstract Error object - * @property error - * - * @discussion - * If the network operation results in an error, this will hold the response error, otherwise it will be nil - */ -@property (nonatomic, readonly, strong) NSError *error; - -/*! - * @abstract Boolean variable that states whether the operation's response should be cached despite coming from a secured source - * @property shouldCacheEvenIfProtocolIsHTTPS - * - * @discussion - * If you set this property to YES, the operation's data will be cached even if the source is secure (HTTPS) - * The default value is NO. MKNetworkKit will not cache responses from secure servers - */ -@property (nonatomic, assign) BOOL shouldCacheResponseEvenIfProtocolIsHTTPS; - -/*! - * @abstract Boolean variable that states whether the operation's response should be cached - * @property shouldNotCacheResponse - * - * @discussion - * If you set this property to YES, the operation's data will not be cached even if the engine's useCache is enabled - * The default value is NO. MKNetworkKit will cache responses based on the engine setting. - * This property should be used sparingly if your backend isn't written adhering to HTTP 1.1 caching standards - */ -@property (nonatomic, assign) BOOL shouldNotCacheResponse; - -/*! - * @abstract Boolean variable that states whether the operation should continue if the certificate is invalid. - * @property shouldContinueWithInvalidCertificate - * - * @discussion - * If you set this property to YES, the operation will continue as if the certificate was valid (if you use Server Trust Auth) - * The default value is NO. MKNetworkKit will not run an operation with a server that is not trusted. - */ -@property (nonatomic, assign) BOOL shouldContinueWithInvalidCertificate; - -/*! - * @abstract Boolean variable that states whether the request should automatically include an Accept-Language header. - * @property shouldSendAcceptLanguageHeader - * - * @discussion - * If set to YES, then MKNetworkKit will generate an Accept-Language header using [NSLocale preferredLanguages] + "en-us". - * This is set by MKNetworkEngine when it creates the MKNetworkOperation instance, so it gets its default from there. - */ -@property (nonatomic, assign) BOOL shouldSendAcceptLanguageHeader; - -/*! - * @abstract Cache headers of the response - * @property cacheHeaders - * - * @discussion - * If the network operation is a GET, this dictionary will be populated with relevant cache related headers - * MKNetworkKit assumes a 7 day cache for images and 1 minute cache for all requests with no-cache set - * This property is internal to MKNetworkKit. Modifying this is not recommended and will result in unexpected behaviour - */ -@property (strong, nonatomic) NSMutableDictionary *cacheHeaders; - -/*! - * @abstract Authentication methods - * - * @discussion - * If your request needs to be authenticated, set your username and password using this method. - */ --(void) setUsername:(NSString*) name password:(NSString*) password; - -/*! - * @abstract Authentication methods - * - * @discussion - * If your request needs to be authenticated using HTTP Basic, use this method to set your username and password. - * Calling this method with basicAuth:NO is same as calling setUserName:password: - * @seealso - * setUserName:password: - */ --(void) setUsername:(NSString*) username password:(NSString*) password basicAuth:(BOOL) bYesOrNo; - -/*! - * @abstract Authentication methods (Client Certificate) - * @property clientCertificate - * - * @discussion - * If your request needs to be authenticated using a client certificate, set the certificate path here - */ -@property (copy, nonatomic) NSString *clientCertificate; - -/*! - * @abstract Authentication methods (Password for the Client Certificate) - * @property clientCertificatePassword - * - * @discussion - * If your client certificate is encrypted with a password, specify it here - */ -@property (copy, nonatomic) NSString *clientCertificatePassword; - -/*! - * @abstract Custom authentication handler - * @property authHandler - * - * @discussion - * If your request needs to be authenticated using a custom method (like a Web page/HTML Form), add a block method here - * and process the NSURLAuthenticationChallenge - */ -@property (nonatomic, copy) MKNKAuthBlock authHandler; - -/*! - * @abstract Handler that you implement to monitor reachability changes - * @property operationStateChangedHandler - * - * @discussion - * The framework calls this handler whenever the operation state changes - */ -@property (copy, nonatomic) void (^operationStateChangedHandler)(MKNetworkOperationState newState); - -/*! - * @abstract controls persistence of authentication credentials - * @property credentialPersistence - * - * @discussion - * The default value is set to NSURLCredentialPersistenceForSession, change it to NSURLCredentialPersistenceNone to avoid caching issues (isse #35) - */ -@property (nonatomic, assign) NSURLCredentialPersistence credentialPersistence; -#if TARGET_OS_IPHONE - -/*! - * @abstract notification that has to be shown when an error occurs and the app is in background - * @property localNotification - * - * @discussion - * The default value nil. No notification is shown when an error occurs. - * To show a notification when the app is in background and the network operation running in background fails, - * set this parameter to a UILocalNotification object - */ -@property (nonatomic, strong) UILocalNotification *localNotification; - -/*! - * @abstract Shows a local notification when an error occurs - * @property shouldShowLocalNotificationOnError - * - * @discussion - * The default value NO. No notification is shown when an error occurs. - * When set to YES, MKNetworkKit shows the NSError localizedDescription text as a notification when the app is in background and the network operation ended in error. - * To customize the local notification text, use the property localNotification - - * @seealso - * localNotification - */ -@property (nonatomic, assign) BOOL shouldShowLocalNotificationOnError; -#endif - -/*! - * @abstract Add additional POST/GET parameters to your request - * - * @discussion - * If you ever need to set additional params after creating your operation, you this method. - * You normally set default parameters to the params parameter when you create a operation. - * On specific cases where you need to add a new parameter for a call, you can use this - */ --(void) addParams:(NSDictionary*) paramsDictionary; - -/*! - * @abstract Add additional header - * - * @discussion Add a single additional header. See addHeaders for a full discussion. - */ --(void) addHeader:(NSString*)key withValue:(NSString*)value; - -/*! - * @abstract Add additional header parameters - * - * @discussion - * If you ever need to set additional headers after creating your operation, you this method. - * You normally set default headers to the engine and they get added to every request you create. - * On specific cases where you need to set a new header parameter for just a single API call, you can use this - */ --(void) addHeaders:(NSDictionary*) headersDictionary; - -/*! - * @abstract Set a header, overwriting any value already set. - * - * @discussion addHeader will append the value to any header already set. If you want to overwrite - * that value, then use setHeader instead. - */ --(void) setHeader:(NSString*)key withValue:(NSString*)value; - -/*! - * @abstract Sets the authorization header after prefixing it with a given auth type - * - * @discussion - * If you need to set the HTTP Authorization header, you can use this convinience method. - * This method internally calls addHeaders: - * The authType parameter is a string that you can prefix to your auth token to tell your server what kind of authentication scheme you want to use. HTTP Basic Authentication uses the string "Basic" for authType - * To use HTTP Basic Authentication, consider using the method setUsername:password:basicAuth: instead. - * - * Example - * [op setAuthorizationHeaderValue:@"abracadabra" forAuthType:@"Token"] will set the header value to - * "Authorization: Token abracadabra" - * - * @seealso - * setUsername:password:basicAuth: - * addHeaders: - */ --(void) setAuthorizationHeaderValue:(NSString*) token forAuthType:(NSString*) authType; - -/*! - * @abstract Attaches a file to the request - * - * @discussion - * This method lets you attach a file to the request - * The method has a side effect. It changes the HTTPMethod to "POST" regardless of what it was before. - * It also changes the post format to multipart/form-data - * The mime-type is assumed to be application/octet-stream - */ --(void) addFile:(NSString*) filePath forKey:(NSString*) key; - -/*! - * @abstract Attaches a file to the request and allows you to specify a mime-type - * - * @discussion - * This method lets you attach a file to the request - * The method has a side effect. It changes the HTTPMethod to "POST" regardless of what it was before. - * It also changes the post format to multipart/form-data - */ --(void) addFile:(NSString*) filePath forKey:(NSString*) key mimeType:(NSString*) mimeType; - -/*! - * @abstract Attaches a resource to the request from a NSData pointer - * - * @discussion - * This method lets you attach a NSData object to the request. The behaviour is exactly similar to addFile:forKey: - * The method has a side effect. It changes the HTTPMethod to "POST" regardless of what it was before. - * It also changes the post format to multipart/form-data - * The mime-type is assumed to be application/octet-stream - */ --(void) addData:(NSData*) data forKey:(NSString*) key; - -/*! - * @abstract Attaches a resource to the request from a NSData pointer and allows you to specify a mime-type - * - * @discussion - * This method lets you attach a NSData object to the request. The behaviour is exactly similar to addFile:forKey:mimeType: - * The method has a side effect. It changes the HTTPMethod to "POST" regardless of what it was before. - * It also changes the post format to multipart/form-data - */ --(void) addData:(NSData*) data forKey:(NSString*) key mimeType:(NSString*) mimeType fileName:(NSString*) fileName; - -/*! - * @abstract Block Handler for completion and error - * - * @discussion - * This method sets your completion and error blocks. If your operation's response data was previously called, - * the completion block will be called almost immediately with the cached response. You can check if the completion - * handler was invoked with a cached data or with real data by calling the isCachedResponse method. - * This method is deprecated in favour of addCompletionHandler:errorHandler: that returns the completedOperation in the error block as well. - * While I will still continue to support this method, I'll remove it completely in a future release. - * - * @seealso - * isCachedResponse - * addCompletionHandler:errorHandler: - */ --(void) onCompletion:(MKNKResponseBlock) response onError:(MKNKErrorBlock) error DEPRECATED_ATTRIBUTE; - -/*! - * @abstract adds a block Handler for completion and error - * - * @discussion - * This method sets your completion and error blocks. If your operation's response data was previously called, - * the completion block will be called almost immediately with the cached response. You can check if the completion - * handler was invoked with a cached data or with real data by calling the isCachedResponse method. - * - * @seealso - * onCompletion:onError: - */ --(void) addCompletionHandler:(MKNKResponseBlock) response errorHandler:(MKNKResponseErrorBlock) error; - -/*! - * @abstract Block Handler for tracking 304 not modified state - * - * @discussion - * This method will be called if the server sends a 304 HTTP status for your request. - * - */ --(void) onNotModified:(MKNKVoidBlock) notModifiedBlock; - -/*! - * @abstract Block Handler for tracking upload progress - * - * @discussion - * This method can be used to update your progress bars when an upload is in progress. - * The value range of the progress is 0 to 1. - * - */ --(void) onUploadProgressChanged:(MKNKProgressBlock) uploadProgressBlock; - -/*! - * @abstract Block Handler for tracking download progress - * - * @discussion - * This method can be used to update your progress bars when a download is in progress. - * The value range of the progress is 0 to 1. - * - */ --(void) onDownloadProgressChanged:(MKNKProgressBlock) downloadProgressBlock; - -/*! - * @abstract Uploads a resource from a stream - * - * @discussion - * This method can be used to upload a resource for a post body directly from a stream. - * - */ --(void) setUploadStream:(NSInputStream*) inputStream; - -/*! - * @abstract Downloads a resource directly to a file or any output stream - * - * @discussion - * This method can be used to download a resource directly to a stream (It's normally a file in most cases). - * Calling this method multiple times adds new streams to the same operation. - * A stream cannot be removed after it is added. - * - */ --(void) addDownloadStream:(NSOutputStream*) outputStream; - -/*! - * @abstract Helper method to check if the response is from cache - * - * @discussion - * This method should be used to check if your response is cached. - * When you enable caching on MKNetworkEngine, your completionHandler will be called with cached data first and then - * with real data, later after fetching. In your handler, you can call this method to check if it is from cache or not - * - */ --(BOOL) isCachedResponse; - -/*! - * @abstract Helper method to retrieve the contents - * - * @discussion - * This method is used for accessing the downloaded data. If the operation is still in progress, the method returns nil instead of partial data. To access partial data, use a downloadStream. - * - * @seealso - * addDownloadStream: - */ --(NSData*) responseData; - -/*! - * @abstract Helper method to retrieve the contents as a NSString - * - * @discussion - * This method is used for accessing the downloaded data. If the operation is still in progress, the method returns nil instead of partial data. To access partial data, use a downloadStream. The method also converts the responseData to a NSString using the stringEncoding specified in the operation - * - * @seealso - * addDownloadStream: - * stringEncoding - */ --(NSString*)responseString; - -/*! - * @abstract Helper method to print the request as a cURL command - * - * @discussion - * This method is used for displaying the request you created as a cURL command - * - */ --(NSString*) curlCommandLineString; - -/*! - * @abstract Helper method to retrieve the contents as a NSString encoded using a specific string encoding - * - * @discussion - * This method is used for accessing the downloaded data. If the operation is still in progress, the method returns nil instead of partial data. To access partial data, use a downloadStream. The method also converts the responseData to a NSString using the stringEncoding specified in the parameter - * - * @seealso - * addDownloadStream: - * stringEncoding - */ --(NSString*) responseStringWithEncoding:(NSStringEncoding) encoding; - -/*! - * @abstract Helper method to retrieve the contents as a UIImage - * - * @discussion - * This method is used for accessing the downloaded data as a UIImage. If the operation is still in progress, the method returns nil instead of a partial image. To access partial data, use a downloadStream. If the response is not a valid image, this method returns nil. This method doesn't obey the response mime type property. If the server response with a proper image data but set the mime type incorrectly, this method will still be able access the response as an image. - * - * @seealso - * addDownloadStream: - */ -#if TARGET_OS_IPHONE --(UIImage*) responseImage; --(void) decompressedResponseImageOfSize:(CGSize) size completionHandler:(void (^)(UIImage *decompressedImage)) imageDecompressionHandler; -#elif TARGET_OS_MAC --(NSImage*) responseImage; --(NSXMLDocument*) responseXML; -#endif - -/*! - * @abstract Helper method to retrieve the contents as a NSDictionary or NSArray depending on the JSON contents - * - * @discussion - * This method is used for accessing the downloaded data as a NSDictionary or an NSArray. If the operation is still in progress, the method returns nil. If the response is not a valid JSON, this method returns nil. - * - * @seealso - * responseJSONWithCompletionHandler: - - * @availability - * iOS 5 and above or Mac OS 10.7 and above - */ --(id) responseJSON; - -/*! - * @abstract Helper method to retrieve the contents as a NSDictionary or NSArray depending on the JSON contents in the background - * - * @discussion - * This method is used for accessing the downloaded data as a NSDictionary or an NSArray. If the operation is still in progress, the method returns nil. If the response is not a valid JSON, this method returns nil. The difference between this and responseJSON is that, this method decodes JSON in the background. - * - * @see also - * responseJSON - * responseJSONWithOptions:completionHandler: - * - * @availability - * iOS 5 and above or Mac OS 10.7 and above - */ --(void) responseJSONWithCompletionHandler:(void (^)(id jsonObject)) jsonDecompressionHandler; - -/*! - * @abstract Helper method to retrieve the contents as a NSDictionary or NSArray depending on the JSON contents in the background - * - * @discussion - * This method is used for accessing the downloaded data as a NSDictionary or an NSArray. If the operation is still in progress, the method returns nil. If the response is not a valid JSON, this method returns nil. The difference between this and responseJSON is that, this method decodes JSON in the background and allows passing JSON reading options like parsing JSON fragments. - * - * @see also - * responseJSON - * responseJSONWithCompletionHandler: - * - * @availability - * iOS 5 and above or Mac OS 10.7 and above - */ --(void) responseJSONWithOptions:(NSJSONReadingOptions) options completionHandler:(void (^)(id jsonObject)) jsonDecompressionHandler; - -/*! - * @abstract Overridable custom method where you can add your custom business logic error handling - * - * @discussion - * This optional method can be overridden to do custom error handling. Be sure to call [super operationSucceeded] at the last. - * For example, a valid HTTP response (200) like "Item not found in database" might have a custom business error code - * You can override this method and called [super failWithError:customError]; to notify that HTTP call was successful but the method - * ended as a failed call - * - */ --(void) operationSucceeded; - -/*! - * @abstract Overridable custom method where you can add your custom business logic error handling - * - * @discussion - * This optional method can be overridden to do custom error handling. Be sure to call [super operationSucceeded] at the last. - * For example, a invalid HTTP response (401) like "Unauthorized" might be a valid case in your app. - * You can override this method and called [super operationSucceeded]; to notify that HTTP call failed but the method - * ended as a success call. For example, Facebook login failed, but to your business implementation, it's not a problem as you - * are going to try alternative login mechanisms. - * - */ --(void) operationFailedWithError:(NSError*) error; - -/*! - * @abstract Copy this MKNetworkOperation, with the intention of retrying the call. - * - * @discussion This means that the request parameters and callbacks are all preserved, but anything related - * to an ongoing request is discarded, so that a new request with the same configuration can be made. - */ --(instancetype) copyForRetry; - -// internal methods called by MKNetworkEngine only. -// Don't touch --(BOOL) isCacheable; --(void) setCachedData:(NSData*) cachedData; --(void) setCacheHandler:(MKNKResponseBlock) cacheHandler; --(void) updateHandlersFromOperation:(MKNetworkOperation*) operation; --(void) updateOperationBasedOnPreviousHeaders:(NSMutableDictionary*) headers; --(NSString*) uniqueIdentifier; - -- (instancetype)initWithURLString:(NSString *)aURLString - params:(NSDictionary *)params - httpMethod:(NSString *)method; -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.m deleted file mode 100644 index 4932304..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/MKNetworkOperation.m +++ /dev/null @@ -1,1518 +0,0 @@ -// -// MKNetworkOperation.m -// MKNetworkKit -// -// Created by Mugunth Kumar (@mugunthkumar) on 11/11/11. -// Copyright (C) 2011-2020 by Steinlogic Consulting and Training Pte Ltd - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import "MKNetworkKit.h" - -#import - -#ifdef __OBJC_GC__ -#error MKNetworkKit does not support Objective-C Garbage Collection -#endif - -#if TARGET_OS_IPHONE -#ifndef __IPHONE_5_0 -#error MKNetworkKit does not support iOS 4 and lower -#endif -#endif - -#if ! __has_feature(objc_arc) -#error MKNetworkKit is ARC only. Either turn on ARC for the project or use -fobjc-arc flag -#endif - -OSStatus extractIdentityAndTrust(CFDataRef inPKCS12Data, - SecIdentityRef *outIdentity, - SecTrustRef *outTrust, - CFStringRef keyPassword); - -@interface MKNetworkOperation (/*Private Methods*/) -@property (strong, nonatomic) NSURLConnection *connection; -@property (copy, nonatomic) NSString *uniqueId; -@property (strong, nonatomic) NSMutableURLRequest *request; -@property (strong, nonatomic) NSHTTPURLResponse *response; - -@property (strong, nonatomic) NSMutableDictionary *fieldsToBePosted; -@property (strong, nonatomic) NSMutableArray *filesToBePosted; -@property (strong, nonatomic) NSMutableArray *dataToBePosted; - -@property (copy, nonatomic) NSString *username; -@property (copy, nonatomic) NSString *password; - -@property (nonatomic, strong) NSMutableArray *responseBlocks; -@property (nonatomic, strong) NSMutableArray *errorBlocks; -@property (nonatomic, strong) NSMutableArray *errorBlocksType2; - -@property (nonatomic, assign) MKNetworkOperationState state; -@property (nonatomic, assign) BOOL isCancelled; - -@property (strong, nonatomic) NSMutableData *mutableData; -@property (assign, nonatomic) NSUInteger downloadedDataSize; - -@property (nonatomic, strong) NSMutableArray *notModifiedHandlers; - -@property (nonatomic, strong) NSMutableArray *uploadProgressChangedHandlers; -@property (nonatomic, strong) NSMutableArray *downloadProgressChangedHandlers; -@property (nonatomic, copy) MKNKEncodingBlock postDataEncodingHandler; - -@property (nonatomic, assign) NSInteger startPosition; - -@property (nonatomic, strong) NSMutableArray *downloadStreams; -@property (nonatomic, copy) NSData *cachedResponse; -@property (nonatomic, copy) MKNKResponseBlock cacheHandlingBlock; - -@property (nonatomic, assign) SecTrustRef serverTrust; - -#if TARGET_OS_IPHONE -@property (nonatomic, assign) UIBackgroundTaskIdentifier backgroundTaskId; -#endif - -@property (strong, nonatomic) NSError *error; - -- (instancetype)initWithURLString:(NSString *)aURLString - params:(NSDictionary *)body - httpMethod:(NSString *)method; - --(NSData*) bodyData; - --(NSString*) encodedPostDataString; -- (void) showLocalNotification; -- (void) endBackgroundTask; - -@end - -@implementation MKNetworkOperation - -@dynamic freezable; - -// A RESTful service should always return the same response for a given URL and it's parameters. -// this means if these values are correct, you can cache the responses -// This is another reason why we check only GET methods. -// even if URL and others are same, POST, DELETE, PUT methods should not be cached and should not be treated equal. - --(BOOL) isCacheable { - - if(self.shouldNotCacheResponse) return NO; - if(self.username != nil) return NO; - if(self.password != nil) return NO; - if(self.clientCertificate != nil) return NO; - if(self.clientCertificatePassword != nil) return NO; - if(![self.request.HTTPMethod isEqualToString:@"GET"]) return NO; - if([self.request.URL.scheme.lowercaseString isEqualToString:@"https"]) return self.shouldCacheResponseEvenIfProtocolIsHTTPS; - if(self.downloadStreams.count > 0) return NO; // should not cache operations that have streams attached - return YES; -} - - -//=========================================================== -// + (BOOL)automaticallyNotifiesObserversForKey: -// -//=========================================================== -+ (BOOL)automaticallyNotifiesObserversForKey: (NSString *)theKey -{ - BOOL automatic; - - if ([theKey isEqualToString:@"postDataEncoding"]) { - automatic = NO; - } else { - automatic = [super automaticallyNotifiesObserversForKey:theKey]; - } - - return automatic; -} - -//=========================================================== -// postDataEncoding -//=========================================================== -- (MKNKPostDataEncodingType)postDataEncoding -{ - return _postDataEncoding; -} -- (void)setPostDataEncoding:(MKNKPostDataEncodingType)aPostDataEncoding -{ - _postDataEncoding = aPostDataEncoding; - - NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); - - switch (self.postDataEncoding) { - - case MKNKPostDataEncodingTypeURL: { - [self.request setValue: - [NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset] - forHTTPHeaderField:@"Content-Type"]; - } - break; - case MKNKPostDataEncodingTypeJSON: { - [self.request setValue: - [NSString stringWithFormat:@"application/json; charset=%@", charset] - forHTTPHeaderField:@"Content-Type"]; - } - break; - case MKNKPostDataEncodingTypePlist: { - [self.request setValue: - [NSString stringWithFormat:@"application/x-plist; charset=%@", charset] - forHTTPHeaderField:@"Content-Type"]; - } - - default: - break; - } -} - --(NSString*) encodedPostDataString { - - NSString *returnValue = @""; - if(self.postDataEncodingHandler) - returnValue = self.postDataEncodingHandler(self.fieldsToBePosted); - else if(self.postDataEncoding == MKNKPostDataEncodingTypeURL) - returnValue = [self.fieldsToBePosted urlEncodedKeyValueString]; - else if(self.postDataEncoding == MKNKPostDataEncodingTypeJSON) - returnValue = [self.fieldsToBePosted jsonEncodedKeyValueString]; - else if(self.postDataEncoding == MKNKPostDataEncodingTypePlist) - returnValue = [self.fieldsToBePosted plistEncodedKeyValueString]; - return returnValue; -} - --(void) setCustomPostDataEncodingHandler:(MKNKEncodingBlock) postDataEncodingHandler forType:(NSString*) contentType { - - NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); - self.postDataEncoding = MKNKPostDataEncodingTypeCustom; - self.postDataEncodingHandler = postDataEncodingHandler; - [self.request setValue: - [NSString stringWithFormat:@"%@; charset=%@", contentType, charset] - forHTTPHeaderField:@"Content-Type"]; -} -//=========================================================== -// freezable -//=========================================================== -- (BOOL)freezable -{ - return _freezable; -} - --(NSString*) url { - - return [[self.request URL] absoluteString]; -} - --(NSURLRequest*) readonlyRequest { - - return [self.request copy]; -} - --(NSHTTPURLResponse*) readonlyResponse { - - return [self.response copy]; -} - -- (NSDictionary *) readonlyPostDictionary { - - return [self.fieldsToBePosted copy]; -} - --(NSString*) HTTPMethod { - - return self.request.HTTPMethod; -} - --(NSInteger) HTTPStatusCode { - - if(self.response) - return self.response.statusCode; - else - return 0; -} - -- (void)setFreezable:(BOOL)flag -{ - // get method cannot be frozen. - // No point in freezing a method that doesn't change server state. - if([self.request.HTTPMethod isEqualToString:@"GET"] && flag) return; - _freezable = flag; - - if(_freezable && self.uniqueId == nil) - self.uniqueId = [NSString uniqueString]; -} - - --(BOOL) isEqual:(id)object { - if(object == self) - return YES; - if(!object || ![object isKindOfClass:[self class]]) - return NO; - if([self.request.HTTPMethod isEqualToString:@"GET"] || [self.request.HTTPMethod isEqualToString:@"HEAD"]) { - - MKNetworkOperation *anotherObject = (MKNetworkOperation*) object; - return ([[self uniqueIdentifier] isEqualToString:[anotherObject uniqueIdentifier]]); - } - - return NO; -} - --(NSUInteger) hash { - return [[self uniqueIdentifier] hash]; -} - --(NSString*) uniqueIdentifier { - - NSMutableString *str = [NSMutableString stringWithFormat:@"%@ %@", self.request.HTTPMethod, self.url]; - - if(self.username || self.password) { - - [str appendFormat:@" [%@:%@]", - self.username ? self.username : @"", - self.password ? self.password : @""]; - } - - if(self.freezable) { - - [str appendString:self.uniqueId]; - } - return [str md5]; -} - --(BOOL) isCachedResponse { - - return self.cachedResponse != nil; -} - --(void) notifyCache { - - if(![self isCacheable]) return; - if(!([self.response statusCode] >= 200 && [self.response statusCode] < 300)) return; - - if(![self isCancelled]) - self.cacheHandlingBlock(self); -} - --(MKNetworkOperationState) state { - - return (MKNetworkOperationState)_state; -} - --(void) setState:(MKNetworkOperationState)newState { - - switch (newState) { - case MKNetworkOperationStateReady: - [self willChangeValueForKey:@"isReady"]; - break; - case MKNetworkOperationStateExecuting: - [self willChangeValueForKey:@"isReady"]; - [self willChangeValueForKey:@"isExecuting"]; - break; - case MKNetworkOperationStateFinished: - [self willChangeValueForKey:@"isExecuting"]; - [self willChangeValueForKey:@"isFinished"]; - break; - } - - _state = newState; - - switch (newState) { - case MKNetworkOperationStateReady: - [self didChangeValueForKey:@"isReady"]; - break; - case MKNetworkOperationStateExecuting: - [self didChangeValueForKey:@"isReady"]; - [self didChangeValueForKey:@"isExecuting"]; - break; - case MKNetworkOperationStateFinished: - [self didChangeValueForKey:@"isExecuting"]; - [self didChangeValueForKey:@"isFinished"]; - break; - } - - if(self.operationStateChangedHandler) { - self.operationStateChangedHandler(newState); - } -} - -- (void)encodeWithCoder:(NSCoder *)encoder -{ - [encoder encodeInteger:(NSInteger)self.stringEncoding forKey:@"stringEncoding"]; - [encoder encodeInteger:_postDataEncoding forKey:@"postDataEncoding"]; - - [encoder encodeObject:self.uniqueId forKey:@"uniqueId"]; - [encoder encodeObject:self.request forKey:@"request"]; - [encoder encodeObject:self.response forKey:@"response"]; - [encoder encodeObject:self.fieldsToBePosted forKey:@"fieldsToBePosted"]; - [encoder encodeObject:self.filesToBePosted forKey:@"filesToBePosted"]; - [encoder encodeObject:self.dataToBePosted forKey:@"dataToBePosted"]; - [encoder encodeObject:self.username forKey:@"username"]; - [encoder encodeObject:self.password forKey:@"password"]; - [encoder encodeObject:self.clientCertificate forKey:@"clientCertificate"]; - [encoder encodeObject:self.clientCertificatePassword forKey:@"clientCertificatePassword"]; - [encoder encodeBool:self.shouldContinueWithInvalidCertificate forKey:@"shouldContinueWithInvalidCertificate"]; -#if TARGET_OS_IPHONE - [encoder encodeObject:self.localNotification forKey:@"localNotification"]; -#endif - self.state = MKNetworkOperationStateReady; - [encoder encodeInt32:_state forKey:@"state"]; - [encoder encodeBool:self.isCancelled forKey:@"isCancelled"]; - [encoder encodeObject:self.mutableData forKey:@"mutableData"]; - [encoder encodeInteger:(NSInteger)self.downloadedDataSize forKey:@"downloadedDataSize"]; - [encoder encodeObject:self.downloadStreams forKey:@"downloadStreams"]; - [encoder encodeInteger:self.startPosition forKey:@"startPosition"]; - [encoder encodeInteger:self.credentialPersistence forKey:@"credentialPersistence"]; -} - -- (instancetype)initWithCoder:(NSCoder *)decoder -{ - self = [super init]; - if (self) { - [self setStringEncoding:(NSStringEncoding)[decoder decodeIntegerForKey:@"stringEncoding"]]; - _postDataEncoding = (MKNKPostDataEncodingType) [decoder decodeIntegerForKey:@"postDataEncoding"]; - self.request = [decoder decodeObjectForKey:@"request"]; - self.uniqueId = [decoder decodeObjectForKey:@"uniqueId"]; - - self.response = [decoder decodeObjectForKey:@"response"]; - self.fieldsToBePosted = [decoder decodeObjectForKey:@"fieldsToBePosted"]; - self.filesToBePosted = [decoder decodeObjectForKey:@"filesToBePosted"]; - self.dataToBePosted = [decoder decodeObjectForKey:@"dataToBePosted"]; - self.username = [decoder decodeObjectForKey:@"username"]; - self.password = [decoder decodeObjectForKey:@"password"]; - self.clientCertificate = [decoder decodeObjectForKey:@"clientCertificate"]; - self.clientCertificatePassword = [decoder decodeObjectForKey:@"clientCertificatePassword"]; -#if TARGET_OS_IPHONE - self.localNotification = [decoder decodeObjectForKey:@"localNotification"]; -#endif - [self setState:(MKNetworkOperationState)[decoder decodeInt32ForKey:@"state"]]; - self.isCancelled = [decoder decodeBoolForKey:@"isCancelled"]; - self.mutableData = [decoder decodeObjectForKey:@"mutableData"]; - self.downloadedDataSize = [decoder decodeIntegerForKey:@"downloadedDataSize"]; - self.downloadStreams = [decoder decodeObjectForKey:@"downloadStreams"]; - self.startPosition = [decoder decodeIntegerForKey:@"startPosition"]; - self.credentialPersistence = [decoder decodeIntegerForKey:@"credentialPersistence"]; - } - return self; -} - -- (instancetype)copyWithZone:(NSZone *)zone -{ - MKNetworkOperation *theCopy = [[[self class] allocWithZone:zone] init]; // use designated initializer - - theCopy.postDataEncoding = _postDataEncoding; - [theCopy setStringEncoding:self.stringEncoding]; - [theCopy setUniqueId:[self.uniqueId copy]]; - - [theCopy setConnection:[self.connection copy]]; - [theCopy setRequest:[self.request copy]]; - [theCopy setResponse:[self.response copy]]; - [theCopy setFieldsToBePosted:[self.fieldsToBePosted copy]]; - [theCopy setFilesToBePosted:[self.filesToBePosted copy]]; - [theCopy setDataToBePosted:[self.dataToBePosted copy]]; - [theCopy setUsername:[self.username copy]]; - [theCopy setPassword:[self.password copy]]; - [theCopy setClientCertificate:[self.clientCertificate copy]]; - [theCopy setClientCertificatePassword:[self.clientCertificatePassword copy]]; - [theCopy setResponseBlocks:[self.responseBlocks copy]]; - [theCopy setErrorBlocks:[self.errorBlocks copy]]; - [theCopy setErrorBlocksType2:[self.errorBlocksType2 copy]]; - [theCopy setState:self.state]; - [theCopy setIsCancelled:self.isCancelled]; - [theCopy setMutableData:[self.mutableData copy]]; - [theCopy setDownloadedDataSize:self.downloadedDataSize]; - [theCopy setNotModifiedHandlers:[self.notModifiedHandlers copy]]; - [theCopy setUploadProgressChangedHandlers:[self.uploadProgressChangedHandlers copy]]; - [theCopy setDownloadProgressChangedHandlers:[self.downloadProgressChangedHandlers copy]]; - [theCopy setDownloadStreams:[self.downloadStreams copy]]; - [theCopy setCachedResponse:[self.cachedResponse copy]]; - [theCopy setCacheHandlingBlock:self.cacheHandlingBlock]; - [theCopy setStartPosition:self.startPosition]; - [theCopy setCredentialPersistence:self.credentialPersistence]; - - return theCopy; -} - - -- (instancetype)mutableCopyWithZone:(NSZone *)zone -{ - MKNetworkOperation *theCopy = [[[self class] allocWithZone:zone] init]; // use designated initializer - - theCopy.postDataEncoding = _postDataEncoding; - [theCopy setStringEncoding:self.stringEncoding]; - [theCopy setUniqueId:[self.uniqueId copy]]; - - [theCopy setConnection:[self.connection mutableCopy]]; - [theCopy setRequest:[self.request mutableCopy]]; - [theCopy setResponse:[self.response mutableCopy]]; - [theCopy setFieldsToBePosted:[self.fieldsToBePosted mutableCopy]]; - [theCopy setFilesToBePosted:[self.filesToBePosted mutableCopy]]; - [theCopy setDataToBePosted:[self.dataToBePosted mutableCopy]]; - [theCopy setUsername:[self.username copy]]; - [theCopy setPassword:[self.password copy]]; - [theCopy setClientCertificate:[self.clientCertificate copy]]; - [theCopy setClientCertificatePassword:[self.clientCertificatePassword copy]]; - [theCopy setResponseBlocks:[self.responseBlocks mutableCopy]]; - [theCopy setErrorBlocks:[self.errorBlocks mutableCopy]]; - [theCopy setErrorBlocksType2:[self.errorBlocksType2 mutableCopy]]; - [theCopy setState:self.state]; - [theCopy setIsCancelled:self.isCancelled]; - [theCopy setMutableData:[self.mutableData mutableCopy]]; - [theCopy setDownloadedDataSize:self.downloadedDataSize]; - [theCopy setNotModifiedHandlers:[self.notModifiedHandlers mutableCopy]]; - [theCopy setUploadProgressChangedHandlers:[self.uploadProgressChangedHandlers mutableCopy]]; - [theCopy setDownloadProgressChangedHandlers:[self.downloadProgressChangedHandlers mutableCopy]]; - [theCopy setDownloadStreams:[self.downloadStreams mutableCopy]]; - [theCopy setCachedResponse:[self.cachedResponse mutableCopy]]; - [theCopy setCacheHandlingBlock:self.cacheHandlingBlock]; - [theCopy setStartPosition:self.startPosition]; - [theCopy setCredentialPersistence:self.credentialPersistence]; - - return theCopy; -} - -- (instancetype)copyForRetry -{ - MKNetworkOperation *theCopy = [[[self class] alloc] init]; - - [theCopy setConnection:nil]; - [theCopy setResponse:nil]; - [theCopy setState:MKNetworkOperationStateReady]; - [theCopy setIsCancelled:NO]; - [theCopy setDownloadedDataSize:0]; - [theCopy setStartPosition:0]; - - theCopy.postDataEncoding = _postDataEncoding; - [theCopy setStringEncoding:self.stringEncoding]; - [theCopy setUniqueId:[self.uniqueId copy]]; - [theCopy setRequest:[self.request copy]]; - [theCopy setFieldsToBePosted:[self.fieldsToBePosted mutableCopy]]; - [theCopy setFilesToBePosted:[self.filesToBePosted mutableCopy]]; - [theCopy setDataToBePosted:[self.dataToBePosted mutableCopy]]; - [theCopy setUsername:[self.username copy]]; - [theCopy setPassword:[self.password copy]]; - [theCopy setClientCertificate:[self.clientCertificate copy]]; - [theCopy setClientCertificatePassword:[self.clientCertificatePassword copy]]; - [theCopy setResponseBlocks:[self.responseBlocks mutableCopy]]; - [theCopy setErrorBlocks:[self.errorBlocks mutableCopy]]; - [theCopy setErrorBlocksType2:[self.errorBlocksType2 mutableCopy]]; - [theCopy setMutableData:[self.mutableData mutableCopy]]; - [theCopy setNotModifiedHandlers:[self.notModifiedHandlers mutableCopy]]; - [theCopy setUploadProgressChangedHandlers:[self.uploadProgressChangedHandlers mutableCopy]]; - [theCopy setDownloadProgressChangedHandlers:[self.downloadProgressChangedHandlers mutableCopy]]; - [theCopy setDownloadStreams:[self.downloadStreams mutableCopy]]; - [theCopy setCachedResponse:[self.cachedResponse mutableCopy]]; - [theCopy setCacheHandlingBlock:self.cacheHandlingBlock]; - [theCopy setCredentialPersistence:self.credentialPersistence]; - - return theCopy; -} - --(void) dealloc { - - [_connection cancel]; - _connection = nil; -} - --(void) updateHandlersFromOperation:(MKNetworkOperation*) operation { - - [self.responseBlocks addObjectsFromArray:operation.responseBlocks]; - [self.errorBlocks addObjectsFromArray:operation.errorBlocks]; - [self.errorBlocksType2 addObjectsFromArray:operation.errorBlocksType2]; - [self.notModifiedHandlers addObjectsFromArray:operation.notModifiedHandlers]; - [self.uploadProgressChangedHandlers addObjectsFromArray:operation.uploadProgressChangedHandlers]; - [self.downloadProgressChangedHandlers addObjectsFromArray:operation.downloadProgressChangedHandlers]; - [self.downloadStreams addObjectsFromArray:operation.downloadStreams]; -} - --(void) setCachedData:(NSData*) cachedData { - - self.cachedResponse = cachedData; - [self operationSucceeded]; -} - --(void) updateOperationBasedOnPreviousHeaders:(NSMutableDictionary*) headers { - - NSString *lastModified = headers[@"Last-Modified"]; - NSString *eTag = headers[@"ETag"]; - if(lastModified) { - [self.request setValue:lastModified forHTTPHeaderField:@"IF-MODIFIED-SINCE"]; - } - - if(eTag) { - [self.request setValue:eTag forHTTPHeaderField:@"IF-NONE-MATCH"]; - } -} - --(void) setUsername:(NSString*) username password:(NSString*) password { - - self.username = username; - self.password = password; -} - --(void) setUsername:(NSString*) username password:(NSString*) password basicAuth:(BOOL) bYesOrNo { - - [self setUsername:username password:password]; - NSString *base64EncodedString = [[[NSString stringWithFormat:@"%@:%@", self.username, self.password] dataUsingEncoding:NSUTF8StringEncoding] base64EncodedString]; - - [self setAuthorizationHeaderValue:base64EncodedString forAuthType:@"Basic"]; -} - --(void) onCompletion:(MKNKResponseBlock) response onError:(MKNKErrorBlock) error { - - [self.responseBlocks addObject:[response copy]]; - [self.errorBlocks addObject:[error copy]]; -} - --(void) addCompletionHandler:(MKNKResponseBlock)response errorHandler:(MKNKResponseErrorBlock)error { - - if(response) - [self.responseBlocks addObject:[response copy]]; - if(error) - [self.errorBlocksType2 addObject:[error copy]]; -} - --(void) onNotModified:(MKNKVoidBlock)notModifiedBlock { - - [self.notModifiedHandlers addObject:[notModifiedBlock copy]]; -} - --(void) onUploadProgressChanged:(MKNKProgressBlock) uploadProgressBlock { - - [self.uploadProgressChangedHandlers addObject:[uploadProgressBlock copy]]; -} - --(void) onDownloadProgressChanged:(MKNKProgressBlock) downloadProgressBlock { - - [self.downloadProgressChangedHandlers addObject:[downloadProgressBlock copy]]; -} - --(void) setUploadStream:(NSInputStream*) inputStream { - - self.request.HTTPBodyStream = inputStream; -} - --(void) addDownloadStream:(NSOutputStream*) outputStream { - - [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; - [self.downloadStreams addObject:outputStream]; -} - -- (id)initWithURLString:(NSString *)aURLString - params:(NSDictionary *)params - httpMethod:(NSString *)method - -{ - if((self = [super init])) { - - self.responseBlocks = [NSMutableArray array]; - self.errorBlocks = [NSMutableArray array]; - self.errorBlocksType2 = [NSMutableArray array]; - self.filesToBePosted = [NSMutableArray array]; - self.dataToBePosted = [NSMutableArray array]; - self.fieldsToBePosted = [NSMutableDictionary dictionary]; - - self.notModifiedHandlers = [NSMutableArray array]; - self.uploadProgressChangedHandlers = [NSMutableArray array]; - self.downloadProgressChangedHandlers = [NSMutableArray array]; - self.downloadStreams = [NSMutableArray array]; - - self.credentialPersistence = NSURLCredentialPersistenceForSession; - - NSURL *finalURL = nil; - - if(params) - self.fieldsToBePosted = [params mutableCopy]; - - self.stringEncoding = NSUTF8StringEncoding; // use a delegate to get these values later - - if(!method) method = @"GET"; - - if ([method isEqualToString:@"GET"]) - self.cacheHeaders = [NSMutableDictionary dictionary]; - - if (([method isEqualToString:@"GET"] || - [method isEqualToString:@"DELETE"]) && (params && [params count] > 0)) { - - finalURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", aURLString, - [self.fieldsToBePosted urlEncodedKeyValueString]]]; - } else { - finalURL = [NSURL URLWithString:aURLString]; - } - - if(finalURL == nil) { - - DLog(@"Cannot create a URL with %@ and parameters %@ and method %@", aURLString, self.fieldsToBePosted, method); - return nil; - } - - self.request = [NSMutableURLRequest requestWithURL:finalURL - cachePolicy:NSURLRequestReloadIgnoringLocalCacheData - timeoutInterval:kMKNetworkKitRequestTimeOutInSeconds]; - - [self.request setHTTPMethod:method]; - - if (([method isEqualToString:@"POST"] || - [method isEqualToString:@"PUT"]) && (params && [params count] > 0)) { - - self.postDataEncoding = MKNKPostDataEncodingTypeURL; - } - - self.state = MKNetworkOperationStateReady; - } - - return self; -} - --(void) addParams:(NSDictionary*) paramsDictionary { - - [self.fieldsToBePosted addEntriesFromDictionary:paramsDictionary]; -} - --(void) addHeaders:(NSDictionary*) headersDictionary { - - [headersDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - [self.request addValue:obj forHTTPHeaderField:key]; - }]; -} - --(void) addHeader:(NSString*)key withValue:(NSString*)value { - - [self.request addValue:value forHTTPHeaderField:key]; -} - --(void) setHeader:(NSString*)key withValue:(NSString*)value { - - [self.request setValue:value forHTTPHeaderField:key]; -} - --(void) setAuthorizationHeaderValue:(NSString*) token forAuthType:(NSString*) authType { - - [self.request setValue:[NSString stringWithFormat:@"%@ %@", authType, token] - forHTTPHeaderField:@"Authorization"]; -} -/* - Printing a MKNetworkOperation object is printed in curl syntax - */ - --(NSString*) description { - - NSMutableString *displayString = [NSMutableString stringWithFormat:@"%@\nRequest\n-------\n%@", - [[NSDate date] descriptionWithLocale:[NSLocale currentLocale]], - [self curlCommandLineString]]; - - NSString *responseString = [self responseString]; - if([responseString length] > 0) { - [displayString appendFormat:@"\n--------\nResponse\n--------\n%@\n", responseString]; - } - - return displayString; -} - --(NSString*) curlCommandLineString -{ - __block NSMutableString *displayString = [NSMutableString stringWithFormat:@"curl -X %@", self.request.HTTPMethod]; - - if([self.filesToBePosted count] == 0 && [self.dataToBePosted count] == 0) { - [[self.request allHTTPHeaderFields] enumerateKeysAndObjectsUsingBlock:^(id key, id val, BOOL *stop) - { - [displayString appendFormat:@" -H \'%@: %@\'", key, val]; - }]; - } - - [displayString appendFormat:@" \'%@\'", self.url]; - - if ([self.request.HTTPMethod isEqualToString:@"POST"] || - [self.request.HTTPMethod isEqualToString:@"PUT"] || - [self.request.HTTPMethod isEqualToString:@"PATCH"]) { - - NSString *option = [self.filesToBePosted count] == 0 ? @"-d" : @"-F"; - if(self.postDataEncoding == MKNKPostDataEncodingTypeURL) { - [self.fieldsToBePosted enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - - [displayString appendFormat:@" %@ \'%@=%@\'", option, key, obj]; - }]; - } else { - [displayString appendFormat:@" -d \'%@\'", [self encodedPostDataString]]; - } - - - [self.filesToBePosted enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - - NSDictionary *thisFile = (NSDictionary*) obj; - [displayString appendFormat:@" -F \'%@=@%@;type=%@\'", thisFile[@"name"], - thisFile[@"filepath"], thisFile[@"mimetype"]]; - }]; - - /* Not sure how to do this via curl - [self.dataToBePosted enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - - NSDictionary *thisData = (NSDictionary*) obj; - [displayString appendFormat:@" --data-binary \"%@\"", [thisData objectForKey:@"data"]]; - }];*/ - } - - return displayString; -} - - --(void) addData:(NSData*) data forKey:(NSString*) key { - - [self addData:data forKey:key mimeType:@"application/octet-stream" fileName:@"file"]; -} - --(void) addData:(NSData*) data forKey:(NSString*) key mimeType:(NSString*) mimeType fileName:(NSString*) fileName { - - if ([self.request.HTTPMethod isEqualToString:@"GET"]) { - [self.request setHTTPMethod:@"POST"]; - } - - NSDictionary *dict = @{@"data": data, - @"name": key, - @"mimetype": mimeType, - @"filename": fileName}; - - [self.dataToBePosted addObject:dict]; -} - --(void) addFile:(NSString*) filePath forKey:(NSString*) key { - - [self addFile:filePath forKey:key mimeType:@"application/octet-stream"]; -} - --(void) addFile:(NSString*) filePath forKey:(NSString*) key mimeType:(NSString*) mimeType { - - if ([self.request.HTTPMethod isEqualToString:@"GET"]) { - [self.request setHTTPMethod:@"POST"]; - } - - NSDictionary *dict = @{@"filepath": filePath, - @"name": key, - @"mimetype": mimeType}; - - [self.filesToBePosted addObject:dict]; -} - --(NSData*) bodyData { - - if([self.filesToBePosted count] == 0 && [self.dataToBePosted count] == 0) { - - return [[self encodedPostDataString] dataUsingEncoding:self.stringEncoding]; - } - - NSString *boundary = @"0xKhTmLbOuNdArY"; - NSMutableData *body = [NSMutableData data]; - __block NSUInteger postLength = 0; - - [self.fieldsToBePosted enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - - NSString *thisFieldString = [NSString stringWithFormat: - @"--%@\r\nContent-Disposition: form-data; name=\"%@\"\r\n\r\n%@", - boundary, key, obj]; - - [body appendData:[thisFieldString dataUsingEncoding:[self stringEncoding]]]; - [body appendData:[@"\r\n" dataUsingEncoding:[self stringEncoding]]]; - }]; - - [self.filesToBePosted enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - - NSDictionary *thisFile = (NSDictionary*) obj; - NSString *thisFieldString = [NSString stringWithFormat: - @"--%@\r\nContent-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\nContent-Type: %@\r\nContent-Transfer-Encoding: binary\r\n\r\n", - boundary, - thisFile[@"name"], - [thisFile[@"filepath"] lastPathComponent], - thisFile[@"mimetype"]]; - - [body appendData:[thisFieldString dataUsingEncoding:[self stringEncoding]]]; - [body appendData: [NSData dataWithContentsOfFile:thisFile[@"filepath"]]]; - [body appendData:[@"\r\n" dataUsingEncoding:[self stringEncoding]]]; - }]; - - [self.dataToBePosted enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - - NSDictionary *thisDataObject = (NSDictionary*) obj; - NSString *thisFieldString = [NSString stringWithFormat: - @"--%@\r\nContent-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\nContent-Type: %@\r\nContent-Transfer-Encoding: binary\r\n\r\n", - boundary, - thisDataObject[@"name"], - thisDataObject[@"filename"], - thisDataObject[@"mimetype"]]; - - [body appendData:[thisFieldString dataUsingEncoding:[self stringEncoding]]]; - [body appendData:thisDataObject[@"data"]]; - [body appendData:[@"\r\n" dataUsingEncoding:[self stringEncoding]]]; - }]; - - if (postLength >= 1) - [self.request setValue:[NSString stringWithFormat:@"%lu", (unsigned long) postLength] forHTTPHeaderField:@"Content-Length"]; - - [body appendData: [[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:self.stringEncoding]]; - - NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); - - if(([self.filesToBePosted count] > 0) || ([self.dataToBePosted count] > 0)) { - [self.request setValue:[NSString stringWithFormat:@"multipart/form-data; charset=%@; boundary=%@", charset, boundary] - forHTTPHeaderField:@"Content-Type"]; - - [self.request setValue:[NSString stringWithFormat:@"%lu", (unsigned long) [body length]] forHTTPHeaderField:@"Content-Length"]; - } - - return body; -} - - --(void) setCacheHandler:(MKNKResponseBlock) cacheHandler { - - self.cacheHandlingBlock = cacheHandler; -} - -#pragma mark - -#pragma Main method --(void) main { - - @autoreleasepool { - [self start]; - } -} - --(void) endBackgroundTask { - -#if TARGET_OS_IPHONE - dispatch_async(dispatch_get_main_queue(), ^{ - if (self.backgroundTaskId != UIBackgroundTaskInvalid) { - [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId]; - self.backgroundTaskId = UIBackgroundTaskInvalid; - } - }); -#endif -} - -- (void) start -{ - -#if TARGET_OS_IPHONE - self.backgroundTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ - - dispatch_async(dispatch_get_main_queue(), ^{ - if (self.backgroundTaskId != UIBackgroundTaskInvalid) - { - [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskId]; - self.backgroundTaskId = UIBackgroundTaskInvalid; - [self cancel]; - } - }); - }]; - -#endif - - if(!self.isCancelled) { - - if (([self.request.HTTPMethod isEqualToString:@"POST"] || - [self.request.HTTPMethod isEqualToString:@"PUT"] || - [self.request.HTTPMethod isEqualToString:@"PATCH"]) && !self.request.HTTPBodyStream) { - - [self.request setHTTPBody:[self bodyData]]; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - self.connection = [[NSURLConnection alloc] initWithRequest:self.request - delegate:self - startImmediately:NO]; - - [self.connection scheduleInRunLoop:[NSRunLoop currentRunLoop] - forMode:NSRunLoopCommonModes]; - - [self.connection start]; - }); - - self.state = MKNetworkOperationStateExecuting; - } - else { - self.state = MKNetworkOperationStateFinished; - [self endBackgroundTask]; - } -} - -#pragma - -#pragma mark NSOperation stuff - -- (BOOL)isConcurrent -{ - return YES; -} - -- (BOOL)isReady { - - return (self.state == MKNetworkOperationStateReady && [super isReady]); -} - -- (BOOL)isFinished -{ - return (self.state == MKNetworkOperationStateFinished); -} - -- (BOOL)isExecuting { - - return (self.state == MKNetworkOperationStateExecuting); -} - --(void) cancel { - - if([self isFinished]) - return; - - @synchronized(self) { - self.isCancelled = YES; - - [self.connection cancel]; - - [self.responseBlocks removeAllObjects]; - self.responseBlocks = nil; - - [self.errorBlocks removeAllObjects]; - self.errorBlocks = nil; - - [self.errorBlocksType2 removeAllObjects]; - self.errorBlocksType2 = nil; - - [self.notModifiedHandlers removeAllObjects]; - self.notModifiedHandlers = nil; - - [self.uploadProgressChangedHandlers removeAllObjects]; - self.uploadProgressChangedHandlers = nil; - - [self.downloadProgressChangedHandlers removeAllObjects]; - self.downloadProgressChangedHandlers = nil; - - for(NSOutputStream *stream in self.downloadStreams) - [stream close]; - - [self.downloadStreams removeAllObjects]; - self.downloadStreams = nil; - - self.authHandler = nil; - self.mutableData = nil; - self.downloadedDataSize = 0; - - self.cacheHandlingBlock = nil; - - if(self.state == MKNetworkOperationStateExecuting) - self.state = MKNetworkOperationStateFinished; // This notifies the queue and removes the operation. - // if the operation is not removed, the spinner continues to spin, not a good UX - - [self endBackgroundTask]; - } - [super cancel]; -} - -#pragma mark - -#pragma mark NSURLConnection delegates - -- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { - - self.state = MKNetworkOperationStateFinished; - self.mutableData = nil; - self.downloadedDataSize = 0; - for(NSOutputStream *stream in self.downloadStreams) - [stream close]; - - [self operationFailedWithError:error]; - [self endBackgroundTask]; -} - -// https://developer.apple.com/library/mac/#documentation/security/conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html -OSStatus extractIdentityAndTrust(CFDataRef inPKCS12Data, // 5 - SecIdentityRef *outIdentity, - SecTrustRef *outTrust, - CFStringRef keyPassword) -{ - OSStatus securityError = errSecSuccess; - - - const void *keys[] = { kSecImportExportPassphrase }; - const void *values[] = { keyPassword }; - CFDictionaryRef optionsDictionary = NULL; - - /* Create a dictionary containing the passphrase if one - was specified. Otherwise, create an empty dictionary. */ - optionsDictionary = CFDictionaryCreate( - NULL, keys, - values, (keyPassword ? 1 : 0), - NULL, NULL); // 6 - - CFArrayRef items = NULL; - securityError = SecPKCS12Import(inPKCS12Data, - optionsDictionary, - &items); // 7 - - - // - if (securityError == 0) { // 8 - CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0); - const void *tempIdentity = NULL; - tempIdentity = CFDictionaryGetValue (myIdentityAndTrust, - kSecImportItemIdentity); - CFRetain(tempIdentity); - *outIdentity = (SecIdentityRef)tempIdentity; - const void *tempTrust = NULL; - tempTrust = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemTrust); - - CFRetain(tempTrust); - *outTrust = (SecTrustRef)tempTrust; - } - - if (optionsDictionary) - CFRelease(optionsDictionary); // 9 - - if (items) - CFRelease(items); - - return securityError; -} - -- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { - - if (challenge.previousFailureCount == 0) { - - if (((challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodDefault) || - (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPBasic) || - (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPDigest) || - (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodNTLM)) && - (self.username && self.password)) - { - - // for NTLM, we will assume user name to be of the form "domain\\username" - NSURLCredential *credential = [NSURLCredential credentialWithUser:self.username - password:self.password - persistence:self.credentialPersistence]; - - [challenge.sender useCredential:credential forAuthenticationChallenge:challenge]; - } - else if ((challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate) && self.clientCertificate) { - - NSError *error = nil; - NSData *certData = [[NSData alloc] initWithContentsOfFile:self.clientCertificate options:0 error:&error]; - - SecIdentityRef identity; - SecTrustRef trust; - OSStatus status = extractIdentityAndTrust((__bridge CFDataRef) certData, &identity, &trust, (__bridge CFStringRef) self.clientCertificatePassword); - if(status == errSecSuccess) { - SecCertificateRef certificate; - SecIdentityCopyCertificate(identity, &certificate); - const void *certs[] = { certificate }; - CFArrayRef certsArray = CFArrayCreate(NULL, certs, 1, NULL); - NSArray *certificatesForCredential = (__bridge NSArray *)certsArray; - NSURLCredential *credential = [NSURLCredential credentialWithIdentity:identity - certificates:certificatesForCredential - persistence:NSURLCredentialPersistencePermanent]; - [challenge.sender useCredential:credential forAuthenticationChallenge:challenge]; - CFRelease(identity); - CFRelease(certificate); - CFRelease(certsArray); - } else { - [challenge.sender cancelAuthenticationChallenge:challenge]; - } - } - else if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) { - - if(challenge.previousFailureCount < 5) { - - self.serverTrust = challenge.protectionSpace.serverTrust; - SecTrustResultType result; - SecTrustEvaluate(self.serverTrust, &result); - - if(result == kSecTrustResultProceed || - result == kSecTrustResultUnspecified //The cert is valid, but user has not explicitly accepted/denied. Ok to proceed (Ch 15: iOS PTL :Pg 269) - ) { - - [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; - } else { - - // invalid or revoked certificate - if(self.shouldContinueWithInvalidCertificate) { - DLog(@"Certificate is invalid, but self.shouldContinueWithInvalidCertificate is YES"); - [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; - } else { - DLog(@"Certificate is invalid, continuing without credentials. Might result in 401 Unauthorized"); - [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; - } - } - } else { - - [challenge.sender cancelAuthenticationChallenge:challenge]; - } - } - else if (self.authHandler) { - - // forward the authentication to the view controller that created this operation - // If this happens for NSURLAuthenticationMethodHTMLForm, you have to - // do some shit work like showing a modal webview controller and close it after authentication. - // I HATE THIS. - self.authHandler(challenge); - } - else { - [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; - } - } else { - // apple proposes to cancel authentication, which results in NSURLErrorDomain error -1012, but we prefer to trigger a 401 - // [[challenge sender] cancelAuthenticationChallenge:challenge]; - [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; - } -} - -- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { - - NSUInteger size = [self.response expectedContentLength] < 0 ? 0 : (NSUInteger)[self.response expectedContentLength]; - self.response = (NSHTTPURLResponse*) response; - - // dont' save data if the operation was created to download directly to a stream. - if([self.downloadStreams count] == 0) - self.mutableData = [NSMutableData dataWithCapacity:size]; - else - self.mutableData = nil; - - for(NSOutputStream *stream in self.downloadStreams) - [stream open]; - - NSDictionary *httpHeaders = [self.response allHeaderFields]; - - // if you attach a stream to the operation, MKNetworkKit will not cache the response. - // Streams are usually "big data chunks" that doesn't need caching anyways. - - if([self.request.HTTPMethod isEqualToString:@"GET"] && [self.downloadStreams count] == 0) { - - // We have all this complicated cache handling since NSURLRequestReloadRevalidatingCacheData is not implemented - // do cache processing only if the request is a "GET" method - NSString *lastModified = httpHeaders[@"Last-Modified"]; - NSString *eTag = httpHeaders[@"ETag"]; - NSString *expiresOn = httpHeaders[@"Expires"]; - - NSString *contentType = httpHeaders[@"Content-Type"]; - // if contentType is image, - - NSDate *expiresOnDate = nil; - - if([contentType rangeOfString:@"image"].location != NSNotFound) { - - // For images let's assume a expiry date of 7 days if there is no eTag or Last Modified. - if(!eTag && !lastModified) - expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultImageCacheDuration]; - else - expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultImageHeadRequestDuration]; - } - - NSString *cacheControl = httpHeaders[@"Cache-Control"]; // max-age, must-revalidate, no-cache - NSArray *cacheControlEntities = [cacheControl componentsSeparatedByString:@","]; - - for(NSString *substring in cacheControlEntities) { - - if([substring rangeOfString:@"max-age"].location != NSNotFound) { - - // do some processing to calculate expiresOn - NSString *maxAge = nil; - NSArray *array = [substring componentsSeparatedByString:@"="]; - if([array count] > 1) - maxAge = array[1]; - - expiresOnDate = [[NSDate date] dateByAddingTimeInterval:[maxAge intValue]]; - } - if([substring rangeOfString:@"no-cache"].location != NSNotFound) { - - // Don't cache this request - expiresOnDate = [[NSDate date] dateByAddingTimeInterval:kMKNetworkKitDefaultCacheDuration]; - } - } - - // if there was a cacheControl entity, we would have a expiresOnDate that is not nil. - // "Cache-Control" headers take precedence over "Expires" headers - - if(expiresOnDate) - expiresOn = [expiresOnDate rfc1123String]; - - // now remember lastModified, eTag and expires for this request in cache - if(expiresOn) - (self.cacheHeaders)[@"Expires"] = expiresOn; - if(lastModified) - (self.cacheHeaders)[@"Last-Modified"] = lastModified; - if(eTag) - (self.cacheHeaders)[@"ETag"] = eTag; - } -} - -- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { - - if (self.downloadedDataSize == 0) { - // This is the first batch of data - // Check for a range header and make changes as neccesary - NSString *rangeString = [[self request] valueForHTTPHeaderField:@"Range"]; - if ([rangeString hasPrefix:@"bytes="] && [rangeString hasSuffix:@"-"]) { - NSString *bytesText = [rangeString substringWithRange:NSMakeRange(6, [rangeString length] - 7)]; - self.startPosition = [bytesText integerValue]; - self.downloadedDataSize = self.startPosition; - DLog(@"Resuming at %lu bytes", (unsigned long) self.startPosition); - } - } - - if([self.downloadStreams count] == 0) - [self.mutableData appendData:data]; - - for(NSOutputStream *stream in self.downloadStreams) { - - if ([stream hasSpaceAvailable]) { - const uint8_t *dataBuffer = [data bytes]; - [stream write:&dataBuffer[0] maxLength:[data length]]; - } - } - - self.downloadedDataSize += [data length]; - - for(MKNKProgressBlock downloadProgressBlock in self.downloadProgressChangedHandlers) { - - if([self.response expectedContentLength] > 0) { - - double progress = (double)(self.downloadedDataSize) / (double)(self.startPosition + [self.response expectedContentLength]); - downloadProgressBlock(progress); - } - } -} - -- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten - totalBytesWritten:(NSInteger)totalBytesWritten -totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite { - - for(MKNKProgressBlock uploadProgressBlock in self.uploadProgressChangedHandlers) { - - if(totalBytesExpectedToWrite > 0) { - uploadProgressBlock(((double)totalBytesWritten/(double)totalBytesExpectedToWrite)); - } - } -} - -// http://stackoverflow.com/questions/1446509/handling-redirects-correctly-with-nsurlconnection -- (NSURLRequest *)connection: (NSURLConnection *)inConnection - willSendRequest: (NSURLRequest *)inRequest - redirectResponse: (NSURLResponse *)inRedirectResponse; -{ - NSMutableURLRequest *r = [self.request mutableCopy]; - if (inRedirectResponse) { - [r setURL: [inRequest URL]]; - } else { - // Note that we need to configure the Accept-Language header this late in processing - // because NSURLRequest adds a default Accept-Language header late in the day, so we - // have to undo that here. - // For discussion see: - // http://lists.apple.com/archives/macnetworkprog/2009/Sep/msg00022.html - // http://stackoverflow.com/questions/5695914/nsurlrequest-where-an-app-can-find-the-default-headers-for-http-request - NSString* accept_language = self.shouldSendAcceptLanguageHeader ? [self languagesFromLocale] : nil; - [r setValue:accept_language forHTTPHeaderField:@"Accept-Language"]; - } - return r; -} - -- (NSString*)languagesFromLocale { - return [NSString stringWithFormat:@"%@, en-us", [[NSLocale preferredLanguages] componentsJoinedByString:@", "]]; -} - -- (void)connectionDidFinishLoading:(NSURLConnection *)connection { - - if([self isCancelled]) - return; - - self.state = MKNetworkOperationStateFinished; - - for(NSOutputStream *stream in self.downloadStreams) - [stream close]; - - if (self.response.statusCode >= 200 && self.response.statusCode < 300 && ![self isCancelled]) { - - self.cachedResponse = nil; // remove cached data - - [self notifyCache]; - [self operationSucceeded]; - - } - if (self.response.statusCode >= 300 && self.response.statusCode < 400) { - - if(self.response.statusCode == 301) { - DLog(@"%@ has moved to %@", self.url, [self.response.URL absoluteString]); - } - else if(self.response.statusCode == 304) { - - for(MKNKVoidBlock notModifiedBlock in self.notModifiedHandlers) { - - notModifiedBlock(); - } - } - else if(self.response.statusCode == 307) { - DLog(@"%@ temporarily redirected", self.url); - } - else { - DLog(@"%@ returned status %d", self.url, (int) self.response.statusCode); - } - - } else if (self.response.statusCode >= 400 && self.response.statusCode < 600 && ![self isCancelled]) { - - [self operationFailedWithError:[NSError errorWithDomain:NSURLErrorDomain - code:self.response.statusCode - userInfo:self.response.allHeaderFields]]; - } - [self endBackgroundTask]; - -} - -#pragma mark - -#pragma mark Our methods to get data - --(NSData*) responseData { - - if([self isFinished]) - return self.mutableData; - else if(self.cachedResponse) - return self.cachedResponse; - else - return nil; -} - --(NSString*)responseString { - - return [self responseStringWithEncoding:self.stringEncoding]; -} - --(NSString*) responseStringWithEncoding:(NSStringEncoding) encoding { - - return [[NSString alloc] initWithData:[self responseData] encoding:encoding]; -} - -#if TARGET_OS_IPHONE --(UIImage*) responseImage { - - return [UIImage imageWithData:[self responseData]]; -} - --(void) decompressedResponseImageOfSize:(CGSize) size completionHandler:(void (^)(UIImage *decompressedImage)) imageDecompressionHandler { - - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ - - CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)([self responseData]), NULL); - CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, (__bridge CFDictionaryRef)(@{(id)kCGImageSourceShouldCache:@(YES)})); - UIImage *decompressedImage = [UIImage imageWithCGImage:cgImage]; - if(source) - CFRelease(source); - if(cgImage) - CGImageRelease(cgImage); - - dispatch_async(dispatch_get_main_queue(), ^{ - imageDecompressionHandler(decompressedImage); - }); - }); -} - -#elif TARGET_OS_MAC --(NSImage*) responseImage { - - return [[NSImage alloc] initWithData:[self responseData]]; -} - --(NSXMLDocument*) responseXML { - - return [[NSXMLDocument alloc] initWithData:[self responseData] options:0 error:nil]; -} -#endif - --(id) responseJSON { - - if([self responseData] == nil) return nil; - NSError *error = nil; - id returnValue = [NSJSONSerialization JSONObjectWithData:[self responseData] options:0 error:&error]; - if(error) DLog(@"JSON Parsing Error: %@", error); - return returnValue; -} - --(void) responseJSONWithCompletionHandler:(void (^)(id jsonObject)) jsonDecompressionHandler { - - [self responseJSONWithOptions:0 completionHandler:jsonDecompressionHandler]; -} - --(void) responseJSONWithOptions:(NSJSONReadingOptions) options completionHandler:(void (^)(id jsonObject)) jsonDecompressionHandler { - - if([self responseData] == nil) { - - jsonDecompressionHandler(nil); - return; - } - - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ - - NSError *error = nil; - id returnValue = [NSJSONSerialization JSONObjectWithData:[self responseData] options:options error:&error]; - if(error) { - - DLog(@"JSON Parsing Error: %@", error); - jsonDecompressionHandler(nil); - return; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - - jsonDecompressionHandler(returnValue); - }); - }); -} - -#pragma mark - -#pragma mark Overridable methods - --(void) operationSucceeded { - - for(MKNKResponseBlock responseBlock in self.responseBlocks) - responseBlock(self); -} - --(void) showLocalNotification { -#if TARGET_OS_IPHONE - - if(self.localNotification) { - - [[UIApplication sharedApplication] presentLocalNotificationNow:self.localNotification]; - } else if(self.shouldShowLocalNotificationOnError) { - - UILocalNotification *localNotification = [[UILocalNotification alloc] init]; - - localNotification.alertBody = [self.error localizedDescription]; - localNotification.alertAction = NSLocalizedString(@"Dismiss", @""); - - [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification]; - } -#endif -} - --(void) operationFailedWithError:(NSError*) error { - - self.error = error; - DLog(@"%@, [%@]", self, [self.error localizedDescription]); - for(MKNKErrorBlock errorBlock in self.errorBlocks) - errorBlock(error); - - for(MKNKResponseErrorBlock errorBlock in self.errorBlocksType2) - errorBlock(self, error); - -#if TARGET_OS_IPHONE - if([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) - [self showLocalNotification]; -#endif - -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.h b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.h deleted file mode 100644 index 7e5c889..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - Copyright (c) 2011, Tony Million. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. 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. - - 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 -#import -#import -#import -#import - -/** - * Does ARC support support GCD objects? - * It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ - **/ -#if TARGET_OS_IPHONE - -// Compiling for iOS - -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later -#define NEEDS_DISPATCH_RETAIN_RELEASE 0 -#else // iOS 5.X or earlier -#define NEEDS_DISPATCH_RETAIN_RELEASE 1 -#endif - -#else - -// Compiling for Mac OS X - -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later -#define NEEDS_DISPATCH_RETAIN_RELEASE 0 -#else -#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier -#endif - -#endif - - -extern NSString *const kReachabilityChangedNotification; - -typedef enum -{ - // Apple NetworkStatus Compatible Names. - NotReachable = 0, - ReachableViaWiFi = 2, - ReachableViaWWAN = 1 -} NetworkStatus; - -@class Reachability; - -typedef void (^NetworkReachable)(Reachability * reachability); -typedef void (^NetworkUnreachable)(Reachability * reachability); - -@interface Reachability : NSObject - -@property (nonatomic, copy) NetworkReachable reachableBlock; -@property (nonatomic, copy) NetworkUnreachable unreachableBlock; - - -@property (nonatomic, assign) BOOL reachableOnWWAN; - -+(Reachability*)reachabilityWithHostname:(NSString*)hostname; -+(Reachability*)reachabilityForInternetConnection; -+(Reachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress; -+(Reachability*)reachabilityForLocalWiFi; - --(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref; - --(BOOL)startNotifier; --(void)stopNotifier; - --(BOOL)isReachable; --(BOOL)isReachableViaWWAN; --(BOOL)isReachableViaWiFi; - -// WWAN may be available, but not active until a connection has been established. -// WiFi may require a connection for VPN on Demand. --(BOOL)isConnectionRequired; // Identical DDG variant. --(BOOL)connectionRequired; // Apple's routine. -// Dynamic, on demand connection? --(BOOL)isConnectionOnDemand; -// Is user intervention required? --(BOOL)isInterventionRequired; - --(NetworkStatus)currentReachabilityStatus; --(SCNetworkReachabilityFlags)reachabilityFlags; --(NSString*)currentReachabilityString; --(NSString*)currentReachabilityFlags; - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.m b/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.m deleted file mode 100644 index c423c9b..0000000 --- a/TalkinToTheNet/TalkinToTheNet/MKNetworkKit/Reachability/Reachability.m +++ /dev/null @@ -1,492 +0,0 @@ -/* - Copyright (c) 2011, Tony Million. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. 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. - - 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 "Reachability.h" - - -NSString *const kReachabilityChangedNotification = @"kReachabilityChangedNotification"; - -@interface Reachability () - -@property (nonatomic, assign) SCNetworkReachabilityRef reachabilityRef; - - -#if NEEDS_DISPATCH_RETAIN_RELEASE -@property (nonatomic, assign) dispatch_queue_t reachabilitySerialQueue; -#else -@property (nonatomic, strong) dispatch_queue_t reachabilitySerialQueue; -#endif - - -@property (nonatomic, strong) id reachabilityObject; - --(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags; --(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags; - -@end - -static NSString *reachabilityFlags(SCNetworkReachabilityFlags flags) -{ - return [NSString stringWithFormat:@"%c%c %c%c%c%c%c%c%c", -#if TARGET_OS_IPHONE - (flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-', -#else - 'X', -#endif - (flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-', - (flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-', - (flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-', - (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-', - (flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-', - (flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-']; -} - -//Start listening for reachability notifications on the current run loop -static void TMReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info) -{ -#pragma unused (target) - Reachability *reachability = ((__bridge Reachability*)info); - - // we probably dont need an autoreleasepool here as GCD docs state each queue has its own autorelease pool - // but what the heck eh? - @autoreleasepool - { - [reachability reachabilityChanged:flags]; - } -} - - -@implementation Reachability - -#pragma mark - class constructor methods -+(Reachability*)reachabilityWithHostname:(NSString*)hostname -{ - SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]); - if (ref) - { - id reachability = [[self alloc] initWithReachabilityRef:ref]; - -#if __has_feature(objc_arc) - return reachability; -#else - return [reachability autorelease]; -#endif - - } - - return nil; -} - -+(Reachability *)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress -{ - SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress); - if (ref) - { - id reachability = [[self alloc] initWithReachabilityRef:ref]; - -#if __has_feature(objc_arc) - return reachability; -#else - return [reachability autorelease]; -#endif - } - - return nil; -} - -+(Reachability *)reachabilityForInternetConnection -{ - struct sockaddr_in zeroAddress; - bzero(&zeroAddress, sizeof(zeroAddress)); - zeroAddress.sin_len = sizeof(zeroAddress); - zeroAddress.sin_family = AF_INET; - - return [self reachabilityWithAddress:&zeroAddress]; -} - -+(Reachability*)reachabilityForLocalWiFi -{ - struct sockaddr_in localWifiAddress; - bzero(&localWifiAddress, sizeof(localWifiAddress)); - localWifiAddress.sin_len = sizeof(localWifiAddress); - localWifiAddress.sin_family = AF_INET; - // IN_LINKLOCALNETNUM is defined in as 169.254.0.0 - localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); - - return [self reachabilityWithAddress:&localWifiAddress]; -} - - -// initialization methods - --(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref -{ - self = [super init]; - if (self != nil) - { - self.reachableOnWWAN = YES; - self.reachabilityRef = ref; - } - - return self; -} - --(void)dealloc -{ - [self stopNotifier]; - - if(self.reachabilityRef) - { - CFRelease(self.reachabilityRef); - self.reachabilityRef = nil; - } - -#if !(__has_feature(objc_arc)) - [super dealloc]; -#endif - - -} - -#pragma mark - notifier methods - -// Notifier -// NOTE: this uses GCD to trigger the blocks - they *WILL NOT* be called on THE MAIN THREAD -// - In other words DO NOT DO ANY UI UPDATES IN THE BLOCKS. -// INSTEAD USE dispatch_async(dispatch_get_main_queue(), ^{UISTUFF}) (or dispatch_sync if you want) - --(BOOL)startNotifier -{ - SCNetworkReachabilityContext context = { 0, NULL, NULL, NULL, NULL }; - - // this should do a retain on ourself, so as long as we're in notifier mode we shouldn't disappear out from under ourselves - // woah - self.reachabilityObject = self; - - - - // first we need to create a serial queue - // we allocate this once for the lifetime of the notifier - self.reachabilitySerialQueue = dispatch_queue_create("com.tonymillion.reachability", NULL); - if(!self.reachabilitySerialQueue) - { - return NO; - } - - - context.info = (__bridge void *)self; - - if (!SCNetworkReachabilitySetCallback(self.reachabilityRef, TMReachabilityCallback, &context)) - { -#ifdef DEBUG - NSLog(@"SCNetworkReachabilitySetCallback() failed: %s", SCErrorString(SCError())); -#endif - - //clear out the dispatch queue - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; - - return NO; - } - - // set it as our reachability queue which will retain the queue - if(!SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, self.reachabilitySerialQueue)) - { -#ifdef DEBUG - NSLog(@"SCNetworkReachabilitySetDispatchQueue() failed: %s", SCErrorString(SCError())); -#endif - - //UH OH - FAILURE! - - // first stop any callbacks! - SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL); - - // then clear out the dispatch queue - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; - - return NO; - } - - return YES; -} - --(void)stopNotifier -{ - // first stop any callbacks! - SCNetworkReachabilitySetCallback(self.reachabilityRef, NULL, NULL); - - // unregister target from the GCD serial dispatch queue - SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, NULL); - - if(self.reachabilitySerialQueue) - { -#if NEEDS_DISPATCH_RETAIN_RELEASE - dispatch_release(self.reachabilitySerialQueue); -#endif - self.reachabilitySerialQueue = nil; - } - - self.reachabilityObject = nil; -} - -#pragma mark - reachability tests - -// this is for the case where you flick the airplane mode -// you end up getting something like this: -//Reachability: WR ct----- -//Reachability: -- ------- -//Reachability: WR ct----- -//Reachability: -- ------- -// we treat this as 4 UNREACHABLE triggers - really apple should do better than this - -#define testcase (kSCNetworkReachabilityFlagsConnectionRequired | kSCNetworkReachabilityFlagsTransientConnection) - --(BOOL)isReachableWithFlags:(SCNetworkReachabilityFlags)flags -{ - BOOL connectionUP = YES; - - if(!(flags & kSCNetworkReachabilityFlagsReachable)) - connectionUP = NO; - - if( (flags & testcase) == testcase ) - connectionUP = NO; - -#if TARGET_OS_IPHONE - if(flags & kSCNetworkReachabilityFlagsIsWWAN) - { - // we're on 3G - if(!self.reachableOnWWAN) - { - // we dont want to connect when on 3G - connectionUP = NO; - } - } -#endif - - return connectionUP; -} - --(BOOL)isReachable -{ - SCNetworkReachabilityFlags flags; - - if(!SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - return NO; - - return [self isReachableWithFlags:flags]; -} - --(BOOL)isReachableViaWWAN -{ -#if TARGET_OS_IPHONE - - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - { - // check we're REACHABLE - if(flags & kSCNetworkReachabilityFlagsReachable) - { - // now, check we're on WWAN - if(flags & kSCNetworkReachabilityFlagsIsWWAN) - { - return YES; - } - } - } -#endif - - return NO; -} - --(BOOL)isReachableViaWiFi -{ - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - { - // check we're reachable - if((flags & kSCNetworkReachabilityFlagsReachable)) - { -#if TARGET_OS_IPHONE - // check we're NOT on WWAN - if((flags & kSCNetworkReachabilityFlagsIsWWAN)) - { - return NO; - } -#endif - return YES; - } - } - - return NO; -} - - -// WWAN may be available, but not active until a connection has been established. -// WiFi may require a connection for VPN on Demand. --(BOOL)isConnectionRequired -{ - return [self connectionRequired]; -} - --(BOOL)connectionRequired -{ - SCNetworkReachabilityFlags flags; - - if(SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - { - return (flags & kSCNetworkReachabilityFlagsConnectionRequired); - } - - return NO; -} - -// Dynamic, on demand connection? --(BOOL)isConnectionOnDemand -{ - SCNetworkReachabilityFlags flags; - - if (SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - { - return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && - (flags & (kSCNetworkReachabilityFlagsConnectionOnTraffic | kSCNetworkReachabilityFlagsConnectionOnDemand))); - } - - return NO; -} - -// Is user intervention required? --(BOOL)isInterventionRequired -{ - SCNetworkReachabilityFlags flags; - - if (SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - { - return ((flags & kSCNetworkReachabilityFlagsConnectionRequired) && - (flags & kSCNetworkReachabilityFlagsInterventionRequired)); - } - - return NO; -} - - -#pragma mark - reachability status stuff - --(NetworkStatus)currentReachabilityStatus -{ - if([self isReachable]) - { - if([self isReachableViaWiFi]) - return ReachableViaWiFi; - -#if TARGET_OS_IPHONE - return ReachableViaWWAN; -#endif - } - - return NotReachable; -} - --(SCNetworkReachabilityFlags)reachabilityFlags -{ - SCNetworkReachabilityFlags flags = 0; - - if(SCNetworkReachabilityGetFlags(self.reachabilityRef, &flags)) - { - return flags; - } - - return 0; -} - --(NSString*)currentReachabilityString -{ - NetworkStatus temp = [self currentReachabilityStatus]; - - if(temp == self.reachableOnWWAN) - { - // updated for the fact we have CDMA phones now! - return NSLocalizedString(@"Cellular", @""); - } - if (temp == ReachableViaWiFi) - { - return NSLocalizedString(@"WiFi", @""); - } - - return NSLocalizedString(@"No Connection", @""); -} - --(NSString*)currentReachabilityFlags -{ - return reachabilityFlags([self reachabilityFlags]); -} - -#pragma mark - callback function calls this method - --(void)reachabilityChanged:(SCNetworkReachabilityFlags)flags -{ - if([self isReachableWithFlags:flags]) - { - if(self.reachableBlock) - { - self.reachableBlock(self); - } - } - else - { - if(self.unreachableBlock) - { - self.unreachableBlock(self); - } - } - - // this makes sure the change notification happens on the MAIN THREAD - dispatch_async(dispatch_get_main_queue(), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification - object:self]; - }); -} - -@end diff --git a/TalkinToTheNet/TalkinToTheNet/ViewController.m b/TalkinToTheNet/TalkinToTheNet/ViewController.m index 945792d..20d8edd 100644 --- a/TalkinToTheNet/TalkinToTheNet/ViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/ViewController.m @@ -7,12 +7,12 @@ // #import "ViewController.h" -#import "FourSquareKit.h" -#import "MKNetworkKit.h" +#import "APIManager.h" +#import - -@interface ViewController () -@property (nonatomic) UXRFourSquareNetworkingEngine *fourSquareEngine; +@interface ViewController () +@property CLLocationManager *locationManager; +@property CLLocation *currentLocation; @end @@ -20,29 +20,47 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - [self registerNetworkingEngine]; - [self getNearbyTacoRestaurants]; + [self setupLocationManager]; +} + +#pragma mark - Location methods +-(void)setupLocationManager{ + self.locationManager = [[CLLocationManager alloc]init]; + self.locationManager.delegate = self; + self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; + if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { + [self.locationManager requestWhenInUseAuthorization]; + } + [self.locationManager startUpdatingLocation]; } --(void)registerNetworkingEngine{ - NSString *yourClientId = @"RCPNIN1V5V5GCZ0F3RSFCNFIOD2K2240ZIW2ZANAOFIJWV1O"; - NSString *yourClientSecret = @"4YZZKIM1UUUXTVG4K3RX2Y4BV3TIG2RZDIB1KUTJJJPCTK5G"; - NSString *yourCallbackURl = @"http://google.com"; - [UXRFourSquareNetworkingEngine registerFourSquareEngineWithClientId:yourClientId andSecret:yourClientSecret andCallBackURL:yourCallbackURl]; - self.fourSquareEngine = [UXRFourSquareNetworkingEngine sharedInstance]; +-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ + self.currentLocation = [locations lastObject]; } --(void)getNearbyTacoRestaurants{ - NSString *locationString = @"Seattle"; - NSString *query = @"tacos"; - [self.fourSquareEngine exploreRestaurantsNearLocation:locationString - withQuery:query - withCompletionBlock:^(NSArray *restaurants) { - UXRFourSquareRestaurantModel *restaurantModel = (UXRFourSquareRestaurantModel *)restaurants[0]; - NSLog(@"%@",restaurantModel); - } failureBlock:^(NSError *error) { - // Error - }]; +-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ + UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"There was an error retrieving your location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; + [errorAlert show]; + NSLog(@"Error: %@",error.description); } +-(void)makeFoursquareRequestWithSearchTerm:(NSString *)searchTerm ForLocation:(CLLocation *)location WithCallbackBlock:(void(^)())block{ + + NSString *latitude = [NSString stringWithFormat:@"%.1f",location.coordinate.latitude]; + NSString *longitude = [NSString stringWithFormat:@"%.1f",location.coordinate.longitude]; + + NSString *urlString = [NSString stringWithFormat: @"https://api.foursquare.com/v2/venues/search?client_id=RCPNIN1V5V5GCZ0F3RSFCNFIOD2K2240ZIW2ZANAOFIJWV1O&client_secret=4YZZKIM1UUUXTVG4K3RX2Y4BV3TIG2RZDIB1KUTJJJPCTK5G&v=20130815&ll=%@,%@&query=%@",latitude,longitude, searchTerm]; + NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; + NSURL *url = [NSURL URLWithString:encodedString]; + + [APIManager GETRequestWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if (data != nil){ + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + } + }]; + + block(); +} + + @end From 31044f5e83ea7cec0f3e8f740a8ef773c05e455d Mon Sep 17 00:00:00 2001 From: Derek316x Date: Tue, 22 Sep 2015 13:08:08 -0400 Subject: [PATCH 4/5] added restaurants from api to C4QRestaurant objects --- .../TalkinToTheNet.xcodeproj/project.pbxproj | 6 +++ .../TalkinToTheNet/Base.lproj/Main.storyboard | 52 +++++++++++++++++++ TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h | 20 +++++++ TalkinToTheNet/TalkinToTheNet/C4QRestaurant.m | 13 +++++ .../TalkinToTheNet/ViewController.m | 42 ++++++++++++++- 5 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h create mode 100644 TalkinToTheNet/TalkinToTheNet/C4QRestaurant.m diff --git a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj index 579a249..b864854 100644 --- a/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj +++ b/TalkinToTheNet/TalkinToTheNet.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 69E41EF71BB0F5F600D7324C /* APIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E41EF61BB0F5F600D7324C /* APIManager.m */; settings = {ASSET_TAGS = (); }; }; 69E420171BB10B3D00D7324C /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 69E420161BB10B3D00D7324C /* CoreLocation.framework */; }; + 69E4201A1BB1BC1F00D7324C /* C4QRestaurant.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E420191BB1BC1F00D7324C /* C4QRestaurant.m */; settings = {ASSET_TAGS = (); }; }; 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4A1BAF859400A92AD2 /* main.m */; }; 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */; }; 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7DCD501BAF859400A92AD2 /* ViewController.m */; }; @@ -21,6 +22,8 @@ 69E41EF51BB0F5F600D7324C /* APIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIManager.h; sourceTree = ""; }; 69E41EF61BB0F5F600D7324C /* APIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APIManager.m; sourceTree = ""; }; 69E420161BB10B3D00D7324C /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; + 69E420181BB1BC1F00D7324C /* C4QRestaurant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = C4QRestaurant.h; sourceTree = ""; }; + 69E420191BB1BC1F00D7324C /* C4QRestaurant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = C4QRestaurant.m; sourceTree = ""; }; 8D7DCD461BAF859400A92AD2 /* TalkinToTheNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TalkinToTheNet.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8D7DCD4A1BAF859400A92AD2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -67,6 +70,8 @@ children = ( 8D7DCD4C1BAF859400A92AD2 /* AppDelegate.h */, 8D7DCD4D1BAF859400A92AD2 /* AppDelegate.m */, + 69E420181BB1BC1F00D7324C /* C4QRestaurant.h */, + 69E420191BB1BC1F00D7324C /* C4QRestaurant.m */, 69E41EF51BB0F5F600D7324C /* APIManager.h */, 69E41EF61BB0F5F600D7324C /* APIManager.m */, 8D7DCD4F1BAF859400A92AD2 /* ViewController.h */, @@ -159,6 +164,7 @@ buildActionMask = 2147483647; files = ( 69E41EF71BB0F5F600D7324C /* APIManager.m in Sources */, + 69E4201A1BB1BC1F00D7324C /* C4QRestaurant.m in Sources */, 8D7DCD511BAF859400A92AD2 /* ViewController.m in Sources */, 8D7DCD4E1BAF859400A92AD2 /* AppDelegate.m in Sources */, 8D7DCD4B1BAF859400A92AD2 /* main.m in Sources */, diff --git a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard index f9440a8..96ddf50 100644 --- a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard +++ b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard @@ -3,6 +3,7 @@ + @@ -16,8 +17,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h b/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h new file mode 100644 index 0000000..851991c --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h @@ -0,0 +1,20 @@ +// +// C4QRestaurant.h +// TalkinToTheNet +// +// Created by Z on 9/22/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface C4QRestaurant : NSObject + +@property NSString *name; +@property NSString *address; + +@property NSInteger *ratCount; +@property NSInteger *roachCount; +@property NSInteger *flyCount; + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.m b/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.m new file mode 100644 index 0000000..8a8645c --- /dev/null +++ b/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.m @@ -0,0 +1,13 @@ +// +// C4QRestaurant.m +// TalkinToTheNet +// +// Created by Z on 9/22/15. +// Copyright © 2015 Mike Kavouras. All rights reserved. +// + +#import "C4QRestaurant.h" + +@implementation C4QRestaurant + +@end diff --git a/TalkinToTheNet/TalkinToTheNet/ViewController.m b/TalkinToTheNet/TalkinToTheNet/ViewController.m index 20d8edd..d26ecd4 100644 --- a/TalkinToTheNet/TalkinToTheNet/ViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/ViewController.m @@ -9,11 +9,19 @@ #import "ViewController.h" #import "APIManager.h" #import +#import "C4QRestaurant.h" + +@interface ViewController () -@interface ViewController () @property CLLocationManager *locationManager; @property CLLocation *currentLocation; +@property (weak, nonatomic) IBOutlet UILabel *latLabel; +@property (weak, nonatomic) IBOutlet UILabel *longLabel; +@property (weak, nonatomic) IBOutlet UITextField *searchTextField; + +@property (nonatomic) NSMutableArray *restaurants; + @end @implementation ViewController @@ -21,6 +29,8 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupLocationManager]; + + self.searchTextField.delegate = self; } #pragma mark - Location methods @@ -36,6 +46,8 @@ -(void)setupLocationManager{ -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ self.currentLocation = [locations lastObject]; + self.latLabel.text = [NSString stringWithFormat:@"%f.1f", self.currentLocation.coordinate.latitude]; + self.longLabel.text = [NSString stringWithFormat:@"%f.1f", self.currentLocation.coordinate.longitude]; } -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ @@ -44,6 +56,24 @@ -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *) NSLog(@"Error: %@",error.description); } +#pragma mark - textfield delegate methods + +-(BOOL)textFieldShouldReturn:(UITextField *)textField{ + + [self makeFoursquareRequestWithSearchTerm:textField.text ForLocation:self.currentLocation WithCallbackBlock:^{ + for (C4QRestaurant *restuarant in self.restaurants) { + NSLog(@"%@",restuarant.name); + } + + }]; + //dismisses the keyboard + [self.view endEditing:YES]; + + return YES; +} + +#pragma mark - search methods + -(void)makeFoursquareRequestWithSearchTerm:(NSString *)searchTerm ForLocation:(CLLocation *)location WithCallbackBlock:(void(^)())block{ NSString *latitude = [NSString stringWithFormat:@"%.1f",location.coordinate.latitude]; @@ -55,10 +85,18 @@ -(void)makeFoursquareRequestWithSearchTerm:(NSString *)searchTerm ForLocation:(C [APIManager GETRequestWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (data != nil){ + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + NSDictionary *venues = [[json objectForKey:@"response"] objectForKey:@"venues"]; + + self.restaurants = [[NSMutableArray alloc] init]; + for (NSDictionary *venue in venues) { + C4QRestaurant *restaurant = [[C4QRestaurant alloc] init]; + restaurant.name = [venue objectForKey: @"name"]; + [self.restaurants addObject:restaurant]; + } } }]; - block(); } From 9169c2caf8b98d6260c2f476def746e969a44788 Mon Sep 17 00:00:00 2001 From: Derek316x Date: Fri, 25 Sep 2015 20:52:56 -0400 Subject: [PATCH 5/5] got violation api data --- .../TalkinToTheNet/Base.lproj/Main.storyboard | 19 +++++ TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h | 5 ++ .../TalkinToTheNet/ViewController.m | 76 +++++++++++++++++-- 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard index 96ddf50..82ba250 100644 --- a/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard +++ b/TalkinToTheNet/TalkinToTheNet/Base.lproj/Main.storyboard @@ -38,21 +38,39 @@ + + + + + + + + + + + + + + + + + + @@ -69,6 +87,7 @@ + diff --git a/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h b/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h index 851991c..029425a 100644 --- a/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h +++ b/TalkinToTheNet/TalkinToTheNet/C4QRestaurant.h @@ -11,7 +11,12 @@ @interface C4QRestaurant : NSObject @property NSString *name; +@property NSString *phoneNumber; + @property NSString *address; +@property NSString *buildingNumber; +@property NSString *street; +@property NSString *zipcode; @property NSInteger *ratCount; @property NSInteger *roachCount; diff --git a/TalkinToTheNet/TalkinToTheNet/ViewController.m b/TalkinToTheNet/TalkinToTheNet/ViewController.m index d26ecd4..82ecb5f 100644 --- a/TalkinToTheNet/TalkinToTheNet/ViewController.m +++ b/TalkinToTheNet/TalkinToTheNet/ViewController.m @@ -11,7 +11,12 @@ #import #import "C4QRestaurant.h" -@interface ViewController () +@interface ViewController () < +CLLocationManagerDelegate, +UITextFieldDelegate, +UITableViewDataSource, +UITableViewDelegate +> @property CLLocationManager *locationManager; @property CLLocation *currentLocation; @@ -19,6 +24,7 @@ @interface ViewController () @property (weak, nonatomic) IBOutlet UILabel *latLabel; @property (weak, nonatomic) IBOutlet UILabel *longLabel; @property (weak, nonatomic) IBOutlet UITextField *searchTextField; +@property (weak, nonatomic) IBOutlet UITableView *tableView; @property (nonatomic) NSMutableArray *restaurants; @@ -31,6 +37,10 @@ - (void)viewDidLoad { [self setupLocationManager]; self.searchTextField.delegate = self; + self.tableView.delegate = self; + self.tableView.dataSource = self; + +// [self getViolationDataForNYCRestaurants]; } #pragma mark - Location methods @@ -41,7 +51,6 @@ -(void)setupLocationManager{ if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; } - [self.locationManager startUpdatingLocation]; } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ @@ -63,23 +72,28 @@ -(BOOL)textFieldShouldReturn:(UITextField *)textField{ [self makeFoursquareRequestWithSearchTerm:textField.text ForLocation:self.currentLocation WithCallbackBlock:^{ for (C4QRestaurant *restuarant in self.restaurants) { NSLog(@"%@",restuarant.name); + NSLog(@"%@",restuarant.phoneNumber); + NSLog(@"********"); } - + [self.tableView reloadData]; }]; + //dismisses the keyboard [self.view endEditing:YES]; return YES; } -#pragma mark - search methods +#pragma mark - foursquare api methods -(void)makeFoursquareRequestWithSearchTerm:(NSString *)searchTerm ForLocation:(CLLocation *)location WithCallbackBlock:(void(^)())block{ + //start updating location at beginning of method; stop updating location at end + [self.locationManager startUpdatingLocation]; NSString *latitude = [NSString stringWithFormat:@"%.1f",location.coordinate.latitude]; NSString *longitude = [NSString stringWithFormat:@"%.1f",location.coordinate.longitude]; - NSString *urlString = [NSString stringWithFormat: @"https://api.foursquare.com/v2/venues/search?client_id=RCPNIN1V5V5GCZ0F3RSFCNFIOD2K2240ZIW2ZANAOFIJWV1O&client_secret=4YZZKIM1UUUXTVG4K3RX2Y4BV3TIG2RZDIB1KUTJJJPCTK5G&v=20130815&ll=%@,%@&query=%@",latitude,longitude, searchTerm]; + NSString *urlString = [NSString stringWithFormat: @"https://api.foursquare.com/v2/venues/search?client_id=RCPNIN1V5V5GCZ0F3RSFCNFIOD2K2240ZIW2ZANAOFIJWV1O&client_secret=4YZZKIM1UUUXTVG4K3RX2Y4BV3TIG2RZDIB1KUTJJJPCTK5G&v=20130815§ion=food&ll=%@,%@&query=%@",latitude,longitude, searchTerm]; NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; NSURL *url = [NSURL URLWithString:encodedString]; @@ -90,15 +104,61 @@ -(void)makeFoursquareRequestWithSearchTerm:(NSString *)searchTerm ForLocation:(C NSDictionary *venues = [[json objectForKey:@"response"] objectForKey:@"venues"]; self.restaurants = [[NSMutableArray alloc] init]; + for (NSDictionary *venue in venues) { C4QRestaurant *restaurant = [[C4QRestaurant alloc] init]; restaurant.name = [venue objectForKey: @"name"]; - [self.restaurants addObject:restaurant]; + NSString *phoneNumber = [[venue objectForKey:@"contact"] objectForKey:@"phone"]; + if (phoneNumber != nil) { //only add restaurants with a phone number + restaurant.phoneNumber = phoneNumber; + [self.restaurants addObject:restaurant]; + } } } + block(); + [self.locationManager stopUpdatingLocation]; }]; - block(); } +#pragma mark - inspection data api methods -@end +-(void)getViolationDataForNYCRestaurants{ + + NSString *urlString = [NSString stringWithFormat: @"https://data.cityofnewyork.us/resource/9w7m-hzhe.json"]; + NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; + NSURL *url = [NSURL URLWithString:encodedString]; + + [APIManager GETRequestWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if (data != nil){ + NSArray *jsonViolations = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; + for (NSDictionary *violation in jsonViolations) { + NSString *name = [violation objectForKey:@"dba"]; + NSString *violationCode = [violation objectForKey:@"violation_code"]; + NSLog(@"%@ - %@",name,violationCode); + } + } + }]; +} + +#pragma mark - tableView methods + +-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ + return 1; +} + +-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ + return self.restaurants.count; +} + +-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RestaurantCellIdentifier" forIndexPath:indexPath]; + + C4QRestaurant *restaurantForCell = self.restaurants[indexPath.row]; + + cell.textLabel.text = restaurantForCell.name; + + return cell; +} + +@end \ No newline at end of file