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
-
.autocomplete(query) ⇒ OpenStruct
Search Keybase for identity components.
-
.discover(**query) ⇒ OpenStruct
Discover Keybase users from external identities.
-
.fetch_and_structify(endpoint, query) ⇒ OpenStruct
private
Make a GET request to the given endpoint with the given parameters.
-
.lookup(**query) ⇒ OpenStruct
Look up a user, users, or external identity.
-
.merkle_block(**query) ⇒ OpenStruct
Retrieve a Merkle node corresponding to a given hash.
-
.merkle_root(**query) ⇒ OpenStruct
Retrieve the current site-wide Merkle root hash.
-
.user?(user) ⇒ Boolean
Test whether the given user exists on Keybase.
Class Method Details
.autocomplete(query) ⇒ OpenStruct
Search Keybase for identity components.
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
Any identity supported by keybase should work (e.g, domain,
hackernews, reddit, github, etc.)
Discover Keybase users from external identities.
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
Any identity supported by keybase should work (e.g, domain,
hackernews, reddit, github, etc.)
Look up a user, users, or external identity.
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.
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.
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
This call only works on Keybase usernames, not external identities.
Test whether the given user exists on Keybase.
39 40 41 |
# File 'lib/keybase/api/api.rb', line 39 def user?(user) lookup(username: user).status.code.zero? end |