module Keybase::API
Represents (parts of) the Keybase
REST API
. @see keybase.io/docs/api/1.0
Constants
- BASE_URL
The base URL for the majority of
API
calls.- VERSION
The current version of `keybase-unofficial-api`.
Public Class Methods
Make a GET request to the given endpoint with the given parameters. @param endpoint [String] the keybase API
endpoint @param query [Hash] the request parameters @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::APIError] if the API
call fails @api private
# 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
Search Keybase
for identity components. @param query [String] the string to search for @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::APIError] if the API
call fails @example
Keybase::API.autocomplete "William Woodruff"
@see keybase.io/docs/api/1.0/call/user/autocomplete
# File lib/keybase/api/api.rb, line 71 def autocomplete(query) api_call "/user/autocomplete.json", q: query end
Discover Keybase
users from external identities. @param query [Hash] the request parameters @option query flatten [Boolean] whether or not to remove duplicates @option query usernames_only [Boolean] whether or not to reply with
only names
@return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::APIError] if the API
call fails @example
Keybase::API.discover github: "woodruffw", flatten: true
@note Any identity supported by keybase should work (e.g, `domain`,
`hackernews`, `reddit`, `github`, etc.)
@see keybase.io/docs/api/1.0/call/user/discover
# File lib/keybase/api/api.rb, line 87 def discover(**query) api_call "/user/discover.json", query end
Look up a user, users, or external identity. @param query [Hash] the request parameters @option query username [String] the username to look up @option query usernames [Array<String>] multiple usernames to look up @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::APIError] if the API
call fails @example
Keybase::API.lookup username: "yossarian" Keybase::API.lookup github: "woodruffw"
@note Any identity supported by keybase should work (e.g, `domain`,
`hackernews`, `reddit`, `github`, etc.)
@see keybase.io/docs/api/1.0/call/user/lookup
# File lib/keybase/api/api.rb, line 47 def lookup(**query) query[:usernames] = Core::U[query[:usernames]] api_call "/user/lookup.json", query end
Retrieve a Merkle node corresponding to a given hash. @param query [Hash] the request parameters @option query hash [String] the hash of the block to look up @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::APIError] if the API
call fails @see keybase.io/docs/api/1.0/call/merkle/block
# File lib/keybase/api/api.rb, line 109 def merkle_block(**query) api_call "/merkle/block.json", query end
Retrieve the current site-wide Merkle root hash. @param query [Hash] the request parameters @option query seqno [Integer] a specific Merkle root to return, if found @option query ctime [Integer] return the first root on or after the
given time (UTC)
@return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::APIError] if the API
call fails @see keybase.io/docs/api/1.0/call/merkle/root
# File lib/keybase/api/api.rb, line 99 def merkle_root(**query) api_call "/merkle/root.json", query end
Cleans up the object returned by {api_call}. @param struct [OpenStruct] a structified response from the Keybase
API
@raise [Exceptions::APIError] when the struct contains an error message
# File lib/keybase/api/api.rb, line 18 def unwrap(struct) raise Exceptions::APIError, struct.status.desc unless struct.status.code.zero? struct end
Test whether the given user exists on Keybase
. @param user [String] the username to test @return [Boolean] whether or not the user exists @example
Keybase::API.user? "yossarian" # => true Keybase::API.user? "idonotexist" # => false
@note This call only works on Keybase
usernames, not external identities.
# File lib/keybase/api/api.rb, line 60 def user?(user) lookup(username: user).status.code.zero? rescue false end