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

Upgrade to Webflow API v2 #23

Closed
wants to merge 11 commits into from
Closed

Upgrade to Webflow API v2 #23

wants to merge 11 commits into from

Conversation

vfonic
Copy link
Contributor

@vfonic vfonic commented Nov 14, 2023

Hi @penseo!

I've spent some time to upgrade the client to Webflow API v2. I've also added a few gems to help with development and testing.
I've fixed and re-recorded all VCR cassettes of all the tests so that they all pass.

Let me know how you'd like to proceed?
Should I fork the gem, call it differently and publish it to RubyGems under a new name or can you have a look or can you make me a maintainer?

Seems like the command to add a maintainer to be able to push to RubyGems is gem owner [GEM NAME] --add [USER EMAIL]

My RubyGems email is viktor.fonic [at] gmail.com

Thanks!
Viktor

vfonic added 10 commits May 23, 2023 14:49
- update GitHub action
- Move TEST_API_TOKEN from codebase
- Add 'rubocop' and 'rubocop-minitest' gems
- Setup default Rake task to run both RuboCop and minitest tests
- Fix a few client issues; Don't rely on ActiveSupport's `Array.wrap`
- Fix all tests
- Fix error class
@phoet
Copy link
Contributor

phoet commented Nov 14, 2023

Hi Viktor,

I will try to review this as soon as possible and add you as a maintainer so that you can publish a new mayor version.

Maybe there is a way to support both API versions?

Cheers

@phoet
Copy link
Contributor

phoet commented Nov 14, 2023

Ah, I'm actually no longer maintainer of this repo 😸 Let @sega handle it.


require 'webflow'

TEST_API_TOKEN = '1f0da5c9368af9cb2dcd65d22a6600a8ffa069f70729e129a09787203bc2c2be'
Copy link
Contributor

Choose a reason for hiding this comment

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

This is intentional, dont remove the test token. Use it as a fallback throughout.

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 couldn't get a single API query to return anything other than:

/Users/viktor/Developer/gems/webflow-ruby/lib/webflow/client.rb:152:in `request': Request not authorized (Webflow::Error)

That's why I left it to the user (developer) to pass in their own working API token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the use of the token that doesn't work?

Copy link
Contributor

Choose a reason for hiding this comment

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

hm, looks like it has vanished... 🤷 at least i fixed my blog while looking for it 😆

result
end

def update_item(collection_id, item_id, data, is_archived: false, is_draft: false, publish: false) # rubocop:disable Metrics/ParameterLists
Copy link
Contributor

Choose a reason for hiding this comment

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

increase the limit or disable this rule instead please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, this rule has those limitations for a reason.
https://docs.rubocop.org/rubocop/cops_metrics.html#metricsparameterlists

I believe the default limit of 5 is a good limit, maybe even too generous/high. It was only disabled here in one place. I find that to be better than increasing the limit globally to 6, which makes this rule's function almost useless, and allows developers to easily add one more argument, as there's no "warning" about having too many arguments.
https://thoughtbot.com/blog/sandi-metz-rules-for-developers#four-method-arguments

I think disabling rules inline is fine. It stands right there in the code, in your face, so that you can see it and try to figure out a way to refactor your code so that you can remove the inline disable.

But if you really have strong opinion, perhaps we could add CountKeywordArgs: false and we could remove the inline disable?

Copy link
Contributor

Choose a reason for hiding this comment

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

i dislike 90% of the preconfigured rubocop rules, so please ignore me if you feel different about it. i just really hate cluttering the code for a tool. that should generally be forbidden.

end

def create_item(collection_id, data, live: false)
post("/collections/#{collection_id}/items", {fields: data}, live: live)
def delete_item(collection_id, item_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

delete_and_unpublish then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it's deleted, it's pretty much unpublished, since it's actually gone. This is Webflow API internal bug that we cannot fix. And this is an implementation detail of how delete_item works. I don't think the user of webflow-ruby needs to know all the workarounds we need to implement. They just want to know the API & methods of the gem so that they can use them. delete_item to me sounds much clearer than delete_and_unpublish.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, that's probably true. as long as the underlying primites are still exposed and one can implement something more custom i'm fine with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhh, I see...
I wasn't keeping in consideration supporting the underlying low-level API access.

In this case, we lost the original "delete item" low-level API access.
Since it wasn't working as expected in the first place, I'm not sure if we really lost anything?
I "lost" a lot of time debugging and figuring out why items with publish: true (ex live: true) aren't visible on the live site. The (still not fixed) Webflow bug causes changes to not being published anymore for any updates to any items, after the buggy "delete item" request is made.

I'm just thinking of the use-case where someone might need the low-level access to the API? Perhaps if there's more functionality added to the API and the gem doesn't get updated regularly / on time.

Should we just expose the access to request and add a comment saying that it's a low-level API and there most likely exists a higher-level method that can be used instead?

Or if you want to add low-level (buggy) delete_item, I'd vote for keeping the working, higher-level delete_item as-is and add a new method delete_item_single / delete_item_raw / delete_item_something with the comment explaining why there are two methods and which one works / is recommended to be used.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

just re-reading the documentation and your comments, i think this should definitively be an additional method.

is it correct that delete_item works fine if you publish the site afterwards? bc, that is what i would have expected in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Publishing a website is discouraged and has a special very low limit of 1 call every 60 seconds:
https://developers.webflow.com/changelog/publish-site-api-new-rate-limits

It's also not the same as publishing a single item (whether it's create, update or delete). Publishing, publishes all of the pending work in design + pending collection items.

But you're right that we are missing "mark for deletion" (delete, pending).
It's tricky to test delete pending as I'm not sure whether it would work or the mentioned bug would happen. The issue is that, if I remember correctly, the API returns everything as it should be, but on your actual Webflow site, you can see that the new changes are not being applied. So it's impossible to write an automated test to test this (the automated test would have to navigate to a Webflow site and check that there's no such item on the page).

If you have time please take over and feel free to look into this and add the missing functionality.
Otherwise, I can add a comment about delete pending missing in the gem and invite people to add it if someone needs it. Unfortunately, I don't have the time right now to look into this buggy functionality and try to figure out in which cases it works in which cases it doesn't.

Copy link
Contributor

Choose a reason for hiding this comment

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

i dont really understand the webflow API versioning here, is the "v2 BETA" before or after "v2"? well at least there is another method for delete and publish https://docs.developers.webflow.com/v2.0.0-beta/reference/delete-item-live

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 think it started as API v2 beta and then they released API v2 and "forgot" to update API v2 beta to API beta or API v3 beta.

I totally missed that they've added these live methods for create, update, and delete. I assume this will be a part of API v3.

When they launch API v3, I'll try to keep the gem updated.

@vfonic
Copy link
Contributor Author

vfonic commented Nov 14, 2023

Hey @phoet thanks for the review! I replied to your comments.
I feel like there's nothing to be changed in the code, but please have a look and let me know.
I thought through all of the changes I've made and each change was done for a reason.

@vfonic
Copy link
Contributor Author

vfonic commented Nov 15, 2023

Maybe there is a way to support both API versions?

API v1 is legacy:
https://docs.developers.webflow.com/reference/designer-api-reference

So I don't see the need to support it.
Who needs legacy support, can use < v2 version of this gem.

@vfonic
Copy link
Contributor Author

vfonic commented Nov 21, 2023

Hey @phoet, how's it going? Let me know if you're waiting for anything from my side.

Re live parameters / endpoints, those are on unstable API so I wouldn't add those to this version.

Re rubocop directives, I can remove those, maybe switch to standardrb...

@phoet
Copy link
Contributor

phoet commented Nov 23, 2023

@vfonic I already pointed out that I'm no longer maintainer in this repo, someone else like @sega needs to handle this stuff

@vfonic
Copy link
Contributor Author

vfonic commented Nov 28, 2023

Hey @sega, do you have any time to look into this?

@vfonic
Copy link
Contributor Author

vfonic commented Dec 5, 2023

I figured it's gonna be easier if I just release this as a new gem. I've refactored / rewritten many parts of the gem and made it more opinionated. It no longer aligns with the webflow-ruby philosophy of providing the "bare metal", it's much more opinionated now (for better or for worse).

Perhaps webflow-ruby should stay the way it is.

The idea of the new gem webflow-rb is to offer higher level API so that it can just be used.
There are PROs and CONs to this like to everything else.

@vfonic vfonic closed this Dec 5, 2023
@phoet
Copy link
Contributor

phoet commented Dec 5, 2023

Sorry that you got no reply from anyone in the @penseo org! Thanks for taking the time trying to contribute to upstream.

@phoet
Copy link
Contributor

phoet commented Dec 5, 2023

Bildschirmfoto 2023-12-05 um 21 36 07

0 public Members 😆

@vfonic
Copy link
Contributor Author

vfonic commented Dec 5, 2023

horatio

@phoet
Copy link
Contributor

phoet commented Dec 5, 2023

I happen to know that they have at least 2 programmers on staff. 🤷

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.

None yet

2 participants