From 781c96a1f6670fbb17e29c1a01a8e90e59f21e20 Mon Sep 17 00:00:00 2001 From: Christopher de Haan Date: Sun, 12 Sep 2021 17:51:27 -0700 Subject: [PATCH] Dependency Updates (#25) * Replace ObjectMapper with Codable * Validate AF requests * Use Decodable opposed to Codable * Update .gitmodules * Bump AlamoFire version * Convert to URL on decoding * Clean up spacing in Example * Format variables correctly for decoding in CDYelpEvent * Parse dates as Date opposed to String * Update example documentation * update version number * update dependency versions * fix SwiftPackageManager * Update CHANGELOG.md * remove travis.yml * Update CHANGELOG.md --- .gitmodules | 3 - .swiftlint.yml | 15 +- .travis.yml | 59 ---- CDYelpFusionKit.podspec | 5 +- CDYelpFusionKit.xcodeproj/project.pbxproj | 169 +---------- CHANGELOG.md | 34 ++- Cartfile | 3 +- Cartfile.resolved | 3 +- Carthage/Checkouts/Alamofire | 2 +- Carthage/Checkouts/ObjectMapper | 1 - Example/Source/ViewController.swift | 109 ++++--- Package.swift | 12 +- README.md | 11 +- Source/Alamofire+ObjectMapper.swift | 190 ------------ Source/CDImage+CDYelpFusionKit.swift | 6 + Source/CDYelpAPIClient.swift | 336 ++++++++++++--------- Source/CDYelpAutoCompleteResponse.swift | 25 +- Source/CDYelpBusiness.swift | 81 ++--- Source/CDYelpBusinessResponse.swift | 17 +- Source/CDYelpCategoriesResponse.swift | 13 +- Source/CDYelpCategory.swift | 29 +- Source/CDYelpCategoryResponse.swift | 13 +- Source/CDYelpCenter.swift | 17 +- Source/CDYelpCoordinates.swift | 17 +- Source/CDYelpError.swift | 21 +- Source/CDYelpEvent.swift | 93 +++--- Source/CDYelpEventsResponse.swift | 21 +- Source/CDYelpHour.swift | 21 +- Source/CDYelpLocation.swift | 45 ++- Source/CDYelpOpen.swift | 25 +- Source/CDYelpRegion.swift | 13 +- Source/CDYelpReview.swift | 37 +-- Source/CDYelpReviewsResponse.swift | 25 +- Source/CDYelpRouter.swift | 6 + Source/CDYelpSearchResponse.swift | 25 +- Source/CDYelpTerm.swift | 13 +- Source/CDYelpUser.swift | 29 +- Source/DateFormatter+CDYelpFusionKit.swift | 46 +++ Source/Parameters+CDYelpFusionKit.swift | 6 + Source/URL+CDYelpFusionKit.swift | 6 + 40 files changed, 644 insertions(+), 958 deletions(-) delete mode 100644 .travis.yml delete mode 160000 Carthage/Checkouts/ObjectMapper delete mode 100644 Source/Alamofire+ObjectMapper.swift create mode 100644 Source/DateFormatter+CDYelpFusionKit.swift diff --git a/.gitmodules b/.gitmodules index eae6a94..b07b6de 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "Carthage/Checkouts/Alamofire"] path = Carthage/Checkouts/Alamofire url = https://github.com/Alamofire/Alamofire.git -[submodule "Carthage/Checkouts/ObjectMapper"] - path = Carthage/Checkouts/ObjectMapper - url = https://github.com/tristanhimmelman/ObjectMapper.git diff --git a/.swiftlint.yml b/.swiftlint.yml index b2d1a57..9f2ddcf 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,4 +1,5 @@ disabled_rules: # rule identifiers to exclude from running + - inclusive_language included: # paths to include during linting. `--path` is ignored if present. - Source - Example/Source @@ -12,18 +13,18 @@ colon: apply_to_dictionaries: false # complexity of a function cyclomatic_complexity: - error: 55 - warning: 50 + error: 60 + warning: 55 # number of lines allowed in a function function_body_length: - error: 50 - warning: 45 + error: 60 + warning: 55 # number of parameters allowed for a function function_parameter_count: 15 # number of lines allowed in a file file_length: error: 1200 - warning: 700 + warning: 750 # rules related to vars/lets identifier_name: excluded: @@ -36,5 +37,5 @@ line_length: warning: 195 # number of lines allowed in a type declaration type_body_length: - error: 400 - warning: 350 + error: 450 + warning: 400 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index eda7ee4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,59 +0,0 @@ -os: osx -osx_image: xcode11.6 -branches: - only: - - master -env: - global: - - LC_CTYPE=en_US.UTF-8 - - LANG=en_US.UTF-8 - - WORKSPACE=CDYelpFusionKit.xcworkspace - - IOS_FRAMEWORK_SCHEME="CDYelpFusionKit iOS" - - MACOS_FRAMEWORK_SCHEME="CDYelpFusionKit macOS" - - TVOS_FRAMEWORK_SCHEME="CDYelpFusionKit tvOS" - - WATCHOS_FRAMEWORK_SCHEME="CDYelpFusionKit watchOS" - - EXAMPLE_SCHEME="iOS Example" - matrix: - - DESTINATION="OS=6.2.1,name=Apple Watch Series 5 - 44mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - DESTINATION="OS=5.3,name=Apple Watch Series 4 - 44mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - DESTINATION="OS=4.2,name=Apple Watch Series 3 - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - DESTINATION="OS=3.2,name=Apple Watch Series 2 - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - - DESTINATION="OS=13.6,name=iPhone 11" SCHEME="$IOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="NO" BUILD_EXAMPLE="YES" POD_LINT="NO" - - DESTINATION="OS=12.4,name=iPhone X" SCHEME="$IOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="NO" BUILD_EXAMPLE="YES" POD_LINT="NO" - - DESTINATION="OS=11.4,name=iPhone 8" SCHEME="$IOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="NO" BUILD_EXAMPLE="YES" POD_LINT="NO" - - DESTINATION="OS=10.3.1,name=iPhone 7" SCHEME="$IOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="NO" BUILD_EXAMPLE="YES" POD_LINT="NO" - - - DESTINATION="OS=13.4,name=Apple TV 4K (at 1080p)" SCHEME="$TVOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - DESTINATION="OS=12.4,name=Apple TV 4K (at 1080p)" SCHEME="$TVOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - DESTINATION="OS=11.4,name=Apple TV 4K" SCHEME="$TVOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - DESTINATION="OS=10.2,name=Apple TV" SCHEME="$TVOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - - DESTINATION="arch=x86_64" SCHEME="$MACOS_FRAMEWORK_SCHEME" BUILD_FRAMEWORK="YES" BUILD_EXAMPLE="NO" POD_LINT="YES" -before_install: - - gem install cocoapods --no-document --quiet - - pod repo update -script: - - set -o pipefail - - xcodebuild -version - - xcodebuild -showsdks - - # Build Framework in Debug if specified - - if [ $BUILD_FRAMEWORK == "YES" ]; then - xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty; - fi - - # Build Framework in Release if specified - - if [ $BUILD_FRAMEWORK == "YES" ]; then - xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO build | xcpretty; - fi - - # Build Example in Debug if specified - - if [ $BUILD_EXAMPLE == "YES" ]; then - xcodebuild -workspace "$WORKSPACE" -scheme "$EXAMPLE_SCHEME" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty; - fi - - # Run `pod lib lint` if specified - - if [ $POD_LINT == "YES" ]; then - travis_wait 60 pod lib lint --allow-warnings --use-libraries; - fi diff --git a/CDYelpFusionKit.podspec b/CDYelpFusionKit.podspec index 578eae0..2248c28 100644 --- a/CDYelpFusionKit.podspec +++ b/CDYelpFusionKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'CDYelpFusionKit' - s.version = '2.1.1' + s.version = '3.0.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'An extensive Swift wrapper for the Yelp Fusion API.' s.description = <<-DESC @@ -20,6 +20,5 @@ Pod::Spec.new do |s| s.source_files = 'Source/*.swift' s.resources = ['Resources/*.xcassets'] - s.dependency 'Alamofire', '5.2.2' - s.dependency 'ObjectMapper', '4.2.0' + s.dependency 'Alamofire', '5.4.3' end diff --git a/CDYelpFusionKit.xcodeproj/project.pbxproj b/CDYelpFusionKit.xcodeproj/project.pbxproj index 77c59c1..5ceb5ca 100644 --- a/CDYelpFusionKit.xcodeproj/project.pbxproj +++ b/CDYelpFusionKit.xcodeproj/project.pbxproj @@ -8,17 +8,9 @@ /* Begin PBXBuildFile section */ 5F09D2EA1F282938001877E9 /* CDYelpEnums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F09D2E91F282938001877E9 /* CDYelpEnums.swift */; }; - 5F6BC9D524FBF71100EC41A7 /* Alamofire+ObjectMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F6BC9D424FBF71100EC41A7 /* Alamofire+ObjectMapper.swift */; }; - 5F6BC9D624FBF71100EC41A7 /* Alamofire+ObjectMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F6BC9D424FBF71100EC41A7 /* Alamofire+ObjectMapper.swift */; }; - 5F6BC9D724FBF71100EC41A7 /* Alamofire+ObjectMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F6BC9D424FBF71100EC41A7 /* Alamofire+ObjectMapper.swift */; }; - 5F6BC9D824FBF71100EC41A7 /* Alamofire+ObjectMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F6BC9D424FBF71100EC41A7 /* Alamofire+ObjectMapper.swift */; }; 5F6BC9E824FBFAE100EC41A7 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F6BC9AB24FBF0E300EC41A7 /* Alamofire.framework */; }; - 5F6BC9F224FBFAEE00EC41A7 /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F6BC9C424FBF0ED00EC41A7 /* ObjectMapper.framework */; }; 5F6BC9F424FC037700EC41A7 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F6BC9AF24FBF0E300EC41A7 /* Alamofire.framework */; }; - 5F6BC9F524FC037C00EC41A7 /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F6BC9C624FBF0ED00EC41A7 /* ObjectMapper.framework */; }; - 5F6BC9F624FC038900EC41A7 /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F6BC9CA24FBF0ED00EC41A7 /* ObjectMapper.framework */; }; 5F6BC9F724FC038D00EC41A7 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F6BC9B324FBF0E300EC41A7 /* Alamofire.framework */; }; - 5F6BC9F824FC039200EC41A7 /* ObjectMapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F6BC9C824FBF0ED00EC41A7 /* ObjectMapper.framework */; }; 5F6BC9F924FC039600EC41A7 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F6BC9B724FBF0E300EC41A7 /* Alamofire.framework */; }; 5F854DFE1FB44B0F00335D73 /* CDColor+CDYelpFusionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F854DFD1FB44B0F00335D73 /* CDColor+CDYelpFusionKit.swift */; }; 5F854E071FB44B1F00335D73 /* CDImage+CDYelpFusionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F854E061FB44B1F00335D73 /* CDImage+CDYelpFusionKit.swift */; }; @@ -44,6 +36,10 @@ 5FBF0EBB1EC000B1004C1F6B /* CDYelpTerm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBF0EA21EC000B1004C1F6B /* CDYelpTerm.swift */; }; 5FBF0EBC1EC000B1004C1F6B /* CDYelpUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBF0EA31EC000B1004C1F6B /* CDYelpUser.swift */; }; 5FBF0EBE1EC000B1004C1F6B /* Parameters+CDYelpFusionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FBF0EA51EC000B1004C1F6B /* Parameters+CDYelpFusionKit.swift */; }; + 5FC92B5026668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC92B4F26668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift */; }; + 5FC92B5126668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC92B4F26668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift */; }; + 5FC92B5226668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC92B4F26668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift */; }; + 5FC92B5326668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC92B4F26668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift */; }; 5FDB32991FAACE8E00A9CF71 /* CDYelpEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FDB32981FAACE8E00A9CF71 /* CDYelpEvent.swift */; }; 5FDB32A21FAACF4100A9CF71 /* CDYelpEventsResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FDB32A11FAACF4100A9CF71 /* CDYelpEventsResponse.swift */; }; B266344D1FBEA1B8003B09CE /* String+CDYelpFusionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = B266344C1FBEA1B8003B09CE /* String+CDYelpFusionKit.swift */; }; @@ -203,72 +199,15 @@ remoteGlobalIDString = E4202FE01B667AA100C997FB; remoteInfo = "Alamofire watchOS"; }; - 5F6BC9C324FBF0ED00EC41A7 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 6AAC8F7619F03C2900E7A677; - remoteInfo = "ObjectMapper-iOS"; - }; - 5F6BC9C524FBF0ED00EC41A7 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = CD1602FF1AC023D5000CD69A; - remoteInfo = "ObjectMapper-macOS"; - }; - 5F6BC9C724FBF0ED00EC41A7 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 6A2AD03D1B2C78540097E150; - remoteInfo = "ObjectMapper-watchOS"; - }; - 5F6BC9C924FBF0ED00EC41A7 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 6A05B7A61BE274BE00F19B53; - remoteInfo = "ObjectMapper-tvOS"; - }; - 5F6BC9CB24FBF0ED00EC41A7 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 6AAC8F8119F03C2900E7A677; - remoteInfo = "ObjectMapper-iOSTests"; - }; - 5F6BC9CD24FBF0ED00EC41A7 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = CD1603091AC023D6000CD69A; - remoteInfo = "ObjectMapper-macOSTests"; - }; - 5F6BC9CF24FBF0ED00EC41A7 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 6A05B7AF1BE274BE00F19B53; - remoteInfo = "ObjectMapper-tvOSTests"; - }; - 5F6BC9D124FBF0ED00EC41A7 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = DBB9B41F2142A25100078E5A; - remoteInfo = "ObjectMapper-Mac-Static"; - }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ 5F09D2E91F282938001877E9 /* CDYelpEnums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDYelpEnums.swift; sourceTree = ""; }; 5F6BC9A024FBF0E300EC41A7 /* Alamofire.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Alamofire.xcodeproj; path = Carthage/Checkouts/Alamofire/Alamofire.xcodeproj; sourceTree = ""; }; - 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ObjectMapper.xcodeproj; path = Carthage/Checkouts/ObjectMapper/ObjectMapper.xcodeproj; sourceTree = ""; }; - 5F6BC9D424FBF71100EC41A7 /* Alamofire+ObjectMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Alamofire+ObjectMapper.swift"; sourceTree = ""; }; 5F854DFD1FB44B0F00335D73 /* CDColor+CDYelpFusionKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CDColor+CDYelpFusionKit.swift"; sourceTree = ""; }; 5F854E061FB44B1F00335D73 /* CDImage+CDYelpFusionKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CDImage+CDYelpFusionKit.swift"; sourceTree = ""; }; 5F854E1B1FB44D6A00335D73 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = Resources/Images.xcassets; sourceTree = SOURCE_ROOT; }; + 5F88711226EECEE3004A3814 /* ci.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; name = ci.yml; path = .github/workflows/ci.yml; sourceTree = ""; }; 5FBF0E671EBFFEB0004C1F6B /* CDYelpFusionKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CDYelpFusionKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5FBF0E8D1EC000B1004C1F6B /* CDYelpAPIClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDYelpAPIClient.swift; sourceTree = ""; }; 5FBF0E8E1EC000B1004C1F6B /* CDYelpAutoCompleteResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDYelpAutoCompleteResponse.swift; sourceTree = ""; }; @@ -292,9 +231,9 @@ 5FBF0EA31EC000B1004C1F6B /* CDYelpUser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDYelpUser.swift; sourceTree = ""; }; 5FBF0EA41EC000B1004C1F6B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5FBF0EA51EC000B1004C1F6B /* Parameters+CDYelpFusionKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Parameters+CDYelpFusionKit.swift"; sourceTree = ""; }; + 5FC92B4F26668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+CDYelpFusionKit.swift"; sourceTree = ""; }; 5FDB32981FAACE8E00A9CF71 /* CDYelpEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDYelpEvent.swift; sourceTree = ""; }; 5FDB32A11FAACF4100A9CF71 /* CDYelpEventsResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDYelpEventsResponse.swift; sourceTree = ""; }; - B20430A521C2906C0072D3C0 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = ""; }; B25523B2218D02FF007CDD7A /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; B25523C5218D037B007CDD7A /* PULL_REQUEST_TEMPLATE.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = PULL_REQUEST_TEMPLATE.md; path = .github/PULL_REQUEST_TEMPLATE.md; sourceTree = ""; }; B25523C6218D037B007CDD7A /* ISSUE_TEMPLATE.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = ISSUE_TEMPLATE.md; path = .github/ISSUE_TEMPLATE.md; sourceTree = ""; }; @@ -321,7 +260,6 @@ buildActionMask = 2147483647; files = ( 5F6BC9E824FBFAE100EC41A7 /* Alamofire.framework in Frameworks */, - 5F6BC9F224FBFAEE00EC41A7 /* ObjectMapper.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -330,7 +268,6 @@ buildActionMask = 2147483647; files = ( 5F6BC9F424FC037700EC41A7 /* Alamofire.framework in Frameworks */, - 5F6BC9F524FC037C00EC41A7 /* ObjectMapper.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -339,7 +276,6 @@ buildActionMask = 2147483647; files = ( 5F6BC9F724FC038D00EC41A7 /* Alamofire.framework in Frameworks */, - 5F6BC9F624FC038900EC41A7 /* ObjectMapper.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -348,7 +284,6 @@ buildActionMask = 2147483647; files = ( 5F6BC9F924FC039600EC41A7 /* Alamofire.framework in Frameworks */, - 5F6BC9F824FC039200EC41A7 /* ObjectMapper.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -369,21 +304,6 @@ name = Products; sourceTree = ""; }; - 5F6BC9B924FBF0ED00EC41A7 /* Products */ = { - isa = PBXGroup; - children = ( - 5F6BC9C424FBF0ED00EC41A7 /* ObjectMapper.framework */, - 5F6BC9C624FBF0ED00EC41A7 /* ObjectMapper.framework */, - 5F6BC9C824FBF0ED00EC41A7 /* ObjectMapper.framework */, - 5F6BC9CA24FBF0ED00EC41A7 /* ObjectMapper.framework */, - 5F6BC9CC24FBF0ED00EC41A7 /* ObjectMapper-iOSTests.xctest */, - 5F6BC9CE24FBF0ED00EC41A7 /* ObjectMapper-macOSTests.xctest */, - 5F6BC9D024FBF0ED00EC41A7 /* ObjectMapper-tvOSTests.xctest */, - 5F6BC9D224FBF0ED00EC41A7 /* libObjectMapper.a */, - ); - name = Products; - sourceTree = ""; - }; 5F854E1A1FB44D4400335D73 /* Resources */ = { isa = PBXGroup; children = ( @@ -400,7 +320,6 @@ 5FBF0E8C1EC000B1004C1F6B /* Source */, 5FBF0E681EBFFEB0004C1F6B /* Products */, 5F6BC9A024FBF0E300EC41A7 /* Alamofire.xcodeproj */, - 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */, ); sourceTree = ""; }; @@ -431,9 +350,9 @@ 5FBF0EBF1EC000BC004C1F6B /* Extensions */ = { isa = PBXGroup; children = ( - 5F6BC9D424FBF71100EC41A7 /* Alamofire+ObjectMapper.swift */, 5F854DFD1FB44B0F00335D73 /* CDColor+CDYelpFusionKit.swift */, 5F854E061FB44B1F00335D73 /* CDImage+CDYelpFusionKit.swift */, + 5FC92B4F26668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift */, 5FBF0EA51EC000B1004C1F6B /* Parameters+CDYelpFusionKit.swift */, B266344C1FBEA1B8003B09CE /* String+CDYelpFusionKit.swift */, B285DA681FBE217800FA9ABB /* URL+CDYelpFusionKit.swift */, @@ -504,8 +423,8 @@ isa = PBXGroup; children = ( B25523B2218D02FF007CDD7A /* .swiftlint.yml */, - B20430A521C2906C0072D3C0 /* .travis.yml */, B29CB00A1FBBBAE80090F336 /* CDYelpFusionKit.podspec */, + 5F88711226EECEE3004A3814 /* ci.yml */, B29CB00C1FBBBAE80090F336 /* LICENSE */, B29CB00B1FBBBAE80090F336 /* Package.swift */, ); @@ -682,10 +601,6 @@ ProductGroup = 5F6BC9A124FBF0E300EC41A7 /* Products */; ProjectRef = 5F6BC9A024FBF0E300EC41A7 /* Alamofire.xcodeproj */; }, - { - ProductGroup = 5F6BC9B924FBF0ED00EC41A7 /* Products */; - ProjectRef = 5F6BC9B824FBF0ED00EC41A7 /* ObjectMapper.xcodeproj */; - }, ); projectRoot = ""; targets = ( @@ -747,62 +662,6 @@ remoteRef = 5F6BC9B624FBF0E300EC41A7 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 5F6BC9C424FBF0ED00EC41A7 /* ObjectMapper.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = ObjectMapper.framework; - remoteRef = 5F6BC9C324FBF0ED00EC41A7 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 5F6BC9C624FBF0ED00EC41A7 /* ObjectMapper.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = ObjectMapper.framework; - remoteRef = 5F6BC9C524FBF0ED00EC41A7 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 5F6BC9C824FBF0ED00EC41A7 /* ObjectMapper.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = ObjectMapper.framework; - remoteRef = 5F6BC9C724FBF0ED00EC41A7 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 5F6BC9CA24FBF0ED00EC41A7 /* ObjectMapper.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = ObjectMapper.framework; - remoteRef = 5F6BC9C924FBF0ED00EC41A7 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 5F6BC9CC24FBF0ED00EC41A7 /* ObjectMapper-iOSTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "ObjectMapper-iOSTests.xctest"; - remoteRef = 5F6BC9CB24FBF0ED00EC41A7 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 5F6BC9CE24FBF0ED00EC41A7 /* ObjectMapper-macOSTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "ObjectMapper-macOSTests.xctest"; - remoteRef = 5F6BC9CD24FBF0ED00EC41A7 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 5F6BC9D024FBF0ED00EC41A7 /* ObjectMapper-tvOSTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "ObjectMapper-tvOSTests.xctest"; - remoteRef = 5F6BC9CF24FBF0ED00EC41A7 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 5F6BC9D224FBF0ED00EC41A7 /* libObjectMapper.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libObjectMapper.a; - remoteRef = 5F6BC9D124FBF0ED00EC41A7 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ @@ -934,7 +793,6 @@ 5FBF0EAB1EC000B1004C1F6B /* CDYelpCenter.swift in Sources */, 5FBF0EAC1EC000B1004C1F6B /* CDYelpConstants.swift in Sources */, 5FBF0EAD1EC000B1004C1F6B /* CDYelpCoordinates.swift in Sources */, - 5F6BC9D524FBF71100EC41A7 /* Alamofire+ObjectMapper.swift in Sources */, 5F09D2EA1F282938001877E9 /* CDYelpEnums.swift in Sources */, 5FBF0EAE1EC000B1004C1F6B /* CDYelpError.swift in Sources */, 5FDB32991FAACE8E00A9CF71 /* CDYelpEvent.swift in Sources */, @@ -945,6 +803,7 @@ 5FBF0EB61EC000B1004C1F6B /* CDYelpRegion.swift in Sources */, 5FBF0EB71EC000B1004C1F6B /* CDYelpReview.swift in Sources */, 5FBF0EB81EC000B1004C1F6B /* CDYelpReviewsResponse.swift in Sources */, + 5FC92B5026668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift in Sources */, 5FBF0EB91EC000B1004C1F6B /* CDYelpRouter.swift in Sources */, 5FBF0EBA1EC000B1004C1F6B /* CDYelpSearchResponse.swift in Sources */, 5FBF0EBB1EC000B1004C1F6B /* CDYelpTerm.swift in Sources */, @@ -973,7 +832,6 @@ B285DA021FBD35C100FA9ABB /* CDYelpCenter.swift in Sources */, B285DA141FBD35C100FA9ABB /* CDYelpConstants.swift in Sources */, B285DA031FBD35C100FA9ABB /* CDYelpCoordinates.swift in Sources */, - 5F6BC9D624FBF71100EC41A7 /* Alamofire+ObjectMapper.swift in Sources */, B285DA151FBD35C100FA9ABB /* CDYelpEnums.swift in Sources */, B285DA041FBD35C100FA9ABB /* CDYelpError.swift in Sources */, B285DA051FBD35C100FA9ABB /* CDYelpEvent.swift in Sources */, @@ -984,6 +842,7 @@ B285DA0A1FBD35C100FA9ABB /* CDYelpRegion.swift in Sources */, B285DA0B1FBD35C100FA9ABB /* CDYelpReview.swift in Sources */, B285DA0C1FBD35C100FA9ABB /* CDYelpReviewsResponse.swift in Sources */, + 5FC92B5126668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift in Sources */, B285DA161FBD35C100FA9ABB /* CDYelpRouter.swift in Sources */, B285DA0D1FBD35C100FA9ABB /* CDYelpSearchResponse.swift in Sources */, B285DA0E1FBD35C100FA9ABB /* CDYelpTerm.swift in Sources */, @@ -1012,7 +871,6 @@ B285DA461FBE1BCE00FA9ABB /* CDYelpCenter.swift in Sources */, B285DA581FBE1BCE00FA9ABB /* CDYelpConstants.swift in Sources */, B285DA471FBE1BCE00FA9ABB /* CDYelpCoordinates.swift in Sources */, - 5F6BC9D724FBF71100EC41A7 /* Alamofire+ObjectMapper.swift in Sources */, B285DA591FBE1BCE00FA9ABB /* CDYelpEnums.swift in Sources */, B285DA481FBE1BCE00FA9ABB /* CDYelpError.swift in Sources */, B285DA491FBE1BCE00FA9ABB /* CDYelpEvent.swift in Sources */, @@ -1023,6 +881,7 @@ B285DA4E1FBE1BCE00FA9ABB /* CDYelpRegion.swift in Sources */, B285DA4F1FBE1BCE00FA9ABB /* CDYelpReview.swift in Sources */, B285DA501FBE1BCE00FA9ABB /* CDYelpReviewsResponse.swift in Sources */, + 5FC92B5226668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift in Sources */, B285DA5A1FBE1BCE00FA9ABB /* CDYelpRouter.swift in Sources */, B285DA511FBE1BCE00FA9ABB /* CDYelpSearchResponse.swift in Sources */, B285DA521FBE1BCE00FA9ABB /* CDYelpTerm.swift in Sources */, @@ -1051,7 +910,6 @@ B2C6E2001FBCF3A400FE8462 /* CDYelpCenter.swift in Sources */, B2C6E2121FBCF3A400FE8462 /* CDYelpConstants.swift in Sources */, B2C6E2011FBCF3A400FE8462 /* CDYelpCoordinates.swift in Sources */, - 5F6BC9D824FBF71100EC41A7 /* Alamofire+ObjectMapper.swift in Sources */, B2C6E2131FBCF3A400FE8462 /* CDYelpEnums.swift in Sources */, B2C6E2021FBCF3A400FE8462 /* CDYelpError.swift in Sources */, B2C6E2031FBCF3A400FE8462 /* CDYelpEvent.swift in Sources */, @@ -1062,6 +920,7 @@ B2C6E2081FBCF3A400FE8462 /* CDYelpRegion.swift in Sources */, B2C6E2091FBCF3A400FE8462 /* CDYelpReview.swift in Sources */, B2C6E20A1FBCF3A400FE8462 /* CDYelpReviewsResponse.swift in Sources */, + 5FC92B5326668EEE00E016A2 /* DateFormatter+CDYelpFusionKit.swift in Sources */, B2C6E2141FBCF3A400FE8462 /* CDYelpRouter.swift in Sources */, B2C6E20B1FBCF3A400FE8462 /* CDYelpSearchResponse.swift in Sources */, B2C6E20C1FBCF3A400FE8462 /* CDYelpTerm.swift in Sources */, @@ -1131,7 +990,7 @@ INFOPLIST_FILE = Source/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 2.1.1; + MARKETING_VERSION = 3.0.0; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.christopherdehaan.CDYelpFusionKit; PRODUCT_NAME = CDYelpFusionKit; @@ -1195,7 +1054,7 @@ INFOPLIST_FILE = Source/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 2.1.1; + MARKETING_VERSION = 3.0.0; PRODUCT_BUNDLE_IDENTIFIER = com.christopherdehaan.CDYelpFusionKit; PRODUCT_NAME = CDYelpFusionKit; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/CHANGELOG.md b/CHANGELOG.md index f21f2ca..52f500b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. `CDYelpFusionKit` adheres to [Semantic Versioning](https://semver.org/). +#### 3.x Releases +- `3.0.x` Releases - [3.0.0](#300) + #### 2.x Releases - `2.1.x` Releases - [2.1.0](#210) | [2.1.1](#211) - `2.0.x` Releases - [2.0.0](#200) @@ -16,6 +19,35 @@ All notable changes to this project will be documented in this file. --- +## [3.0.0](https://github.com/chrisdhaan/CDYelpFusionKit/releases/tag/3.0.0) +## Dependencies +Released on 2021-09-12. + +#### Added +- [x] Client + - [x] `validate` to API methods + +#### Updated + +- [x] Client + - [x] `responseObject` model transformation to `responseDecodable` +- [x] Models + - [x] Decodable, Encodable APIs + - [x] `class` to `struct` + - [x] `var` to `let` +- [x] Dependencies + - [x] Alamofire +- [x] Switch Package Manager + - [x] Configuration + +#### Removed +- [x] Dependencies + - [x] ObjectMapper +- [x] Travis CI + - [x] Configuration + +--- + ## [2.1.1](https://github.com/chrisdhaan/CDYelpFusionKit/releases/tag/2.1.1) ## Bug Fixes Released on 2021-05-30. @@ -25,7 +57,7 @@ Released on 2021-05-30. - [x] Models - [x] `URL` types to `String` - [x] `Date` types to `String` -- [x] Switch Package Manager +- [x] Swift Package Manager - [x] To build with `swift-tools-version:5.1` --- diff --git a/Cartfile b/Cartfile index 5141be2..b4ddc47 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1 @@ -github "Alamofire/Alamofire" == 5.2.2 -github "tristanhimmelman/ObjectMapper" == 4.2.0 \ No newline at end of file +github "Alamofire/Alamofire" == 5.4.3 \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index 0b03e5d..8bba57c 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1 @@ -github "Alamofire/Alamofire" "5.2.2" -github "tristanhimmelman/ObjectMapper" "4.2.0" +github "Alamofire/Alamofire" "5.4.3" diff --git a/Carthage/Checkouts/Alamofire b/Carthage/Checkouts/Alamofire index becd9a7..f96b619 160000 --- a/Carthage/Checkouts/Alamofire +++ b/Carthage/Checkouts/Alamofire @@ -1 +1 @@ -Subproject commit becd9a729a37bdbef5bc39dc3c702b99f9e3d046 +Subproject commit f96b619bcb2383b43d898402283924b80e2c4bae diff --git a/Carthage/Checkouts/ObjectMapper b/Carthage/Checkouts/ObjectMapper deleted file mode 160000 index 0b96a73..0000000 --- a/Carthage/Checkouts/ObjectMapper +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0b96a734de3ea1c87374ae677064f86adb0716ec diff --git a/Example/Source/ViewController.swift b/Example/Source/ViewController.swift index ca636a5..801ca81 100644 --- a/Example/Source/ViewController.swift +++ b/Example/Source/ViewController.swift @@ -221,12 +221,11 @@ extension ViewController: UITableViewDelegate { openNow: true, openAt: nil, attributes: nil) { (response) in - - if let response = response, - let businesses = response.businesses, - businesses.count > 0 { - print(businesses) - } + if let response = response, + let businesses = response.businesses, + businesses.count > 0 { + print(businesses) + } } case 1: CDYelpFusionKitManager.shared.apiClient.searchBusinesses(byPhoneNumber: "+14157492060") { (response) in @@ -242,20 +241,18 @@ extension ViewController: UITableViewDelegate { location: "San Francisco", latitude: nil, longitude: nil) { (response) in - - if let response = response, - let businesses = response.businesses, - businesses.count > 0 { - print(businesses) - } + if let response = response, + let businesses = response.businesses, + businesses.count > 0 { + print(businesses) + } } case 3: CDYelpFusionKitManager.shared.apiClient.fetchBusiness(forId: "north-india-restaurant-san-francisco", locale: nil) { (business) in - - if let business = business { - print(business) - } + if let business = business { + print(business) + } } case 4: CDYelpFusionKitManager.shared.apiClient.searchBusinesses(name: "Gary Danko", @@ -272,42 +269,47 @@ extension ViewController: UITableViewDelegate { yelpBusinessId: nil, limit: 5, matchThresholdType: .normal) { (response) in - - if let response = response, - let businesses = response.businesses, - businesses.count > 0 { - print(businesses) - } + if let response = response, + let businesses = response.businesses, + businesses.count > 0 { + print(businesses) + } } case 5: CDYelpFusionKitManager.shared.apiClient.fetchReviews(forBusinessId: "north-india-restaurant-san-francisco", locale: nil) { (response) in - - if let response = response, - let reviews = response.reviews, - reviews.count > 0 { - print(reviews) - } + if let response = response, + let reviews = response.reviews, + reviews.count > 0 { + print(reviews) + } } case 6: - CDYelpFusionKitManager.shared.apiClient.autocompleteBusinesses(byText: "Pizza Hut", + CDYelpFusionKitManager.shared.apiClient.autocompleteBusinesses(byText: "Pizza Delivery", latitude: 37.786572, longitude: -122.415192, locale: nil) { (response) in - - if let response = response, - let businesses = response.businesses, - businesses.count > 0 { - print(businesses) - } + if let response = response { + if let businesses = response.businesses, + businesses.count > 0 { + print(businesses) + } + if let categories = response.categories, + categories.count > 0 { + print(categories) + } + if let terms = response.terms, + terms.count > 0 { + print(terms) + } + } } case 7: - CDYelpFusionKitManager.shared.apiClient.fetchEvent(forId: "city-of-san-francisco-san-francisco", + CDYelpFusionKitManager.shared.apiClient.fetchEvent(forId: "san-francisco-yelp-celebrates-pride-month-2021", locale: nil) { (event) in - - if let event = event { - print(event) - } + if let event = event { + print(event) + } } case 8: CDYelpFusionKitManager.shared.apiClient.searchEvents(byLocale: nil, @@ -324,22 +326,20 @@ extension ViewController: UITableViewDelegate { longitude: -122.415192, radius: 10000, excludedEvents: nil) { (response) in - - if let response = response, - let events = response.events, - events.count > 0 { - print(events) - } + if let response = response, + let events = response.events, + events.count > 0 { + print(events) + } } case 9: CDYelpFusionKitManager.shared.apiClient.fetchFeaturedEvent(forLocale: nil, location: nil, latitude: 37.786572, longitude: -122.415192) { (event) in - - if let event = event { - print(event) - } + if let event = event { + print(event) + } } case 10: CDYelpFusionKitManager.shared.apiClient.fetchCategories(forLocale: nil) { (response) in @@ -352,11 +352,10 @@ extension ViewController: UITableViewDelegate { case 11: CDYelpFusionKitManager.shared.apiClient.fetchCategory(forAlias: .fastFood, andLocale: nil) { (response) in - - if let response = response, - let category = response.category { - print(category) - } + if let response = response, + let category = response.category { + print(category) + } } default: break diff --git a/Package.swift b/Package.swift index 8106a8a..9669c74 100644 --- a/Package.swift +++ b/Package.swift @@ -42,12 +42,18 @@ let package = Package( targets: ["CDYelpFusionKit"]) ], dependencies: [ - .package(url: "https://github.com/Alamofire/Alamofire.git", "5.2.2") - .package(url: "https://github.com/tristanhimmelman/ObjectMapper", "4.2.0") + .package( + url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.4.3")) ], targets: [ .target( + dependencies: [ + .product(name: "Alamofire", package: "Alamofire") + ], + linkerSettings: [ + .linkedFramework("UIKit", .when(platforms: [.iOS, .tvOS])) + ], name: "CDYelpFusionKit", - path: "CDYelpFusionKit") + path: "Source") ], swiftLanguageVersions: [.v5]) diff --git a/README.md b/README.md index ea4c40c..5fc031d 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,6 @@ For a demonstration of the capabilities of CDYelpFusionKit; run the iOS Example ## Dependencies - [Alamofire](https://github.com/Alamofire/Alamofire) -- [ObjectMapper](https://github.com/Hearst-DD/ObjectMapper) --- @@ -118,7 +117,7 @@ For a demonstration of the capabilities of CDYelpFusionKit; run the iOS Example [CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate CDYelpFusionKit into your Xcode project using CocoaPods, specify it in your `Podfile`: ```ruby -pod 'CDYelpFusionKit', '2.1.1' +pod 'CDYelpFusionKit', '3.0.0' ``` ### Carthage @@ -126,7 +125,7 @@ pod 'CDYelpFusionKit', '2.1.1' [Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate CDYelpFusionKit into your Xcode project using Carthage, specify it in your `Cartfile`: ```ogdl -github "chrisdhaan/CDYelpFusionKit" == 2.1.1 +github "chrisdhaan/CDYelpFusionKit" == 3.0.0 ``` ### Swift Package Manager @@ -326,7 +325,7 @@ yelpAPIClient.searchBusinesses(byTerm: "Food", ```swift public func searchBusinesses(byPhoneNumber phoneNumber: String!, // Required - completion: @escaping (CDYelpSearchResponse?) -> Void) + completion: @escaping (CDYelpSearchResponse?) -> Void) ``` The following lines of code show an example query to the phone search endpoint. @@ -487,7 +486,7 @@ The autocomplete endpoint has a `locale` parameter which allows for query result The following lines of code show an example query to the autocomplete endpoint. ```swift -yelpAPIClient.autocompleteBusinesses(byText: "Pizza Hut", +yelpAPIClient.autocompleteBusinesses(byText: "Pizza Delivery", latitude: 37.786572, longitude: -122.415192, locale: nil) { (response) in @@ -513,7 +512,7 @@ The event lookup endpoint has a `locale` parameter which allows for query result The following lines of code show an example query to the event lookup endpoint. ```swift -yelpAPIClient.fetchEvent(forId: "city-of-san-francisco-san-francisco", +yelpAPIClient.fetchEvent(forId: "san-francisco-yelp-celebrates-pride-month-2021", locale: nil) { (event) in if let event = event { diff --git a/Source/Alamofire+ObjectMapper.swift b/Source/Alamofire+ObjectMapper.swift deleted file mode 100644 index bf0a5cf..0000000 --- a/Source/Alamofire+ObjectMapper.swift +++ /dev/null @@ -1,190 +0,0 @@ -// -// UIColor+CDYelpFusionKit.swift -// CDYelpFusionKit -// -// Created by Christopher de Haan on 8/30/20. -// -// Copyright © 2016-2021 Christopher de Haan -// -// 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 Foundation -import Alamofire -import ObjectMapper - -extension DataRequest { - - enum ErrorCode: Int { - case noData = 1 - case dataSerializationFailed = 2 - } - - /// Utility function for extracting JSON from response - internal static func processResponse(request: URLRequest?, response: HTTPURLResponse?, data: Data?, keyPath: String?) -> Any? { - - let jsonResponseSerializer = JSONResponseSerializer(options: .allowFragments) - if let result = try? jsonResponseSerializer.serialize(request: request, response: response, data: data, error: nil) { - - let JSON: Any? - if let keyPath = keyPath, keyPath.isEmpty == false { - JSON = (result as AnyObject?)?.value(forKeyPath: keyPath) - } else { - JSON = result - } - - return JSON - } - - return nil - } - - internal static func newError(_ code: ErrorCode, failureReason: String) -> NSError { - let errorDomain = "com.cdyelpfusionkit.error" - - let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason] - let returnError = NSError(domain: errorDomain, code: code.rawValue, userInfo: userInfo) - - return returnError - } - - /// Utility function for checking for errors in response - internal static func checkResponseForError(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) -> Error? { - if let error = error { - return error - } - guard data != nil else { - let failureReason = "Data could not be serialized. Input data was nil." - let error = newError(.noData, failureReason: failureReason) - return error - } - return nil - } - - /// BaseMappable Object Serializer - public static func objectMapperSerializer(_ keyPath: String?, mapToObject object: T? = nil, context: MapContext? = nil) -> MappableResponseSerializer { - - return MappableResponseSerializer(keyPath, mapToObject: object, context: context, serializeCallback: { request, response, data, error in - - let JSONObject = processResponse(request: request, response: response, data: data, keyPath: keyPath) - - if let object = object { - _ = Mapper(context: context, shouldIncludeNilValues: false).map(JSONObject: JSONObject, toObject: object) - return object - } else if let parsedObject = Mapper(context: context, shouldIncludeNilValues: false).map(JSONObject: JSONObject) { - return parsedObject - } - - let failureReason = "ObjectMapper failed to serialize response." - throw AFError.responseSerializationFailed(reason: .decodingFailed(error: newError(.dataSerializationFailed, failureReason: failureReason))) - }) - } - - /// ImmutableMappable Array Serializer - public static func objectMapperImmutableSerializer(_ keyPath: String?, context: MapContext? = nil) -> MappableResponseSerializer { - - return MappableResponseSerializer(keyPath, context: context, serializeCallback: { request, response, data, error in - - let JSONObject = processResponse(request: request, response: response, data: data, keyPath: keyPath) - - if let JSONObject = JSONObject, - let parsedObject = (try? Mapper(context: context, shouldIncludeNilValues: false).map(JSONObject: JSONObject) as T) { - return parsedObject - } else { - let failureReason = "ObjectMapper failed to serialize response." - throw AFError.responseSerializationFailed(reason: .decodingFailed(error: newError(.dataSerializationFailed, failureReason: failureReason))) - } - }) - } - /** - Adds a handler to be called once the request has finished. - - - parameter queue: The queue on which the completion handler is dispatched. - - parameter keyPath: The key path where object mapping should be performed - - parameter object: An object to perform the mapping on to - - parameter completionHandler: A closure to be executed once the request has finished and the data has been mapped by ObjectMapper. - - - returns: The request. - */ - @discardableResult - public func responseObject(queue: DispatchQueue = .main, keyPath: String? = nil, mapToObject object: T? = nil, context: MapContext? = nil, completionHandler: @escaping (AFDataResponse) -> Void) -> Self { - return response(queue: queue, responseSerializer: DataRequest.objectMapperSerializer(keyPath, mapToObject: object, context: context), completionHandler: completionHandler) - } - - @discardableResult - public func responseObject(queue: DispatchQueue = .main, keyPath: String? = nil, mapToObject object: T? = nil, context: MapContext? = nil, completionHandler: @escaping (AFDataResponse) -> Void) -> Self { - return response(queue: queue, responseSerializer: DataRequest.objectMapperImmutableSerializer(keyPath, context: context), completionHandler: completionHandler) - } -} - -public final class MappableResponseSerializer: ResponseSerializer { - /// The `JSONDecoder` instance used to decode responses. - public let decoder: DataDecoder = JSONDecoder() - /// HTTP response codes for which empty responses are allowed. - public let emptyResponseCodes: Set - /// HTTP request methods for which empty responses are allowed. - public let emptyRequestMethods: Set - - public let keyPath: String? - public let context: MapContext? - public let object: T? - - public let serializeCallback: (URLRequest?, HTTPURLResponse?, Data?, Error?) throws -> T - - /// Creates an instance using the values provided. - /// - /// - Parameters: - /// - keyPath: - /// - object: - /// - context: - /// - emptyResponseCodes: The HTTP response codes for which empty responses are allowed. Defaults to - /// `[204, 205]`. - /// - emptyRequestMethods: The HTTP request methods for which empty responses are allowed. Defaults to `[.head]`. - /// - serializeCallback: - public init(_ keyPath: String?, mapToObject object: T? = nil, context: MapContext? = nil, - emptyResponseCodes: Set = MappableResponseSerializer.defaultEmptyResponseCodes, - emptyRequestMethods: Set = MappableResponseSerializer.defaultEmptyRequestMethods, - serializeCallback: @escaping (URLRequest?, HTTPURLResponse?, Data?, Error?) throws -> T) { - - self.emptyResponseCodes = emptyResponseCodes - self.emptyRequestMethods = emptyRequestMethods - - self.keyPath = keyPath - self.context = context - self.object = object - self.serializeCallback = serializeCallback - } - - public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) throws -> T { - guard error == nil else { throw error! } - - guard let data = data, !data.isEmpty else { - guard emptyResponseAllowed(forRequest: request, response: response) else { - throw AFError.responseSerializationFailed(reason: .inputDataNilOrZeroLength) - } - - guard let emptyValue = Empty.value as? T else { - throw AFError.responseSerializationFailed(reason: .invalidEmptyResponse(type: "\(T.self)")) - } - - return emptyValue - } - return try self.serializeCallback(request, response, data, error) - } -} diff --git a/Source/CDImage+CDYelpFusionKit.swift b/Source/CDImage+CDYelpFusionKit.swift index 8e9bbc8..3b88eaf 100644 --- a/Source/CDImage+CDYelpFusionKit.swift +++ b/Source/CDImage+CDYelpFusionKit.swift @@ -25,6 +25,12 @@ // THE SOFTWARE. // +#if !os(OSX) + import UIKit +#else + import Foundation +#endif + public extension CDImage { private class func cdImage(named name: String!) -> CDImage? { diff --git a/Source/CDYelpAPIClient.swift b/Source/CDYelpAPIClient.swift index 6d73fe8..2641897 100644 --- a/Source/CDYelpAPIClient.swift +++ b/Source/CDYelpAPIClient.swift @@ -25,6 +25,12 @@ // THE SOFTWARE. // +#if !os(OSX) + import UIKit +#else + import Foundation +#endif + import Alamofire public class CDYelpAPIClient: NSObject { @@ -32,7 +38,7 @@ public class CDYelpAPIClient: NSObject { private let apiKey: String! private lazy var manager: Alamofire.Session = { if let apiKey = self.apiKey, - apiKey.count > 0 { + apiKey.count > 0 { // Get the default headers var headers = HTTPHeaders.default // Add the Authorization header @@ -73,7 +79,7 @@ public class CDYelpAPIClient: NSObject { /// public func isAuthenticated() -> Bool { if self.apiKey != nil, - self.apiKey.count > 0 { + self.apiKey.count > 0 { return true } return false @@ -121,7 +127,7 @@ public class CDYelpAPIClient: NSObject { attributes: [CDYelpAttributeFilter]?, completion: @escaping (CDYelpSearchResponse?) -> Void) { assert((latitude != nil && longitude != nil) || - (location != nil), "Either a latitude and longitude or a location are required to query the Yelp Fusion API search endpoint.") + (location != nil), "Either a latitude and longitude or a location are required to query the Yelp Fusion API search endpoint.") if let radius = radius { assert((radius > 0 && radius <= 40000), "The radius must be 40,000 meters or less to query the Yelp Fusion API search endpoint.") } @@ -146,19 +152,22 @@ public class CDYelpAPIClient: NSObject { openAt: openAt, attributes: attributes) - self.manager.request(CDYelpRouter.search(parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let searchResponse): - if let error = searchResponse.error { - print("searchBusinesses(byTerm) error: ", error.description ?? "") + self.manager + .request(CDYelpRouter.search(parameters: parameters)) + .validate() + .responseDecodable { (response: DataResponse) in + + switch response.result { + case .success(let searchResponse): + if let error = searchResponse.error { + print("searchBusinesses(byTerm) error: ", error.description ?? "") + } + completion(searchResponse) + case .failure(let error): + print("searchBusinesses(byTerm) failure: ", error.localizedDescription) + completion(nil) } - completion(searchResponse) - case .failure(let error): - print("searchBusinesses(byTerm) failure: ", error.localizedDescription) - completion(nil) } - } } } @@ -179,19 +188,22 @@ public class CDYelpAPIClient: NSObject { let parameters = Parameters.phoneParameters(withPhoneNumber: phoneNumber) - self.manager.request(CDYelpRouter.phone(parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let searchResponse): - if let error = searchResponse.error { - print("searchBusinesses(byPhone) error: ", error.description ?? "") + self.manager + .request(CDYelpRouter.phone(parameters: parameters)) + .validate() + .responseDecodable { (response: DataResponse) in + + switch response.result { + case .success(let searchResponse): + if let error = searchResponse.error { + print("searchBusinesses(byPhone) error: ", error.description ?? "") + } + completion(searchResponse) + case .failure(let error): + print("searchBusinesses(byPhone) failure: ", error.localizedDescription) + completion(nil) } - completion(searchResponse) - case .failure(let error): - print("searchBusinesses(byPhone) failure: ", error.localizedDescription) - completion(nil) } - } } } @@ -214,7 +226,7 @@ public class CDYelpAPIClient: NSObject { completion: @escaping (CDYelpSearchResponse?) -> Void) { assert(type != nil, "A transaction type is required to query the Yelp Fusion API transactions endpoint.") assert((latitude != nil && longitude != nil) || - (location != nil), "Either a latitude and longitude or a location are required to query the Yelp Fusion API transactions endpoint.") + (location != nil), "Either a latitude and longitude or a location are required to query the Yelp Fusion API transactions endpoint.") if self.isAuthenticated() == true { @@ -222,20 +234,23 @@ public class CDYelpAPIClient: NSObject { latitude: latitude, longitude: longitude) - self.manager.request(CDYelpRouter.transactions(type: type.rawValue, - parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let searchResponse): - if let error = searchResponse.error { - print("searchTransactions(byType) error: ", error.description ?? "") + self.manager + .request(CDYelpRouter.transactions(type: type.rawValue, + parameters: parameters)) + .validate() + .responseDecodable { (response: DataResponse) in + + switch response.result { + case .success(let searchResponse): + if let error = searchResponse.error { + print("searchTransactions(byType) error: ", error.description ?? "") + } + completion(searchResponse) + case .failure(let error): + print("searchTransactions(byType) failure: ", error.localizedDescription) + completion(nil) } - completion(searchResponse) - case .failure(let error): - print("searchTransactions(byType) failure: ", error.localizedDescription) - completion(nil) } - } } } @@ -257,17 +272,20 @@ public class CDYelpAPIClient: NSObject { let parameters = Parameters.businessParameters(withLocale: locale) - self.manager.request(CDYelpRouter.business(id: id, - parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let business): - completion(business) - case .failure(let error): - print("fetchBusiness(byId) failure: ", error.localizedDescription) - completion(nil) + self.manager + .request(CDYelpRouter.business(id: id, + parameters: parameters)) + .validate() + .responseDecodable { (response: DataResponse) in + + switch response.result { + case .success(let business): + completion(business) + case .failure(let error): + print("fetchBusiness(byId) failure: ", error.localizedDescription) + completion(nil) + } } - } } } @@ -350,19 +368,22 @@ public class CDYelpAPIClient: NSObject { limit: limit, matchThresholdType: matchThresholdType) - self.manager.request(CDYelpRouter.matches(parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let searchResponse): - if let error = searchResponse.error { - print("searchBusinessMatches(byType) error: ", error.description ?? "") + self.manager + .request(CDYelpRouter.matches(parameters: parameters)) + .validate() + .responseDecodable { (response: DataResponse) in + + switch response.result { + case .success(let searchResponse): + if let error = searchResponse.error { + print("searchBusinessMatches(byType) error: ", error.description ?? "") + } + completion(searchResponse) + case .failure(let error): + print("searchBusinessMatches(byType) failure: ", error.localizedDescription) + completion(nil) } - completion(searchResponse) - case .failure(let error): - print("searchBusinessMatches(byType) failure: ", error.localizedDescription) - completion(nil) } - } } } @@ -384,21 +405,27 @@ public class CDYelpAPIClient: NSObject { if self.isAuthenticated() == true { let parameters = Parameters.reviewsParameters(withLocale: locale) + let decoder = JSONDecoder() + decoder.dateDecodingStrategy = .formatted(DateFormatter.reviews) + + self.manager + .request(CDYelpRouter.reviews(id: id, + parameters: parameters)) + .validate() + .responseDecodable(decoder: decoder, + completionHandler: { (response: DataResponse) in + switch response.result { + case .success(let reviewsResponse): + if let error = reviewsResponse.error { + print("fetchReviews(forBusinessId) error: ", error.description ?? "") + } + completion(reviewsResponse) + case .failure(let error): + print("fetchReviews(forBusinessId) failure: ", error.localizedDescription) + completion(nil) + } + }) - self.manager.request(CDYelpRouter.reviews(id: id, - parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let reviewsResponse): - if let error = reviewsResponse.error { - print("fetchReviews(forBusinessId) error: ", error.description ?? "") - } - completion(reviewsResponse) - case .failure(let error): - print("fetchReviews(forBusinessId) failure: ", error.localizedDescription) - completion(nil) - } - } } } @@ -420,8 +447,8 @@ public class CDYelpAPIClient: NSObject { locale: CDYelpLocale?, completion: @escaping (CDYelpAutoCompleteResponse?) -> Void) { assert((text != nil && text.count > 0) && - latitude != nil && - longitude != nil, "A search term, latitude, and longitude are required to query the Yelp Fusion API autocomplete endpoint.") + latitude != nil && + longitude != nil, "A search term, latitude, and longitude are required to query the Yelp Fusion API autocomplete endpoint.") if self.isAuthenticated() == true { @@ -430,19 +457,22 @@ public class CDYelpAPIClient: NSObject { longitude: longitude, locale: locale) - self.manager.request(CDYelpRouter.autocomplete(parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let autocompleteResponse): - if let error = autocompleteResponse.error { - print("autocompleteBusinesses(byText) error: ", error.description ?? "") + self.manager + .request(CDYelpRouter.autocomplete(parameters: parameters)) + .validate() + .responseDecodable { (response: DataResponse) in + + switch response.result { + case .success(let autocompleteResponse): + if let error = autocompleteResponse.error { + print("autocompleteBusinesses(byText) error: ", error.description ?? "") + } + completion(autocompleteResponse) + case .failure(let error): + print("autocompleteBusinesses(byText) failure: ", error.localizedDescription) + completion(nil) } - completion(autocompleteResponse) - case .failure(let error): - print("autocompleteBusinesses(byText) failure: ", error.localizedDescription) - completion(nil) } - } } } @@ -466,18 +496,23 @@ public class CDYelpAPIClient: NSObject { if self.isAuthenticated() == true { let parameters = Parameters.eventParameters(withLocale: locale) - - self.manager.request(CDYelpRouter.event(id: id, - parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let event): - completion(event) - case .failure(let error): - print("fetchEvent(forId) failure: ", error.localizedDescription) - completion(nil) - } - } + let decoder = JSONDecoder() + decoder.dateDecodingStrategy = .formatted(DateFormatter.events) + + self.manager + .request(CDYelpRouter.event(id: id, + parameters: parameters)) + .validate() + .responseDecodable(decoder: decoder, + completionHandler: { (response: DataResponse) in + switch response.result { + case .success(let event): + completion(event) + case .failure(let error): + print("fetchEvent(forId) failure: ", error.localizedDescription) + completion(nil) + } + }) } } @@ -540,20 +575,26 @@ public class CDYelpAPIClient: NSObject { longitude: longitude, radius: radius, excludedEvents: excludedEvents) + let decoder = JSONDecoder() + decoder.dateDecodingStrategy = .formatted(DateFormatter.events) + + self.manager + .request(CDYelpRouter.events(parameters: parameters)) + .validate() + .responseDecodable(decoder: decoder, + completionHandler: { (response: DataResponse) in + switch response.result { + case .success(let eventsResponse): + if let error = eventsResponse.error { + print("searchEvents(byLocale) error: ", error.description ?? "") + } + completion(eventsResponse) + case .failure(let error): + print("searchEvents(byLocale) failure: ", error.localizedDescription) + completion(nil) + } + }) - self.manager.request(CDYelpRouter.events(parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let eventsResponse): - if let error = eventsResponse.error { - print("searchEvents(byLocale) error: ", error.description ?? "") - } - completion(eventsResponse) - case .failure(let error): - print("searchEvents(byLocale) failure: ", error.localizedDescription) - completion(nil) - } - } } } @@ -575,7 +616,7 @@ public class CDYelpAPIClient: NSObject { longitude: Double?, completion: @escaping (CDYelpEvent?) -> Void) { assert((latitude != nil && longitude != nil) || - (location != nil), "Either a latitude and longitude or a location are required to query the Yelp Fusion API featured event endpoint.") + (location != nil), "Either a latitude and longitude or a location are required to query the Yelp Fusion API featured event endpoint.") if self.isAuthenticated() == true { @@ -583,17 +624,22 @@ public class CDYelpAPIClient: NSObject { location: location, latitude: latitude, longitude: longitude) - - self.manager.request(CDYelpRouter.featuredEvent(parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let event): - completion(event) - case .failure(let error): - print("fetchFeaturedEvent(forLocale) failure: ", error.localizedDescription) - completion(nil) - } - } + let decoder = JSONDecoder() + decoder.dateDecodingStrategy = .formatted(DateFormatter.events) + + self.manager + .request(CDYelpRouter.featuredEvent(parameters: parameters)) + .validate() + .responseDecodable(decoder: decoder, + completionHandler: { (response: DataResponse) in + switch response.result { + case .success(let event): + completion(event) + case .failure(let error): + print("fetchFeaturedEvent(forLocale) failure: ", error.localizedDescription) + completion(nil) + } + }) } } @@ -614,16 +660,19 @@ public class CDYelpAPIClient: NSObject { let parameters = Parameters.categoriesParameters(withLocale: locale) - self.manager.request(CDYelpRouter.allCategories(parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let event): - completion(event) - case .failure(let error): - print("fetchCategories(forLocale) alias: ", error.localizedDescription) - completion(nil) + self.manager + .request(CDYelpRouter.allCategories(parameters: parameters)) + .validate() + .responseDecodable { (response: DataResponse) in + + switch response.result { + case .success(let event): + completion(event) + case .failure(let error): + print("fetchCategories(forLocale) alias: ", error.localizedDescription) + completion(nil) + } } - } } } @@ -645,17 +694,20 @@ public class CDYelpAPIClient: NSObject { let parameters = Parameters.categoriesParameters(withLocale: locale) - self.manager.request(CDYelpRouter.categoryDetails(alias: alias.rawValue, - parameters: parameters)).responseObject { (response: DataResponse) in - - switch response.result { - case .success(let event): - completion(event) - case .failure(let error): - print("fetchCategory(forAlias) alias: ", error.localizedDescription) - completion(nil) + self.manager + .request(CDYelpRouter.categoryDetails(alias: alias.rawValue, + parameters: parameters)) + .validate() + .responseDecodable { (response: DataResponse) in + + switch response.result { + case .success(let event): + completion(event) + case .failure(let error): + print("fetchCategory(forAlias) alias: ", error.localizedDescription) + completion(nil) + } } - } } } diff --git a/Source/CDYelpAutoCompleteResponse.swift b/Source/CDYelpAutoCompleteResponse.swift index cec3725..3e9cff2 100644 --- a/Source/CDYelpAutoCompleteResponse.swift +++ b/Source/CDYelpAutoCompleteResponse.swift @@ -25,22 +25,17 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpAutoCompleteResponse: Decodable { -public class CDYelpAutoCompleteResponse: Mappable { + public let terms: [CDYelpTerm]? + public let businesses: [CDYelpBusiness]? + public let categories: [CDYelpCategory]? + public let error: CDYelpError? - public var terms: [CDYelpTerm]? - public var businesses: [CDYelpBusiness]? - public var categories: [CDYelpCategory]? - public var error: CDYelpError? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - terms <- map["terms"] - businesses <- map["businesses"] - categories <- map["categories"] - error <- map["error"] + enum CodingKeys: String, CodingKey { + case terms + case businesses + case categories + case error } } diff --git a/Source/CDYelpBusiness.swift b/Source/CDYelpBusiness.swift index 27a3f84..faec3a3 100644 --- a/Source/CDYelpBusiness.swift +++ b/Source/CDYelpBusiness.swift @@ -25,48 +25,49 @@ // THE SOFTWARE. // -import ObjectMapper +#if !os(OSX) + import UIKit +#else + import Foundation +#endif -public class CDYelpBusiness: Mappable { +public struct CDYelpBusiness: Decodable { - public var id: String? - public var name: String? - public var imageUrl: String? - public var isClosed: Bool? - public var url: String? - public var price: String? - public var phone: String? - public var displayPhone: String? - public var photos: [String]? - public var hours: [CDYelpHour]? - public var rating: Double? - public var reviewCount: Int? - public var categories: [CDYelpCategory]? - public var distance: Double? - public var coordinates: CDYelpCoordinates? - public var location: CDYelpLocation? - public var transactions: [String]? + public let id: String? + public let name: String? + public let imageUrl: URL? + public let isClosed: Bool? + public let url: URL? + public let price: String? + public let phone: String? + public let displayPhone: String? + public let photos: [String]? + public let hours: [CDYelpHour]? + public let rating: Double? + public let reviewCount: Int? + public let categories: [CDYelpCategory]? + public let distance: Double? + public let coordinates: CDYelpCoordinates? + public let location: CDYelpLocation? + public let transactions: [String]? - public required init?(map: Map) { - } - - public func mapping(map: Map) { - id <- map["id"] - name <- map["name"] - imageUrl <- map["image_url"] - isClosed <- map["is_closed"] - url <- map["url"] - price <- map["price"] - phone <- map["phone"] - displayPhone <- map["display_phone"] - photos <- map["photos"] - hours <- map["hours"] - rating <- map["rating"] - reviewCount <- map["review_count"] - categories <- map["categories"] - distance <- map["distance"] - coordinates <- map["coordinates"] - location <- map["location"] - transactions <- map["transactions"] + enum CodingKeys: String, CodingKey { + case id + case name + case imageUrl = "image_url" + case isClosed = "is_closed" + case url + case price + case phone + case displayPhone = "display_phone" + case photos + case hours + case rating + case reviewCount = "review_count" + case categories + case distance + case coordinates + case location + case transactions } } diff --git a/Source/CDYelpBusinessResponse.swift b/Source/CDYelpBusinessResponse.swift index c7a8f2c..d26f1cb 100644 --- a/Source/CDYelpBusinessResponse.swift +++ b/Source/CDYelpBusinessResponse.swift @@ -25,18 +25,13 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpBusinessResponse: Decodable { -public class CDYelpBusinessResponse: Mappable { + public let business: CDYelpBusiness? + public let error: CDYelpError? - public var business: CDYelpBusiness? - public var error: CDYelpError? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - business <- map[""] - error <- map["error"] + enum CodingKeys: String, CodingKey { + case business = "" + case error } } diff --git a/Source/CDYelpCategoriesResponse.swift b/Source/CDYelpCategoriesResponse.swift index 79caa9f..e2568a3 100644 --- a/Source/CDYelpCategoriesResponse.swift +++ b/Source/CDYelpCategoriesResponse.swift @@ -25,16 +25,11 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpCategoriesResponse: Decodable { -public class CDYelpCategoriesResponse: Mappable { + public let categories: [CDYelpCategory]? - public var categories: [CDYelpCategory]? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - categories <- map["categories"] + enum CodingKeys: String, CodingKey { + case categories } } diff --git a/Source/CDYelpCategory.swift b/Source/CDYelpCategory.swift index e8ca7ca..4f1e823 100644 --- a/Source/CDYelpCategory.swift +++ b/Source/CDYelpCategory.swift @@ -25,24 +25,19 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpCategory: Decodable { -public class CDYelpCategory: Mappable { + public let alias: String? + public let title: String? + public let parentAliases: [String]? + public let countryWhitelist: [String]? + public let countryBlacklist: [String]? - public var alias: String? - public var title: String? - public var parentAliases: [String]? - public var countryWhitelist: [String]? - public var countryBlacklist: [String]? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - alias <- map["alias"] - title <- map["title"] - parentAliases <- map["parent_aliases"] - countryWhitelist <- map["country_whitelist"] - countryBlacklist <- map["country_blacklist"] + enum CodingKeys: String, CodingKey { + case alias + case title + case parentAliases = "parent_aliases" + case countryWhitelist = "country_whitelist" + case countryBlacklist = "country_blacklist" } } diff --git a/Source/CDYelpCategoryResponse.swift b/Source/CDYelpCategoryResponse.swift index 5bd5f22..9283d68 100644 --- a/Source/CDYelpCategoryResponse.swift +++ b/Source/CDYelpCategoryResponse.swift @@ -25,16 +25,11 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpCategoryResponse: Decodable { -public class CDYelpCategoryResponse: Mappable { + public let category: CDYelpCategory? - public var category: CDYelpCategory? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - category <- map["category"] + enum CodingKeys: String, CodingKey { + case category } } diff --git a/Source/CDYelpCenter.swift b/Source/CDYelpCenter.swift index a88d7b1..ab43a0c 100644 --- a/Source/CDYelpCenter.swift +++ b/Source/CDYelpCenter.swift @@ -25,18 +25,13 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpCenter: Decodable { -public class CDYelpCenter: Mappable { + public let latitude: Double? + public let longitude: Double? - public var latitude: Double? - public var longitude: Double? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - latitude <- map["latitude"] - longitude <- map["longitude"] + enum CodingKeys: String, CodingKey { + case latitude + case longitude } } diff --git a/Source/CDYelpCoordinates.swift b/Source/CDYelpCoordinates.swift index b9e5da8..c88943a 100644 --- a/Source/CDYelpCoordinates.swift +++ b/Source/CDYelpCoordinates.swift @@ -25,18 +25,13 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpCoordinates: Decodable { -public class CDYelpCoordinates: Mappable { + public let latitude: Double? + public let longitude: Double? - public var latitude: Double? - public var longitude: Double? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - latitude <- map["latitude"] - longitude <- map["longitude"] + enum CodingKeys: String, CodingKey { + case latitude + case longitude } } diff --git a/Source/CDYelpError.swift b/Source/CDYelpError.swift index c5cc2ad..7686a62 100644 --- a/Source/CDYelpError.swift +++ b/Source/CDYelpError.swift @@ -25,20 +25,15 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpError: Decodable { -public class CDYelpError: Mappable { + public let description: String? + public let field: String? + public let code: String? - public var description: String? - public var field: String? - public var code: String? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - description <- map["description"] - field <- map["field"] - code <- map["code"] + enum CodingKeys: String, CodingKey { + case description + case field + case code } } diff --git a/Source/CDYelpEvent.swift b/Source/CDYelpEvent.swift index 43afeca..fce7c91 100644 --- a/Source/CDYelpEvent.swift +++ b/Source/CDYelpEvent.swift @@ -25,54 +25,55 @@ // THE SOFTWARE. // -import ObjectMapper +#if !os(OSX) + import UIKit +#else + import Foundation +#endif -public class CDYelpEvent: Mappable { +public struct CDYelpEvent: Decodable { - public var attendingCount: Int? - public var category: String? - public var cost: Int? - public var costMax: Int? - public var description: String? - public var eventSiteUrl: String? - public var id: String? - public var imageUrl: String? - public var interestedCount: Int? - public var isCanceled: Bool? - public var isFree: Bool? - public var isOfficial: Bool? - public var latitude: Double? - public var longitude: Double? - public var name: String? - public var ticketsUrl: String? - public var timeEnd: String? - public var timeStart: String? - public var location: CDYelpLocation? - public var businessId: String? + public let attendingCount: Int? + public let category: String? + public let cost: Int? + public let costMax: Double? + public let description: String? + public let eventSiteUrl: URL? + public let id: String? + public let imageUrl: URL? + public let interestedCount: Int? + public let isCanceled: Bool? + public let isFree: Bool? + public let isOfficial: Bool? + public let latitude: Double? + public let longitude: Double? + public let name: String? + public let ticketsUrl: String? + public let timeEnd: Date? + public let timeStart: Date? + public let location: CDYelpLocation? + public let businessId: String? - public required init?(map: Map) { - } - - public func mapping(map: Map) { - attendingCount <- map["attending_count"] - category <- map["category"] - cost <- map["cost"] - costMax <- map["cost_max"] - description <- map["description"] - eventSiteUrl <- map["event_site_url"] - id <- map["id"] - imageUrl <- map["image_url"] - interestedCount <- map["interested_count"] - isCanceled <- map["is_canceled"] - isFree <- map["is_free"] - isOfficial <- map["is_official"] - latitude <- map["latitude"] - longitude <- map["longitude"] - name <- map["name"] - ticketsUrl <- map["tickets_url"] - timeEnd <- map["time_end"] - timeStart <- map["time_start"] - location <- map["location"] - businessId <- map["business_id"] + enum CodingKeys: String, CodingKey { + case attendingCount = "attending_count" + case category + case cost + case costMax = "cost_max" + case description + case eventSiteUrl = "event_site_url" + case id + case imageUrl = "image_url" + case interestedCount = "interested_count" + case isCanceled = "is_canceled" + case isFree = "is_free" + case isOfficial = "is_official" + case latitude + case longitude + case name + case ticketsUrl = "tickets_url" + case timeEnd = "time_end" + case timeStart = "time_start" + case location + case businessId = "business_id" } } diff --git a/Source/CDYelpEventsResponse.swift b/Source/CDYelpEventsResponse.swift index 0ef38c1..07c13b7 100644 --- a/Source/CDYelpEventsResponse.swift +++ b/Source/CDYelpEventsResponse.swift @@ -25,20 +25,15 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpEventsResponse: Decodable { -public class CDYelpEventsResponse: Mappable { + public let total: Int? + public let events: [CDYelpEvent]? + public let error: CDYelpError? - public var total: Int? - public var events: [CDYelpEvent]? - public var error: CDYelpError? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - total <- map["total"] - events <- map["events"] - error <- map["error"] + enum CodingKeys: String, CodingKey { + case total + case events + case error } } diff --git a/Source/CDYelpHour.swift b/Source/CDYelpHour.swift index f190eb7..6fa9c11 100644 --- a/Source/CDYelpHour.swift +++ b/Source/CDYelpHour.swift @@ -25,20 +25,15 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpHour: Decodable { -public class CDYelpHour: Mappable { + public let hoursType: String? + public let open: [CDYelpOpen]? + public let isOpenNow: Bool? - public var hoursType: String? - public var open: [CDYelpOpen]? - public var isOpenNow: Bool? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - hoursType <- map["hours_type"] - open <- map["open"] - isOpenNow <- map["is_open_now"] + enum CodingKeys: String, CodingKey { + case hoursType = "hours_type" + case open + case isOpenNow = "is_open_now" } } diff --git a/Source/CDYelpLocation.swift b/Source/CDYelpLocation.swift index d0679b1..bedc052 100644 --- a/Source/CDYelpLocation.swift +++ b/Source/CDYelpLocation.swift @@ -25,32 +25,27 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpLocation: Decodable { -public class CDYelpLocation: Mappable { + public let addressOne: String? + public let addressTwo: String? + public let addressThree: String? + public let city: String? + public let state: String? + public let zipCode: String? + public let country: String? + public let displayAddress: [String]? + public let crossStreets: String? - public var addressOne: String? - public var addressTwo: String? - public var addressThree: String? - public var city: String? - public var state: String? - public var zipCode: String? - public var country: String? - public var displayAddress: [String]? - public var crossStreets: String? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - addressOne <- map["address1"] - addressTwo <- map["address2"] - addressThree <- map["address3"] - city <- map["city"] - state <- map["state"] - zipCode <- map["zip_code"] - country <- map["country"] - displayAddress <- map["display_address"] - crossStreets <- map["cross_streets"] + enum CodingKeys: String, CodingKey { + case addressOne = "address1" + case addressTwo = "address2" + case addressThree = "address3" + case city + case state + case zipCode = "zip_code" + case country + case displayAddress = "display_address" + case crossStreets = "cross_streets" } } diff --git a/Source/CDYelpOpen.swift b/Source/CDYelpOpen.swift index 2b6e949..679cee7 100644 --- a/Source/CDYelpOpen.swift +++ b/Source/CDYelpOpen.swift @@ -25,22 +25,17 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpOpen: Decodable { -public class CDYelpOpen: Mappable { + public let isOvernight: Bool? + public let end: String? + public let day: Int? + public let start: String? - public var isOvernight: Bool? - public var end: String? - public var day: Int? - public var start: String? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - isOvernight <- map["is_overnight"] - end <- map["end"] - day <- map["day"] - start <- map["start"] + enum CodingKeys: String, CodingKey { + case isOvernight = "is_overnight" + case end + case day + case start } } diff --git a/Source/CDYelpRegion.swift b/Source/CDYelpRegion.swift index 9f7c97e..c0ee086 100644 --- a/Source/CDYelpRegion.swift +++ b/Source/CDYelpRegion.swift @@ -25,16 +25,11 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpRegion: Decodable { -public class CDYelpRegion: Mappable { + public let center: CDYelpCenter? - public var center: CDYelpCenter? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - center <- map["center"] + enum CodingKeys: String, CodingKey { + case center } } diff --git a/Source/CDYelpReview.swift b/Source/CDYelpReview.swift index 5637eb9..ad1287b 100644 --- a/Source/CDYelpReview.swift +++ b/Source/CDYelpReview.swift @@ -25,26 +25,27 @@ // THE SOFTWARE. // -import ObjectMapper +#if !os(OSX) + import UIKit +#else + import Foundation +#endif -public class CDYelpReview: Mappable { +public struct CDYelpReview: Decodable { - public var id: String? - public var text: String? - public var url: String? - public var rating: Int? - public var timeCreated: String? - public var user: CDYelpUser? + public let id: String? + public let text: String? + public let url: URL? + public let rating: Int? + public let timeCreated: Date? + public let user: CDYelpUser? - public required init?(map: Map) { - } - - public func mapping(map: Map) { - id <- map["id"] - text <- map["text"] - url <- map["url"] - rating <- map["rating"] - timeCreated <- map["time_created"] - user <- map["user"] + enum CodingKeys: String, CodingKey { + case id + case text + case url + case rating + case timeCreated = "time_created" + case user } } diff --git a/Source/CDYelpReviewsResponse.swift b/Source/CDYelpReviewsResponse.swift index 96f08cc..2636471 100644 --- a/Source/CDYelpReviewsResponse.swift +++ b/Source/CDYelpReviewsResponse.swift @@ -25,22 +25,17 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpReviewsResponse: Decodable { -public class CDYelpReviewsResponse: Mappable { + public let total: Int? + public let possibleLanguages: [String]? + public let reviews: [CDYelpReview]? + public let error: CDYelpError? - public var total: Int? - public var possibleLanguages: [String]? - public var reviews: [CDYelpReview]? - public var error: CDYelpError? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - total <- map["total"] - possibleLanguages <- map["possible_languages"] - reviews <- map["reviews"] - error <- map["error"] + enum CodingKeys: String, CodingKey { + case total + case possibleLanguages = "possible_languages" + case reviews + case error } } diff --git a/Source/CDYelpRouter.swift b/Source/CDYelpRouter.swift index 964a6a2..d5dcf13 100644 --- a/Source/CDYelpRouter.swift +++ b/Source/CDYelpRouter.swift @@ -25,6 +25,12 @@ // THE SOFTWARE. // +#if !os(OSX) + import UIKit +#else + import Foundation +#endif + import Alamofire enum CDYelpRouter: URLRequestConvertible { diff --git a/Source/CDYelpSearchResponse.swift b/Source/CDYelpSearchResponse.swift index 95d39bd..f088cc8 100644 --- a/Source/CDYelpSearchResponse.swift +++ b/Source/CDYelpSearchResponse.swift @@ -25,22 +25,17 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpSearchResponse: Decodable { -public class CDYelpSearchResponse: Mappable { + public let total: Int? + public let businesses: [CDYelpBusiness]? + public let region: CDYelpRegion? + public let error: CDYelpError? - public var total: Int? - public var businesses: [CDYelpBusiness]? - public var region: CDYelpRegion? - public var error: CDYelpError? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - total <- map["total"] - businesses <- map["businesses"] - region <- map["region"] - error <- map["error"] + enum CodingKeys: String, CodingKey { + case total + case businesses + case region + case error } } diff --git a/Source/CDYelpTerm.swift b/Source/CDYelpTerm.swift index 13f0750..8a7e413 100644 --- a/Source/CDYelpTerm.swift +++ b/Source/CDYelpTerm.swift @@ -25,16 +25,11 @@ // THE SOFTWARE. // -import ObjectMapper +public struct CDYelpTerm: Decodable { -public class CDYelpTerm: Mappable { + public let text: String? - public var text: String? - - public required init?(map: Map) { - } - - public func mapping(map: Map) { - text <- map["text"] + enum CodingKeys: String, CodingKey { + case text } } diff --git a/Source/CDYelpUser.swift b/Source/CDYelpUser.swift index f41bf98..6a22c07 100644 --- a/Source/CDYelpUser.swift +++ b/Source/CDYelpUser.swift @@ -25,22 +25,23 @@ // THE SOFTWARE. // -import ObjectMapper +#if !os(OSX) + import UIKit +#else + import Foundation +#endif -public class CDYelpUser: Mappable { +public struct CDYelpUser: Decodable { - public var id: String? - public var profileUrl: String? - public var name: String? - public var imageUrl: String? + public let id: String? + public let profileUrl: URL? + public let name: String? + public let imageUrl: URL? - public required init?(map: Map) { - } - - public func mapping(map: Map) { - id <- map["id"] - profileUrl <- map["profile_url"] - name <- map["name"] - imageUrl <- map["image_url"] + enum CodingKeys: String, CodingKey { + case id + case profileUrl = "profile_url" + case name + case imageUrl = "image_url" } } diff --git a/Source/DateFormatter+CDYelpFusionKit.swift b/Source/DateFormatter+CDYelpFusionKit.swift new file mode 100644 index 0000000..b4586a5 --- /dev/null +++ b/Source/DateFormatter+CDYelpFusionKit.swift @@ -0,0 +1,46 @@ +// +// DateFormatter+CDYelpFusionKit.swift +// CDYelpFusionKit +// +// Created by Christopher de Haan on 6/1/21. +// +// Copyright © 2016-2021 Christopher de Haan +// +// 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 !os(OSX) + import UIKit +#else + import Foundation +#endif + +extension DateFormatter { + static let events: DateFormatter = { + let formatter = DateFormatter() + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" + return formatter + }() + + static let reviews: DateFormatter = { + let formatter = DateFormatter() + formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + return formatter + }() +} diff --git a/Source/Parameters+CDYelpFusionKit.swift b/Source/Parameters+CDYelpFusionKit.swift index 06bb692..13cf14a 100644 --- a/Source/Parameters+CDYelpFusionKit.swift +++ b/Source/Parameters+CDYelpFusionKit.swift @@ -25,6 +25,12 @@ // THE SOFTWARE. // +#if !os(OSX) + import UIKit +#else + import Foundation +#endif + import Alamofire extension Dictionary where Key: ExpressibleByStringLiteral, Value: Any { diff --git a/Source/URL+CDYelpFusionKit.swift b/Source/URL+CDYelpFusionKit.swift index 212ea27..25ed998 100644 --- a/Source/URL+CDYelpFusionKit.swift +++ b/Source/URL+CDYelpFusionKit.swift @@ -25,6 +25,12 @@ // THE SOFTWARE. // +#if !os(OSX) + import UIKit +#else + import Foundation +#endif + public extension URL { // MARK: - Private Methods