diff --git a/Bin/run-build.sh b/Bin/run-build.sh new file mode 100755 index 0000000..678172c --- /dev/null +++ b/Bin/run-build.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [ ! -d Source ]; then + cd .. +fi +cd Source +xctool build -project OCGoogleDirectionsAPI.xcodeproj -scheme OCGoogleDirectionsAPI -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO diff --git a/Bin/run-tests.sh b/Bin/run-tests.sh new file mode 100755 index 0000000..94cf089 --- /dev/null +++ b/Bin/run-tests.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [ ! -d Source ]; then + cd .. +fi +cd Source +xctool test -project OCGoogleDirectionsAPI.xcodeproj -scheme OCGoogleDirectionsAPITests -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a15ad2..50a614d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,21 @@ # OCGoogleDirectionsAPI CHANGELOG -## 0.1.0 +## 0.1.5 -Initial release. +- Added scripts to build and run tests (Bin/run-build.sh, Bin/run-tests.sh) +- Added fare and duration_in_traffic to response +- Added transit_mode, transit_routing_preference, traffic_model, arrival_time, +departure_time to request + +## 0.1.2 +- Fixed copy-paste error of kCGGoogleDirectionsResponseAttributeBounds. (thanks @djmadcat) ## 0.1.1 - Fixed init method to initialise locationString property properly. - Fixed missing summary parsing. (thanks @DmitryPR) +## 0.1.0 -## 0.1.2 - -- Fixed copy-paste error of kCGGoogleDirectionsResponseAttributeBounds. (thanks @djmadcat) \ No newline at end of file +Initial release. diff --git a/OCGoogleDirectionsAPI.podspec b/OCGoogleDirectionsAPI.podspec index 5f70a8f..0170091 100644 --- a/OCGoogleDirectionsAPI.podspec +++ b/OCGoogleDirectionsAPI.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "OCGoogleDirectionsAPI" - s.version = "0.1.4" + s.version = "0.1.5" s.summary = "A lightweight wrapper for The Google Directions API." s.homepage = "https://github.com/marciniwanicki/OCGoogleDirectionsAPI" s.license = 'MIT' s.author = { "Marcin Iwanicki" => "marcin.iwanicki@appliwings.com" } - s.source = { :git => "https://github.com/marciniwanicki/OCGoogleDirectionsAPI.git", :tag => "0.1.4" } + s.source = { :git => "https://github.com/marciniwanicki/OCGoogleDirectionsAPI.git", :tag => "0.1.5" } s.ios.deployment_target = '7.0' s.requires_arc = true diff --git a/README.md b/README.md index 71dc8eb..81f1f9e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ As Google wrote: "The Google Directions API is a service that calculates directions between locations using an HTTP request. You can search for directions for several modes of transportation, include transit, driving, walking or cycling. Directions may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates. The Directions API can return multi-part directions using a series of waypoints." -# 0.1.4 +# 0.1.5 The OCGoogleDirectionsAPI library allows your iOS apps to deal with this powerful service easily. IMPORTANT: It uses `NSURLSession` only available in iOS 7.0+. It is not compatible with iOS 6.x and lower. @@ -18,7 +18,7 @@ The OCGoogleDirectionsAPI library allows your iOS apps to deal with this powerfu #### Podfile ```ruby platform :ios, '7.0' -pod "OCGoogleDirectionsAPI", "~> 0.1.4" +pod "OCGoogleDirectionsAPI", "~> 0.1.5" ``` ## How to get started @@ -87,19 +87,11 @@ To create an isntance of `OCDirectionsRequest` you can use one of the following ```objc + (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationLocation:(CLLocation *)destination; -+ (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationLocation:(CLLocation *)destination sensor:(BOOL)sensor; - + (instancetype)requestWithOriginString:(NSString *)origin andDestinationLocation:(CLLocation *)destination; -+ (instancetype)requestWithOriginString:(NSString *)origin andDestinationLocation:(CLLocation *)destination sensor:(BOOL)sensor; - + (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationString:(NSString *)destination; -+ (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationString:(NSString *)destination sensor:(BOOL)sensor; - + (instancetype)requestWithOriginString:(NSString *)origin andDestinationString:(NSString *)destination; - -+ (instancetype)requestWithOriginString:(NSString *)origin andDestinationString:(NSString *)destination sensor:(BOOL)sensor; ``` ### Request attributes @@ -127,7 +119,7 @@ Here you can find the list of supported languages: [https://developers.google.co There are 3 different restrictions: * `OCDirectionsRequestRestrictionAvoidTolls` * `OCDirectionsRequestRestrictionAvoidHighways` -* `OCDirectionsRequestRestrictionAviodFerries` +* `OCDirectionsRequestRestrictionAvoidFerries` You can ask to avoid one or even all of them by calling the `setRestrictions:` method. @@ -174,6 +166,25 @@ CLLocation *secondLocation = [[CLLocation alloc] initWithLatitude:51.1314 longit [request setWaypointsOptimise:YES]; ``` +### Traffic model + +```objc +[request setTrafficModel:OCDirectionsRequestTrafficModelOptimistic]; +``` + +### Transit mode + +```objc +[request setTransitMode:OCDirectionsRequestTransitModeBus | OCDirectionsRequestTransitModeTrain]; +``` + +### Transit routing preference + +```objc +[request setTransitRoutingPreference:OCDirectionsRequestTransitRoutingPreferenceFewerTransfers]; +``` + + ## Response @@ -188,6 +199,7 @@ Classes: * [OCDirectionsDuration](#ocdirectionsduration) * [OCDirectionsStep](#ocdirectionsstep) * [OCDirectionsWaypoint](#ocdirectionswaypoint) +* [OCDirectionsFare](#ocdirectionsfare) ### OCDirectionsResponse @@ -199,6 +211,7 @@ Properties: * errorMessage `NSString*` * route `NSDirectionsRoute*` +Be aware that `geocoded_waypoints` property is not supported in the current version (#8). ### OCDirectionsResponseStatus @@ -233,6 +246,7 @@ Properties: * dictionary `NSDictionary*` * distance `OCDirectionsDistance*` * duration `OCDirectionsDuration*` +* durationInTraffic `OCDirectionsDuration*` * endAddress `NSString*` * endLocation `OCLocationCoordinate2D` * startAddress `NSString*` @@ -262,9 +276,9 @@ Properties: * dictionary `NSDictionary*` * text `NSString*` * value `NSNumber*` + - -### OCDirectionsDuration +### OCDirectionsDuration Properties: * dictionary `NSDictionary*` @@ -295,11 +309,20 @@ Properties: * stepInterpolation `NSNumber*` +### OCDirectionsFare + +Properties: +* dictionary `NSDictionary*` +* currency `NSString*` +* text `NSString*` +* value `NSNumber*` + + ## Contact -Did you find a bug? Do you have great ideas how to make the library better? or you just want to say hello:) ... please do not hesitate to contact me via mail marcin.iwanicki[at]live.com or twitter @marciniwanicki. +Did you find a bug? Do you have great ideas how to make the library better? or you just want to say hello:) ... drop me a line on twitter @marciniwanicki. -## To Do +## TODO * Add samples. * Write unit tests. diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 2a2fb5f..0000000 --- a/Rakefile +++ /dev/null @@ -1,148 +0,0 @@ -desc "Runs the specs [EMPTY]" -task :spec do - # Provide your own implementation -end - -task :version do - git_remotes = `git remote`.strip.split("\n") - - if git_remotes.count > 0 - puts "-- fetching version number from github" - sh 'git fetch' - - remote_version = remote_spec_version - end - - if remote_version.nil? - puts "There is no current released version. You're about to release a new Pod." - version = "0.0.1" - else - puts "The current released version of your pod is " + remote_spec_version.to_s() - version = suggested_version_number - end - - puts "Enter the version you want to release (" + version + ") " - new_version_number = $stdin.gets.strip - if new_version_number == "" - new_version_number = version - end - - replace_version_number(new_version_number) -end - -desc "Release a new version of the Pod" -task :release do - - puts "* Running version" - sh "rake version" - - unless ENV['SKIP_CHECKS'] - if `git symbolic-ref HEAD 2>/dev/null`.strip.split('/').last != 'master' - $stderr.puts "[!] You need to be on the `master' branch in order to be able to do a release." - exit 1 - end - - if `git tag`.strip.split("\n").include?(spec_version) - $stderr.puts "[!] A tag for version `#{spec_version}' already exists. Change the version in the podspec" - exit 1 - end - - puts "You are about to release `#{spec_version}`, is that correct? [y/n]" - exit if $stdin.gets.strip.downcase != 'y' - end - - puts "* Running specs" - sh "rake spec" - - puts "* Linting the podspec" - sh "pod lib lint" - - # Then release - sh "git commit #{podspec_path} CHANGELOG.md -m 'Release #{spec_version}'" - sh "git tag -a #{spec_version} -m 'Release #{spec_version}'" - sh "git push origin master" - sh "git push origin --tags" - sh "pod push master #{podspec_path}" -end - -# @return [Pod::Version] The version as reported by the Podspec. -# -def spec_version - require 'cocoapods' - spec = Pod::Specification.from_file(podspec_path) - spec.version -end - -# @return [Pod::Version] The version as reported by the Podspec from remote. -# -def remote_spec_version - require 'cocoapods-core' - - if spec_file_exist_on_remote? - remote_spec = eval(`git show origin/master:#{podspec_path}`) - remote_spec.version - else - nil - end -end - -# @return [Bool] If the remote repository has a copy of the podpesc file or not. -# -def spec_file_exist_on_remote? - test_condition = `if git rev-parse --verify --quiet origin/master:#{podspec_path} >/dev/null; - then - echo 'true' - else - echo 'false' - fi` - - 'true' == test_condition.strip -end - -# @return [String] The relative path of the Podspec. -# -def podspec_path - podspecs = Dir.glob('*.podspec') - if podspecs.count == 1 - podspecs.first - else - raise "Could not select a podspec" - end -end - -# @return [String] The suggested version number based on the local and remote version numbers. -# -def suggested_version_number - if spec_version != remote_spec_version - spec_version.to_s() - else - next_version(spec_version).to_s() - end -end - -# @param [Pod::Version] version -# the version for which you need the next version -# -# @note It is computed by bumping the last component of the versino string by 1. -# -# @return [Pod::Version] The version that comes next after the version supplied. -# -def next_version(version) - version_components = version.to_s().split("."); - last = (version_components.last.to_i() + 1).to_s - version_components[-1] = last - Pod::Version.new(version_components.join(".")) -end - -# @param [String] new_version_number -# the new version number -# -# @note This methods replaces the version number in the podspec file with a new version number. -# -# @return void -# -def replace_version_number(new_version_number) - text = File.read(podspec_path) - text.gsub!(/(s.version( )*= ")#{spec_version}(")/, "\\1#{new_version_number}\\3") - File.open(podspec_path, "w") { |file| file.puts text } -end \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI.xcconfig b/Source/OCGoogleDirectionsAPI.xcconfig new file mode 100644 index 0000000..5183934 --- /dev/null +++ b/Source/OCGoogleDirectionsAPI.xcconfig @@ -0,0 +1,94 @@ +// XcodeWarnings by Jon Reid, http://qualitycoding.org/about/ +// Source: https://github.com/jonreid/XcodeWarnings + +// Apple LLVM 7.0 - Warning Policies +GCC_TREAT_WARNINGS_AS_ERRORS = YES + +// Apple LLVM 7.0 - Warnings - All languages +GCC_WARN_CHECK_SWITCH_STATEMENTS = YES +GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES +CLANG_WARN_DOCUMENTATION_COMMENTS = YES +CLANG_WARN_EMPTY_BODY = YES +GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_BOOL_CONVERSION = YES +CLANG_WARN_CONSTANT_CONVERSION = YES +GCC_WARN_64_TO_32_BIT_CONVERSION = YES +CLANG_WARN_ENUM_CONVERSION = YES +CLANG_WARN_INT_CONVERSION = YES +CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES +CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES +GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES +GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR +GCC_WARN_MISSING_PARENTHESES = YES +GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES +GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES +GCC_WARN_ABOUT_MISSING_NEWLINE = YES +CLANG_WARN_ASSIGN_ENUM = YES +GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES +GCC_WARN_SIGN_COMPARE = YES +CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES +GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES +GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES +GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES +GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE +GCC_WARN_UNKNOWN_PRAGMAS = YES +CLANG_WARN_UNREACHABLE_CODE = YES +GCC_WARN_UNUSED_FUNCTION = YES +GCC_WARN_UNUSED_LABEL = YES +//GCC_WARN_UNUSED_PARAMETER = YES +GCC_WARN_UNUSED_VALUE = YES +GCC_WARN_UNUSED_VARIABLE = YES + +// Apple LLVM 7.0 - Warnings - C++ +CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES +GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES +GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES +GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES +CLANG_WARN_CXX0X_EXTENSIONS = YES + +// Apple LLVM 7.0 - Warnings - Objective-C +CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES +GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES +//GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES +CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR + +// Apple LLVM 7.0 - Warnings - Objective-C and ARC +CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES + +// Static Analyzer - Analysis Policy +RUN_CLANG_STATIC_ANALYZER = YES +CLANG_STATIC_ANALYZER_MODE_ON_ANALYZE_ACTION = Deep +CLANG_STATIC_ANALYZER_MODE = Deep + +// Static Analyzer - Generic Issues +CLANG_ANALYZER_DEADCODE_DEADSTORES = YES +CLANG_ANALYZER_MEMORY_MANAGEMENT = YES +CLANG_ANALYZER_GCD = YES + +// Static Analyzer - Checks - Objective-C +CLANG_ANALYZER_OBJC_ATSYNC = YES +CLANG_ANALYZER_OBJC_NSCFERROR = YES +CLANG_ANALYZER_OBJC_INCOMP_METHOD_TYPES = YES +CLANG_ANALYZER_OBJC_COLLECTIONS = YES +CLANG_ANALYZER_OBJC_UNUSED_IVARS = YES +CLANG_ANALYZER_OBJC_SELF_INIT = YES +CLANG_ANALYZER_OBJC_RETAIN_COUNT = YES + +// Static Analyzer - Checks - Security +CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES +CLANG_ANALYZER_SECURITY_KEYCHAIN_API = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_UNCHECKEDRETURN = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_GETPW_GETS = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_MKSTEMP = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_VFORK = YES diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj index d92ca7e..6f8e4c8 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj @@ -9,20 +9,6 @@ /* Begin PBXBuildFile section */ 2793762A18E8C3890059C103 /* OCDirectionsRequestURLCreatorJSONTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2793762918E8C3890059C103 /* OCDirectionsRequestURLCreatorJSONTests.m */; }; 27A8A2E718CF8B9900C24A6A /* OCDirectionsRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A8A2E618CF8B9900C24A6A /* OCDirectionsRequestTests.m */; }; - 27A8A2E818CF8E8900C24A6A /* OCDirectionsRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E91718C65A580035B80F /* OCDirectionsRequest.m */; }; - 27A8A2E918CF8ED000C24A6A /* OCDirectionsCommonTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E91018C65A580035B80F /* OCDirectionsCommonTypes.m */; }; - 27A8A2EA18CF8EDA00C24A6A /* OCDirectionsAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E90918C65A580035B80F /* OCDirectionsAPIClient.m */; }; - 27A8A2EB18CF8EE000C24A6A /* OCDirectionsRequestURLCreatorJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E90D18C65A580035B80F /* OCDirectionsRequestURLCreatorJSON.m */; }; - 27A8A2ED18CF8EE900C24A6A /* OCDirectionsBounds.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E91E18C65A580035B80F /* OCDirectionsBounds.m */; }; - 27A8A2EE18CF8EEC00C24A6A /* OCDirectionsDistance.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92018C65A580035B80F /* OCDirectionsDistance.m */; }; - 27A8A2EF18CF8EEE00C24A6A /* OCDirectionsDuration.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92218C65A580035B80F /* OCDirectionsDuration.m */; }; - 27A8A2F018CF8EF100C24A6A /* OCDirectionsLeg.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92418C65A580035B80F /* OCDirectionsLeg.m */; }; - 27A8A2F118CF8EF400C24A6A /* OCDirectionsPolyline.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92618C65A580035B80F /* OCDirectionsPolyline.m */; }; - 27A8A2F218CF8EF700C24A6A /* OCDirectionsRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92818C65A580035B80F /* OCDirectionsRoute.m */; }; - 27A8A2F318CF8EFB00C24A6A /* OCDirectionsStep.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92A18C65A580035B80F /* OCDirectionsStep.m */; }; - 27A8A2F418CF8EFE00C24A6A /* OCDirectionsWaypoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92C18C65A580035B80F /* OCDirectionsWaypoint.m */; }; - 27A8A2F518CF8F0000C24A6A /* OCDirectionsResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92E18C65A580035B80F /* OCDirectionsResponse.m */; }; - 27A8A2F618CF8F0D00C24A6A /* CLLocation+CoortindateFromDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E93418C65A580035B80F /* CLLocation+CoortindateFromDictionary.m */; }; 27C6E8B618C6578B0035B80F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6E8B518C6578B0035B80F /* Foundation.framework */; }; 27C6E8C518C6578B0035B80F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6E8B518C6578B0035B80F /* Foundation.framework */; }; 27C6EB8418C65A590035B80F /* OCDirectionsAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E90918C65A580035B80F /* OCDirectionsAPIClient.m */; }; @@ -41,6 +27,8 @@ 27C6EBA018C65A590035B80F /* CLLocation+CoortindateFromDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E93418C65A580035B80F /* CLLocation+CoortindateFromDictionary.m */; }; 27C6ECC118C65FDC0035B80F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 27C6E8CE18C6578B0035B80F /* InfoPlist.strings */; }; 27C6ECCD18C67ACC0035B80F /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6E8C318C6578B0035B80F /* XCTest.framework */; }; + 516C94BB1C9F2E8F0095322F /* libOCGoogleDirectionsAPI.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6ECCB18C67A910035B80F /* libOCGoogleDirectionsAPI.a */; }; + 524E8C2300316B8EBFB04BDB /* OCDirectionsFare.m in Sources */ = {isa = PBXBuildFile; fileRef = 524E8125ADC56AD2FA29F498 /* OCDirectionsFare.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -116,6 +104,12 @@ 27C6ECC318C6608E0035B80F /* OCGoogleDirectionsAPI-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OCGoogleDirectionsAPI-Info.plist"; sourceTree = ""; }; 27C6ECCB18C67A910035B80F /* libOCGoogleDirectionsAPI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOCGoogleDirectionsAPI.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27C6ECCC18C67A910035B80F /* OCGoogleDirectionsAPITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OCGoogleDirectionsAPITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 516C94BC1C9F31550095322F /* OCGoogleDirectionsAPI.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = OCGoogleDirectionsAPI.xcconfig; sourceTree = ""; }; + 524E8125ADC56AD2FA29F498 /* OCDirectionsFare.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCDirectionsFare.m; sourceTree = ""; }; + 524E82C69FF2B59CF5097950 /* OCDirectionsRequestTrafficModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTrafficModel.h; sourceTree = ""; }; + 524E8A60179A39E791889072 /* OCDirectionsRequestTransitRoutingPreference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitRoutingPreference.h; sourceTree = ""; }; + 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitMode.h; sourceTree = ""; }; + 524E8EF40C63F7BA5F9C6A91 /* OCDirectionsFare.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsFare.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -131,6 +125,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 516C94BB1C9F2E8F0095322F /* libOCGoogleDirectionsAPI.a in Frameworks */, 27C6ECCD18C67ACC0035B80F /* XCTest.framework in Frameworks */, 27C6E8C518C6578B0035B80F /* Foundation.framework in Frameworks */, ); @@ -188,6 +183,7 @@ 27C6E87B18C654650035B80F = { isa = PBXGroup; children = ( + 516C94BC1C9F31550095322F /* OCGoogleDirectionsAPI.xcconfig */, 27C6E8B718C6578B0035B80F /* OCGoogleDirectionsAPI */, 27C6E8CB18C6578B0035B80F /* OCGoogleDirectionsAPITests */, 27C6E8B418C6578B0035B80F /* Frameworks */, @@ -292,6 +288,9 @@ 27C6E91218C65A580035B80F /* OCDirectionsRequestTravelMode.h */, 27C6E91318C65A580035B80F /* OCDirectionsRequestUnit.h */, 27C6E91418C65A580035B80F /* OCDirectionsResponseVehicleType.h */, + 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */, + 524E82C69FF2B59CF5097950 /* OCDirectionsRequestTrafficModel.h */, + 524E8A60179A39E791889072 /* OCDirectionsRequestTransitRoutingPreference.h */, ); path = Common; sourceTree = ""; @@ -334,6 +333,8 @@ 27C6E92A18C65A580035B80F /* OCDirectionsStep.m */, 27C6E92B18C65A580035B80F /* OCDirectionsWaypoint.h */, 27C6E92C18C65A580035B80F /* OCDirectionsWaypoint.m */, + 524E8125ADC56AD2FA29F498 /* OCDirectionsFare.m */, + 524E8EF40C63F7BA5F9C6A91 /* OCDirectionsFare.h */, ); path = Attributes; sourceTree = ""; @@ -408,7 +409,7 @@ 27C6E87C18C654650035B80F /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0510; + LastUpgradeCheck = 0720; TargetAttributes = { 27C6E8C118C6578B0035B80F = { TestTargetID = 27C6E8DD18C658B70035B80F; @@ -463,6 +464,7 @@ 27C6EB9818C65A590035B80F /* OCDirectionsRoute.m in Sources */, 27C6EB8E18C65A590035B80F /* OCDirectionsBounds.m in Sources */, 27C6EB9A18C65A590035B80F /* OCDirectionsStep.m in Sources */, + 524E8C2300316B8EBFB04BDB /* OCDirectionsFare.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -470,22 +472,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 27A8A2EB18CF8EE000C24A6A /* OCDirectionsRequestURLCreatorJSON.m in Sources */, 27A8A2E718CF8B9900C24A6A /* OCDirectionsRequestTests.m in Sources */, - 27A8A2EE18CF8EEC00C24A6A /* OCDirectionsDistance.m in Sources */, - 27A8A2EF18CF8EEE00C24A6A /* OCDirectionsDuration.m in Sources */, - 27A8A2F518CF8F0000C24A6A /* OCDirectionsResponse.m in Sources */, - 27A8A2ED18CF8EE900C24A6A /* OCDirectionsBounds.m in Sources */, - 27A8A2F318CF8EFB00C24A6A /* OCDirectionsStep.m in Sources */, - 27A8A2EA18CF8EDA00C24A6A /* OCDirectionsAPIClient.m in Sources */, - 27A8A2F118CF8EF400C24A6A /* OCDirectionsPolyline.m in Sources */, - 27A8A2F618CF8F0D00C24A6A /* CLLocation+CoortindateFromDictionary.m in Sources */, - 27A8A2E918CF8ED000C24A6A /* OCDirectionsCommonTypes.m in Sources */, - 27A8A2F418CF8EFE00C24A6A /* OCDirectionsWaypoint.m in Sources */, - 27A8A2F018CF8EF100C24A6A /* OCDirectionsLeg.m in Sources */, - 27A8A2E818CF8E8900C24A6A /* OCDirectionsRequest.m in Sources */, 2793762A18E8C3890059C103 /* OCDirectionsRequestURLCreatorJSONTests.m in Sources */, - 27A8A2F218CF8EF700C24A6A /* OCDirectionsRoute.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -513,7 +501,9 @@ /* Begin XCBuildConfiguration section */ 27C6E88018C654650035B80F /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 516C94BC1C9F31550095322F /* OCGoogleDirectionsAPI.xcconfig */; buildSettings = { + ENABLE_TESTABILITY = YES; INFOPLIST_FILE = "OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; @@ -523,6 +513,7 @@ }; 27C6E88118C654650035B80F /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 516C94BC1C9F31550095322F /* OCGoogleDirectionsAPI.xcconfig */; buildSettings = { INFOPLIST_FILE = "OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; @@ -567,6 +558,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = "com.github.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -603,6 +595,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = "com.github.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -627,11 +620,6 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - "$(DEVELOPER_FRAMEWORKS_DIR)", - ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -651,6 +639,7 @@ INFOPLIST_FILE = "OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "cx.idev.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; TEST_HOST = "$(BUNDLE_LOADER)"; @@ -677,11 +666,6 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - "$(DEVELOPER_FRAMEWORKS_DIR)", - ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch"; @@ -693,6 +677,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = "OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; + PRODUCT_BUNDLE_IDENTIFIER = "cx.idev.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; TEST_HOST = "$(BUNDLE_LOADER)"; diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPI.xcscheme b/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPI.xcscheme index 5355682..fa055a1 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPI.xcscheme +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPI.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + + + + + + + + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -23,24 +39,36 @@ + + + + + + requestURLCreator; +@property (nonatomic) id requestURLCreator; - (instancetype)init; diff --git a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m index 5ddc486..ba26e1e 100644 --- a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m +++ b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m @@ -19,76 +19,68 @@ @implementation OCDirectionsAPIClient static NSString *_defaultKey; -- (instancetype)init -{ - return [self initWithKey:_defaultKey]; +- (instancetype)init { + return [self initWithKey:_defaultKey]; } -- (instancetype)initWithNoKey -{ - return [self initWithKey:nil]; +- (instancetype)initWithNoKey { + return [self initWithKey:nil]; } -- (instancetype)initWithNoKeyUseHttps:(BOOL)useHttps -{ - return [self initWithKey:nil useHttps:useHttps]; +- (instancetype)initWithNoKeyUseHttps:(BOOL)useHttps { + return [self initWithKey:nil useHttps:useHttps]; } -- (instancetype)initWithKey:(NSString *)key -{ +- (instancetype)initWithKey:(NSString *)key { return [self initWithKey:key useHttps:YES]; } -- (instancetype)initWithKey:(NSString *)key useHttps:(BOOL)useHttps -{ +- (instancetype)initWithKey:(NSString *)key useHttps:(BOOL)useHttps { self = [super init]; if (self) { self.key = key; self.useHttps = useHttps; - self.requestURLCreator = [OCDirectionsRequestURLCreatorJSON new]; + self.requestURLCreator = [OCDirectionsRequestURLCreatorJSON new]; } return self; } -+ (void)provideAPIKey:(NSString *)key -{ ++ (void)provideAPIKey:(NSString *)key { _defaultKey = key; } -- (void)directions:(OCDirectionsRequest *)request response:(OCDirectionsRequestCallback)callback -{ +- (void)directions:(OCDirectionsRequest *)request response:(OCDirectionsRequestCallback)callback { NSURL *url = [self urlFromRequest:request]; - + NSURLSession *session = [NSURLSession sharedSession]; [[session dataTaskWithURL:url completionHandler:^(NSData *data, - NSURLResponse *response, - NSError *error) { - + NSURLResponse *response, + NSError *error) { + if (error) { callback(nil, error); return; } - + NSError *jsonParsingError = nil; - NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonParsingError]; - + NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonParsingError]; + if (jsonParsingError) { callback(nil, jsonParsingError); return; } - + OCDirectionsResponse *directionsResponse = [OCDirectionsResponse responseFromDictionary:dictionary]; callback(directionsResponse, nil); return; - + }] resume]; } -- (NSURL *)urlFromRequest:(OCDirectionsRequest *)request -{ - NSURL *url = [self.requestURLCreator urlFromRequest:request useHttps:self.useHttps andKey:self.key]; - return url; +- (NSURL *)urlFromRequest:(OCDirectionsRequest *)request { + NSURL *url = [self.requestURLCreator urlFromRequest:request useHttps:self.useHttps andKey:self.key]; + return url; } @end diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.h b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.h index 7b57262..cb8e96c 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.h +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.h @@ -9,6 +9,6 @@ #import #import "OCDirectionsRequestURLCreator.h" -@interface OCDirectionsRequestURLCreatorJSON : NSObject +@interface OCDirectionsRequestURLCreatorJSON : NSObject @end diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m index f43ac49..76dc2be 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m @@ -22,49 +22,60 @@ static NSString *const kOCGoogleDirectionsRequestAttributeRestrictions = @"&avoid="; static NSString *const kOCGoogleDirectionsRequestAttributeUnits = @"&units="; static NSString *const kOCGoogleDirectionsRequestAttributeRegion = @"®ion="; +static NSString *const kOCGoogleDirectionsRequestAttributeArrivalTime = @"&arrival_time="; +static NSString *const kOCGoogleDirectionsRequestAttributeDepartureTime = @"&departure_time="; static NSString *const kOCGoogleDirectionsRequestAttributeLanguage = @"&language="; static NSString *const kOCGoogleDirectionsRequestAttributeKey = @"&key="; static NSString *const kOCGoogleDirectionsRequestAttributeAlternatives = @"&alternatives="; +static NSString *const kOCGoogleDirectionsRequestAttributeTrafficModel = @"&traffic_model="; +static NSString *const kOCGoogleDirectionsRequestAttributeTransitMode = @"&transit_mode="; +static NSString *const kOCGoogleDirectionsRequestAttributeTransitRoutingPreference = @"&transit_routing_preference="; static NSString *const kOCGoogleDirectionsRequestAttributeSeparator = @"|"; +static NSString *const kOCGoogleDirectionsRequestAttributeValueDepartureTimeNow = @"now"; + @implementation OCDirectionsRequestURLCreatorJSON #pragma mark - Public methods -- (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key -{ - OCAssertParameterNotNil(request, @"Request is nil."); - + +- (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key { + OCAssertParameterNotNil(request, @"Request is nil."); + NSMutableString *string = [self baseStringWithHttps:useHttps]; - + [self appendOrigin:request toString:string]; [self appendDestination:request toString:string]; [self appendSensor:request toString:string]; [self appendTravelMode:request toString:string]; [self appendWaypoints:request toString:string]; [self appendRestrictions:request toString:string]; + [self appendLanguage:request toString:string]; + [self appendUnit:request toString:string]; [self appendRegion:request toString:string]; - [self appendLanguage:request toString:string]; + [self appendArrivalTime:request toString:string]; + [self appendDepartureTime:request toString:string]; [self appendAlternatives:request toString:string]; + [self appendTrafficModel:request toString:string]; + [self appendTransitMode:request toString:string]; + [self appendTransitRoutingPreference:request toString:string]; [self appendKey:key toString:string]; - - NSString *stringEncoded = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - return stringEncoded; + + return string; } -- (NSURL *)urlFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key -{ - OCAssertParameterNotNil(request, @"Request is nil."); +- (NSURL *)urlFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key { + OCAssertParameterNotNil(request, @"Request is nil."); OCAssertParameterNotNil(key, @"Key is nil."); - + NSString *requestString = [self stringFromRequest:request useHttps:useHttps andKey:key]; NSURL *url = [[NSURL alloc] initWithString:requestString]; return url; } #pragma mark - Private methods -- (NSMutableString *)baseStringWithHttps:(BOOL)useHttps -{ + +- (NSMutableString *)baseStringWithHttps:(BOOL)useHttps { NSMutableString *baseString = [NSMutableString new]; if (useHttps) { [baseString appendString:kOCGoogleDirectionsAPIHTTPS]; @@ -72,196 +83,264 @@ - (NSMutableString *)baseStringWithHttps:(BOOL)useHttps [baseString appendString:kOCGoogleDirectionsAPIHTTP]; } [baseString appendString:kOCGoogleDirectionsAPIJSON]; - + return baseString; } -#pragma mark - Appenders -- (void)appendOrigin:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +#pragma mark - + +- (void)appendOrigin:(OCDirectionsRequest *)request toString:(NSMutableString *)string { [string appendString:kOCGoogleDirectionsRequestAttributeOrigin]; - + if (request.originLocation) { NSString *originString = [self stringFormCLLocation:request.originLocation]; [string appendString:originString]; } else { - [string appendString:request.originString]; + [string appendString:[self encodeParameter:request.originString]]; } } -- (void)appendDestination:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendDestination:(OCDirectionsRequest *)request toString:(NSMutableString *)string { [string appendString:kOCGoogleDirectionsRequestAttributeDestination]; - + if (request.destinationLocation) { NSString *destinationString = [self stringFormCLLocation:request.destinationLocation]; [string appendString:destinationString]; } else { - [string appendString:request.destinationString]; + [string appendString:[self encodeParameter:request.destinationString]]; } } -- (void)appendSensor:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ - /* - Checks if sensor flag is set. If no, just skip it as it is no longer required. - */ - if (!request.sensorFlagUsed) { - return; - } - +- (void)appendSensor:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + /* + Checks if sensor flag is set. If no, just skip it as it is no longer required. + */ + if (!request.sensorFlagUsed) { + return; + } + [string appendString:kOCGoogleDirectionsRequestAttributeSensor]; - + NSString *sensorString = [self stringFromBOOL:request.sensor]; [string appendString:sensorString]; } -- (void)appendTravelMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendTravelMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.travelMode == OCDirectionsRequestTravelModeDriving) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeTravelMode]; - + NSString *travelModeString = [OCDirectionsCommonTypes stringFormTravelMode:request.travelMode]; [string appendString:travelModeString]; } -- (void)appendWaypoints:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendWaypoints:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.waypoints == nil) { return; } - + if ([request.waypoints count] == 0) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeWaypoints]; - + if (request.waypointsOptimise) { [string appendString:kOCGoogleDirectionsRequestAttributeWaypointsOptimize]; [string appendString:kOCGoogleDirectionsRequestAttributeSeparator]; } - + NSUInteger count = [request.waypoints count]; NSUInteger iter = 0; for (id waypoint in request.waypoints) { if ([waypoint isKindOfClass:[NSString class]]) { - NSString *waypointString = (NSString *)waypoint; - [string appendString:waypointString]; + NSString *waypointString = (NSString *) waypoint; + [string appendString:[self encodeParameter:waypointString]]; } else if ([waypoint isKindOfClass:[CLLocation class]]) { - CLLocation *waypointLocation = (CLLocation *)waypoint; + CLLocation *waypointLocation = (CLLocation *) waypoint; NSString *waypointString = [self stringFormCLLocation:waypointLocation]; - [string appendString:waypointString]; + [string appendString:[self encodeParameter:waypointString]]; } - + if (++iter < count) { [string appendString:kOCGoogleDirectionsRequestAttributeSeparator]; } } } -- (void)appendRestrictions:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendRestrictions:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.restrictions == nil) { return; } - + if ([request.restrictions count] == 0) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeRestrictions]; - + NSUInteger count = [request.waypoints count]; NSUInteger iter = 0; for (NSString *restriction in request.restrictions) { - [string appendString:restriction]; - + [string appendString:[self encodeParameter:restriction]]; + if (++iter < count) { [string appendString:kOCGoogleDirectionsRequestAttributeSeparator]; } } } -- (void)appendUnit:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendUnit:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.unit == OCDirectionsRequestUnitDefault) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeUnits]; - + NSString *unitString = [self stringFormUnit:request.unit]; [string appendString:unitString]; } -- (void)appendRegion:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendRegion:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.region == nil) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeRegion]; - [string appendString:request.region]; + [string appendString:[self encodeParameter:request.region]]; +} + +- (void)appendArrivalTime:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.arrivalTime == nil) { + return; + } + + NSString *arrivalTimeValue = @(request.arrivalTime.timeIntervalSince1970).stringValue; + + [string appendString:kOCGoogleDirectionsRequestAttributeArrivalTime]; + [string appendString:arrivalTimeValue]; +} + +- (void)appendDepartureTime:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.departureTime == nil) { + return; + } + + NSString *departureTimeString = [request.departureTime isEqualToDate:kOCDirectionsRequestDepartureTimeNow] + ? kOCGoogleDirectionsRequestAttributeValueDepartureTimeNow + : @(request.departureTime.timeIntervalSince1970).stringValue; + + [string appendString:kOCGoogleDirectionsRequestAttributeDepartureTime]; + [string appendString:departureTimeString]; } -- (void)appendLanguage:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ - if (request.language == nil) { - return; - } - - [string appendString:kOCGoogleDirectionsRequestAttributeLanguage]; - [string appendString:request.language]; +- (void)appendLanguage:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.language == nil) { + return; + } + + [string appendString:kOCGoogleDirectionsRequestAttributeLanguage]; + [string appendString:[self encodeParameter:request.language]]; } -- (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ - if (request.alternatives == NO) { +- (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (!request.alternatives) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeAlternatives]; - + NSString *alternativesString = [self stringFromBOOL:request.alternatives]; [string appendString:alternativesString]; } -- (void)appendKey:(NSString *)key toString:(NSMutableString *)string -{ - /** - API key is not requred. - */ - if (key) { - [string appendString:kOCGoogleDirectionsRequestAttributeKey]; - [string appendString:key]; - } +- (void)appendTrafficModel:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.trafficModel == OCDirectionsRequestTrafficModelDefault) { + return; + } + + NSString *trafficModelString = [OCDirectionsCommonTypes stringFromTrafficModel:request.trafficModel]; + + [string appendString:kOCGoogleDirectionsRequestAttributeTrafficModel]; + [string appendString:trafficModelString]; +} + +- (void)appendTransitMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.transitMode == OCDirectionsRequestTransitModeDefault) { + return; + } + + NSMutableString *transitModeString = [NSMutableString string]; + for (NSUInteger transitMode = OCDirectionsRequestTransitModeBus; + transitMode < (OCDirectionsRequestTransitModeRail << 1); + transitMode <<= 1) { + + if ((request.transitMode & transitMode) == 0) { + continue; + } + + if (transitModeString.length > 0) { + [transitModeString appendString:kOCGoogleDirectionsRequestAttributeSeparator]; + } + + [transitModeString appendString:[OCDirectionsCommonTypes stringFromTransitModel:transitMode]]; + } + + [string appendString:kOCGoogleDirectionsRequestAttributeTransitMode]; + [string appendString:transitModeString]; +} + +- (void)appendTransitRoutingPreference:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.transitRoutingPreference == OCDirectionsRequestTransitRoutingPreferenceDefault) { + return; + } + + NSString *transitRoutingPreferenceString = [OCDirectionsCommonTypes stringFromTransitRoutingPreference:request.transitRoutingPreference]; + [string appendString:kOCGoogleDirectionsRequestAttributeTransitRoutingPreference]; + [string appendString:transitRoutingPreferenceString]; +} + +- (void)appendKey:(NSString *)key toString:(NSMutableString *)string { + /** + API key is not required. + */ + if (key) { + [string appendString:kOCGoogleDirectionsRequestAttributeKey]; + [string appendString:[self encodeParameter:key]]; + } } #pragma mark - Helpers -- (NSString *)stringFormCLLocation:(CLLocation *)location -{ + +- (NSString *)stringFormCLLocation:(CLLocation *)location { NSString *string = [NSString stringWithFormat:@"%f,%f", location.coordinate.latitude, location.coordinate.longitude]; return string; } -- (NSString *)stringFromBOOL:(BOOL)boolValue -{ +- (NSString *)stringFromBOOL:(BOOL)boolValue { NSString *string = boolValue ? @"true" : @"false"; return string; } -- (NSString *)stringFormUnit:(OCDirectionsRequestUnit)unit -{ +- (NSString *)stringFormUnit:(OCDirectionsRequestUnit)unit { switch (unit) { - case OCDirectionsRequestUnitDefault: return @""; // should never happen - case OCDirectionsRequestUnitImperial: return @"imperial"; - case OCDirectionsRequestUnitMetric: return @"metric"; + case OCDirectionsRequestUnitDefault: + return @""; // should never happen + case OCDirectionsRequestUnitImperial: + return @"imperial"; + case OCDirectionsRequestUnitMetric: + return @"metric"; } + return @""; +} + +- (NSString *)encodeParameter:(NSString *)parameter { + NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet]; + NSString *encodedParameter = [parameter stringByAddingPercentEncodingWithAllowedCharacters:set]; + return encodedParameter; } @end diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h index 425f2b0..431ac03 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h @@ -12,6 +12,9 @@ #import "OCDirectionsRequestRestriction.h" #import "OCDirectionsRequestUnit.h" #import "OCDirectionsResponseVehicleType.h" +#import "OCDirectionsRequestTransitMode.h" +#import "OCDirectionsRequestTrafficModel.h" +#import "OCDirectionsRequestTransitRoutingPreference.h" @interface OCDirectionsCommonTypes : NSObject @@ -33,5 +36,28 @@ + (NSDictionary *)vehicleTypesDictionary; +@end + +@interface OCDirectionsCommonTypes (TransitMode) + ++ (NSString *)stringFromTransitModel:(OCDirectionsRequestTransitMode)transitMode; + ++ (NSDictionary *)transitModeDictionary; + +@end + +@interface OCDirectionsCommonTypes (TrafficModel) + ++ (NSString *)stringFromTrafficModel:(OCDirectionsRequestTrafficModel)trafficModel; + ++ (NSDictionary *)trafficModelDictionary; + +@end + +@interface OCDirectionsCommonTypes (TransitRoutingPreference) + ++ (NSString *)stringFromTransitRoutingPreference:(OCDirectionsRequestTransitRoutingPreference)transitRoutingPreference; + ++ (NSDictionary *)transitRoutingPreferenceDictionary; @end diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m index 4cfb332..5b4953f 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m @@ -15,32 +15,29 @@ @implementation OCDirectionsCommonTypes @implementation OCDirectionsCommonTypes (TravelMode) -+ (NSString *)stringFormTravelMode:(OCDirectionsRequestTravelMode)travelMode -{ - NSArray *keys = [[[self class] travelModeDictionary] allKeysForObject:@(travelMode)]; ++ (NSString *)stringFormTravelMode:(OCDirectionsRequestTravelMode)travelMode { + NSArray *keys = [[self travelModeDictionary] allKeysForObject:@(travelMode)]; return [keys firstObject]; } -+ (OCDirectionsRequestTravelMode)travelModeFromString:(NSString *)travelModeString -{ - NSNumber *number = [[[self class] travelModeDictionary] objectForKey:travelModeString]; - OCDirectionsRequestTravelMode travelMode = (OCDirectionsRequestTravelMode)number.unsignedIntegerValue; - ++ (OCDirectionsRequestTravelMode)travelModeFromString:(NSString *)travelModeString { + NSNumber *number = [self travelModeDictionary][travelModeString]; + OCDirectionsRequestTravelMode travelMode = (OCDirectionsRequestTravelMode) number.unsignedIntegerValue; return travelMode; } -+ (NSDictionary *)travelModeDictionary -{ ++ (NSDictionary *)travelModeDictionary { static NSDictionary *dictionary; - + if (dictionary == nil) { - dictionary = @{@"driving" : @(OCDirectionsRequestTravelModeDriving), - @"walking" : @(OCDirectionsRequestTravelModeWalking), - @"bicycling" : @(OCDirectionsRequestTravelModeBicycling), - @"transit" : @(OCDirectionsRequestTravelModeTransit) - }; + dictionary = @{ + @"driving" : @(OCDirectionsRequestTravelModeDriving), + @"walking" : @(OCDirectionsRequestTravelModeWalking), + @"bicycling" : @(OCDirectionsRequestTravelModeBicycling), + @"transit" : @(OCDirectionsRequestTravelModeTransit) + }; } - + return dictionary; } @@ -48,40 +45,99 @@ + (NSDictionary *)travelModeDictionary @implementation OCDirectionsCommonTypes (VehicalType) -+ (OCDirectionsResponseVehicleType)vehicleTypeFromString:(NSString *)vehicleTypeString -{ - NSNumber *number = [[[self class] vehicleTypesDictionary] objectForKey:vehicleTypeString]; - OCDirectionsResponseVehicleType vehicleType = (OCDirectionsResponseVehicleType)number.unsignedIntegerValue; - ++ (OCDirectionsResponseVehicleType)vehicleTypeFromString:(NSString *)vehicleTypeString { + NSNumber *number = [self vehicleTypesDictionary][vehicleTypeString]; + OCDirectionsResponseVehicleType vehicleType = (OCDirectionsResponseVehicleType) number.unsignedIntegerValue; return vehicleType; } -+ (NSDictionary *)vehicleTypesDictionary -{ ++ (NSDictionary *)vehicleTypesDictionary { static NSDictionary *dictionary; - + if (dictionary == nil) { - dictionary = @{@"RAIL" : @(OCDirectionsResponseVehicleTypeRail), - @"METRO_RAIL" : @(OCDirectionsResponseVehicleTypeMetroRail), - @"SUBWAY" : @(OCDirectionsResponseVehicleTypeSubway), - @"TRAM" : @(OCDirectionsResponseVehicleTypeTram), - @"MONORAIL" : @(OCDirectionsResponseVehicleTypeMonorail), - @"HEAVY_RAIL" : @(OCDirectionsResponseVehicleTypeHeavyRail), - @"COMMUTER_TRAIN" : @(OCDirectionsResponseVehicleTypeCommuterTrain), - @"HIGH_SPEED_TRAIN" : @(OCDirectionsResponseVehicleTypeHighSpeedTrain), - @"BUS" : @(OCDirectionsResponseVehicleTypeBus), - @"INTERCITY_BUS" : @(OCDirectionsResponseVehicleTypeIntercityBus), - @"TROLLEYBUS" : @(OCDirectionsResponseVehicleTypeTrolleybus), - @"SHARE_TAXI" : @(OCDirectionsResponseVehicleTypeShareTaxi), - @"FERRY" : @(OCDirectionsResponseVehicleTypeFerry), - @"CABLE_CAR" : @(OCDirectionsResponseVehicleTypeCableCar), - @"GONDOLA_LIFT" : @(OCDirectionsResponseVehicleTypeGondolaLift), - @"FUNICULAR" : @(OCDirectionsResponseVehicleTypeFunicular), - @"OTHER" : @(OCDirectionsResponseVehicleTypeOther) - }; + dictionary = @{ + @"RAIL" : @(OCDirectionsResponseVehicleTypeRail), + @"METRO_RAIL" : @(OCDirectionsResponseVehicleTypeMetroRail), + @"SUBWAY" : @(OCDirectionsResponseVehicleTypeSubway), + @"TRAM" : @(OCDirectionsResponseVehicleTypeTram), + @"MONORAIL" : @(OCDirectionsResponseVehicleTypeMonorail), + @"HEAVY_RAIL" : @(OCDirectionsResponseVehicleTypeHeavyRail), + @"COMMUTER_TRAIN" : @(OCDirectionsResponseVehicleTypeCommuterTrain), + @"HIGH_SPEED_TRAIN" : @(OCDirectionsResponseVehicleTypeHighSpeedTrain), + @"BUS" : @(OCDirectionsResponseVehicleTypeBus), + @"INTERCITY_BUS" : @(OCDirectionsResponseVehicleTypeIntercityBus), + @"TROLLEYBUS" : @(OCDirectionsResponseVehicleTypeTrolleybus), + @"SHARE_TAXI" : @(OCDirectionsResponseVehicleTypeShareTaxi), + @"FERRY" : @(OCDirectionsResponseVehicleTypeFerry), + @"CABLE_CAR" : @(OCDirectionsResponseVehicleTypeCableCar), + @"GONDOLA_LIFT" : @(OCDirectionsResponseVehicleTypeGondolaLift), + @"FUNICULAR" : @(OCDirectionsResponseVehicleTypeFunicular), + @"OTHER" : @(OCDirectionsResponseVehicleTypeOther) + }; } - + return dictionary; } @end + +@implementation OCDirectionsCommonTypes (TransitMode) + ++ (NSString *)stringFromTransitModel:(OCDirectionsRequestTransitMode)transitMode { + return [self transitModeDictionary][@(transitMode)]; +} + ++ (NSDictionary *)transitModeDictionary { + static NSDictionary *transitModeDictionary; + if (transitModeDictionary == nil) { + transitModeDictionary = @{ + @(OCDirectionsRequestTransitModeBus) : @"bus", + @(OCDirectionsRequestTransitModeSubway) : @"subway", + @(OCDirectionsRequestTransitModeTrain) : @"train", + @(OCDirectionsRequestTransitModeTram) : @"tram", + @(OCDirectionsRequestTransitModeRail) : @"rail" + }; + } + return transitModeDictionary; +} + +@end + +@implementation OCDirectionsCommonTypes (TrafficModel) + ++ (NSString *)stringFromTrafficModel:(OCDirectionsRequestTrafficModel)trafficModel { + return [self trafficModelDictionary][@(trafficModel)]; +} + ++ (NSDictionary *)trafficModelDictionary { + static NSDictionary *trafficModelDictionary; + if (trafficModelDictionary == nil) { + trafficModelDictionary = @{ + @(OCDirectionsRequestTrafficModelBestGuess) : @"best_guess", + @(OCDirectionsRequestTrafficModelPessimistic) : @"pessimistic", + @(OCDirectionsRequestTrafficModelOptimistic) : @"optimistic" + }; + } + return trafficModelDictionary; +} + +@end + +@implementation OCDirectionsCommonTypes (TransitRoutingPreference) + ++ (NSString *)stringFromTransitRoutingPreference:(OCDirectionsRequestTransitRoutingPreference)transitRoutingPreference { + return [self transitRoutingPreferenceDictionary][@(transitRoutingPreference)]; +} + ++ (NSDictionary *)transitRoutingPreferenceDictionary { + static NSDictionary *transitRoutingPreference; + if (transitRoutingPreference == nil) { + transitRoutingPreference = @{ + @(OCDirectionsRequestTransitRoutingPreferenceLessWalking) : @"less_walking", + @(OCDirectionsRequestTransitRoutingPreferenceFewerTransfers) : @"fewer_transfers", + }; + } + return transitRoutingPreference; +} + +@end diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h index c8aa2aa..2d94119 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h @@ -10,15 +10,15 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestRestriction) { /** avoid tools */ - OCDirectionsRequestRestrictionAvoidTolls, - + OCDirectionsRequestRestrictionAvoidTolls, + /** avoid highways */ - OCDirectionsRequestRestrictionAvoidHighways, - + OCDirectionsRequestRestrictionAvoidHighways, + /** avoid ferries */ - OCDirectionsRequestRestrictionAviodFerries + OCDirectionsRequestRestrictionAvoidFerries }; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h new file mode 100644 index 0000000..37b464e --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h @@ -0,0 +1,34 @@ +// +// OCDirectionsRequestTrafficModel.h +// OCGoogleDirectionsAPI +// +// Created by Marcin Iwanicki on 3/20/16. +// Copyright (c) 2014 Marcin Iwanicki. All rights reserved. +// + + +typedef NS_ENUM(NSUInteger, OCDirectionsRequestTrafficModel) { + /** + * not specified + */ + OCDirectionsRequestTrafficModelDefault, + + /** + * (default) indicates that the returned duration_in_traffic should be the best estimate of travel time given + * what is known about both historical traffic conditions and live traffic. + * Live traffic becomes more important the closer the departure_time is to now. + */ + OCDirectionsRequestTrafficModelBestGuess, + + /** + * indicates that the returned duration_in_traffic should be longer than the actual travel time on most days, + * though occasional days with particularly bad traffic conditions may exceed this value. + */ + OCDirectionsRequestTrafficModelPessimistic, + + /** + * indicates that the returned duration_in_traffic should be shorter than the actual travel time on most days, + * though occasional days with particularly good traffic conditions may be faster than this value. + */ + OCDirectionsRequestTrafficModelOptimistic +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h new file mode 100644 index 0000000..773f1dc --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h @@ -0,0 +1,40 @@ +// +// OCDirectionsRequestTravelMode.h +// OCGoogleDirectionsAPI +// +// Created by Marcin Iwanicki on 3/20/16. +// Copyright (c) 2014 Marcin Iwanicki. All rights reserved. +// + +typedef NS_OPTIONS(NSUInteger, OCDirectionsRequestTransitMode) { + /** + * not specified + */ + OCDirectionsRequestTransitModeDefault = 0, + + /** + * indicates that the calculated route should prefer travel by bus. + */ + OCDirectionsRequestTransitModeBus = 1 << 1, + + /** + * indicates that the calculated route should prefer travel by subway. + */ + OCDirectionsRequestTransitModeSubway = 1 << 2, + + /** + * indicates that the calculated route should prefer travel by train. + */ + OCDirectionsRequestTransitModeTrain = 1 << 3, + + /** + * indicates that the calculated route should prefer travel by tram and light rail. + */ + OCDirectionsRequestTransitModeTram = 1 << 4, + + /** + * indicates that the calculated route should prefer travel by train, tram, light rail, and subway. + * This is equivalent to train|tram|subway. + */ + OCDirectionsRequestTransitModeRail = 1 << 5 +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h new file mode 100644 index 0000000..fd48b42 --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h @@ -0,0 +1,25 @@ +// +// OCDirectionsRequestTrafficModel.h +// OCGoogleDirectionsAPI +// +// Created by Marcin Iwanicki on 3/20/16. +// Copyright (c) 2014 Marcin Iwanicki. All rights reserved. +// + + +typedef NS_ENUM(NSUInteger, OCDirectionsRequestTransitRoutingPreference) { + /** + * not specified + */ + OCDirectionsRequestTransitRoutingPreferenceDefault, + + /** + * indicates that the calculated route should prefer limited amounts of walking. + */ + OCDirectionsRequestTransitRoutingPreferenceLessWalking, + + /** + * indicates that the calculated route should prefer a limited number of transfers. + */ + OCDirectionsRequestTransitRoutingPreferenceFewerTransfers +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h index a73fa48..dd66005 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h @@ -10,20 +10,20 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestTravelMode) { /** (default) indicates standard driving directions using the road */ - OCDirectionsRequestTravelModeDriving, - + OCDirectionsRequestTravelModeDriving, + /** requests walking directions via pedestrian paths & sidewalks (where available). */ - OCDirectionsRequestTravelModeWalking, - + OCDirectionsRequestTravelModeWalking, + /** requests bicycling directions via bicycle paths & preferred streets (where available). */ - OCDirectionsRequestTravelModeBicycling, - + OCDirectionsRequestTravelModeBicycling, + /** requests directions via public transit routes (where available). */ - OCDirectionsRequestTravelModeTransit -}; \ No newline at end of file + OCDirectionsRequestTravelModeTransit +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h index 34eefcd..aa9ac75 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h @@ -10,15 +10,15 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestUnit) { /** when not specified */ - OCDirectionsRequestUnitDefault, - + OCDirectionsRequestUnitDefault, + /** specifies usage of the metric system. Textual distances are returned using kilometers and meters. */ - OCDirectionsRequestUnitMetric, - + OCDirectionsRequestUnitMetric, + /** specifies usage of the Imperial (English) system. Textual distances are returned using miles and feet. */ - OCDirectionsRequestUnitImperial -}; \ No newline at end of file + OCDirectionsRequestUnitImperial +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsResponseVehicleType.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsResponseVehicleType.h index 16f74df..7e7e00e 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsResponseVehicleType.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsResponseVehicleType.h @@ -11,89 +11,89 @@ typedef NS_ENUM(NSUInteger, OCDirectionsResponseVehicleType) { // Not available. // */ // OCDirectionsResponseVehicleTypeNotAvailable, - + /** Rail. */ - OCDirectionsResponseVehicleTypeRail, - + OCDirectionsResponseVehicleTypeRail, + /** Light rail transit. */ - OCDirectionsResponseVehicleTypeMetroRail, - + OCDirectionsResponseVehicleTypeMetroRail, + /** Underground light rail. */ - OCDirectionsResponseVehicleTypeSubway, - + OCDirectionsResponseVehicleTypeSubway, + /** Above ground light rail. */ - OCDirectionsResponseVehicleTypeTram, - + OCDirectionsResponseVehicleTypeTram, + /** Monorail. */ - OCDirectionsResponseVehicleTypeMonorail, - + OCDirectionsResponseVehicleTypeMonorail, + /** Heavy rail. */ - OCDirectionsResponseVehicleTypeHeavyRail, - + OCDirectionsResponseVehicleTypeHeavyRail, + /** Commuter rail. */ - OCDirectionsResponseVehicleTypeCommuterTrain, - + OCDirectionsResponseVehicleTypeCommuterTrain, + /** High speed train. */ - OCDirectionsResponseVehicleTypeHighSpeedTrain, - + OCDirectionsResponseVehicleTypeHighSpeedTrain, + /** Bus. */ - OCDirectionsResponseVehicleTypeBus, - + OCDirectionsResponseVehicleTypeBus, + /** Intercity bus. */ - OCDirectionsResponseVehicleTypeIntercityBus, - + OCDirectionsResponseVehicleTypeIntercityBus, + /** Trolleybus. */ - OCDirectionsResponseVehicleTypeTrolleybus, - + OCDirectionsResponseVehicleTypeTrolleybus, + /** Share taxi is a kind of bus with the ability to drop off and pick up passengers anywhere on its route. */ - OCDirectionsResponseVehicleTypeShareTaxi, - + OCDirectionsResponseVehicleTypeShareTaxi, + /** Ferry. */ - OCDirectionsResponseVehicleTypeFerry, - + OCDirectionsResponseVehicleTypeFerry, + /** A vehicle that operates on a cable, usually on the ground. Aerial cable cars may be of the type OCDirectionsResponseVehicleTypeGondolaLift. */ - OCDirectionsResponseVehicleTypeCableCar, - + OCDirectionsResponseVehicleTypeCableCar, + /** An aerial cable car. */ - OCDirectionsResponseVehicleTypeGondolaLift, - + OCDirectionsResponseVehicleTypeGondolaLift, + /** A vehicle that is pulled up a steep incline by a cable. A Funicular typically consists of two cars, with each car acting as a counterweight for the other. */ - OCDirectionsResponseVehicleTypeFunicular, - + OCDirectionsResponseVehicleTypeFunicular, + /** All other vehicles will return this type. */ - OCDirectionsResponseVehicleTypeOther, + OCDirectionsResponseVehicleTypeOther, }; diff --git a/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist b/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist index 066c269..58ded33 100644 --- a/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist +++ b/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist @@ -9,7 +9,7 @@ CFBundleIconFile CFBundleIdentifier - com.github.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch b/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch index eb2007e..7b649da 100644 --- a/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch +++ b/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch @@ -5,5 +5,7 @@ // #ifdef __OBJC__ - #import + +#import + #endif diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index a8fd17f..3125721 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -9,72 +9,116 @@ #import #import #import "OCDirectionsCommonTypes.h" +#import "OCDirectionsRequestTransitMode.h" + +#define kOCDirectionsRequestDepartureTimeNow [OCDirectionsRequest departureTimeNow] @interface OCDirectionsRequest : NSObject #pragma mark - Required /** - Origin - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. + * Origin - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. */ @property (nonatomic, readonly) CLLocation *originLocation; // CLLocation or NSString @property (nonatomic, copy, readonly) NSString *originString; /** - Destination - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. + * Destination - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. */ @property (nonatomic, readonly) CLLocation *destinationLocation; // CLLocation or NSString @property (nonatomic, copy, readonly) NSString *destinationString; /* - Indicates whether or not the directions request comes from a device with a location sensor. This value must be either true or false. + * Indicates whether or not the directions request comes from a device with a location sensor. This value must be either true or false. */ @property (nonatomic, readonly) BOOL sensor; #pragma mark - Optional + @property (nonatomic) OCDirectionsRequestTravelMode travelMode; /** - When calculating routes using the Directions API, you may also specify waypoints for driving, walking or bicycling directions. Waypoints are not available for transit directions. Waypoints allow you to calculate routes through additional locations, in which case the returned route passes through the given waypoints. - - Formally it is an array of NSStrings and CLLocations. + * When calculating routes using the Directions API, you may also specify waypoints for driving, walking or bicycling + * directions. Waypoints are not available for transit directions. Waypoints allow you to calculate routes through + * additional locations, in which case the returned route passes through the given waypoints. + * + * Formally it is an array of NSStrings and CLLocations. */ @property (nonatomic) NSArray *waypoints; /** - Optimizes the provided route by rearranging the waypoints in a more efficient order. (This optimization is an application of the Travelling Salesman Problem.) + * Optimizes the provided route by rearranging the waypoints in a more efficient order. + * (This optimization is an application of the Travelling Salesman Problem.) */ @property (nonatomic) BOOL waypointsOptimise; /** - Directions may be calculated that adhere to certain restrictions. - Use an array of DirectionsRequestRestriction types ie. @[DirectionsRequestAvoidTollsRestriction, DirectionsRequestAviodFerriesRestriction] + * Directions may be calculated that adhere to certain restrictions. + * Use an array of DirectionsRequestRestriction types ie. + * @[DirectionsRequestAvoidTollsRestriction, DirectionsRequestAvoidFerriesRestriction] */ @property (nonatomic) NSArray *restrictions; /** - Directions results contain text within distance fields that may be displayed to the user to indicate the distance of a particular "step" of the route. By default, this text uses the unit system of the origin's country or region. + * Directions results contain text within distance fields that may be displayed to the user to indicate + * the distance of a particular "step" of the route. By default, this text uses the unit system of the origin's country + * or region. */ @property (nonatomic) OCDirectionsRequestUnit unit; /** - You can also set the Directions service to return results biased to a particular region by use of the region parameter. This parameter takes a ccTLD (country code top-level domain) argument specifying the region bias. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland"). - - You may utilize any domain in which the main Google Maps application has launched driving directions. + * You can also set the Directions service to return results biased to a particular region by use of the region parameter. + * This parameter takes a ccTLD (country code top-level domain) argument specifying the region bias. + * Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, + * the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" + * (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland"). + * You may utilize any domain in which the main Google Maps application has launched driving directions. */ @property (nonatomic, copy) NSString *region; /** - You can also set the Directions service to return results is specific language. - If language is not supplied, the service will attempt to use the native language of the domain from which the request is sent. + * Specifies the desired time of arrival for transit directions. + * You can specify either departure_time or arrival_time, but not both. + */ +@property (nonatomic) NSDate *arrivalTime; + +/** + * Specifies the desired time of departure. According to the doc you can specify a value of now, + * which sets the departure time to the current time (correct to the nearest second). However due to + * client/server time differences [NSDate new] might work incorrectly, please use kOCDirectionsRequestDepartureTimeNow + * for that kind of requests. + */ +@property (nonatomic) NSDate *departureTime; + + +/** + * You can also set the Directions service to return results is specific language. + * If language is not supplied, the service will attempt to use the native language of the domain from which the request is sent. */ @property (nonatomic, copy) NSString *language; /** - Directions service may return several routes if you pass alternatives. + * Directions service may return several routes if you pass alternatives. */ @property (nonatomic) BOOL alternatives; /** - Indicates whether sensor flag has been used or not. + * Specifies the assumptions to use when calculating time in traffic. + */ +@property (nonatomic) OCDirectionsRequestTrafficModel trafficModel; + +/** + * Specifies one or more preferred modes of transit. + */ +@property (nonatomic) OCDirectionsRequestTransitMode transitMode; + +/** + * Specifies preferences for transit routes. Using this parameter, you can bias the options returned, + * rather than accepting the default best route chosen by the API. + */ +@property (nonatomic) OCDirectionsRequestTransitRoutingPreference transitRoutingPreference; + +/** + * Indicates whether sensor flag has been used or not. */ @property (nonatomic, getter=isSensorFlagUsed, readonly) BOOL sensorFlagUsed; @@ -112,4 +156,6 @@ - (BOOL)isValid; -@end \ No newline at end of file ++ (NSDate *)departureTimeNow; + +@end diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m index bbf7e82..bcda606 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m @@ -25,8 +25,8 @@ @interface OCDirectionsRequest () @implementation OCDirectionsRequest #pragma mark - Public init -- (instancetype)init -{ + +- (instancetype)init { self = [super init]; if (self) { // Do nothing @@ -35,96 +35,89 @@ - (instancetype)init } #pragma mark - Private init + - (instancetype)initWithOriginLocation:(CLLocation *)origin - andDestinationLocation:(CLLocation *)destination -{ - self = [super init]; - if (self) { - self.originLocation = origin; - self.destinationLocation = destination; - } - - return self; + andDestinationLocation:(CLLocation *)destination { + self = [super init]; + if (self) { + self.originLocation = origin; + self.destinationLocation = destination; + } + + return self; } - (instancetype)initWithOriginLocation:(CLLocation *)origin andDestinationLocation:(CLLocation *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { self = [self initWithOriginLocation:origin andDestinationLocation:destination]; if (self) { self.sensor = sensor; - self.sensorFlagUsed = YES; + self.sensorFlagUsed = YES; } - + return self; } - (instancetype)initWithOriginString:(NSString *)origin - andDestinationLocation:(CLLocation *)destination -{ - self = [super init]; - if (self) { - self.originString = origin; - self.destinationLocation = destination; - } - return self; + andDestinationLocation:(CLLocation *)destination { + self = [super init]; + if (self) { + self.originString = origin; + self.destinationLocation = destination; + } + return self; } - (instancetype)initWithOriginString:(NSString *)origin andDestinationLocation:(CLLocation *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { self = [self initWithOriginString:origin andDestinationLocation:destination]; if (self) { self.sensor = sensor; - self.sensorFlagUsed = YES; + self.sensorFlagUsed = YES; } return self; } - (instancetype)initWithOriginLocation:(CLLocation *)origin - andDestinationString:(NSString *)destination -{ - self = [super init]; - if (self) { - self.originLocation = origin; - self.destinationString = destination; - } - return self; + andDestinationString:(NSString *)destination { + self = [super init]; + if (self) { + self.originLocation = origin; + self.destinationString = destination; + } + return self; } - (instancetype)initWithOriginLocation:(CLLocation *)origin andDestinationString:(NSString *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { self = [self initWithOriginLocation:origin andDestinationString:destination]; if (self) { self.sensor = sensor; - self.sensorFlagUsed = YES; + self.sensorFlagUsed = YES; } return self; } - (instancetype)initWithOriginString:(NSString *)origin - andDestinationString:(NSString *)destination -{ - self = [super init]; - if (self) { - self.originString = origin; - self.destinationString = destination; - } - return self; + andDestinationString:(NSString *)destination { + self = [super init]; + if (self) { + self.originString = origin; + self.destinationString = destination; + } + return self; } - (instancetype)initWithOriginString:(NSString *)origin andDestinationString:(NSString *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { self = [self initWithOriginString:origin andDestinationString:destination]; if (self) { self.sensor = sensor; - self.sensorFlagUsed = YES; + self.sensorFlagUsed = YES; } return self; } @@ -134,122 +127,117 @@ - (instancetype)initWithOriginString:(NSString *)origin @implementation OCDirectionsRequest (Creation) + (instancetype)requestWithOriginLocation:(CLLocation *)origin - andDestinationLocation:(CLLocation *)destination -{ - OCAssertParameterNotNil(origin, @"Origin location is nil."); - OCAssertParameterNotNil(destination, @"Destination location is nil."); - - OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginLocation:origin - andDestinationLocation:destination]; - - return request; + andDestinationLocation:(CLLocation *)destination { + OCAssertParameterNotNil(origin, @"Origin location is nil."); + OCAssertParameterNotNil(destination, @"Destination location is nil."); + + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] + initWithOriginLocation:origin + andDestinationLocation:destination]; + + return request; } + (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationLocation:(CLLocation *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { OCAssertParameterNotNil(origin, @"Origin location is nil."); OCAssertParameterNotNil(destination, @"Destination location is nil."); - + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginLocation:origin - andDestinationLocation:destination - sensor:sensor]; - + initWithOriginLocation:origin + andDestinationLocation:destination + sensor:sensor]; + return request; } + (instancetype)requestWithOriginString:(NSString *)origin - andDestinationLocation:(CLLocation *)destination -{ - OCAssertParameterNotNil(origin, @"Origin string is nil."); - OCAssertParameterNotNil(destination, @"Destination location is nil."); - - OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginString:origin - andDestinationLocation:destination]; - return request; + andDestinationLocation:(CLLocation *)destination { + OCAssertParameterNotNil(origin, @"Origin string is nil."); + OCAssertParameterNotNil(destination, @"Destination location is nil."); + + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] + initWithOriginString:origin + andDestinationLocation:destination]; + return request; } + (instancetype)requestWithOriginString:(NSString *)origin andDestinationLocation:(CLLocation *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { OCAssertParameterNotNil(origin, @"Origin string is nil."); OCAssertParameterNotNil(destination, @"Destination location is nil."); - + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginString:origin - andDestinationLocation:destination - sensor:sensor]; + initWithOriginString:origin + andDestinationLocation:destination + sensor:sensor]; return request; } + (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationString:(NSString *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { OCAssertParameterNotNil(origin, @"Origin location is nil."); OCAssertParameterNotNil(destination, @"Destination string is nil."); - + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginLocation:origin - andDestinationString:destination - sensor:sensor]; + initWithOriginLocation:origin + andDestinationString:destination + sensor:sensor]; return request; } + (instancetype)requestWithOriginLocation:(CLLocation *)origin - andDestinationString:(NSString *)destination -{ - OCAssertParameterNotNil(origin, @"Origin location is nil."); - OCAssertParameterNotNil(destination, @"Destination string is nil."); - - OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginLocation:origin - andDestinationString:destination]; - return request; + andDestinationString:(NSString *)destination { + OCAssertParameterNotNil(origin, @"Origin location is nil."); + OCAssertParameterNotNil(destination, @"Destination string is nil."); + + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] + initWithOriginLocation:origin + andDestinationString:destination]; + return request; } + (instancetype)requestWithOriginString:(NSString *)origin - andDestinationString:(NSString *)destination -{ + andDestinationString:(NSString *)destination { OCAssertParameterNotNil(origin, @"Origin string is nil."); OCAssertParameterNotNil(destination, @"Destination string is nil."); - + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginString:origin - andDestinationString:destination]; + initWithOriginString:origin + andDestinationString:destination]; return request; } + (instancetype)requestWithOriginString:(NSString *)origin - andDestinationString:(NSString *)destination - sensor:(BOOL)sensor -{ - OCAssertParameterNotNil(origin, @"Origin string is nil."); - OCAssertParameterNotNil(destination, @"Destination string is nil."); - - OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginString:origin - andDestinationString:destination - sensor:sensor]; - return request; -} - -- (BOOL)isValid -{ - if (self.originLocation == nil && self.originString == nil) { - return NO; - } - - if (self.destinationLocation == nil && self.destinationString == nil) { - return NO; - } - - return YES; + andDestinationString:(NSString *)destination + sensor:(BOOL)sensor { + OCAssertParameterNotNil(origin, @"Origin string is nil."); + OCAssertParameterNotNil(destination, @"Destination string is nil."); + + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] + initWithOriginString:origin + andDestinationString:destination + sensor:sensor]; + return request; +} + +- (BOOL)isValid { + if (self.originLocation == nil && self.originString == nil) { + return NO; + } + + if (self.destinationLocation == nil && self.destinationString == nil) { + return NO; + } + + return YES; +} + ++ (NSDate *)departureTimeNow { + return [NSDate dateWithTimeIntervalSince1970:0]; } @end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h index 53b3e8b..d157c68 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h @@ -11,10 +11,10 @@ @interface OCDirectionsBounds : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D southwest; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D northeast; +@property (nonatomic, readonly) CLLocationCoordinate2D southwest; +@property (nonatomic, readonly) CLLocationCoordinate2D northeast; + (instancetype)boundsFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.m index a80557f..ebd6743 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.m @@ -14,44 +14,41 @@ @implementation OCDirectionsBounds -+ (instancetype)boundsFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)boundsFromDictionary:(NSDictionary *)dictionary { OCDirectionsBounds *bounds = [[OCDirectionsBounds alloc] initWithDictionary:dictionary]; return bounds; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadSouthwest]; [self loadNortheast]; } -- (void)loadSouthwest -{ +- (void)loadSouthwest { NSDictionary *southwestDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeBoundsSouthwest]; CLLocationCoordinate2D coordinate = [CLLocation coordinateFromDictionary:southwestDictionary]; _southwest = coordinate; } -- (void)loadNortheast -{ +- (void)loadNortheast { NSDictionary *northeastDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeBoundsNortheast]; CLLocationCoordinate2D coordinate = [CLLocation coordinateFromDictionary:northeastDictionary]; - + _northeast = coordinate; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h index 82774eb..c38a195 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h @@ -12,10 +12,10 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeDistance; @interface OCDirectionsDistance : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; @property (nonatomic, copy, readonly) NSString *text; -@property (nonatomic, copy, readonly) NSNumber *value; +@property (nonatomic, readonly) NSNumber *value; + (instancetype)distanceFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.m index 72299a3..da03c1e 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.m @@ -15,42 +15,39 @@ @implementation OCDirectionsDistance -+ (instancetype)distanceFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)distanceFromDictionary:(NSDictionary *)dictionary { OCDirectionsDistance *distance = [[OCDirectionsDistance alloc] initWithDictionary:dictionary]; return distance; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadText]; [self loadValue]; } -- (void)loadText -{ +- (void)loadText { NSString *text = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDistanceText]; - + _text = text; } -- (void)loadValue -{ +- (void)loadValue { NSNumber *value = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDistanceValue]; - + _value = value; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h index 5d58148..41e9565 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h @@ -9,13 +9,14 @@ #import extern NSString *const kCGGoogleDirectionsResponseAttributeDuration; +extern NSString *const kCGGoogleDirectionsResponseAttributeDurationInTraffic; @interface OCDirectionsDuration : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; @property (nonatomic, copy, readonly) NSString *text; -@property (nonatomic, copy, readonly) NSNumber *value; +@property (nonatomic, readonly) NSNumber *value; + (instancetype)durationFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m index e018d67..b0763da 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m @@ -9,48 +9,46 @@ #import "OCDirectionsDuration.h" NSString *const kCGGoogleDirectionsResponseAttributeDuration = @"duration"; +NSString *const kCGGoogleDirectionsResponseAttributeDurationInTraffic = @"duration_in_traffic"; static NSString *const kCGGoogleDirectionsResponseAttributeDurationText = @"text"; static NSString *const kCGGoogleDirectionsResponseAttributeDurationValue = @"value"; @implementation OCDirectionsDuration -+ (instancetype)durationFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)durationFromDictionary:(NSDictionary *)dictionary { OCDirectionsDuration *duration = [[OCDirectionsDuration alloc] initWithDictionary:dictionary]; return duration; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadText]; [self loadValue]; } -- (void)loadText -{ +- (void)loadText { NSString *text = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDurationText]; - + _text = text; } -- (void)loadValue -{ +- (void)loadValue { NSNumber *value = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDurationValue]; - + _value = value; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h new file mode 100644 index 0000000..d3ed1b0 --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h @@ -0,0 +1,30 @@ +// +// Created by Marcin Iwanicki on 20/03/2016. +// + +#import + +extern NSString *const kCGGoogleDirectionsResponseAttributeFare; + +@interface OCDirectionsFare : NSObject + +@property (nonatomic, readonly) NSDictionary *dictionary; + +/** + * An ISO 4217 currency code indicating the currency that the amount is expressed in. + */ +@property (nonatomic, copy, readonly) NSString *currency; + +/** + * The total fare amount, formatted in the requested language. + */ +@property (nonatomic, copy, readonly) NSString *text; + +/** + * The total fare amount, in the currency specified above. + */ +@property (nonatomic, readonly) NSNumber *value; + ++ (instancetype)fareFromDictionary:(NSDictionary *)dictionary; + +@end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m new file mode 100644 index 0000000..1d8159f --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m @@ -0,0 +1,57 @@ +// +// Created by Marcin Iwanicki on 20/03/2016. +// + +#import "OCDirectionsFare.h" + +NSString *const kCGGoogleDirectionsResponseAttributeFare = @"fare"; + +static NSString *const kCGGoogleDirectionsResponseAttributeFareCurrency = @"currency"; +static NSString *const kCGGoogleDirectionsResponseAttributeFareValue = @"value"; +static NSString *const kCGGoogleDirectionsResponseAttributeFareText = @"text"; + +@implementation OCDirectionsFare + +#pragma mark - Public + ++ (instancetype)fareFromDictionary:(NSDictionary *)dictionary { + return [[OCDirectionsFare alloc] initWithDictionary:dictionary]; +} + +#pragma mark - Private + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { + self = [super init]; + if (self) { + _dictionary = dictionary; + + [self loadAllProperties]; + } + return self; +} + +- (void)loadAllProperties { + [self loadCurrency]; + [self loadText]; + [self loadValue]; +} + +- (void)loadCurrency { + NSString *currency = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFareCurrency]; + + _currency = currency; +} + +- (void)loadText { + NSString *text = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFareText]; + + _text = text; +} + +- (void)loadValue { + NSNumber *value = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFareValue]; + + _value = value; +} + +@end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h index 972e236..e08e5cb 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h @@ -13,16 +13,17 @@ @interface OCDirectionsLeg : NSObject -@property (nonatomic, strong, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property (nonatomic, strong, readonly) OCDirectionsDistance *distance; -@property (nonatomic, strong, readonly) OCDirectionsDuration *duration; +@property (nonatomic, readonly) OCDirectionsDistance *distance; +@property (nonatomic, readonly) OCDirectionsDuration *duration; +@property (nonatomic, readonly) OCDirectionsDuration *durationInTraffic; @property (nonatomic, copy, readonly) NSString *endAddress; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D endLocation; +@property (nonatomic, readonly) CLLocationCoordinate2D endLocation; @property (nonatomic, copy, readonly) NSString *startAddress; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D startLocation; -@property (nonatomic, strong, readonly) NSArray *steps; -@property (nonatomic, strong, readonly) NSArray *viaWaypoint; +@property (nonatomic, readonly) CLLocationCoordinate2D startLocation; +@property (nonatomic, readonly) NSArray *steps; +@property (nonatomic, readonly) NSArray *viaWaypoint; + (instancetype)legFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m index b5978ff..34996d8 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m @@ -19,30 +19,30 @@ @implementation OCDirectionsLeg -+ (instancetype)legFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)legFromDictionary:(NSDictionary *)dictionary { OCDirectionsLeg *leg = [[OCDirectionsLeg alloc] initWithDictionary:dictionary]; - + return leg; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadDistance]; [self loadDuration]; + [self loadDurationInTraffic]; [self loadEndAddress]; [self loadEndLocation]; [self loadStartAddress]; @@ -51,74 +51,73 @@ - (void)loadAllProperties [self loadViaWaypoint]; } -- (void)loadDistance -{ +- (void)loadDistance { NSDictionary *distanceDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDistance]; OCDirectionsDistance *distance = [OCDirectionsDistance distanceFromDictionary:distanceDictionary]; - + _distance = distance; } -- (void)loadDuration -{ +- (void)loadDuration { NSDictionary *durationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDuration]; OCDirectionsDuration *duration = [OCDirectionsDuration durationFromDictionary:durationDictionary]; - + _duration = duration; } -- (void)loadEndAddress -{ +- (void)loadDurationInTraffic { + NSDictionary *durationInTrafficDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDurationInTraffic]; + OCDirectionsDuration *durationInTraffic = [OCDirectionsDuration durationFromDictionary:durationInTrafficDictionary]; + + _durationInTraffic = durationInTraffic; +} + +- (void)loadEndAddress { NSString *endAddress = [_dictionary objectForKey:kCGgoogleDirectionsResponseAttributeEndAddress]; _endAddress = endAddress; } -- (void)loadEndLocation -{ +- (void)loadEndLocation { NSDictionary *endLocationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeEndLocation]; CLLocationCoordinate2D endLocation = [CLLocation coordinateFromDictionary:endLocationDictionary]; - + _endLocation = endLocation; } -- (void)loadStartAddress -{ +- (void)loadStartAddress { NSString *startAddress = [_dictionary objectForKey:kCGgoogleDirectionsResponseAttributeStartAddress]; - + _startAddress = startAddress; } -- (void)loadStartLocation -{ +- (void)loadStartLocation { NSDictionary *startLocationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStartLocation]; CLLocationCoordinate2D startLocation = [CLLocation coordinateFromDictionary:startLocationDictionary]; - + _startLocation = startLocation; } -- (void)loadSteps -{ +- (void)loadSteps { NSArray *stepsArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeSteps]; NSMutableArray *steps = [[NSMutableArray alloc] initWithCapacity:stepsArray.count]; - + for (NSDictionary *stepDictionary in stepsArray) { OCDirectionsStep *step = [OCDirectionsStep stepFromDictionary:stepDictionary]; [steps addObject:step]; } - + _steps = steps; } -- (void)loadViaWaypoint -{ +- (void)loadViaWaypoint { NSArray *viaWaypointArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeViaWaypoint]; NSMutableArray *viaWaypoint = [[NSMutableArray alloc] initWithCapacity:viaWaypointArray.count]; for (NSDictionary *viaWaypointDictionary in viaWaypointArray) { OCDirectionsWaypoint *waypoint = [OCDirectionsWaypoint waypointFromDictionary:viaWaypointDictionary]; [viaWaypoint addObject:waypoint]; } - + _viaWaypoint = viaWaypoint; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h index 72e7aa7..5a36c80 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h @@ -10,7 +10,7 @@ @interface OCDirectionsPolyline : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; @property (nonatomic, copy, readonly) NSString *points; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.m index aff858f..e91547a 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.m @@ -12,34 +12,32 @@ @implementation OCDirectionsPolyline -+ (instancetype)polylineFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)polylineFromDictionary:(NSDictionary *)dictionary { OCDirectionsPolyline *polyline = [[OCDirectionsPolyline alloc] initWithDictionary:dictionary]; return polyline; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadPoints]; } -- (void)loadPoints -{ +- (void)loadPoints { NSString *points = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributePolylinePoints]; - + _points = points; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h index 8ff3218..817d4fa 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h @@ -10,44 +10,59 @@ #import "OCDirectionsPolyline.h" #import "OCDirectionsBounds.h" +@class OCDirectionsFare; + @interface OCDirectionsRoute : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; /** - legs[] contains an array which contains information about a leg of the route, between two locations within the given route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will contain exactly one leg within the legs array.) Each leg consists of a series of steps. (See Directions Legs below.) + * legs[] contains an array which contains information about a leg of the route, between two locations within the given + * route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will + * contain exactly one leg within the legs array.) Each leg consists of a series of steps. (See Directions Legs below.) */ -@property (nonatomic, strong, readonly) NSArray *legs; +@property (nonatomic, readonly) NSArray *legs; /** - copyrights contains the copyrights text to be displayed for this route. You must handle and display this information yourself. + * copyrights contains the copyrights text to be displayed for this route. You must handle and display this information + * yourself. */ @property (nonatomic, copy, readonly) NSString *copyrights; /* - warnings[] contains an array of warnings to be displayed when showing these directions. You must handle and display these warnings yourself. + * warnings[] contains an array of warnings to be displayed when showing these directions. You must handle and display + * these warnings yourself. + */ +@property (nonatomic, readonly) NSArray *warnings; + +/** + * waypoint_order contains an array indicating the order of any waypoints in the calculated route. This waypoints may be + * reordered if the request was passed optimize:true within its waypoints parameter. */ -@property (nonatomic, strong, readonly) NSArray *warnings; +@property (nonatomic, readonly) NSArray *waypointOrder; /** - waypoint_order contains an array indicating the order of any waypoints in the calculated route. This waypoints may be reordered if the request was passed optimize:true within its waypoints parameter. + * overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path + * of the resulting directions. */ -@property (nonatomic, strong, readonly) NSArray *waypointOrder; +@property (nonatomic, readonly) OCDirectionsPolyline *overviewPolyline; /** - overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path of the resulting directions. + * bounds contains the viewport bounding box of the overview_polyline. */ -@property (nonatomic, strong, readonly) OCDirectionsPolyline *overviewPolyline; +@property (nonatomic, readonly) OCDirectionsBounds *bounds; /** - bounds contains the viewport bounding box of the overview_polyline. + * summary contains a short textual description for the route, suitable for naming and disambiguating the route from + * alternatives. */ -@property (nonatomic, strong, readonly) OCDirectionsBounds *bounds; +@property (nonatomic, copy, readonly) NSString *summary; /** - summary contains a short textual description for the route, suitable for naming and disambiguating the route from alternatives. + * fare, if present, contains the total fare (that is, the total ticket costs) on this route. This property is only + * returned for transit requests and only for routes where fare information is available for all transit legs. */ -@property (nonatomic, strong, readonly) NSString *summary; +@property (nonatomic, readonly) OCDirectionsFare *fare; + (instancetype)routeFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m index 6a7f599..4fdf19f 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m @@ -8,6 +8,7 @@ #import "OCDirectionsRoute.h" #import "OCDirectionsLeg.h" +#import "OCDirectionsFare.h" static NSString *const kCGGoogleDirectionsResponseAttributeRouteSummary = @"summary"; static NSString *const kCGGoogleDirectionsResponseAttributeRouteLegs = @"legs"; @@ -19,89 +20,91 @@ @implementation OCDirectionsRoute -+ (instancetype)routeFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)routeFromDictionary:(NSDictionary *)dictionary { OCDirectionsRoute *route = [[OCDirectionsRoute alloc] initWithDictionary:dictionary]; return route; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadLegs]; [self loadCopyrights]; [self loadWarnings]; [self loadWaypointOrder]; [self loadOverviewPolyline]; [self loadBounds]; - [self loadSummary]; + [self loadSummary]; + [self loadFare]; } -- (void)loadLegs -{ +- (void)loadLegs { NSArray *legsArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteLegs]; NSMutableArray *legs = [[NSMutableArray alloc] initWithCapacity:legsArray.count]; for (NSDictionary *legDictionary in legsArray) { OCDirectionsLeg *leg = [OCDirectionsLeg legFromDictionary:legDictionary]; [legs addObject:leg]; } - + _legs = legs; } -- (void)loadCopyrights -{ +- (void)loadCopyrights { NSString *copyrights = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteCopyrights]; - + _copyrights = copyrights; } -- (void)loadWarnings -{ +- (void)loadWarnings { NSArray *warningsArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteWarnings]; - + _warnings = warningsArray; } -- (void)loadWaypointOrder -{ +- (void)loadWaypointOrder { NSArray *waypointOrder = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteWaypointOrder]; - + _waypointOrder = waypointOrder; } -- (void)loadOverviewPolyline -{ +- (void)loadOverviewPolyline { NSDictionary *overviewPolyline = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteOverviewPolyline]; OCDirectionsPolyline *polyline = [OCDirectionsPolyline polylineFromDictionary:overviewPolyline]; - + _overviewPolyline = polyline; } -- (void)loadBounds -{ +- (void)loadBounds { NSDictionary *boundsDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteBounds]; OCDirectionsBounds *bounds = [OCDirectionsBounds boundsFromDictionary:boundsDictionary]; - + _bounds = bounds; } -- (void)loadSummary -{ +- (void)loadSummary { NSString *summary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteSummary]; _summary = summary; } +- (void)loadFare { + NSDictionary *fareDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFare]; + if (fareDictionary) { + OCDirectionsFare *fare = [OCDirectionsFare fareFromDictionary:fareDictionary]; + + _fare = fare; + } +} + @end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h index 2e3178c..c7cd730 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h @@ -18,16 +18,16 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeStartLocation; @interface OCDirectionsStep : NSObject -@property (nonatomic, strong, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property (nonatomic, strong, readonly) OCDirectionsDistance *distance; -@property (nonatomic, strong, readonly) OCDirectionsDuration *duration; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D endLocation; +@property (nonatomic, readonly) OCDirectionsDistance *distance; +@property (nonatomic, readonly) OCDirectionsDuration *duration; +@property (nonatomic, readonly) CLLocationCoordinate2D endLocation; @property (nonatomic, copy, readonly) NSString *htmlInstructions; @property (nonatomic, copy, readonly) NSString *maneuver; -@property (nonatomic, strong, readonly) OCDirectionsPolyline *polyline; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D startLocation; -@property (nonatomic, assign, readonly) OCDirectionsRequestTravelMode travelMode; +@property (nonatomic, readonly) OCDirectionsPolyline *polyline; +@property (nonatomic, readonly) CLLocationCoordinate2D startLocation; +@property (nonatomic, readonly) OCDirectionsRequestTravelMode travelMode; + (instancetype)stepFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.m index 05e8d36..411510c 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.m @@ -20,27 +20,26 @@ @implementation OCDirectionsStep -+ (instancetype)stepFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)stepFromDictionary:(NSDictionary *)dictionary { OCDirectionsStep *step = [[OCDirectionsStep alloc] initWithDictionary:dictionary]; return step; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadDistance]; [self loadDuration]; [self loadEndLocation]; @@ -51,65 +50,57 @@ - (void)loadAllProperties [self loadTravelMode]; } -- (void)loadDistance -{ +- (void)loadDistance { NSDictionary *distanceDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDistance]; OCDirectionsDistance *distance = [OCDirectionsDistance distanceFromDictionary:distanceDictionary]; - + _distance = distance; } -- (void)loadDuration -{ +- (void)loadDuration { NSDictionary *durationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDuration]; OCDirectionsDuration *duration = [OCDirectionsDuration durationFromDictionary:durationDictionary]; - + _duration = duration; } -- (void)loadEndLocation -{ +- (void)loadEndLocation { NSDictionary *endLocationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeEndLocation]; CLLocationCoordinate2D endLocation = [CLLocation coordinateFromDictionary:endLocationDictionary]; - + _endLocation = endLocation; } -- (void)loadHtmlInstructions -{ +- (void)loadHtmlInstructions { NSString *htmlInstructions = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeHtmlInstructions]; - + _htmlInstructions = htmlInstructions; } -- (void)loadManeuver -{ +- (void)loadManeuver { NSString *maneuver = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributManeuver]; - + _maneuver = maneuver; } -- (void)loadPolyline -{ +- (void)loadPolyline { NSDictionary *polylineDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributPolyline]; OCDirectionsPolyline *polyline = [OCDirectionsPolyline polylineFromDictionary:polylineDictionary]; - + _polyline = polyline; } -- (void)loadStartLocation -{ +- (void)loadStartLocation { NSDictionary *startLocationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStartLocation]; CLLocationCoordinate2D startLocation = [CLLocation coordinateFromDictionary:startLocationDictionary]; - + _startLocation = startLocation; } -- (void)loadTravelMode -{ +- (void)loadTravelMode { NSString *travelModeString = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributTravelMode]; OCDirectionsRequestTravelMode travelMode = [OCDirectionsCommonTypes travelModeFromString:travelModeString]; - + _travelMode = travelMode; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h index c6836ac..fd0fa51 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h @@ -11,22 +11,22 @@ @interface OCDirectionsWaypoint : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; /** Not documented yet. */ -@property (nonatomic, assign, readonly) CLLocationCoordinate2D location; +@property (nonatomic, readonly) CLLocationCoordinate2D location; /** Not documented yet. */ -@property (nonatomic, retain, readonly) NSNumber *stepIndex; +@property (nonatomic, readonly) NSNumber *stepIndex; /** Not documented yet. */ -@property (nonatomic, retain, readonly) NSNumber *stepInterpolation; +@property (nonatomic, readonly) NSNumber *stepInterpolation; + (instancetype)waypointFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.m index b675c80..316640f 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.m @@ -15,51 +15,47 @@ @implementation OCDirectionsWaypoint -+ (instancetype)waypointFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)waypointFromDictionary:(NSDictionary *)dictionary { OCDirectionsWaypoint *waypoint = [[OCDirectionsWaypoint alloc] initWithDictionary:dictionary]; return waypoint; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadLocation]; [self loadStepIndex]; [self loadStepInterpolation]; } -- (void)loadLocation -{ +- (void)loadLocation { NSDictionary *locationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeLocation]; CLLocationCoordinate2D location = [CLLocation coordinateFromDictionary:locationDictionary]; - + _location = location; } -- (void)loadStepIndex -{ +- (void)loadStepIndex { NSNumber *stepIndex = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStepIndex]; - + _stepIndex = stepIndex; } -- (void)loadStepInterpolation -{ +- (void)loadStepInterpolation { NSNumber *stepInterpolation = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStepInterpolation]; - + _stepInterpolation = stepInterpolation; } diff --git a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h index 4d01fce..1981905 100644 --- a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h +++ b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h @@ -23,17 +23,17 @@ typedef NS_ENUM(NSUInteger, OCDirectionsResponseStatus) { @interface OCDirectionsResponse : NSObject -@property (nonatomic, strong, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; /** "status" contains metadata on the request. See Status Codes above. */ -@property (nonatomic, assign, readonly) OCDirectionsResponseStatus status; +@property (nonatomic, readonly) OCDirectionsResponseStatus status; /** "routes" contains an array of routes from the origin to the destination. */ -@property (nonatomic, strong, readonly) NSArray *routes; +@property (nonatomic, readonly) NSArray *routes; /** "errorMessage" (optional) field contains more detailed information about the reasons behind the given status code. diff --git a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m index 2c41135..982be4a 100644 --- a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m +++ b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m @@ -14,24 +14,22 @@ @implementation OCDirectionsResponse -+ (instancetype)responseFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)responseFromDictionary:(NSDictionary *)dictionary { OCDirectionsResponse *response = [[OCDirectionsResponse alloc] initWithDictionary:dictionary]; return response; } -- (OCDirectionsRoute *)route -{ +- (OCDirectionsRoute *)route { return self.routes.firstObject; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadStatus]; [self loadRoutes]; [self loadErrorMessage]; @@ -40,52 +38,51 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary } #pragma mark - Private methods -+ (NSDictionary *)statusDictionary -{ + ++ (NSDictionary *)statusDictionary { static NSDictionary *dictionary; - + if (dictionary == nil) { - dictionary = @{@"OK" : @(OCDirectionsResponseStatusOK), - @"NOT_FOUND" : @(OCDirectionsResponseStatusNotFound), - @"ZERO_RESULTS" : @(OCDirectionsResponseStatusZeroResults), - @"MAX_WAYPOINTS_EXCEEDED" : @(OCDirectionsResponseStatusMaxWaypointsExceeded), - @"INVALID_REQUEST" : @(OCDirectionsResponseStatusInvalidRequest), - @"OVER_QUERY_LIMIT" : @(OCDirectionsResponseStatusOverQueryLimit), - @"REQUEST_DENIED" : @(OCDirectionsResponseStatusRequestDenied), - @"UNKNOWN_ERROR" : @(OCDirectionsResponseStatusUnknownError) - }; + dictionary = @{ + @"OK" : @(OCDirectionsResponseStatusOK), + @"NOT_FOUND" : @(OCDirectionsResponseStatusNotFound), + @"ZERO_RESULTS" : @(OCDirectionsResponseStatusZeroResults), + @"MAX_WAYPOINTS_EXCEEDED" : @(OCDirectionsResponseStatusMaxWaypointsExceeded), + @"INVALID_REQUEST" : @(OCDirectionsResponseStatusInvalidRequest), + @"OVER_QUERY_LIMIT" : @(OCDirectionsResponseStatusOverQueryLimit), + @"REQUEST_DENIED" : @(OCDirectionsResponseStatusRequestDenied), + @"UNKNOWN_ERROR" : @(OCDirectionsResponseStatusUnknownError) + }; } return dictionary; } #pragma mark - Load attributes from dictionary -- (void)loadStatus -{ + +- (void)loadStatus { NSString *statusString = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStatus]; - + NSNumber *statusNumber = [[OCDirectionsResponse statusDictionary] objectForKey:statusString]; - + _status = [statusNumber unsignedIntegerValue]; } -- (void)loadRoutes -{ +- (void)loadRoutes { NSArray *routesArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRoutes]; - + NSMutableArray *routes = [[NSMutableArray alloc] initWithCapacity:routesArray.count]; for (NSDictionary *routeDictionary in routesArray) { OCDirectionsRoute *route = [OCDirectionsRoute routeFromDictionary:routeDictionary]; [routes addObject:route]; } - + _routes = routes; } -- (void)loadErrorMessage -{ +- (void)loadErrorMessage { NSString *errorMessage = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeErrorMessage]; - + _errorMessage = errorMessage; } -@end \ No newline at end of file +@end diff --git a/Source/OCGoogleDirectionsAPI/Shared Classes/Assertions/OCAssertParameter.h b/Source/OCGoogleDirectionsAPI/Shared Classes/Assertions/OCAssertParameter.h index d27942c..5ca777e 100644 --- a/Source/OCGoogleDirectionsAPI/Shared Classes/Assertions/OCAssertParameter.h +++ b/Source/OCGoogleDirectionsAPI/Shared Classes/Assertions/OCAssertParameter.h @@ -9,4 +9,4 @@ #import #define OCAssertParameter(condition, args...) if (!condition) [NSException raise:NSInvalidArgumentException format:args]; -#define OCAssertParameterNotNil(parameter, args...) OCAssertParameter(parameter, args); \ No newline at end of file +#define OCAssertParameterNotNil(parameter, args...) OCAssertParameter(parameter, args); diff --git a/Source/OCGoogleDirectionsAPI/Shared Classes/CLLocation/CLLocation+CoortindateFromDictionary.m b/Source/OCGoogleDirectionsAPI/Shared Classes/CLLocation/CLLocation+CoortindateFromDictionary.m index 2105a51..ec4ca74 100644 --- a/Source/OCGoogleDirectionsAPI/Shared Classes/CLLocation/CLLocation+CoortindateFromDictionary.m +++ b/Source/OCGoogleDirectionsAPI/Shared Classes/CLLocation/CLLocation+CoortindateFromDictionary.m @@ -7,18 +7,16 @@ // #import "CLLocation+CoortindateFromDictionary.h" -#import static NSString *const kCGGoogleDirectionsResponseAttributeLat = @"lat"; static NSString *const kCGGoogleDirectionsResponseAttributeLng = @"lng"; @implementation CLLocation (CoortindateFromDictionary) -+ (CLLocationCoordinate2D)coordinateFromDictionary:(NSDictionary *)dictionary -{ ++ (CLLocationCoordinate2D)coordinateFromDictionary:(NSDictionary *)dictionary { NSNumber *lat = [dictionary objectForKey:kCGGoogleDirectionsResponseAttributeLat]; NSNumber *lng = [dictionary objectForKey:kCGGoogleDirectionsResponseAttributeLng]; - + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(lat.doubleValue, lng.doubleValue); return coordinate; } diff --git a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m index 7e9eba3..54a9991 100644 --- a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m +++ b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m @@ -10,8 +10,6 @@ #import #import "OCDirectionsRequestURLCreator.h" #import "OCDirectionsRequestURLCreatorJSON.h" -#import "OCDirectionsRequest.h" -#import "OCDirectionsResponse.h" static NSString *const kTestKey = @"0123456789abcdef"; @@ -26,264 +24,385 @@ @implementation OCDirectionsRequestURLCreatorJSONTests #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" -- (void)setUp -{ +- (void)setUp { [super setUp]; - self.urlCreator = [OCDirectionsRequestURLCreatorJSON new]; + self.urlCreator = [OCDirectionsRequestURLCreatorJSON new]; } -- (void)tearDown -{ +- (void)tearDown { self.urlCreator = nil; - + [super tearDown]; } -- (void)testConformsToOCDiretionsRequestURLCreatorProtocol -{ +- (void)testConformsToOCDiretionsRequestURLCreatorProtocol { XCTAssertTrue([self.urlCreator conformsToProtocol:@protocol(OCDirectionsRequestURLCreator)]); } #pragma mark - Test stringFromRequest:useHttps:andKey: when arguments are invalid -- (void)testStringFromRequestWhenRequestIsNil -{ - // given - OCDirectionsRequest *request = nil; - NSString *key = [self prepareTestKey]; - - // then - XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException); -} - -- (void)testStringFromRequestWhenKeyIsNil -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - NSString *key = nil; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false", response); -} - -- (void)testStringFromRequestWhenRequestAndKeyAreNil -{ - // given - OCDirectionsRequest *request = nil; - NSString *key = nil; - - // then - XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException); + +- (void)testStringFromRequestWhenRequestIsNil { + // given + OCDirectionsRequest *request = nil; + NSString *key = [self prepareTestKey]; + + // then + XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException); +} + +- (void)testStringFromRequestWhenKeyIsNil { + // given + OCDirectionsRequest *request = [self prepareRequest]; + NSString *key = nil; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false", response); +} + +- (void)testStringFromRequestWhenRequestAndKeyAreNil { + // given + OCDirectionsRequest *request = nil; + NSString *key = nil; + + // then + XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException); } #pragma mark - Test stringFromRequest:useHttps:andKey: when arguments are valid -- (void)testStringFromRequestWhenAllArgumentsAreValid -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenAllArgumentsAreValidButNoSensor -{ - // given - OCDirectionsRequest *request = [self prepareNoSensorRequest]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenSensorIsTrue -{ - // given - OCDirectionsRequest *request = [self prepareRequestWithSensor]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=true&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenOriginAndDestinationAreLocations -{ - // given - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] - andDestinationLocation:[self prepareSecondLocation] - sensor:NO]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=40.100000,50.100000&sensor=false&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenOriginAndDestinationAreLocationsButNoSensor -{ - // given - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] - andDestinationLocation:[self prepareSecondLocation]]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=40.100000,50.100000&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenOriginIsStringAndDestinationIsLocation -{ - // given - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"Lodz" - andDestinationLocation:[self prepareSecondLocation] - sensor:NO]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=Lodz&destination=40.100000,50.100000&sensor=false&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenOriginIsLocationAndDestinationIsString -{ - // given - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] - andDestinationString:@"Lodz" - sensor:NO]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=Lodz&sensor=false&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenTravelModeIsDriving -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - request.travelMode = OCDirectionsRequestTravelModeDriving; - - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); // no mode parameter, it is default mode -} - -- (void)testStringFromRequestWhenTravelModeIsWalking -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - request.travelMode = OCDirectionsRequestTravelModeWalking; - - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=walking&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenTravelModeIsBicycling -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - request.travelMode = OCDirectionsRequestTravelModeBicycling; - - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=bicycling&key=0123456789abcdef", response); -} - -- (void)testStringFromRequestWhenTravelModeIsTransit -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - request.travelMode = OCDirectionsRequestTravelModeTransit; - - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=transit&key=0123456789abcdef", response); + +- (void)testStringFromRequestWhenAllArgumentsAreValid { + // given + OCDirectionsRequest *request = [self prepareRequest]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenAllArgumentsAreValidButNoSensor { + // given + OCDirectionsRequest *request = [self prepareNoSensorRequest]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenSensorIsTrue { + // given + OCDirectionsRequest *request = [self prepareRequestWithSensor]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=true&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenOriginAndDestinationAreLocations { + // given + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] + andDestinationLocation:[self prepareSecondLocation] + sensor:NO]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=40.100000,50.100000&sensor=false&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenOriginAndDestinationAreLocationsButNoSensor { + // given + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] + andDestinationLocation:[self prepareSecondLocation]]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=40.100000,50.100000&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenOriginIsStringAndDestinationIsLocation { + // given + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"Lodz" + andDestinationLocation:[self prepareSecondLocation] + sensor:NO]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=Lodz&destination=40.100000,50.100000&sensor=false&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenOriginIsLocationAndDestinationIsString { + // given + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] + andDestinationString:@"Lodz" + sensor:NO]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=Lodz&sensor=false&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenTravelModeIsDriving { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.travelMode = OCDirectionsRequestTravelModeDriving; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); // no mode parameter, it is default mode +} + +- (void)testStringFromRequestWhenTravelModeIsWalking { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.travelMode = OCDirectionsRequestTravelModeWalking; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=walking&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenTravelModeIsBicycling { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.travelMode = OCDirectionsRequestTravelModeBicycling; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=bicycling&key=0123456789abcdef", response); +} + +- (void)testStringFromRequestWhenTravelModeIsTransit { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.travelMode = OCDirectionsRequestTravelModeTransit; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=transit&key=0123456789abcdef", response); +} + +- (void)testStringWhenUnitsIsSet { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.unit = OCDirectionsRequestUnitMetric; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&units=metric&key=0123456789abcdef", response); +} + +- (void)testStringWhenArrivalTimeIsSet { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.arrivalTime = [NSDate dateWithTimeIntervalSince1970:2524668300000]; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&arrival_time=2524668300000&key=0123456789abcdef", response); +} + +- (void)testStringWhenDepartureTimeIsSet { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.departureTime = [NSDate dateWithTimeIntervalSince1970:2524668300000]; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&departure_time=2524668300000&key=0123456789abcdef", response); +} + +- (void)testStringWhenDepartureTimeIsNow { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.departureTime = kOCDirectionsRequestDepartureTimeNow; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&departure_time=now&key=0123456789abcdef", response); +} + +- (void)testStringWhenTrafficModelIsOptimistic { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.trafficModel = OCDirectionsRequestTrafficModelOptimistic; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&traffic_model=optimistic&key=0123456789abcdef", response); + +} + +- (void)testStringWhenTransitModeIsNotSpecified { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitMode = OCDirectionsRequestTransitModeDefault; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); +} + +- (void)testStringWhenTransitModeIsBus { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitMode = OCDirectionsRequestTransitModeBus; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_mode=bus&key=0123456789abcdef", response); +} + +- (void)testStringWhenTransitModeIsRail { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitMode = OCDirectionsRequestTransitModeRail; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_mode=rail&key=0123456789abcdef", response); +} + +- (void)testStringWhenTransitModeIsSubwayAndTram { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitMode = OCDirectionsRequestTransitModeSubway | OCDirectionsRequestTransitModeTram; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_mode=subway|tram&key=0123456789abcdef", response); +} + +- (void)testStringWhenTransitRoutingPreferenceIsLessWalking { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitRoutingPreference = OCDirectionsRequestTransitRoutingPreferenceLessWalking; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_routing_preference=less_walking&key=0123456789abcdef", response); } #pragma mark - Helpers -- (NSString *)prepareTestKey -{ - return kTestKey; + +- (NSString *)prepareTestKey { + return kTestKey; } -- (OCDirectionsRequest *)prepareRequest -{ - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz" sensor:NO]; - return request; +- (OCDirectionsRequest *)prepareRequest { + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz" sensor:NO]; + return request; } -- (OCDirectionsRequest *)prepareNoSensorRequest -{ - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz"]; - return request; +- (OCDirectionsRequest *)prepareNoSensorRequest { + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz"]; + return request; } - -- (OCDirectionsRequest *)prepareRequestWithSensor -{ - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz" sensor:YES]; - return request; + +- (OCDirectionsRequest *)prepareRequestWithSensor { + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz" sensor:YES]; + return request; } -- (CLLocation *)prepareFirstLocation -{ - CLLocation *location = [[CLLocation alloc] initWithLatitude:20.1 longitude:30.1]; - return location; +- (CLLocation *)prepareFirstLocation { + CLLocation *location = [[CLLocation alloc] initWithLatitude:20.1 longitude:30.1]; + return location; } -- (CLLocation *)prepareSecondLocation -{ - CLLocation *location = [[CLLocation alloc] initWithLatitude:40.1 longitude:50.1]; - return location; +- (CLLocation *)prepareSecondLocation { + CLLocation *location = [[CLLocation alloc] initWithLatitude:40.1 longitude:50.1]; + return location; } #pragma clang diagnostic pop diff --git a/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist b/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist index 5f3a288..169b6f7 100644 --- a/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist +++ b/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - cx.idev.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType diff --git a/Source/OCGoogleDirectionsAPITests/Request/OCDirectionsRequestTests.m b/Source/OCGoogleDirectionsAPITests/Request/OCDirectionsRequestTests.m index d698e7f..aa2f966 100644 --- a/Source/OCGoogleDirectionsAPITests/Request/OCDirectionsRequestTests.m +++ b/Source/OCGoogleDirectionsAPITests/Request/OCDirectionsRequestTests.m @@ -6,7 +6,6 @@ // // -#import #import #import "OCDirectionsRequest.h" @@ -20,448 +19,426 @@ @implementation OCDIrestionsRequestTests #pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma mark - Test helpers -- (void)testPrepareFirstLocationHelper -{ - // when - CLLocation *location = [self prepareFirstLocation]; - - // then - XCTAssertNotNil(location); - XCTAssertTrue([location isMemberOfClass:[CLLocation class]]); + +- (void)testPrepareFirstLocationHelper { + // when + CLLocation *location = [self prepareFirstLocation]; + + // then + XCTAssertNotNil(location); + XCTAssertTrue([location isMemberOfClass:[CLLocation class]]); } -- (void)testPrepareSecondLocationHelper -{ - // when - CLLocation *location = [self prepareSecondLocation]; - - // then - XCTAssertNotNil(location); - XCTAssertTrue([location isMemberOfClass:[CLLocation class]]); +- (void)testPrepareSecondLocationHelper { + // when + CLLocation *location = [self prepareSecondLocation]; + + // then + XCTAssertNotNil(location); + XCTAssertTrue([location isMemberOfClass:[CLLocation class]]); } -- (void)testPrepareFirstStringHelper -{ - // when - NSString *string = [self prepareFirstString]; - - // then - XCTAssertNotNil(string); - XCTAssertEqual(@"London", string); +- (void)testPrepareFirstStringHelper { + // when + NSString *string = [self prepareFirstString]; + + // then + XCTAssertNotNil(string); + XCTAssertEqual(@"London", string); } -- (void)testPreapreSecondStringHelper -{ - // when - NSString *string = [self prepareSecondString]; - - // then - XCTAssertNotNil(string); - XCTAssertEqual(@"Reading", string); +- (void)testPreapreSecondStringHelper { + // when + NSString *string = [self prepareSecondString]; + + // then + XCTAssertNotNil(string); + XCTAssertEqual(@"Reading", string); } #pragma mark - Test requestWithOriginLocation:andDestinationLocation:sensor: -- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginIsNil -{ - // given - CLLocation *originLocation = nil; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + +- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginIsNil { + // given + CLLocation *originLocation = nil; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // then + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationLocationWhenDestinationIsNil -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - CLLocation *destinationLocation = nil; - +- (void)testRequestWithOriginLocationAndDestinationLocationWhenDestinationIsNil { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + CLLocation *destinationLocation = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNil -{ - // given - CLLocation *originLocation = nil; - CLLocation *destinationLocation = nil; - +- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNil { + // given + CLLocation *originLocation = nil; + CLLocation *destinationLocation = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNotNil -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:NO]; - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originLocation, request.originLocation); - XCTAssertNil(request.originString); - XCTAssertEqual(destinationLocation, request.destinationLocation); - XCTAssertNil(request.destinationString); - XCTAssertFalse(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNotNil { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:NO]; + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originLocation, request.originLocation); + XCTAssertNil(request.originString); + XCTAssertEqual(destinationLocation, request.destinationLocation); + XCTAssertNil(request.destinationString); + XCTAssertFalse(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } -- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNotNilAndSensorIsTrue -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:YES]; - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originLocation, request.originLocation); - XCTAssertNil(request.originString); - XCTAssertEqual(destinationLocation, request.destinationLocation); - XCTAssertNil(request.destinationString); - XCTAssertTrue(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNotNilAndSensorIsTrue { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:YES]; + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originLocation, request.originLocation); + XCTAssertNil(request.originString); + XCTAssertEqual(destinationLocation, request.destinationLocation); + XCTAssertNil(request.destinationString); + XCTAssertTrue(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } #pragma mark - Test requestWithOriginString:andDestinationLocation:sensor: -- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginIsNil -{ - // given - NSString *originString = nil; - CLLocation *destinationLocation = [self prepareSecondLocation]; - + +- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginIsNil { + // given + NSString *originString = nil; + CLLocation *destinationLocation = [self prepareSecondLocation]; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationLocationWhenDestinationIsNil -{ - // given - NSString *originString = [self prepareFirstString]; - CLLocation *destinationLocation = nil; - +- (void)testRequestWithOriginStringAndDestinationLocationWhenDestinationIsNil { + // given + NSString *originString = [self prepareFirstString]; + CLLocation *destinationLocation = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNil -{ - // given - NSString *originString = nil; - CLLocation *destinationLocation = nil; - +- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNil { + // given + NSString *originString = nil; + CLLocation *destinationLocation = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNotNil -{ - // given - NSString *originString = [self prepareFirstString]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:NO]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originString, request.originString); - XCTAssertNil(request.originLocation); - XCTAssertEqual(destinationLocation, request.destinationLocation); - XCTAssertNil(request.destinationString); - XCTAssertFalse(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNotNil { + // given + NSString *originString = [self prepareFirstString]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:NO]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originString, request.originString); + XCTAssertNil(request.originLocation); + XCTAssertEqual(destinationLocation, request.destinationLocation); + XCTAssertNil(request.destinationString); + XCTAssertFalse(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } -- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNotNilAndSensorIsTrue -{ - // given - NSString *originString = [self prepareFirstString]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:YES]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originString, request.originString); - XCTAssertNil(request.originLocation); - XCTAssertEqual(destinationLocation, request.destinationLocation); - XCTAssertNil(request.destinationString); - XCTAssertTrue(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNotNilAndSensorIsTrue { + // given + NSString *originString = [self prepareFirstString]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:YES]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originString, request.originString); + XCTAssertNil(request.originLocation); + XCTAssertEqual(destinationLocation, request.destinationLocation); + XCTAssertNil(request.destinationString); + XCTAssertTrue(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } #pragma mark - Test requestWithOriginLocation:andDestinationString:sensor: -- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginIsNil -{ - // given - CLLocation *originLocation = nil; - NSString *destinationString = [self prepareSecondString]; - + +- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginIsNil { + // given + CLLocation *originLocation = nil; + NSString *destinationString = [self prepareSecondString]; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationStringWhenDestinationIsNil -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - NSString *destinationString = nil; - +- (void)testRequestWithOriginLocationAndDestinationStringWhenDestinationIsNil { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + NSString *destinationString = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNil -{ - // given - CLLocation *originLocation = nil; - NSString *destinationString = nil; - +- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNil { + // given + CLLocation *originLocation = nil; + NSString *destinationString = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNotNil -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - NSString *destinationString = [self prepareSecondString]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:NO]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originLocation, request.originLocation); - XCTAssertNil(request.originString); - XCTAssertEqual(destinationString, request.destinationString); - XCTAssertNil(request.destinationLocation); - XCTAssertFalse(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNotNil { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + NSString *destinationString = [self prepareSecondString]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:NO]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originLocation, request.originLocation); + XCTAssertNil(request.originString); + XCTAssertEqual(destinationString, request.destinationString); + XCTAssertNil(request.destinationLocation); + XCTAssertFalse(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } -- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNotNilAndSensorIsTrue -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - NSString *destinationString = [self prepareSecondString]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:YES]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originLocation, request.originLocation); - XCTAssertNil(request.originString); - XCTAssertEqual(destinationString, request.destinationString); - XCTAssertNil(request.destinationLocation); - XCTAssertTrue(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNotNilAndSensorIsTrue { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + NSString *destinationString = [self prepareSecondString]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:YES]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originLocation, request.originLocation); + XCTAssertNil(request.originString); + XCTAssertEqual(destinationString, request.destinationString); + XCTAssertNil(request.destinationLocation); + XCTAssertTrue(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } #pragma mark - Test requestWithOriginString:andDestinationString:sensor: -- (void)testRequestWithOriginStringAndDestinationStringWhenOriginIsNil -{ - // given - NSString *originString = nil; - NSString *destinationString = [self prepareSecondString]; - + +- (void)testRequestWithOriginStringAndDestinationStringWhenOriginIsNil { + // given + NSString *originString = nil; + NSString *destinationString = [self prepareSecondString]; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationStringWhenDestinationIsNil -{ - // given - NSString *originString = [self prepareFirstString]; - NSString *destinationString = nil; - +- (void)testRequestWithOriginStringAndDestinationStringWhenDestinationIsNil { + // given + NSString *originString = [self prepareFirstString]; + NSString *destinationString = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNil -{ - // given - NSString *originString = nil; - NSString *destinationString = nil; - +- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNil { + // given + NSString *originString = nil; + NSString *destinationString = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNotNil -{ - // given - NSString *originString = [self prepareFirstString]; - NSString *destinationString = [self prepareSecondString]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:NO]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originString, request.originString); - XCTAssertNil(request.originLocation); - XCTAssertEqual(destinationString, request.destinationString); - XCTAssertNil(request.destinationLocation); - XCTAssertFalse(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNotNil { + // given + NSString *originString = [self prepareFirstString]; + NSString *destinationString = [self prepareSecondString]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:NO]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originString, request.originString); + XCTAssertNil(request.originLocation); + XCTAssertEqual(destinationString, request.destinationString); + XCTAssertNil(request.destinationLocation); + XCTAssertFalse(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } -- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNotNilAndSensorIsTrue -{ - // given - NSString *originString = [self prepareFirstString]; - NSString *destinationString = [self prepareSecondString]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:YES]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originString, request.originString); - XCTAssertNil(request.originLocation); - XCTAssertEqual(destinationString, request.destinationString); - XCTAssertNil(request.destinationLocation); - XCTAssertTrue(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNotNilAndSensorIsTrue { + // given + NSString *originString = [self prepareFirstString]; + NSString *destinationString = [self prepareSecondString]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:YES]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originString, request.originString); + XCTAssertNil(request.originLocation); + XCTAssertEqual(destinationString, request.destinationString); + XCTAssertNil(request.destinationLocation); + XCTAssertTrue(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } #pragma mark - isValid -- (void)testIsValidWhenParametersAreFine -{ - // given - NSString *originString = [self prepareFirstString]; - CLLocation *originLocation = [self prepareFirstLocation]; - NSString *destinationString = [self prepareSecondString]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - OCDirectionsRequest *requestLL = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:YES]; - - OCDirectionsRequest *requestLS = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:YES]; - - OCDirectionsRequest *requestSL = [OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:YES]; - - OCDirectionsRequest *requestSS = [OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:YES]; - - // when - BOOL requestLLIsValid = [requestLL isValid]; - BOOL requestLSIsValid = [requestLS isValid]; - BOOL requestSLIsValid = [requestSL isValid]; - BOOL requestSSIsValid = [requestSS isValid]; - - //then - XCTAssertTrue(requestLLIsValid); - XCTAssertTrue(requestLSIsValid); - XCTAssertTrue(requestSLIsValid); - XCTAssertTrue(requestSSIsValid); + +- (void)testIsValidWhenParametersAreFine { + // given + NSString *originString = [self prepareFirstString]; + CLLocation *originLocation = [self prepareFirstLocation]; + NSString *destinationString = [self prepareSecondString]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + OCDirectionsRequest *requestLL = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:YES]; + + OCDirectionsRequest *requestLS = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:YES]; + + OCDirectionsRequest *requestSL = [OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:YES]; + + OCDirectionsRequest *requestSS = [OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:YES]; + + // when + BOOL requestLLIsValid = [requestLL isValid]; + BOOL requestLSIsValid = [requestLS isValid]; + BOOL requestSLIsValid = [requestSL isValid]; + BOOL requestSSIsValid = [requestSS isValid]; + + //then + XCTAssertTrue(requestLLIsValid); + XCTAssertTrue(requestLSIsValid); + XCTAssertTrue(requestSLIsValid); + XCTAssertTrue(requestSSIsValid); } #pragma mark - Custom verifiers -- (void)verifyPropertiesWithDefaultValuesOfRequest:(OCDirectionsRequest *)request -{ - XCTAssertFalse(request.alternatives); - XCTAssertTrue(request.isValid); - XCTAssertEqual(OCDirectionsRequestTravelModeDriving, request.travelMode); - XCTAssertEqual(OCDirectionsRequestUnitDefault, request.unit); - XCTAssertNil(request.waypoints); - XCTAssertFalse(request.waypointsOptimise); + +- (void)verifyPropertiesWithDefaultValuesOfRequest:(OCDirectionsRequest *)request { + XCTAssertFalse(request.alternatives); + XCTAssertTrue(request.isValid); + XCTAssertEqual(OCDirectionsRequestTravelModeDriving, request.travelMode); + XCTAssertEqual(OCDirectionsRequestUnitDefault, request.unit); + XCTAssertNil(request.waypoints); + XCTAssertFalse(request.waypointsOptimise); } #pragma mark - Helpers -- (CLLocation *)prepareFirstLocation -{ - CLLocation *location = [[CLLocation alloc] initWithLatitude:10.0 longitude:20.0]; - return location; + +- (CLLocation *)prepareFirstLocation { + CLLocation *location = [[CLLocation alloc] initWithLatitude:10.0 longitude:20.0]; + return location; } -- (CLLocation *)prepareSecondLocation -{ - CLLocation *location = [[CLLocation alloc] initWithLatitude:30.0 longitude:40.0]; - return location; +- (CLLocation *)prepareSecondLocation { + CLLocation *location = [[CLLocation alloc] initWithLatitude:30.0 longitude:40.0]; + return location; } -- (NSString *)prepareFirstString -{ - NSString *string = @"London"; - return string; +- (NSString *)prepareFirstString { + NSString *string = @"London"; + return string; } -- (NSString *)prepareSecondString -{ - NSString *string = @"Reading"; - return string; +- (NSString *)prepareSecondString { + NSString *string = @"Reading"; + return string; } #pragma clang diagnostic pop