Skip to content
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

Add "Create a List" method #7

Merged
merged 11 commits into from
Mar 29, 2022
Merged

Conversation

emin-grbo
Copy link
Contributor

Create List method was lacking from the "Manage Lists" group.
https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/introduction

Not sure If this is the correct way to do it, but I tried to follow the same approach as for some other similar methods I saw inside Twift.

@daneden Note 👇
The main concern on my end is: "How do I test this?" 😅
So far I've only worked on personal packages and changing branches was easy 👌 However, when contributing I do not know how to test it without having to do quite a bit of duplication 😅

@emin-grbo emin-grbo changed the title Add create a list method Add "Create a List" method Mar 18, 2022
@@ -262,6 +262,13 @@ public struct DeleteResponse: Codable {
public let deleted: Bool
}

/// A response object pertaining to list created
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type definition should probably live in Twift+Lists.swift instead of Twift+Tweets.swift

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, did not even pay attention to the file I was in. Just saw deletedResponse and thought they would fit nicely together 😂

@@ -262,6 +262,13 @@ public struct DeleteResponse: Codable {
public let deleted: Bool
}

/// A response object pertaining to list created
public struct CreatedListResponse: Codable {
/// If the returned response object contains an id and the name of your List, you have successfully created the List.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc comment will only appear when authors look up the id attribute; you should add doc comments specific to each property and add this comment as a description on the type itself

/// - Parameters:
/// - name: List name (required)
/// - description: Description for the list (optional)
/// - private: true or false (optional)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a nit, but “true or false” is not a super helpful comment when people can see the accepted type is Bool. Try to describe the meaning of the field, e.g. Whether the list is private to the authenticated user or publicly viewable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not used to writing these types of comments but I did pause for a second and thought if I need more context here.

It so makes sense not to mention true/false if they already see a type.
I hope to get better at this 🤞

Comment on lines 117 to 118
"description": description ?? "",
"private": isPrivate ?? false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already have default values for description and isPrivate, you don't need to do this nullish coalescing. Just make the types for the arguments non-optional.

Copy link
Owner

@daneden daneden Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, making description optional does make sense

@daneden
Copy link
Owner

daneden commented Mar 21, 2022

The main concern on my end is: "How do I test this?" 😅

This is a concern for me too! I don’t yet have a solid testing approach other than adding methods to a test SwiftUI app I have in a private repo. I will plan to stub a new issue specifically to set up a testing suite and strategy.

@emin-grbo emin-grbo requested a review from daneden March 21, 2022 21:50
Comment on lines 129 to 130
/// - id: If the returned response object contains an id, response is considered successfull
/// - name: If List name was returned, response is considered successfull
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments should be written directly above their respective struct properties so that they show up in Xcode’s quick help and the generated GitHub wiki docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, had no idea 😅

}

/// A response object pertaining to list created
/// - Returns:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since this is a struct and not a function, Returns isn’t accurate and can be removed

/// - Returns:
/// - id: If the returned response object contains an id, response is considered successfull
/// - name: If List name was returned, response is considered successfull
public struct CreatedListResponse: Codable {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct shouldn’t be a member of the Twift class; I’d pull it out from being nested inside the class and put it at the root of this file, along with PinnedResponse

@daneden daneden mentioned this pull request Mar 26, 2022
10 tasks
@emin-grbo
Copy link
Contributor Author

FYI, I really appreciate you being patient with all these explanations 🙌
Everything makes sense and I am learning new stuff about documentation. Never was "too" careful/knowledgeable there, mostly just "lemme plant a comment right there" 😂

I will take note of all this in the future as not to have some repeated issues 👌

Sources/Twift+Lists.swift Outdated Show resolved Hide resolved
/// A response object pertaining to list created
public struct CreatedListResponse: Codable {
/// If returned response object contains an id, response is considered successfull
public let id: Int
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be typed as List.ID

@daneden
Copy link
Owner

daneden commented Mar 27, 2022

Of course, thanks for your patience with the reviews and revisions! This is helpful for informing contribution guidelines too.

Co-authored-by: Daniel Eden <dan.eden@me.com>
@daneden
Copy link
Owner

daneden commented Mar 27, 2022

@roblack FYI I just updated the main branch to include a demo app; you can use that to test your changes! Feel free to also provide feedback on the demo app since it’s a bit rough-and-ready (just copied from my own sandbox).

Sources/Twift+Lists.swift Outdated Show resolved Hide resolved
Co-authored-by: Daniel Eden <dan.eden@me.com>
@emin-grbo
Copy link
Contributor Author

Oh that is awesome! Will check it out and report back once tested. 🙌
I guess all future PRs should have a "did test in the sandbox app" kinda checkbox? 😅

@daneden
Copy link
Owner

daneden commented Mar 27, 2022

I guess all future PRs should have a "did test in the sandbox app" kinda checkbox? 😅

Yah I’m wondering whether Xcode can drive UI tests in the demo app as a way to test library methods. I have some research to do!

@emin-grbo
Copy link
Contributor Author

Cannot launch the demo app. Seems some files failed to upload?
image

image

Not sure if you want me to post these under issues, not to mix with this PR?

@daneden
Copy link
Owner

daneden commented Mar 27, 2022

@roblack ah, the error for preview content may be legit but you should check the readme in the demo app folder to resolve the Secrets error 😇

@emin-grbo
Copy link
Contributor Author

@daneden I kinda thought "secrets" might be something used "per user", especially after seeing some new fields in the plist file. 🤦‍♂️

I definitely need to take the blindfold off as currently I just do what the comment is and don't really "inspect" things properly. Not sure if this is making sense, but it is to me 😂 Need to be more pro-active!

@daneden
Copy link
Owner

daneden commented Mar 28, 2022

@roblack I managed to fix a couple of issues in the demo app so it should build now (maybe after a clean build folder). I'm adding some custom warnings to make it easier to resolve issues too. Thanks for the feedback!

@emin-grbo
Copy link
Contributor Author

@daneden HOLLY SHIZZ MAN! 🙌 That app looks/works so good, i love it!

2 notes:

  1. Did not know .env is hidden. It was a fairly easy guess so I am sure people would manage, but my thinking is that this library will be used quite a bit by "entry level" people. I am not too advanced myself as well 😂
    So, adding something like "show hidden files with cmnd+shift+." would help.

  2. URL scheme needs to be changed as well in order for an app to work. Could this be placed in the Secrets file as well? As I am guessing Secrets is not touched by git, so changing the schemes myself would register it in the git and then possibly mess up when someone updates the repo from the origin?

Btw, the "Secrets" thing approach with the .env file is just EPIC, love it!

@daneden
Copy link
Owner

daneden commented Mar 29, 2022

@roblack good catch on the URL scheme, added that to the .env.example and README.

Btw, the "Secrets" thing approach with the .env file is just EPIC, love it!

Thanks! Took me a while to figure out a safe way to simplify setup while avoiding accidentally checking in secrets 😅 still not 100% happy with it but it works.

@emin-grbo
Copy link
Contributor Author

Btw I lost track if this PR is good to go?

@daneden
Copy link
Owner

daneden commented Mar 29, 2022

Just tested locally and made one small change 😊 it's a small thing, but the Twitter v2 API doesn’t accept requests to paths with trailing slashes, so POST /2/lists/ results in an error, whereas POST /2/lists does not. Committed to your branch directly, so now it’s good to go!

@daneden daneden merged commit 3eac87d into daneden:main Mar 29, 2022
@emin-grbo
Copy link
Contributor Author

Oh wow, good to know! 🙌 Thank you!

@emin-grbo emin-grbo deleted the add-create-list branch June 16, 2022 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants