-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ported TraktKit to tvOS #36
base: master
Are you sure you want to change the base?
Conversation
Converted frameworks to Universal frameworks Added test for tvOS and macOS
Please wait to merge. I have a couple of issues coming from bad copy&paste. Also I am cleaning it a bit from my comments |
@@ -40,7 +40,7 @@ public class MLKeychain { | |||
let keychainQuery: [String: Any] = [ | |||
kSecClassValue: kSecClassGenericPasswordValue, | |||
kSecAttrAccountValue: key, | |||
kSecReturnDataValue: kCFBooleanTrue, | |||
kSecReturnDataValue: kCFBooleanTrue!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why I have been told by Xcode to fix this one. It was working a year ago I suppose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to look into this some. I'd love to avoid any force unwraps.
…ktKitMacOS (removed TraktKitMacOS-tests)
Ok, it should be fine, now. I forgot to mention that I also added the methods "getDeviceCode" and "getTokenFromDeviceCode", useful to login with a code (to insert via a web browser after authenticating). All tests are working, just giving a warning because I deprecate "set()" as explained above. Also it has been "ported" by Xcode to Swift 5.0 (Xcode made no changes to the source code). |
if #available(iOSApplicationExtension 11.3, *) { | ||
#if DEBUG | ||
print("[\(#function)] Security result error code is: \(String(SecCopyErrorMessageString(status, nil) ?? "UNKNOWN"))") | ||
#endif | ||
} else { | ||
// Fallback on earlier versions | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
public func setOauth2RedirectURL(withClientID: String, clientSecret secret: String, redirectURI: String, staging: Bool = false) { | ||
self.clientID = withClientID | ||
self.clientSecret = secret | ||
self.redirectURI = redirectURI | ||
|
||
self.staging = staging | ||
|
||
self.baseURL = !staging ? "trakt.tv" : "staging.trakt.tv" | ||
self.APIBaseURL = !staging ? "api.trakt.tv" : "api-staging.trakt.tv" | ||
self.oauthURL = URL(string: "https://\(baseURL!)/oauth/authorize?response_type=code&client_id=\(withClientID)&redirect_uri=\(redirectURI)") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be reverted. set
could use a better signature but I'm iffy on setOauth2RedirectURL
, this can be a different PR / change to the tvOS support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no problem. I just wanted to give it a different name because "set" was a bit too generic.
public var deviceCode: String? | ||
public var userCode: String? | ||
public var verificationURL: String? | ||
public var timeInterval: TimeInterval? | ||
public var expiresIn: TimeInterval? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to look into the API some more before I know if a struct would be better than the variables kept in this class. I would recommend adding more documentation from the Trakt API to define all of these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I had looked into that. I wasn't sure either. But I needed them to make the authorization functions working on tvOS.
@@ -16,13 +16,15 @@ public struct User: Codable { | |||
public let name: String? | |||
public let isVIP: Bool? | |||
public let isVIPEP: Bool? | |||
// public let ids: ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes should be reverted, I just merged a PR that added support for this.
@@ -40,7 +40,7 @@ public class MLKeychain { | |||
let keychainQuery: [String: Any] = [ | |||
kSecClassValue: kSecClassGenericPasswordValue, | |||
kSecAttrAccountValue: key, | |||
kSecReturnDataValue: kCFBooleanTrue, | |||
kSecReturnDataValue: kCFBooleanTrue!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to look into this some. I'd love to avoid any force unwraps.
} | ||
|
||
|
||
let urlString = "https://\(baseURL!)/oauth/device/code" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid force unwrapping.
if let deviceCodeDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: AnyObject] { | ||
|
||
welf.deviceCode = deviceCodeDict["device_code"] as? String | ||
welf.userCode = deviceCodeDict["user_code"] as? String | ||
welf.verificationURL = deviceCodeDict["verification_url"] as? String | ||
welf.timeInterval = deviceCodeDict["interval"] as? TimeInterval | ||
welf.expiresIn = deviceCodeDict["expires_in"] as? TimeInterval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think decoding into an object would be preferable to this old way of decoding JSON
return | ||
} | ||
|
||
let urlString = "https://\(baseURL!)/oauth/device/token" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
force unwrap
override func setUp() { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
|
||
// In UI tests it is usually best to stop immediately when a failure occurs. | ||
continueAfterFailure = false | ||
|
||
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. | ||
XCUIApplication().launch() | ||
|
||
// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. | ||
} | ||
|
||
override func tearDown() { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testExample() { | ||
// Use recording to get started writing UI tests. | ||
// Use XCTAssert and related functions to verify your tests produce the correct results. | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this default code can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly don't remember. Probably, I think I just added the tests for the two platforms, but I didn't really look at the code.
override func setUp() { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
override func tearDown() { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testExample() { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct results. | ||
} | ||
|
||
func testPerformanceExample() { | ||
// This is an example of a performance test case. | ||
self.measure { | ||
// Put the code you want to measure the time of here. | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Sorry for the wait on this. I became pretty burnt out. I'll try to be more active when I can. |
Yeah, I am pretty busy myself, now. Working online from home. Also I didn't touch the project for quite a long time. IB for tvOS went banana with Xcode 11. So how does it work? Should I apply the changes requested and update? |
@Michelasso if you can, yes. Resolve the conflicts, and address comments. No rush though |
Converted frameworks to Universal frameworks
Added test for tvOS and macOS
I have also changed a couple of other things. For example I couldn't fetch the avatars, the "user" structure (If I remember correctly. I had actually changed it nearly a year ago and ported the change to this new fork). needed to be more nested.
Also I renamed "set" to "setOauth2RedirectURL", just deprecating the old "set". But I can revert it if you don't like the new name, it just made more sense to me.
Now with Universal Frameworks one just need to add
import TraktKit
no matter the OS type. Thanks to this now all tests are common for iOS, tvOS and macOS (same source files, I just added the targets) and most important, they all succeeded. Also the prototype app I was developing compiled and run without any issue (and using all my modifications).
This is more or less the same work I did for TheMovieDatabaseSwiftWrapper, which has been merged months ago.
Last thing: I had also modified "getUserWatchedHistory" adding the pagination, but when I ported my old function it gave an error compiling. Also I am a bit lost, because I see there is a "getHistory". Are they any different (I have checked the Trakt TV APIs and I must have missed "getHistory")? Should I make a new pull request (after this one) to add the pagination in "getUserWatchedHistory"?