keybase-unofficial 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2fc22bf434a189f47e72c9e7b7482680bc163f8
4
+ data.tar.gz: b400c92a182732b13d3f454da91a495dbba26ced
5
+ SHA512:
6
+ metadata.gz: 4eb9f9a9bbc3975045a88e66373689a1518419c3220c405cabf4086b39e3e9a3bd9b33036185d0bfd511fe56d1dd96bfd4056743b88f67b27282ba214a9fc2a4
7
+ data.tar.gz: 8630e5d3371f3494834f51ffcb069c0ec16c969d603e34ca4b0a65e6365e09e922209a623a34e4ecd0a1048d6a37da9fc1168e1c627f412b2059fb0fd0c4ec71
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ keybase-unofficial
2
+ ==================
3
+
4
+ An unofficial ruby library for Keybase and the Keybase API.
5
+
6
+ Work in progress.
7
+
8
+ ### Example
9
+
10
+ ```ruby
11
+ require "keybase"
12
+
13
+ # reads your local configuration
14
+ Keybase.current_user # => "yossarian"
15
+
16
+ # API access
17
+ person = Keybase::API.lookup username: "yossarian"
18
+ person.them.profile.bio # => "Computer Science and Philosophy student at the University of Maryland, College Park.\n"
19
+ ```
@@ -0,0 +1,41 @@
1
+ require "faraday"
2
+ require "json"
3
+ require "ostruct"
4
+ require "uri"
5
+
6
+ module Keybase
7
+ class API
8
+ BASE_URL = "https://keybase.io/_/api/1.0"
9
+
10
+ class << self
11
+ def lookup(**query)
12
+ if query[:usernames]
13
+ query[:usernames] = query[:usernames].join(",")
14
+ end
15
+
16
+ response = Faraday.get "#{BASE_URL}/user/lookup.json", query
17
+ JSON.parse(response.body, object_class: OpenStruct)
18
+ end
19
+
20
+ def autocomplete(query)
21
+ response = Faraday.get "#{BASE_URL}/user/autocomplete.json", q: query
22
+ JSON.parse(response.body, object_class: OpenStruct)
23
+ end
24
+
25
+ def discover(**query)
26
+ response = Faraday.get "#{BASE_URL}/user/discover.json", query
27
+ JSON.parse(response.body, object_class: OpenStruct)
28
+ end
29
+
30
+ def merkle_root(**query)
31
+ response = Faraday.get "#{BASE_URL}/merkle/root.json", query
32
+ JSON.parse(response.body, object_class: OpenStruct)
33
+ end
34
+
35
+ def merkle_block(**query)
36
+ response = Faraday.get "#{BASE_URL}/merkle/block.json", query
37
+ JSON.parse(response.body, object_class: OpenStruct)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,39 @@
1
+ require "json"
2
+
3
+ module Keybase
4
+ module Configuration
5
+ CONFIG_DIR = File.expand_path("~/.config/keybase").freeze
6
+
7
+ CONFIG_FILE = File.join(CONFIG_DIR, "config.json").freeze
8
+
9
+ CONFIG_HASH = JSON.parse(File.read(CONFIG_FILE)).freeze
10
+
11
+ def current_user
12
+ CONFIG_HASH["current_user"]
13
+ end
14
+
15
+ def users
16
+ CONFIG_HASH["users"].map { |_, v| Keybase::User.new(v) }
17
+ end
18
+
19
+ def private_dir
20
+ "/keybase/private/#{current_user}"
21
+ end
22
+
23
+ def public_dir
24
+ "/keybase/public/#{current_user}"
25
+ end
26
+
27
+ def running?
28
+ # is there a more efficient way to do this that doesn't involve an exec?
29
+ Dir["/proc/[0-9]*/comm"].any? do |comm|
30
+ File.read(comm).chomp == "keybase"
31
+ end
32
+ end
33
+
34
+ def running_version
35
+ raise KeybaseNotRunningError unless Keybase.running?
36
+ `keybase --version`.split[2]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ module Keybase
2
+ class KeybaseError < RuntimeError
3
+ end
4
+
5
+ class KeybaseNotRunningError < KeybaseError
6
+ def initialize
7
+ super "keybase needs to be running"
8
+ end
9
+ end
10
+
11
+ class KBFSNotRunningError < KeybaseError
12
+ def initialize
13
+ super "KBFS needs to be enabled and running"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Keybase
2
+ class KBFS
3
+ def initialize
4
+ raise KeybaseNotRunningError unless Keybase.running?
5
+ raise KBFSNotRunningError unless Dir.exist?("/keybase")
6
+ end
7
+
8
+ # there's nothing here yet.
9
+ # i could add methods for moving files to and from the public
10
+ # and private keybase directories, but that feels overkill.
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Keybase
2
+ class User
3
+ attr_reader :device, :id, :name, :salt
4
+
5
+ def initialize(hsh)
6
+ @device = hsh["device"]
7
+ @id = hsh["id"]
8
+ @name = hsh["name"]
9
+ @salt = hsh["salt"]
10
+ end
11
+ end
12
+ end
data/lib/keybase.rb ADDED
@@ -0,0 +1,11 @@
1
+ require_relative "keybase/exceptions"
2
+ require_relative "keybase/configuration"
3
+ require_relative "keybase/user"
4
+ require_relative "keybase/kbfs"
5
+ require_relative "keybase/api"
6
+
7
+ module Keybase
8
+ VERSION = "0.0.1".freeze
9
+
10
+ extend Configuration
11
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keybase-unofficial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - William Woodruff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A unofficial library for Keybase
28
+ email: william@tuffbizz.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/keybase.rb
35
+ - lib/keybase/api.rb
36
+ - lib/keybase/configuration.rb
37
+ - lib/keybase/exceptions.rb
38
+ - lib/keybase/kbfs.rb
39
+ - lib/keybase/user.rb
40
+ homepage: https://github.com/woodruffw/keybase-unofficial
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.6.8
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: keybase-unofficial - An unofficial library for Keybase.
64
+ test_files: []