Module: Keybase::API

Defined in:
lib/keybase/api/api.rb,
lib/keybase/api.rb

Overview

Represents (parts of) the Keybase REST API.

Constant Summary collapse

VERSION =

The current version of keybase-unofficial-api.

"0.0.2"
BASE_URL =

The base URL for the majority of API calls.

"https://keybase.io/_/api/1.0"

Class Method Summary collapse

Class Method Details

.autocomplete(query) ⇒ OpenStruct

Search Keybase for identity components.

Examples:

Keybase::API.autocomplete "William Woodruff"

See Also:



49
50
51
# File 'lib/keybase/api/api.rb', line 49

def autocomplete(query)
  fetch_and_structify "/user/autocomplete.json", q: query
end

.discover(**query) ⇒ OpenStruct

Note:

Any identity supported by keybase should work (e.g, domain, hackernews, reddit, github, etc.)

Discover Keybase users from external identities.

Examples:

Keybase::API.discover github: "woodruffw", flatten: true

Options Hash (**query):

  • flatten (Boolean)

    whether or not to remove duplicates

  • usernames_only (Boolean)

    whether or not to reply with only names

See Also:



64
65
66
# File 'lib/keybase/api/api.rb', line 64

def discover(**query)
  fetch_and_structify "/user/discover.json", query
end

.fetch_and_structify(endpoint, query) ⇒ OpenStruct

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Make a GET request to the given endpoint with the given parameters.



93
94
95
96
# File 'lib/keybase/api/api.rb', line 93

def fetch_and_structify(endpoint, query)
  response = Faraday.get "#{BASE_URL}#{endpoint}", query
  JSON.parse(response.body, object_class: OpenStruct)
end

.lookup(**query) ⇒ OpenStruct

Note:

Any identity supported by keybase should work (e.g, domain, hackernews, reddit, github, etc.)

Look up a user, users, or external identity.

Examples:

Keybase::API.lookup username: "yossarian"
Keybase::API.lookup github: "woodruffw"

Options Hash (**query):

  • username (String)

    the username to look up

  • usernames (Array<String>)

    multiple usernames to look up

See Also:



26
27
28
29
30
# File 'lib/keybase/api/api.rb', line 26

def lookup(**query)
  query[:usernames] = Core::U[query[:usernames]]

  fetch_and_structify "/user/lookup.json", query
end

.merkle_block(**query) ⇒ OpenStruct

Retrieve a Merkle node corresponding to a given hash.

Options Hash (**query):

  • hash (String)

    the hash of the block to look up

See Also:



84
85
86
# File 'lib/keybase/api/api.rb', line 84

def merkle_block(**query)
  fetch_and_structify "/merkle/block.json", query
end

.merkle_root(**query) ⇒ OpenStruct

Retrieve the current site-wide Merkle root hash.

Options Hash (**query):

  • seqno (Integer)

    a specific Merkle root to return, if found

  • ctime (Integer)

    return the first root on or after the given time (UTC)

See Also:



75
76
77
# File 'lib/keybase/api/api.rb', line 75

def merkle_root(**query)
  fetch_and_structify "/merkle/root.json", query
end

.user?(user) ⇒ Boolean

Note:

This call only works on Keybase usernames, not external identities.

Test whether the given user exists on Keybase.

Examples:

Keybase::API.user? "yossarian" # => true
Keybase::API.user? "idonotexist" # => false


39
40
41
# File 'lib/keybase/api/api.rb', line 39

def user?(user)
  lookup(username: user).status.code.zero?
end