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

Cannot get instance of some entities with valid client without making an api request #82

Closed
G-Rath opened this issue Mar 11, 2021 · 1 comment

Comments

@G-Rath
Copy link
Contributor

G-Rath commented Mar 11, 2021

(This is my first dive into Go, so I'm sure my terminology is wrong - please correct me where that's the case so I can learn ☺)

I'm working on making a custom Terraform provider for interacting with Trello, and am using this library for the underlying api calls.

This has been really good so far - while some of the API is missing methods, the exposure of the underlying CURD methods has made it super easy to implement support without needing to make changes to this library.

My plan is at some point contribute back to this library with some PRs expanding it to cover these gaps, but I've hit up against a particular issue that would be great to get addressed now - specifically, not being able to set the client property on structs.

For example, I'm currently in the process of writing a card_membership resource that uses the "Add a Member to a Card" and "Remove a User from a Card" endpoints to add and remove a member with a given id to and from the card with a given id.

Presently, the card package has AddMemberID & RemoveMember which calls these underlying endpoints - however they use the private client property on the card which I can't set, meaning the only way I can get an instance of trello.Card that won't crash if I try to use card.RemoveMember is by doing an API call like so:

func resourceTrelloCardMembershipDelete(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
	client := meta.(*trello.Client)

	card, err := client.GetCard(data.Get("card_id").(string), trello.Defaults())

	if err != nil {
		return diag.FromErr(err)
	}

	err = card.RemoveMember(data.Get("member_id").(string))

	if err != nil {
		return diag.FromErr(err)
	}

	var diags diag.Diagnostics

	return diags
}

What I'd like to be able to do is this:

func resourceTrelloCardMembershipDelete(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
	client := meta.(*trello.Client)

	card := trello.Card{ID: data.Get("card_id").(string)}

	card.SetClient(client)

	err := card.RemoveMember(data.Get("member_id").(string))

	if err != nil {
		return diag.FromErr(err)
	}

	var diags diag.Diagnostics

	return diags
}

Alternatively, client could be made public so that I can set that property when assigning.

This applies to most of the entities in this library, including Board as NewBoard doesn't assign client.

I'm happy to have a go at doing a PR that implements SetClient, but wanted to open an issue first as there might be a more Go-like solution that should be used :)

@adlio
Copy link
Owner

adlio commented Mar 28, 2021

Thanks for the background and request @G-Rath. I've just pushed v1.9.0 which adds a SetClient() method on Board, Card, and List.

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

No branches or pull requests

2 participants