Module: Keybase::API
- Defined in:
- lib/keybase/api/api.rb,
lib/keybase/api.rb,
lib/keybase/api/exceptions.rb
Overview
Represents (parts of) the Keybase REST API.
Defined Under Namespace
Modules: Exceptions
Constant Summary collapse
- VERSION =
The current version of
keybase-unofficial-api
. "0.1.0"
- BASE_URL =
The base URL for the majority of API calls.
"https://keybase.io/_/api/1.0"
Class Method Summary collapse
-
.api_call(endpoint, query) ⇒ OpenStruct
private
Make a GET request to the given endpoint with the given parameters.
-
.autocomplete(query) ⇒ OpenStruct
Search Keybase for identity components.
-
.discover(**query) ⇒ OpenStruct
Discover Keybase users from external identities.
-
.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.
-
.unwrap(struct) ⇒ Object
Cleans up the object returned by API.api_call.
-
.user?(user) ⇒ Boolean
Test whether the given user exists on Keybase.
Class Method Details
.api_call(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.
30 31 32 33 |
# File 'lib/keybase/api/api.rb', line 30 def api_call(endpoint, query) response = Faraday.get "#{BASE_URL}#{endpoint}", query unwrap JSON.parse response.body, object_class: OpenStruct end |
.autocomplete(query) ⇒ OpenStruct
Search Keybase for identity components.
71 72 73 |
# File 'lib/keybase/api/api.rb', line 71 def autocomplete(query) api_call "/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.
87 88 89 |
# File 'lib/keybase/api/api.rb', line 87 def discover(**query) api_call "/user/discover.json", query 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.
47 48 49 50 51 |
# File 'lib/keybase/api/api.rb', line 47 def lookup(**query) query[:usernames] = Core::U[query[:usernames]] api_call "/user/lookup.json", query end |
.merkle_block(**query) ⇒ OpenStruct
Retrieve a Merkle node corresponding to a given hash.
109 110 111 |
# File 'lib/keybase/api/api.rb', line 109 def merkle_block(**query) api_call "/merkle/block.json", query end |
.merkle_root(**query) ⇒ OpenStruct
Retrieve the current site-wide Merkle root hash.
99 100 101 |
# File 'lib/keybase/api/api.rb', line 99 def merkle_root(**query) api_call "/merkle/root.json", query end |
.unwrap(struct) ⇒ Object
Cleans up the object returned by api_call.
18 19 20 21 22 |
# File 'lib/keybase/api/api.rb', line 18 def unwrap(struct) raise Exceptions::APIError, struct.status.desc unless struct.status.code.zero? struct end |
.user?(user) ⇒ Boolean
This call only works on Keybase usernames, not external identities.
Test whether the given user exists on Keybase.
60 61 62 |
# File 'lib/keybase/api/api.rb', line 60 def user?(user) lookup(username: user).status.code.zero? rescue false end |