keybase-unofficial 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/keybase.rb +3 -1
- data/lib/keybase/api.rb +42 -0
- data/lib/keybase/configuration.rb +11 -0
- data/lib/keybase/exceptions.rb +3 -0
- data/lib/keybase/kbfs.rb +4 -0
- data/lib/keybase/user.rb +14 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db0b875052bf623f798762c590f519e6143115f7
|
4
|
+
data.tar.gz: b501af569c38574f42652f2417513371b4fc2f63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0c47e547ead2245567014a587f0023014e7d251710c3be188302b0f0915fff88fd45c952d763f391d02c30ce58a29e0e24c41dc8bbb3a5a80dff0bdf98b396
|
7
|
+
data.tar.gz: c38b9d94a32786fa374de4bbef4c09cd61d9e1bb3701d7bcda497fded963b3d3daaeacaac07386bbc76f51df80cd5dcd02233e94d87be272b01fa972caa7bfea
|
data/README.md
CHANGED
data/lib/keybase.rb
CHANGED
@@ -4,8 +4,10 @@ require_relative "keybase/user"
|
|
4
4
|
require_relative "keybase/kbfs"
|
5
5
|
require_relative "keybase/api"
|
6
6
|
|
7
|
+
# The primary namespace for keybase-unofficial.
|
7
8
|
module Keybase
|
8
|
-
|
9
|
+
# keybase-unofficial's current version
|
10
|
+
VERSION = "0.0.3".freeze
|
9
11
|
|
10
12
|
extend Configuration
|
11
13
|
end
|
data/lib/keybase/api.rb
CHANGED
@@ -4,10 +4,23 @@ require "ostruct"
|
|
4
4
|
require "uri"
|
5
5
|
|
6
6
|
module Keybase
|
7
|
+
# Represents (parts of) the Keybase REST API.
|
7
8
|
class API
|
9
|
+
# The base URL for the majority of API calls.
|
8
10
|
BASE_URL = "https://keybase.io/_/api/1.0"
|
9
11
|
|
10
12
|
class << self
|
13
|
+
# Look up a user, users, or external identity.
|
14
|
+
# @param query [Hash] the request parameters
|
15
|
+
# @option query username [String] the username to look up
|
16
|
+
# @option query usernames [Array<String>] multiple usernames to look up
|
17
|
+
# @return [OpenStruct] a struct mapping of the JSON response
|
18
|
+
# @example
|
19
|
+
# Keybase::API.lookup username: "yossarian"
|
20
|
+
# Keybase::API.lookup github: "woodruffw"
|
21
|
+
# @note Any identity supported by keybase should work (e.g, `domain`,
|
22
|
+
# `hackernews`, `reddit`, `github`, etc.)
|
23
|
+
# @see https://keybase.io/docs/api/1.0/call/user/lookup
|
11
24
|
def lookup(**query)
|
12
25
|
if query[:usernames]
|
13
26
|
query[:usernames] = query[:usernames].join(",")
|
@@ -17,21 +30,50 @@ module Keybase
|
|
17
30
|
JSON.parse(response.body, object_class: OpenStruct)
|
18
31
|
end
|
19
32
|
|
33
|
+
# Search Keybase for identity components.
|
34
|
+
# @param query [String] the string to search for
|
35
|
+
# @return [OpenStruct] a struct mapping of the JSON response
|
36
|
+
# @example
|
37
|
+
# Keybase::API.autocomplete "William Woodruff"
|
38
|
+
# @see https://keybase.io/docs/api/1.0/call/user/autocomplete
|
20
39
|
def autocomplete(query)
|
21
40
|
response = Faraday.get "#{BASE_URL}/user/autocomplete.json", q: query
|
22
41
|
JSON.parse(response.body, object_class: OpenStruct)
|
23
42
|
end
|
24
43
|
|
44
|
+
# Discover Keybase users from external identities.
|
45
|
+
# @param query [Hash] the request parameters
|
46
|
+
# @option query flatten [Boolean] whether or not to remove duplicates
|
47
|
+
# @option query usernames_only [Boolean] whether or not to reply with
|
48
|
+
# only names
|
49
|
+
# @return [OpenStruct] a struct mapping of the JSON response
|
50
|
+
# @example
|
51
|
+
# Keybase::API.discover github: "woodruffw", flatten: true
|
52
|
+
# @note Any identity supported by keybase should work (e.g, `domain`,
|
53
|
+
# `hackernews`, `reddit`, `github`, etc.)
|
54
|
+
# @see https://keybase.io/docs/api/1.0/call/user/discover
|
25
55
|
def discover(**query)
|
26
56
|
response = Faraday.get "#{BASE_URL}/user/discover.json", query
|
27
57
|
JSON.parse(response.body, object_class: OpenStruct)
|
28
58
|
end
|
29
59
|
|
60
|
+
# Retrieve the current site-wide Merkle root hash.
|
61
|
+
# @param query [Hash] the request parameters
|
62
|
+
# @option query seqno [Integer] a specific Merkle root to return, if found
|
63
|
+
# @option query ctime [Integer] return the first root on or after the
|
64
|
+
# given time (UTC)
|
65
|
+
# @return [OpenStruct] a struct mapping of the JSON response
|
66
|
+
# @see https://keybase.io/docs/api/1.0/call/merkle/root
|
30
67
|
def merkle_root(**query)
|
31
68
|
response = Faraday.get "#{BASE_URL}/merkle/root.json", query
|
32
69
|
JSON.parse(response.body, object_class: OpenStruct)
|
33
70
|
end
|
34
71
|
|
72
|
+
# Retrieve a Merkle node corresponding to a given hash.
|
73
|
+
# @param query [Hash] the request parameters
|
74
|
+
# @option query hash [String] the hash of the block to look up
|
75
|
+
# @return [OpenStruct] a struct mapping of the JSON response
|
76
|
+
# @see https://keybase.io/docs/api/1.0/call/merkle/block
|
35
77
|
def merkle_block(**query)
|
36
78
|
response = Faraday.get "#{BASE_URL}/merkle/block.json", query
|
37
79
|
JSON.parse(response.body, object_class: OpenStruct)
|
@@ -1,29 +1,38 @@
|
|
1
1
|
require "json"
|
2
2
|
|
3
3
|
module Keybase
|
4
|
+
# Methods and constants related to a local Keybase installation.
|
4
5
|
module Configuration
|
6
|
+
# The Keybase configuration directory.
|
5
7
|
CONFIG_DIR = File.expand_path("~/.config/keybase").freeze
|
6
8
|
|
9
|
+
# The Keybase configuration file.
|
7
10
|
CONFIG_FILE = File.join(CONFIG_DIR, "config.json").freeze
|
8
11
|
|
12
|
+
# The hash from Keybase's configuration file.
|
9
13
|
CONFIG_HASH = JSON.parse(File.read(CONFIG_FILE)).freeze
|
10
14
|
|
15
|
+
# @return [String] the currently logged-in user
|
11
16
|
def current_user
|
12
17
|
CONFIG_HASH["current_user"]
|
13
18
|
end
|
14
19
|
|
20
|
+
# @return [Array<Keybase::User>] a list of all local users known to Keybase
|
15
21
|
def users
|
16
22
|
CONFIG_HASH["users"].map { |_, v| Keybase::User.new(v) }
|
17
23
|
end
|
18
24
|
|
25
|
+
# @return [String] the user's private KBFS directory
|
19
26
|
def private_dir
|
20
27
|
"/keybase/private/#{current_user}"
|
21
28
|
end
|
22
29
|
|
30
|
+
# @return [String] the user's public KBFS directory
|
23
31
|
def public_dir
|
24
32
|
"/keybase/public/#{current_user}"
|
25
33
|
end
|
26
34
|
|
35
|
+
# @return [Boolean] whether or not Keybase is currently running
|
27
36
|
def running?
|
28
37
|
# is there a more efficient way to do this that doesn't involve an exec?
|
29
38
|
Dir["/proc/[0-9]*/comm"].any? do |comm|
|
@@ -31,6 +40,8 @@ module Keybase
|
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
43
|
+
# @return [String] the running Keybase's version string
|
44
|
+
# @raise [KeybaseNotRunningError] if Keybase is not running
|
34
45
|
def running_version
|
35
46
|
raise KeybaseNotRunningError unless Keybase.running?
|
36
47
|
`keybase --version`.split[2]
|
data/lib/keybase/exceptions.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Keybase
|
2
|
+
# A top-level exception for the library.
|
2
3
|
class KeybaseError < RuntimeError
|
3
4
|
end
|
4
5
|
|
6
|
+
# Raised whenever Keybase is not running locally.
|
5
7
|
class KeybaseNotRunningError < KeybaseError
|
6
8
|
def initialize
|
7
9
|
super "keybase needs to be running"
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
13
|
+
# Raised whenever KBFS is not running locally.
|
11
14
|
class KBFSNotRunningError < KeybaseError
|
12
15
|
def initialize
|
13
16
|
super "KBFS needs to be enabled and running"
|
data/lib/keybase/kbfs.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Keybase
|
2
|
+
# Represents the Keybase filesystem.
|
3
|
+
# @note This is just a stub for the time being.
|
2
4
|
class KBFS
|
5
|
+
# @raise [KeybaseNotRunningError] unless Keybase is running
|
6
|
+
# @raise [KBFSNotRunningError] unless KBFS is running
|
3
7
|
def initialize
|
4
8
|
raise KeybaseNotRunningError unless Keybase.running?
|
5
9
|
raise KBFSNotRunningError unless Dir.exist?("/keybase")
|
data/lib/keybase/user.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
module Keybase
|
2
|
+
# Represents a user known to the local Keybase process.
|
3
|
+
# These are (presumably) users that have been logged into locally.
|
2
4
|
class User
|
3
|
-
|
5
|
+
# @return [String] the device's unique identifier
|
6
|
+
attr_reader :device
|
7
|
+
|
8
|
+
# @return [String] the user's unique identifier
|
9
|
+
attr_reader :id
|
10
|
+
|
11
|
+
# @return [String] the user's Keybase username
|
12
|
+
attr_reader :name
|
13
|
+
|
14
|
+
# @return [String] some kind of salt
|
15
|
+
# @note I have no idea what this field does.
|
16
|
+
attr_reader :salt
|
4
17
|
|
5
18
|
def initialize(hsh)
|
6
19
|
@device = hsh["device"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keybase-unofficial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
@@ -14,14 +14,14 @@ dependencies:
|
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: A unofficial library for Keybase
|