keybase-unofficial-api 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/keybase/api.rb +2 -1
- data/lib/keybase/api/api.rb +31 -16
- data/lib/keybase/api/exceptions.rb +16 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45e7e413717ec5933b9999bfc86caca02b160385
|
4
|
+
data.tar.gz: d6104e90e99c9025df7fb16a4201366d52902b5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 564a397037d7ca60f3809af6115e34295b2314111efb31d1bfc57c3a7281d4874ed181173caca04bb53a84753007fc9806a5a85df6d8799272d8d8191798178f
|
7
|
+
data.tar.gz: fe047406a0a6c81bab586ad0fb013e64426d5591670192c4fa418e1ca3f65aca5efcf6a740881311ce4ed799eff03fac2b634d356a221c1bb487f53e43152d12
|
data/lib/keybase/api.rb
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
require "keybase/core"
|
4
4
|
|
5
|
+
require_relative "api/exceptions"
|
5
6
|
require_relative "api/api"
|
6
7
|
|
7
8
|
# The primary namespace.
|
8
9
|
module Keybase
|
9
10
|
module API
|
10
11
|
# The current version of `keybase-unofficial-api`.
|
11
|
-
VERSION = "0.0
|
12
|
+
VERSION = "0.1.0"
|
12
13
|
end
|
13
14
|
end
|
data/lib/keybase/api/api.rb
CHANGED
@@ -12,11 +12,32 @@ module Keybase
|
|
12
12
|
BASE_URL = "https://keybase.io/_/api/1.0"
|
13
13
|
|
14
14
|
class << self
|
15
|
+
# Cleans up the object returned by {api_call}.
|
16
|
+
# @param struct [OpenStruct] a structified response from the Keybase API
|
17
|
+
# @raise [Exceptions::APIError] when the struct contains an error message
|
18
|
+
def unwrap(struct)
|
19
|
+
raise Exceptions::APIError, struct.status.desc unless struct.status.code.zero?
|
20
|
+
|
21
|
+
struct
|
22
|
+
end
|
23
|
+
|
24
|
+
# Make a GET request to the given endpoint with the given parameters.
|
25
|
+
# @param endpoint [String] the keybase API endpoint
|
26
|
+
# @param query [Hash] the request parameters
|
27
|
+
# @return [OpenStruct] a struct mapping of the JSON response
|
28
|
+
# @raise [Exceptions::APIError] if the API call fails
|
29
|
+
# @api private
|
30
|
+
def api_call(endpoint, query)
|
31
|
+
response = Faraday.get "#{BASE_URL}#{endpoint}", query
|
32
|
+
unwrap JSON.parse response.body, object_class: OpenStruct
|
33
|
+
end
|
34
|
+
|
15
35
|
# Look up a user, users, or external identity.
|
16
36
|
# @param query [Hash] the request parameters
|
17
37
|
# @option query username [String] the username to look up
|
18
38
|
# @option query usernames [Array<String>] multiple usernames to look up
|
19
39
|
# @return [OpenStruct] a struct mapping of the JSON response
|
40
|
+
# @raise [Exceptions::APIError] if the API call fails
|
20
41
|
# @example
|
21
42
|
# Keybase::API.lookup username: "yossarian"
|
22
43
|
# Keybase::API.lookup github: "woodruffw"
|
@@ -26,7 +47,7 @@ module Keybase
|
|
26
47
|
def lookup(**query)
|
27
48
|
query[:usernames] = Core::U[query[:usernames]]
|
28
49
|
|
29
|
-
|
50
|
+
api_call "/user/lookup.json", query
|
30
51
|
end
|
31
52
|
|
32
53
|
# Test whether the given user exists on Keybase.
|
@@ -37,17 +58,18 @@ module Keybase
|
|
37
58
|
# Keybase::API.user? "idonotexist" # => false
|
38
59
|
# @note This call only works on Keybase usernames, not external identities.
|
39
60
|
def user?(user)
|
40
|
-
lookup(username: user).status.code.zero?
|
61
|
+
lookup(username: user).status.code.zero? rescue false
|
41
62
|
end
|
42
63
|
|
43
64
|
# Search Keybase for identity components.
|
44
65
|
# @param query [String] the string to search for
|
45
66
|
# @return [OpenStruct] a struct mapping of the JSON response
|
67
|
+
# @raise [Exceptions::APIError] if the API call fails
|
46
68
|
# @example
|
47
69
|
# Keybase::API.autocomplete "William Woodruff"
|
48
70
|
# @see https://keybase.io/docs/api/1.0/call/user/autocomplete
|
49
71
|
def autocomplete(query)
|
50
|
-
|
72
|
+
api_call "/user/autocomplete.json", q: query
|
51
73
|
end
|
52
74
|
|
53
75
|
# Discover Keybase users from external identities.
|
@@ -56,13 +78,14 @@ module Keybase
|
|
56
78
|
# @option query usernames_only [Boolean] whether or not to reply with
|
57
79
|
# only names
|
58
80
|
# @return [OpenStruct] a struct mapping of the JSON response
|
81
|
+
# @raise [Exceptions::APIError] if the API call fails
|
59
82
|
# @example
|
60
83
|
# Keybase::API.discover github: "woodruffw", flatten: true
|
61
84
|
# @note Any identity supported by keybase should work (e.g, `domain`,
|
62
85
|
# `hackernews`, `reddit`, `github`, etc.)
|
63
86
|
# @see https://keybase.io/docs/api/1.0/call/user/discover
|
64
87
|
def discover(**query)
|
65
|
-
|
88
|
+
api_call "/user/discover.json", query
|
66
89
|
end
|
67
90
|
|
68
91
|
# Retrieve the current site-wide Merkle root hash.
|
@@ -71,28 +94,20 @@ module Keybase
|
|
71
94
|
# @option query ctime [Integer] return the first root on or after the
|
72
95
|
# given time (UTC)
|
73
96
|
# @return [OpenStruct] a struct mapping of the JSON response
|
97
|
+
# @raise [Exceptions::APIError] if the API call fails
|
74
98
|
# @see https://keybase.io/docs/api/1.0/call/merkle/root
|
75
99
|
def merkle_root(**query)
|
76
|
-
|
100
|
+
api_call "/merkle/root.json", query
|
77
101
|
end
|
78
102
|
|
79
103
|
# Retrieve a Merkle node corresponding to a given hash.
|
80
104
|
# @param query [Hash] the request parameters
|
81
105
|
# @option query hash [String] the hash of the block to look up
|
82
106
|
# @return [OpenStruct] a struct mapping of the JSON response
|
107
|
+
# @raise [Exceptions::APIError] if the API call fails
|
83
108
|
# @see https://keybase.io/docs/api/1.0/call/merkle/block
|
84
109
|
def merkle_block(**query)
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
# Make a GET request to the given endpoint with the given parameters.
|
89
|
-
# @param endpoint [String] the keybase API endpoint
|
90
|
-
# @param query [Hash] the request parameters
|
91
|
-
# @return [OpenStruct] a struct mapping of the JSON response
|
92
|
-
# @api private
|
93
|
-
def fetch_and_structify(endpoint, query)
|
94
|
-
response = Faraday.get "#{BASE_URL}#{endpoint}", query
|
95
|
-
JSON.parse(response.body, object_class: OpenStruct)
|
110
|
+
api_call "/merkle/block.json", query
|
96
111
|
end
|
97
112
|
end
|
98
113
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Keybase
|
4
|
+
module API
|
5
|
+
# A namespace for all exceptions defined by {Keybase::API}.
|
6
|
+
module Exceptions
|
7
|
+
# Raised whenever an {API} call fails.
|
8
|
+
class APIError < Core::Exceptions::KeybaseError
|
9
|
+
# @param message [String] the error message returned by the API
|
10
|
+
def initialize(message)
|
11
|
+
super message
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keybase-unofficial-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Woodruff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -51,7 +51,8 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- lib/keybase/api.rb
|
53
53
|
- lib/keybase/api/api.rb
|
54
|
-
|
54
|
+
- lib/keybase/api/exceptions.rb
|
55
|
+
homepage: https://github.com/kbsecret/keybase-unofficial-api
|
55
56
|
licenses:
|
56
57
|
- MIT
|
57
58
|
metadata: {}
|