Skip to content

Commit

Permalink
feat: add builder method for user param for auth url (#77)
Browse files Browse the repository at this point in the history
* feat: add builder method for user param for auth url

* chore: regenerate docs

* chore: test

* chore: bump version + update docs

---------

Co-authored-by: Smartcar <[email protected]>
  • Loading branch information
allisonc07 and smartcar-ops authored Apr 2, 2024
1 parent 27d1b1d commit 4ec6eb8
Show file tree
Hide file tree
Showing 27 changed files with 147 additions and 57 deletions.
2 changes: 1 addition & 1 deletion SmartcarAuth.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SmartcarAuth'
s.version = '5.3.1'
s.version = '5.4.1'
s.summary = 'Smartcar Authentication SDK for iOS written in Swift 5.'

s.description = <<-DESC
Expand Down
23 changes: 19 additions & 4 deletions SmartcarAuth/SCUrlBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
Bypass the brand selector screen to a specified make.

A list of compatible makes is available on the [Smartcar API Reference](https://smartcar.com/docs/api#connect-direct)
- see: [Smartcar Connect Direct](https://smartcar.com/docs/api#connect-direct)
A list of compatible makes is available on the [Smartcar API Reference](https://smartcar.com/docs/api-reference/makes)
- see: [Bypassing the Brand Screen Selection](https://smartcar.com/docs/connect/advanced-config/flows)
- parameters:
- make: The selected make
- returns:
Expand All @@ -114,7 +114,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Ensure the user only authorizes a single vehicle.

A user's connected service account can be connected to multiple vehicles. Setting this parameter to true forces the user to select only a single vehicle.
- see: [Smartcar Connect Match](https://smartcar.com/docs/api#connect-match)
- see: [Authorizing a Single Vehicle](https://smartcar.com/docs/connect/advanced-config/flows)
- parameters:
- singleSelect: Set to true to ensure only a single vehicle is authorized
- returns:
Expand All @@ -129,7 +129,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Specify the vin a user can authorize in Smartcar Connect.
When `setSingleSelect(...)` is set to true, this parameter can be used to ensure that Smartcar Connect will allow the user to authorize only the vehicle with a specific VIN.

- see: [Smartcar Connect Match](https://smartcar.com/docs/api#connect-match)
- see: [Authorizing a Single Vehicle](https://smartcar.com/docs/connect/advanced-config/flows)
- parameters:
- vin: The specific VIN to authorize
- returns:
Expand Down Expand Up @@ -157,6 +157,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
return self
}

/**
Specify a unique identifier for the vehicle owner to track and aggregate analytics across Connect sessions for each vehicle owner

- parameters:
- user An optional developer-defined unique identifier for a vehicle owner.
- returns:
A reference to this object
*/
public func setUser(user: String) -> SCUrlBuilder {
if (!user.isEmpty) {
self.queryItems.append(URLQueryItem(name: "user", value: user))
}
return self
}

/**
Build a Smartcar Connect authorization URL string
Expand Down
17 changes: 15 additions & 2 deletions SmartcarAuthTests/SCUrlBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SCUrlBuilderTests: XCTestCase {
let flags = ["country:DE", "flag:suboption"]
var testMode = false
var connectMode = SCMode.live
let user = "a60d61bb-3f7b-49bd-b7ec-bf1d87db0e47"

override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
Expand Down Expand Up @@ -155,8 +156,18 @@ class SCUrlBuilderTests: XCTestCase {
expect(urlWithState).to(equal(expectedUrl))
}

func testSCUrlBuilderSetUser() {
let expectedUrl = "https://connect.smartcar.com/oauth/authorize?client_id=" + clientId + "&response_type=code&mode=live&redirect_uri=" + redirectUri + "&scope=read_vehicle_info%20read_odometer&user=a60d61bb-3f7b-49bd-b7ec-bf1d87db0e47"

let urlWithState = SCUrlBuilder(clientId: clientId, redirectUri: redirectUri, scope: scope)
.setUser(user: user)
.build()

expect(urlWithState).to(equal(expectedUrl))
}

func testSCUrlBuilderSetAllSupportedParameters() {
let expectedUrl = "https://connect.smartcar.com/oauth/authorize?client_id=" + clientId + "&response_type=code&mode=simulated&redirect_uri=" + redirectUri + "&scope=read_vehicle_info%20read_odometer&state=" + state + "&approval_prompt=force&make=TESLA&single_select=true&single_select_vin=12345678901234567&flags=country:DE%20flag:suboption"
let expectedUrl = "https://connect.smartcar.com/oauth/authorize?client_id=" + clientId + "&response_type=code&mode=simulated&redirect_uri=" + redirectUri + "&scope=read_vehicle_info%20read_odometer&state=" + state + "&approval_prompt=force&make=TESLA&single_select=true&single_select_vin=12345678901234567&flags=country:DE%20flag:suboption&user=a60d61bb-3f7b-49bd-b7ec-bf1d87db0e47"
self.connectMode = SCMode.simulated

let urlWithState = SCUrlBuilder(clientId: clientId, redirectUri: redirectUri, scope: scope, mode: connectMode)
Expand All @@ -166,13 +177,14 @@ class SCUrlBuilderTests: XCTestCase {
.setSingleSelect(singleSelect: true)
.setSingleSelectVin(vin: vin)
.setFlags(flags: flags)
.setUser(user: user)
.build()

expect(urlWithState).to(equal(expectedUrl))
}

func testSCUrlBuilderSetAllParametersWithTestMode() {
let expectedUrl = "https://connect.smartcar.com/oauth/authorize?client_id=" + clientId + "&response_type=code&mode=simulated&redirect_uri=" + redirectUri + "&scope=read_vehicle_info%20read_odometer&state=" + state + "&approval_prompt=force&make=TESLA&single_select=true&single_select_vin=12345678901234567&flags=country:DE%20flag:suboption"
let expectedUrl = "https://connect.smartcar.com/oauth/authorize?client_id=" + clientId + "&response_type=code&mode=simulated&redirect_uri=" + redirectUri + "&scope=read_vehicle_info%20read_odometer&state=" + state + "&approval_prompt=force&make=TESLA&single_select=true&single_select_vin=12345678901234567&flags=country:DE%20flag:suboption&user=a60d61bb-3f7b-49bd-b7ec-bf1d87db0e47"
self.testMode = true
self.connectMode = SCMode.simulated

Expand All @@ -183,6 +195,7 @@ class SCUrlBuilderTests: XCTestCase {
.setSingleSelect(singleSelect: true)
.setSingleSelectVin(vin: vin)
.setFlags(flags: flags)
.setUser(user: user)
.build()

expect(urlWithState).to(equal(expectedUrl))
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Classes Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">SmartcarAuth 5.3.1 Docs</a> (61% documented)</p>
<p><a href="index.html">SmartcarAuth 5.4.1 Docs</a> (62% documented)</p>
<div class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -200,7 +200,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2023-11-30)</p>
<p>&copy; 2024 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2024-04-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/AuthorizationError.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="AuthorizationError Class Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">SmartcarAuth 5.3.1 Docs</a> (61% documented)</p>
<p><a href="../index.html">SmartcarAuth 5.4.1 Docs</a> (62% documented)</p>
<div class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -170,7 +170,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2023-11-30)</p>
<p>&copy; 2024 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2024-04-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/AuthorizationError/ErrorType.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="ErrorType Enumeration Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../../index.html">SmartcarAuth 5.3.1 Docs</a> (61% documented)</p>
<p><a href="../../index.html">SmartcarAuth 5.4.1 Docs</a> (62% documented)</p>
<div class="header-right">
<form role="search" action="../../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -276,7 +276,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2023-11-30)</p>
<p>&copy; 2024 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2024-04-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
43 changes: 37 additions & 6 deletions docs/Classes/SCUrlBuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="SCUrlBuilder Class Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">SmartcarAuth 5.3.1 Docs</a> (61% documented)</p>
<p><a href="../index.html">SmartcarAuth 5.4.1 Docs</a> (62% documented)</p>
<div class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -296,10 +296,10 @@ <h4>Return Value</h4>
<div class="abstract">
<p>Bypass the brand selector screen to a specified make.</p>

<p>A list of compatible makes is available on the <a href="https://smartcar.com/docs/api#connect-direct">Smartcar API Reference</a></p>
<p>A list of compatible makes is available on the <a href="https://smartcar.com/docs/api-reference/makes">Smartcar API Reference</a></p>
<div class="aside aside-see">
<p class="aside-title">See</p>
<a href="https://smartcar.com/docs/api#connect-direct">Smartcar Connect Direct</a>
<a href="https://smartcar.com/docs/connect/advanced-config/flows">Bypassing the Brand Screen Selection</a>

</div>

Expand Down Expand Up @@ -356,7 +356,7 @@ <h4>Return Value</h4>
<p>A user&rsquo;s connected service account can be connected to multiple vehicles. Setting this parameter to true forces the user to select only a single vehicle.</p>
<div class="aside aside-see">
<p class="aside-title">See</p>
<a href="https://smartcar.com/docs/api#connect-match">Smartcar Connect Match</a>
<a href="https://smartcar.com/docs/connect/advanced-config/flows">Authorizing a Single Vehicle</a>

</div>

Expand Down Expand Up @@ -412,7 +412,7 @@ <h4>Return Value</h4>
When <code><a href="../Classes/SCUrlBuilder.html#/c:@M@SmartcarAuth@objc(cs)SCUrlBuilder(im)setSingleSelectWithSingleSelect:">setSingleSelect(...)</a></code> is set to true, this parameter can be used to ensure that Smartcar Connect will allow the user to authorize only the vehicle with a specific VIN.</p>
<div class="aside aside-see">
<p class="aside-title">See</p>
<a href="https://smartcar.com/docs/api#connect-match">Smartcar Connect Match</a>
<a href="https://smartcar.com/docs/connect/advanced-config/flows">Authorizing a Single Vehicle</a>

</div>

Expand Down Expand Up @@ -501,6 +501,37 @@ <h4>Return Value</h4>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/c:@M@SmartcarAuth@objc(cs)SCUrlBuilder(im)setUserWithUser:"></a>
<a name="//apple_ref/swift/Method/setUser(user:)" class="dashAnchor"></a>
<a class="token" href="#/c:@M@SmartcarAuth@objc(cs)SCUrlBuilder(im)setUserWithUser:">setUser(user:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Specify a unique identifier for the vehicle owner to track and aggregate analytics across Connect sessions for each vehicle owner</p>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">setUser</span><span class="p">(</span><span class="nv">user</span><span class="p">:</span> <span class="kt">String</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">SCUrlBuilder</span></code></pre>

</div>
</div>
<div>
<h4>Return Value</h4>
<p>A reference to this object</p>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
Expand Down Expand Up @@ -539,7 +570,7 @@ <h4>Return Value</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2023-11-30)</p>
<p>&copy; 2024 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2024-04-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/SmartcarAuth.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="SmartcarAuth Class Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">SmartcarAuth 5.3.1 Docs</a> (61% documented)</p>
<p><a href="../index.html">SmartcarAuth 5.4.1 Docs</a> (62% documented)</p>
<div class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -372,7 +372,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2023-11-30)</p>
<p>&copy; 2024 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2024-04-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/VehicleInfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="VehicleInfo Class Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">SmartcarAuth 5.3.1 Docs</a> (61% documented)</p>
<p><a href="../index.html">SmartcarAuth 5.4.1 Docs</a> (62% documented)</p>
<div class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -170,7 +170,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2023-11-30)</p>
<p>&copy; 2024 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2024-04-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Enumerations Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">SmartcarAuth 5.3.1 Docs</a> (61% documented)</p>
<p><a href="index.html">SmartcarAuth 5.4.1 Docs</a> (62% documented)</p>
<div class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -114,7 +114,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2023-11-30)</p>
<p>&copy; 2024 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2024-04-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Enums/SCMode.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="SCMode Enumeration Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">SmartcarAuth 5.3.1 Docs</a> (61% documented)</p>
<p><a href="../index.html">SmartcarAuth 5.4.1 Docs</a> (62% documented)</p>
<div class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -174,7 +174,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2023 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2023-11-30)</p>
<p>&copy; 2024 <a class="link" href="https://github.com/smartcar/ios-sdk" target="_blank" rel="external noopener">Smartcar Inc.</a>. All rights reserved. (Last updated: 2024-04-01)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading

0 comments on commit 4ec6eb8

Please sign in to comment.