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

Tagging API Calls #40

Merged
merged 7 commits into from
Apr 9, 2024
Merged

Tagging API Calls #40

merged 7 commits into from
Apr 9, 2024

Conversation

aklarfeld
Copy link
Contributor

@aklarfeld aklarfeld commented Apr 8, 2024

Description: Tags are able to be passed into the initialization function, or within a context, and then applied to a set of API calls.

There are currently two ways to tag API calls:

  1. Simply pass the tags on initialization, e.g.
   Supergood.init(
      {
        config: { ...SUPERGOOD_CONFIG, allowLocalUrls: true },
        clientId: SUPERGOOD_CLIENT_ID,
        clientSecret: SUPERGOOD_CLIENT_SECRET,
        tags: {
          customTag: 'customValue'
        }
      },
      SUPERGOOD_SERVER
    );
  1. Open up a context for specific API calls, to tag:
      Supergood.withTags({ userId: '123-34-5678' }, async () => {
        const balanceResponse = await client.accountsBalanceGet({
          access_token: ACCESS_TOKEN,
        });
        prettyPrintResponse(balanceResponse);
        response.json(balanceResponse.data);
      })
  • Unit Tests pass on 4/9/24
  • Manual Tests by Alex Klarfeld performed on 4/9/24
  • Test Results: Pass
  • Approved & Reviewed by: Steven Bunting & Josiah Roberts on 4/9/24

@josiah-roberts
Copy link
Collaborator

What happens if we enter a Supergood context multiple times?

      Supergood.init({ tags: { workload: 'backend' } });
      
      Supergood.withContext({ trip: 'in-n-out' }, async () => {
        await Supergood.withContext({ task: 'drive-there' }, async () => {
          await driveThereHttp();
        });
        await Supergood.withContext({ task: 'order' }, async () => {
          await orderHttp();
        });
      })

I think you'd want to merge, but you may have to manage that behavior specifically.

@aklarfeld
Copy link
Contributor Author

What happens if we enter a Supergood context multiple times?

      Supergood.init({ tags: { workload: 'backend' } });
      
      Supergood.withContext({ trip: 'in-n-out' }, async () => {
        await Supergood.withContext({ task: 'drive-there' }, async () => {
          await driveThereHttp();
        });
        await Supergood.withContext({ task: 'order' }, async () => {
          await orderHttp();
        });
      })

I think you'd want to merge, but you may have to manage that behavior specifically.

Good call. I just fixed this and added some tests.

@josiah-roberts
Copy link
Collaborator

One other nit; withContext might be withTags. Just to avoid creating more names of things, given it's called tags in config.

@aklarfeld
Copy link
Contributor Author

One other nit; withContext might be withTags. Just to avoid creating more names of things, given it's called tags in config.

Yeah it's a fair nit, fixing now!

@aklarfeld aklarfeld merged commit 6b6b327 into master Apr 9, 2024
5 checks passed
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