Skip to content
This repository was archived by the owner on Sep 8, 2023. It is now read-only.

Conversation

@aleclarson
Copy link
Contributor

I decided to rewrite this package to use class composition and return errors instead of throwing them. I also made it tree-shakeable, even though it wasn't a necessity.

Anyway, I probably won't ever get time to finish this, but thought it would be cool to share, in case anyone else had similar needs and wanted to contribute. (I will accept PRs that target my fork's modular-rewrite branch.)

Example usage:

import { login, PrivateClient, PublishMutation } from 'threads-api'

// Get a token for a new user…
const client = await login({ username, password })
// …or use an existing token…
const client = new PrivateClient({ token, deviceID })

// Send a request…
const [result, error] = await client.send(PublishMutation, { text: "Hello world" })

// You can access the result like this if you prefer:
const result = await client.send()
if (result.success) {
  result.data
} else {
  result.error
}

There's also a Client class for unauthenticated requests. Instances of Client have a send method that doesn't accept a Mutation or PrivateQuery object (only Query objects, which define an unauthenticated request).

To define a new request type, you must declare a class that extends either Mutation, PrivateQuery, or Query. The class constructor can take any arguments it wants; they are set by client.send calls. The class should override the send method if it needs access to the Client instance. It can set its own url (whose base URL defaults to https://i.instagram.com), headers, searchParams, body, or responseType as instance properties. You can check the existing classes in src/mutations or src/queries for some examples.

Alright, that's it!

@vercel
Copy link

vercel bot commented Aug 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
threads-api ⬜️ Ignored (Inspect) Visit Preview Aug 12, 2023 5:56pm

@aleclarson aleclarson marked this pull request as draft August 12, 2023 02:59
@junhoyeo junhoyeo self-requested a review August 12, 2023 10:57
@junhoyeo
Copy link
Owner

junhoyeo commented Sep 8, 2023

#327

@junhoyeo junhoyeo closed this Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants