No description
Find a file
2022-07-31 13:37:37 +01:00
.github/workflows update generate_documentation action 2022-07-31 13:35:27 +01:00
docs Auto-generated documentation 2020-07-25 15:37:44 +00:00
examples remove bad example 2022-05-24 11:03:14 +01:00
src fix typos, tests pass 2022-06-05 09:06:28 +01:00
tests Refactor, modularise larger endpoint blocks into their own files. 2020-08-20 11:29:30 +01:00
.gitignore remove bad example 2022-05-24 11:03:14 +01:00
LICENSE fix license 2020-07-24 21:42:50 +01:00
README.md Basic Auth 2022-06-05 08:55:52 +01:00
twitter.nimble Update twitter.nimble 2022-07-31 13:37:37 +01:00

twitter .github/workflows/tests.yml

Low-level Twitter API wrapper library for Nim.

Documentation

Installation

From Nimble:

$ nimble install twitter

From GitHub:

$ git clone git://github.com/snus-kin/twitter.nim
$ cd twitter.nim && nimble install

Usage

To use the library, import twitter and compile with -d:ssl

Note: only the free endpoints are wrapped. All mentioned in the API Reference Index have been implemented, please open an issue if you find one that isn't in this reference or if anything new's been added I haven't seen yet.

Example

import twitter, json, strtabs

when isMainModule:
  var parsed = parseFile("credential.json")

  var consumerToken = newConsumerToken(parsed["ConsumerKey"].str,
                                       parsed["ConsumerSecret"].str)
  var twitterAPI = newTwitterAPI(consumerToken,
                                 parsed["AccessToken"].str,
                                 parsed["AccessTokenSecret"].str)

  # Simply get.
  var resp = twitterAPI.get("1.1/account/verify_credentials.json")
  echo resp.status

  # ditto, but selected by screen name.
  resp = twitter.v1.usersLookup(twitterAPI, "sn_fk_n")
  echo pretty parseJson(resp.body)

  # Using proc corresponding twitter REST APIs.
  resp = twitter.v1.statusesUserTimeline(twitterAPI)
  echo pretty parseJson(resp.body)

  # Using `callAPI` template.
  let status = {"status": "hello world"}.newStringTable
  resp = twitterAPI.callAPI(twitter.v1.statusesUpdate, status)
  echo pretty parseJson(resp.body)

See also: examples/ for more extensive examples on the library's use.

To use basic auth, you will have to construct the request using the bare request object.