Skip to content

Commit

Permalink
Merge pull request #42 from stury/objc_to_swift_conversion
Browse files Browse the repository at this point in the history
Objc to swift conversion
  • Loading branch information
stury committed Jul 28, 2022
2 parents 429ffbe + d1fb1b5 commit e328e19
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 644 deletions.
12 changes: 5 additions & 7 deletions Example/Podfile.lock
@@ -1,10 +1,8 @@
PODS:
- OMGHTTPURLRQ/UserAgent (3.2.4)
- TDOAuth (1.4.0):
- TDOAuth/ObjC (= 1.4.0)
- TDOAuth/ObjC (1.4.0):
- TDOAuth/Swift
- TDOAuth/Swift (1.4.0):
- TDOAuth (1.6.0):
- TDOAuth/Swift (= 1.6.0)
- TDOAuth/Swift (1.6.0):
- OMGHTTPURLRQ/UserAgent

DEPENDENCIES:
Expand All @@ -20,8 +18,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
OMGHTTPURLRQ: 9ac96bdf5c90a33f75836630729ea1adc312a9ed
TDOAuth: 0e97e457c75b1da7644f0ee7a45b2d9f0bb8be6c
TDOAuth: e0ee7853a7f5ee8614bf8b15763fba0837bf156c

PODFILE CHECKSUM: 723c3a58be002020721462a9d5959c71505c58b8

COCOAPODS: 1.9.1
COCOAPODS: 1.11.3
14 changes: 9 additions & 5 deletions Example/TDOAuth.xcodeproj/project.pbxproj
Expand Up @@ -518,7 +518,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1130;
LastUpgradeCheck = 1130;
LastUpgradeCheck = 1330;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
Expand Down Expand Up @@ -945,6 +945,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -970,7 +971,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1002,6 +1003,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -1020,7 +1022,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down Expand Up @@ -1124,7 +1126,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 11.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Debug;
};
Expand All @@ -1149,7 +1151,7 @@
SDKROOT = appletvos;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 11.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Release;
};
Expand All @@ -1165,6 +1167,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = "TDOAuth-macOS/TDOAuth_macOS.entitlements";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand Down Expand Up @@ -1194,6 +1197,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = "TDOAuth-macOS/TDOAuth_macOS.entitlements";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1330"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -57,7 +57,7 @@
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/TDOAuth-iOS">
RemotePath = "/$(PRODUCT_NAME)">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FCC06849241C1CAD004997C8"
Expand All @@ -76,7 +76,7 @@
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/TDOAuth-iOS">
RemotePath = "/$(PRODUCT_NAME)">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FCC06849241C1CAD004997C8"
Expand Down
23 changes: 15 additions & 8 deletions Example/Tests/Compat.m
Expand Up @@ -2,7 +2,7 @@
// Licensed under the terms of the MIT license. See LICENSE file in https://github.com/yahoo/TDOAuth for terms.

#import <XCTest/XCTest.h>
#import <TDOAuth/TDOAuth.h>
@import TDOAuth;
#import "TDOAuth_Tests-Swift.h"

@interface ObjcCompatSpec : XCTestCase @end
Expand Down Expand Up @@ -216,7 +216,8 @@ - (void)testPostUrlParameters
NSURLRequest *postRequest = [self.class makePostRequestWithDataEncoding:TDOAuthContentTypeUrlEncodedQuery];

NSString *url = [[postRequest URL] absoluteString];
XCTAssert([url isEqualToString:@"http://api.example.com/service?foo=bar&baz=bonk"],
// In Swift, the order of the key:value pair is undetermined, so either result is correct.
XCTAssert([url isEqualToString:@"http://api.example.com/service?foo=bar&baz=bonk"] || [url isEqualToString:@"http://api.example.com/service?baz=bonk&foo=bar"],
"url does not match expected value");

NSString *contentType = [postRequest valueForHTTPHeaderField: @"Content-Type"];
Expand Down Expand Up @@ -246,9 +247,10 @@ - (void)testHeadUrl
NSURLRequest *headRequest = [self.class makeGenericRequestWithHTTPMethod:@"HEAD"];

NSString *url = [[headRequest URL] absoluteString];
XCTAssert([url isEqualToString:@"http://api.example.com/service?foo=bar&baz=bonk"],
// In Swift, the order of the key:value pair is undetermined, so either result is correct.
XCTAssert([url isEqualToString:@"http://api.example.com/service?foo=bar&baz=bonk"] || [url isEqualToString:@"http://api.example.com/service?baz=bonk&foo=bar"],
"url does not match expected value");

NSString *contentType = [headRequest valueForHTTPHeaderField: @"Content-Type"];
XCTAssertNil(contentType,
@"Content-Type was present when not expected)");
Expand All @@ -264,7 +266,9 @@ - (void)testDeleteUrl
NSURLRequest *deleteRequest = [self.class makeGenericRequestWithHTTPMethod:@"DELETE"];

NSString *url = [[deleteRequest URL] absoluteString];
XCTAssertEqualObjects(url, @"http://api.example.com/service?foo=bar&baz=bonk",
// Swift does not guarantee order for keys in a dictionary. Test both possibilities here.
XCTAssert([url isEqualToString:@"http://api.example.com/service?foo=bar&baz=bonk"] ||
[url isEqualToString:@"http://api.example.com/service?baz=bonk&foo=bar"],
"url does not match expected value");

NSString *contentType = [deleteRequest valueForHTTPHeaderField: @"Content-Type"];
Expand Down Expand Up @@ -388,7 +392,9 @@ - (void)testGenericJson

NSData *body = [genericRequest HTTPBody];
NSString *bodyString = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
XCTAssert([bodyString isEqualToString:@"{\"foo\":\"bar\",\"baz\":\"bonk\"}"],
// In Swift, you are not guaranteed key order, so we need to check both variants here.
XCTAssert([bodyString isEqualToString:@"{\"foo\":\"bar\",\"baz\":\"bonk\"}"] ||
[bodyString isEqualToString:@"{\"baz\":\"bonk\",\"foo\":\"bar\"}"],
"body expected to be JSON object");

}
Expand Down Expand Up @@ -586,8 +592,9 @@ - (void)testGetURLEncoding {
accessToken:@"ijkl"
tokenSecret:@"mnop"];
NSString *url = [[getRequest URL] absoluteString];
XCTAssertEqualObjects(url, @"http://api.example.com/service/%5CsubDirectoryWithBackslash?foo=bar&baz=bonk",
"url does not match expected value");
// In Swift, the order of the key:value pair is undetermined, so either result is correct.
XCTAssert([url isEqualToString:@"http://api.example.com/service/%5CsubDirectoryWithBackslash?foo=bar&baz=bonk"] || [url isEqualToString:@"http://api.example.com/service/%5CsubDirectoryWithBackslash?baz=bonk&foo=bar"],
"url does not match expected value");

NSString *authHeader = [getRequest valueForHTTPHeaderField:@"Authorization"];
NSString *expectedHeader = @"OAuth oauth_token=\"ijkl\", "\
Expand Down
30 changes: 1 addition & 29 deletions Package.swift
Expand Up @@ -14,44 +14,16 @@ let package = Package(
.library(
name: "TDOAuth",
targets: ["TDOAuth"]),
.library(
name: "TDOAuthSwift",
targets: ["TDOAuthSwift"]),
],
dependencies: [
.package(url: "https://github.com/mxcl/OMGHTTPURLRQ.git", .upToNextMajor(from: "3.3.0"))
],
targets: [
.target(
name: "TDOAuth",
dependencies: [
"TDOAuthCompat"
],
path: "Source/compat",
exclude: [
"Compat.swift"
],
publicHeadersPath: "."),
.target(
name: "TDOAuthCompat",
dependencies: [
"TDOAuthSwift"
],
path: "Source/compat",
exclude: [
"TDOAuth.h",
"TDOAuth.m"
]),
.target(
name: "TDOAuthSwift",
dependencies: [
"OMGHTTPURLRQ"
],
path: "Source",
exclude: [
"compat/TDOAuth.h",
"compat/TDOAuth.m",
"compat/Compat.swift"
]),
path: "Source"),
]
)
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -27,7 +27,7 @@ pod 'TDOAuth'

### SwiftPM

Add `.package(url: "https://github.com/yahoo/TDOAuth.git", from: "1.5.0")` to your `package.swift`
Add `.package(url: "https://github.com/yahoo/TDOAuth.git", from: "1.6.0")` to your `package.swift`

## Usage (Swift)

Expand Down Expand Up @@ -130,7 +130,7 @@ While the Swift API simply signs whatever `URLRequest` you provide it, the Objec

Objective-C API Example
```objc
#import <TDOAuth/TDOAuth.h>
@import TDOAuth;

NSURLRequest * request = [TDOAuth URLRequestForPath:@"/v1/service/name"
parameters:@{ "count": @10, "format": "json" }
Expand Down
File renamed without changes.
6 changes: 1 addition & 5 deletions Source/compat/Compat.swift
Expand Up @@ -3,13 +3,9 @@

import Foundation

#if SWIFT_PACKAGE
import TDOAuthSwift

@objc public enum TDOAuthSignatureMethod: Int {
case hmacSha1, hmacSha256
}
#endif

@objc public class TDOAuthCompat: NSObject {

Expand All @@ -20,7 +16,7 @@ import TDOAuthSwift
consumerSecret: String,
accessToken: String?,
tokenSecret: String?,
signatureMethod: TDOAuthSignatureMethod) -> URLRequest? {
signatureMethod: TDOAuthSignatureMethod) -> URLRequest! {


let hmacAlgo: HmacAlgorithm
Expand Down

0 comments on commit e328e19

Please sign in to comment.