urbit-api 0.2.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/urbit/bucket.rb +45 -0
- data/lib/urbit/channel.rb +4 -5
- data/lib/urbit/fact/base_fact.rb +97 -0
- data/lib/urbit/fact/graph_fact.rb +90 -0
- data/lib/urbit/fact/group_fact.rb +124 -0
- data/lib/urbit/fact/metadata_fact.rb +57 -0
- data/lib/urbit/fact/settings_fact.rb +120 -0
- data/lib/urbit/fact.rb +49 -60
- data/lib/urbit/graph.rb +44 -2
- data/lib/urbit/group.rb +164 -0
- data/lib/urbit/group_parser.rb +71 -0
- data/lib/urbit/groups.rb +100 -0
- data/lib/urbit/link.rb +69 -0
- data/lib/urbit/links.rb +39 -0
- data/lib/urbit/message.rb +2 -2
- data/lib/urbit/parser.rb +23 -3
- data/lib/urbit/poke_message.rb +2 -2
- data/lib/urbit/receiver.rb +15 -5
- data/lib/urbit/setting.rb +71 -0
- data/lib/urbit/settings.rb +36 -0
- data/lib/urbit/ship.rb +69 -28
- data/lib/urbit/version.rb +5 -0
- data/lib/{urbit/urbit.rb → urbit.rb} +3 -2
- data/urbit-api.gemspec +7 -8
- metadata +35 -28
- data/.gitignore +0 -25
- data/.rspec +0 -1
- data/.ruby-version +0 -2
- data/CHANGELOG.md +0 -1
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -21
- data/README.gem.md +0 -4
- data/README.md +0 -240
- data/Rakefile +0 -10
- data/_config.yml +0 -2
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/bin/test +0 -2
- data/lib/urbit/api/version.rb +0 -5
- data/misc/graph-store_graph +0 -51
- data/misc/graph-store_keys +0 -15
- data/misc/graph-store_node +0 -34
- data/misc/graph-store_update +0 -76
- data/misc/graph-update_add-graph +0 -20
- data/misc/graph-update_add-nodes +0 -75
- data/misc/post +0 -12
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'urbit/setting'
|
4
|
+
|
5
|
+
module Urbit
|
6
|
+
class Settings < Set
|
7
|
+
class << self
|
8
|
+
def load(ship:)
|
9
|
+
ship.subscribe(app: 'settings-store', path: '/all')
|
10
|
+
scry = ship.scry(app: "settings-store", path: "/all", mark: "json")
|
11
|
+
# scry = self.scry(app: "settings-store", path: "/desk/#{desk}", mark: "json")
|
12
|
+
s = Settings.new
|
13
|
+
if scry[:body]
|
14
|
+
body = JSON.parse scry[:body]
|
15
|
+
body["all"].each do |k, v| # At this level the keys are the desks and the values are the buckets
|
16
|
+
s << Setting.new(ship: ship, desk: k, buckets: v)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@hash = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](desk:)
|
28
|
+
self.select {|s| desk == s.desk}.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def list
|
32
|
+
self.each {|s| puts s.to_string}
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/urbit/ship.rb
CHANGED
@@ -3,6 +3,9 @@ require 'faraday'
|
|
3
3
|
require 'urbit/channel'
|
4
4
|
require 'urbit/config'
|
5
5
|
require 'urbit/graph'
|
6
|
+
require 'urbit/groups'
|
7
|
+
require 'urbit/links'
|
8
|
+
require 'urbit/settings'
|
6
9
|
|
7
10
|
module Urbit
|
8
11
|
class Ship
|
@@ -14,6 +17,9 @@ module Urbit
|
|
14
17
|
@channels = []
|
15
18
|
@config = config
|
16
19
|
@graphs = []
|
20
|
+
@groups = Groups.new ship: self
|
21
|
+
@links = Links.new
|
22
|
+
@settings = nil # Use lazy initialization here
|
17
23
|
@logged_in = false
|
18
24
|
end
|
19
25
|
|
@@ -37,7 +43,7 @@ module Urbit
|
|
37
43
|
# Answers a collection of all the top-level graphs on this ship.
|
38
44
|
# This collection is cached and will need to be invalidated to discover new graphs.
|
39
45
|
#
|
40
|
-
def graphs(flush_cache:
|
46
|
+
def graphs(flush_cache: true)
|
41
47
|
@graphs = [] if flush_cache
|
42
48
|
if @graphs.empty?
|
43
49
|
if self.logged_in?
|
@@ -60,12 +66,32 @@ module Urbit
|
|
60
66
|
self.graphs.collect {|g| g.resource}
|
61
67
|
end
|
62
68
|
|
69
|
+
#
|
70
|
+
# Answers the object managing the Groups on this ship.
|
71
|
+
# This object provides all the helper methods to list, join, leave, &c. a Group
|
72
|
+
#
|
73
|
+
def groups
|
74
|
+
@groups
|
75
|
+
end
|
76
|
+
|
77
|
+
def links
|
78
|
+
@links
|
79
|
+
end
|
80
|
+
|
63
81
|
def login
|
64
82
|
return self if logged_in?
|
65
83
|
|
66
84
|
ensure_connections_closed
|
67
85
|
response = Faraday.post(login_url, "password=#{config.code}")
|
68
86
|
parse_cookie(response)
|
87
|
+
@groups.load
|
88
|
+
|
89
|
+
# For now we will require a subscription to all metadata. it's the glue between %graphs and %groups.
|
90
|
+
# A key issue that arose is that these are both async %subscribe calls and so there are sync issues
|
91
|
+
# if we try to directly link the groups and the graphs. Instead we need to just store the links
|
92
|
+
# and lazy-instatiate the metadata _if_ we have received it.
|
93
|
+
@links.load ship: self
|
94
|
+
|
69
95
|
self
|
70
96
|
end
|
71
97
|
|
@@ -73,35 +99,14 @@ module Urbit
|
|
73
99
|
config.name
|
74
100
|
end
|
75
101
|
|
76
|
-
def
|
77
|
-
|
78
|
-
"delete": {
|
79
|
-
"resource": {
|
80
|
-
"ship": "#{self.name}",
|
81
|
-
"name": "#{graph.name}"
|
82
|
-
}
|
83
|
-
}
|
84
|
-
})
|
85
|
-
|
86
|
-
spider = self.spider(mark_in: 'graph-view-action', mark_out: 'json', thread: 'graph-delete', data: delete_json, args: ["NO_RESPONSE"])
|
87
|
-
if (retcode = (200 == spider[:status]))
|
88
|
-
self.graphs.delete graph
|
89
|
-
end
|
90
|
-
retcode
|
91
|
-
end
|
92
|
-
|
93
|
-
def untilded_name
|
94
|
-
name.gsub('~', '')
|
102
|
+
def open_channels
|
103
|
+
@channels.select {|c| c.open?}
|
95
104
|
end
|
96
105
|
|
97
106
|
def pat_p
|
98
107
|
config.name
|
99
108
|
end
|
100
109
|
|
101
|
-
def open_channels
|
102
|
-
@channels.select {|c| c.open?}
|
103
|
-
end
|
104
|
-
|
105
110
|
#
|
106
111
|
# Poke an app with a message using a mark.
|
107
112
|
#
|
@@ -112,10 +117,27 @@ module Urbit
|
|
112
117
|
(self.add_channel).poke(app: app, mark: mark, message: message)
|
113
118
|
end
|
114
119
|
|
120
|
+
def remove_graph(desk: 'landscape', graph:)
|
121
|
+
delete_json = %Q({
|
122
|
+
"delete": {
|
123
|
+
"resource": {
|
124
|
+
"ship": "#{self.name}",
|
125
|
+
"name": "#{graph.name}"
|
126
|
+
}
|
127
|
+
}
|
128
|
+
})
|
129
|
+
|
130
|
+
spider = self.spider(desk: desk, mark_in: 'graph-view-action', mark_out: 'json', thread: 'graph-delete', data: delete_json, args: ["NO_RESPONSE"])
|
131
|
+
if (retcode = (200 == spider[:status]))
|
132
|
+
self.graphs.delete graph
|
133
|
+
end
|
134
|
+
retcode
|
135
|
+
end
|
136
|
+
|
115
137
|
def scry(app:, path:, mark: 'json')
|
116
138
|
self.login
|
117
139
|
mark = ".#{mark}" unless mark.empty?
|
118
|
-
scry_url = "#{self.
|
140
|
+
scry_url = "#{self.url}/~/scry/#{app}#{path}#{mark}"
|
119
141
|
|
120
142
|
response = Faraday.get(scry_url) do |req|
|
121
143
|
req.headers['Accept'] = 'application/json'
|
@@ -125,9 +147,20 @@ module Urbit
|
|
125
147
|
{status: response.status, code: response.reason_phrase, body: response.body}
|
126
148
|
end
|
127
149
|
|
128
|
-
|
150
|
+
#
|
151
|
+
# Answers the object managing the Settings on this ship.
|
152
|
+
# This object provides all the helper methods to list, update, and remove a Setting
|
153
|
+
#
|
154
|
+
def settings
|
155
|
+
if self.logged_in?
|
156
|
+
@settings = Settings.load(ship: self) if @settings.nil?
|
157
|
+
end
|
158
|
+
@settings
|
159
|
+
end
|
160
|
+
|
161
|
+
def spider(desk: 'landscape', mark_in:, mark_out:, thread:, data:, args: [])
|
129
162
|
self.login
|
130
|
-
url = "#{self.
|
163
|
+
url = "#{self.url}/spider/#{desk}/#{mark_in}/#{thread}/#{mark_out}.json"
|
131
164
|
|
132
165
|
# TODO: This is a huge hack due to the fact that certain spider operations are known to
|
133
166
|
# not return when they should. Instead I just set the timeout low and catch the
|
@@ -175,6 +208,14 @@ module Urbit
|
|
175
208
|
"a Ship(#{self.to_h})"
|
176
209
|
end
|
177
210
|
|
211
|
+
def untilded_name
|
212
|
+
name.gsub('~', '')
|
213
|
+
end
|
214
|
+
|
215
|
+
def url
|
216
|
+
self.config.api_base_url
|
217
|
+
end
|
218
|
+
|
178
219
|
private
|
179
220
|
|
180
221
|
def add_channel
|
@@ -193,7 +234,7 @@ module Urbit
|
|
193
234
|
end
|
194
235
|
|
195
236
|
def login_url
|
196
|
-
"#{
|
237
|
+
"#{self.url}/~/login"
|
197
238
|
end
|
198
239
|
|
199
240
|
def parse_cookie(resp)
|
data/urbit-api.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative 'lib/urbit/
|
1
|
+
require_relative 'lib/urbit/version'
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "urbit-api"
|
5
|
-
spec.version = Urbit::
|
5
|
+
spec.version = Urbit::VERSION
|
6
6
|
spec.authors = ["Daryl Richter"]
|
7
7
|
spec.email = ["daryl@ngzax.com"]
|
8
8
|
|
@@ -18,17 +18,16 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.metadata["changelog_uri"] = "https://github.com/Zaxonomy/urbit-ruby/CHANGELOG.md"
|
19
19
|
|
20
20
|
# Specify which files should be added to the gem when it is released.
|
21
|
-
|
22
|
-
spec.files
|
23
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
-
end
|
21
|
+
spec.files = Dir.glob("lib{.rb,/**/*}", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
|
22
|
+
spec.files += %w[urbit-api.gemspec] # include the gemspec itself because warbler breaks w/o it
|
25
23
|
|
26
24
|
spec.bindir = "exe"
|
27
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
26
|
spec.require_paths = ["lib"]
|
29
27
|
|
30
|
-
spec.add_dependency "faraday", "~>
|
31
|
-
spec.add_dependency "ld-eventsource", "~> 2.
|
28
|
+
spec.add_dependency "faraday", "~> 2.2.0"
|
29
|
+
spec.add_dependency "ld-eventsource", "~> 2.2.0"
|
30
|
+
spec.add_dependency "uri", "0.10.0" # Pinning this for now b/c 0.11 is broken. :(
|
32
31
|
|
33
32
|
spec.add_development_dependency "pry", "~> 0.13"
|
34
33
|
spec.add_development_dependency "rspec", "~> 3.10"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: urbit-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daryl Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,28 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.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
|
-
version:
|
26
|
+
version: 2.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ld-eventsource
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
33
|
+
version: 2.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
40
|
+
version: 2.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: uri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.10.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pry
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,43 +87,36 @@ executables: []
|
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
|
-
-
|
77
|
-
- ".rspec"
|
78
|
-
- ".ruby-version"
|
79
|
-
- CHANGELOG.md
|
80
|
-
- Gemfile
|
81
|
-
- LICENSE.txt
|
82
|
-
- README.gem.md
|
83
|
-
- README.md
|
84
|
-
- Rakefile
|
85
|
-
- _config.yml
|
86
|
-
- bin/console
|
87
|
-
- bin/setup
|
88
|
-
- bin/test
|
90
|
+
- lib/urbit.rb
|
89
91
|
- lib/urbit/ack_message.rb
|
90
92
|
- lib/urbit/api.rb
|
91
|
-
- lib/urbit/
|
93
|
+
- lib/urbit/bucket.rb
|
92
94
|
- lib/urbit/channel.rb
|
93
95
|
- lib/urbit/chat_channel.rb
|
94
96
|
- lib/urbit/close_message.rb
|
95
97
|
- lib/urbit/config.rb
|
96
98
|
- lib/urbit/fact.rb
|
99
|
+
- lib/urbit/fact/base_fact.rb
|
100
|
+
- lib/urbit/fact/graph_fact.rb
|
101
|
+
- lib/urbit/fact/group_fact.rb
|
102
|
+
- lib/urbit/fact/metadata_fact.rb
|
103
|
+
- lib/urbit/fact/settings_fact.rb
|
97
104
|
- lib/urbit/graph.rb
|
105
|
+
- lib/urbit/group.rb
|
106
|
+
- lib/urbit/group_parser.rb
|
107
|
+
- lib/urbit/groups.rb
|
108
|
+
- lib/urbit/link.rb
|
109
|
+
- lib/urbit/links.rb
|
98
110
|
- lib/urbit/message.rb
|
99
111
|
- lib/urbit/node.rb
|
100
112
|
- lib/urbit/parser.rb
|
101
113
|
- lib/urbit/poke_message.rb
|
102
114
|
- lib/urbit/receiver.rb
|
115
|
+
- lib/urbit/setting.rb
|
116
|
+
- lib/urbit/settings.rb
|
103
117
|
- lib/urbit/ship.rb
|
104
118
|
- lib/urbit/subscribe_message.rb
|
105
|
-
- lib/urbit/
|
106
|
-
- misc/graph-store_graph
|
107
|
-
- misc/graph-store_keys
|
108
|
-
- misc/graph-store_node
|
109
|
-
- misc/graph-store_update
|
110
|
-
- misc/graph-update_add-graph
|
111
|
-
- misc/graph-update_add-nodes
|
112
|
-
- misc/post
|
119
|
+
- lib/urbit/version.rb
|
113
120
|
- urbit-api.gemspec
|
114
121
|
homepage: https://www.ngzax.com
|
115
122
|
licenses:
|
data/.gitignore
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
_config-*.yml
|
2
|
-
*.gem
|
3
|
-
*.rbc
|
4
|
-
/coverage/
|
5
|
-
/pkg/
|
6
|
-
/test/tmp/
|
7
|
-
/test/version_tmp/
|
8
|
-
/tmp/
|
9
|
-
|
10
|
-
## Documentation cache and generated files:
|
11
|
-
/.yardoc/
|
12
|
-
/_yardoc/
|
13
|
-
/doc/
|
14
|
-
/rdoc/
|
15
|
-
|
16
|
-
## Environment normalization:
|
17
|
-
/.bundle/
|
18
|
-
/vendor/bundle
|
19
|
-
/lib/bundler/man/
|
20
|
-
|
21
|
-
# for a library or gem, you might want to ignore these files since the code is
|
22
|
-
# intended to run in multiple environments; otherwise, check them in:
|
23
|
-
Gemfile.lock
|
24
|
-
.ruby-version
|
25
|
-
# .ruby-gemset
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--require spec_helper
|
data/.ruby-version
DELETED
data/CHANGELOG.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Nothing to see here.
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2021 Daryl Richter
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.gem.md
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
|
2
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/urbit/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
-
|
4
|
-
TODO: Delete this and the text above, and describe your gem
|