urbit-api 0.2.0 → 0.4.0
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 +4 -4
- data/lib/urbit/bucket.rb +45 -0
- data/lib/urbit/channel.rb +4 -5
- data/lib/urbit/fact/base_fact.rb +99 -0
- data/lib/urbit/fact/graph_fact.rb +92 -0
- data/lib/urbit/fact/group_fact.rb +124 -0
- data/lib/urbit/fact/settings_fact.rb +120 -0
- data/lib/urbit/fact.rb +44 -60
- data/lib/urbit/graph.rb +3 -2
- data/lib/urbit/group.rb +109 -0
- data/lib/urbit/group_manager.rb +100 -0
- data/lib/urbit/group_parser.rb +71 -0
- data/lib/urbit/message.rb +2 -2
- data/lib/urbit/node.rb +45 -5
- 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/settings.rb +103 -0
- data/lib/urbit/ship.rb +63 -28
- data/lib/urbit/version.rb +5 -0
- data/lib/{urbit/urbit.rb → urbit.rb} +3 -2
- data/urbit-api.gemspec +8 -9
- metadata +33 -30
- data/.gitignore +0 -25
- data/.rspec +0 -1
- data/.ruby-version +0 -1
- data/CHANGELOG.md +0 -1
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -21
- data/README.gem.md +0 -4
- data/README.md +0 -237
- 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
data/lib/urbit/ship.rb
CHANGED
@@ -3,17 +3,21 @@ require 'faraday'
|
|
3
3
|
require 'urbit/channel'
|
4
4
|
require 'urbit/config'
|
5
5
|
require 'urbit/graph'
|
6
|
+
require 'urbit/group_manager'
|
7
|
+
require 'urbit/settings'
|
6
8
|
|
7
9
|
module Urbit
|
8
10
|
class Ship
|
9
11
|
attr_accessor :logged_in
|
10
|
-
attr_reader :auth_cookie, :channels, :config
|
12
|
+
attr_reader :auth_cookie, :channels, :config, :group_mgr
|
11
13
|
|
12
14
|
def initialize(config: Config.new)
|
13
15
|
@auth_cookie = nil
|
14
16
|
@channels = []
|
15
17
|
@config = config
|
16
18
|
@graphs = []
|
19
|
+
@group_mgr = GroupManager.new ship: self
|
20
|
+
@settings = nil # Use lazy initialization here
|
17
21
|
@logged_in = false
|
18
22
|
end
|
19
23
|
|
@@ -60,12 +64,28 @@ module Urbit
|
|
60
64
|
self.graphs.collect {|g| g.resource}
|
61
65
|
end
|
62
66
|
|
67
|
+
#
|
68
|
+
# Answers the Group uniquely keyed by path:, if it exists
|
69
|
+
#
|
70
|
+
def group(path:)
|
71
|
+
@group_mgr.find_by_path(path)
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Answers the object managing the Groups on this ship.
|
76
|
+
# This object provides all the helper methods to list, join, leave, &c. a Group
|
77
|
+
#
|
78
|
+
def groups
|
79
|
+
@group_mgr
|
80
|
+
end
|
81
|
+
|
63
82
|
def login
|
64
83
|
return self if logged_in?
|
65
84
|
|
66
85
|
ensure_connections_closed
|
67
86
|
response = Faraday.post(login_url, "password=#{config.code}")
|
68
87
|
parse_cookie(response)
|
88
|
+
@group_mgr.load
|
69
89
|
self
|
70
90
|
end
|
71
91
|
|
@@ -73,35 +93,14 @@ module Urbit
|
|
73
93
|
config.name
|
74
94
|
end
|
75
95
|
|
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('~', '')
|
96
|
+
def open_channels
|
97
|
+
@channels.select {|c| c.open?}
|
95
98
|
end
|
96
99
|
|
97
100
|
def pat_p
|
98
101
|
config.name
|
99
102
|
end
|
100
103
|
|
101
|
-
def open_channels
|
102
|
-
@channels.select {|c| c.open?}
|
103
|
-
end
|
104
|
-
|
105
104
|
#
|
106
105
|
# Poke an app with a message using a mark.
|
107
106
|
#
|
@@ -112,10 +111,27 @@ module Urbit
|
|
112
111
|
(self.add_channel).poke(app: app, mark: mark, message: message)
|
113
112
|
end
|
114
113
|
|
114
|
+
def remove_graph(desk: 'landscape', graph:)
|
115
|
+
delete_json = %Q({
|
116
|
+
"delete": {
|
117
|
+
"resource": {
|
118
|
+
"ship": "#{self.name}",
|
119
|
+
"name": "#{graph.name}"
|
120
|
+
}
|
121
|
+
}
|
122
|
+
})
|
123
|
+
|
124
|
+
spider = self.spider(desk: desk, mark_in: 'graph-view-action', mark_out: 'json', thread: 'graph-delete', data: delete_json, args: ["NO_RESPONSE"])
|
125
|
+
if (retcode = (200 == spider[:status]))
|
126
|
+
self.graphs.delete graph
|
127
|
+
end
|
128
|
+
retcode
|
129
|
+
end
|
130
|
+
|
115
131
|
def scry(app:, path:, mark: 'json')
|
116
132
|
self.login
|
117
133
|
mark = ".#{mark}" unless mark.empty?
|
118
|
-
scry_url = "#{self.
|
134
|
+
scry_url = "#{self.url}/~/scry/#{app}#{path}#{mark}"
|
119
135
|
|
120
136
|
response = Faraday.get(scry_url) do |req|
|
121
137
|
req.headers['Accept'] = 'application/json'
|
@@ -125,9 +141,20 @@ module Urbit
|
|
125
141
|
{status: response.status, code: response.reason_phrase, body: response.body}
|
126
142
|
end
|
127
143
|
|
128
|
-
|
144
|
+
#
|
145
|
+
# Answers the object managing the Settings on this ship.
|
146
|
+
# This object provides all the helper methods to list, update, and remove a Setting
|
147
|
+
#
|
148
|
+
def settings
|
149
|
+
if self.logged_in?
|
150
|
+
@settings = Settings.load(ship: self) if @settings.nil?
|
151
|
+
end
|
152
|
+
@settings
|
153
|
+
end
|
154
|
+
|
155
|
+
def spider(desk: 'landscape', mark_in:, mark_out:, thread:, data:, args: [])
|
129
156
|
self.login
|
130
|
-
url = "#{self.
|
157
|
+
url = "#{self.url}/spider/#{desk}/#{mark_in}/#{thread}/#{mark_out}.json"
|
131
158
|
|
132
159
|
# TODO: This is a huge hack due to the fact that certain spider operations are known to
|
133
160
|
# not return when they should. Instead I just set the timeout low and catch the
|
@@ -175,6 +202,14 @@ module Urbit
|
|
175
202
|
"a Ship(#{self.to_h})"
|
176
203
|
end
|
177
204
|
|
205
|
+
def untilded_name
|
206
|
+
name.gsub('~', '')
|
207
|
+
end
|
208
|
+
|
209
|
+
def url
|
210
|
+
self.config.api_base_url
|
211
|
+
end
|
212
|
+
|
178
213
|
private
|
179
214
|
|
180
215
|
def add_channel
|
@@ -193,7 +228,7 @@ module Urbit
|
|
193
228
|
end
|
194
229
|
|
195
230
|
def login_url
|
196
|
-
"#{
|
231
|
+
"#{self.url}/~/login"
|
197
232
|
end
|
198
233
|
|
199
234
|
def parse_cookie(resp)
|
data/urbit-api.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
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
|
-
spec.email = ["daryl@
|
7
|
+
spec.email = ["daryl@ngzax.com"]
|
8
8
|
|
9
9
|
spec.summary = %q{The Ruby interface to the Urbit HTTP API}
|
10
10
|
spec.description = %q{Access your urbit ship the ruby way. It's a Martian gem.}
|
@@ -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.4.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-03-18 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
|
@@ -68,48 +82,37 @@ dependencies:
|
|
68
82
|
version: '3.10'
|
69
83
|
description: Access your urbit ship the ruby way. It's a Martian gem.
|
70
84
|
email:
|
71
|
-
- daryl@
|
85
|
+
- daryl@ngzax.com
|
72
86
|
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/settings_fact.rb
|
97
103
|
- lib/urbit/graph.rb
|
104
|
+
- lib/urbit/group.rb
|
105
|
+
- lib/urbit/group_manager.rb
|
106
|
+
- lib/urbit/group_parser.rb
|
98
107
|
- lib/urbit/message.rb
|
99
108
|
- lib/urbit/node.rb
|
100
109
|
- lib/urbit/parser.rb
|
101
110
|
- lib/urbit/poke_message.rb
|
102
111
|
- lib/urbit/receiver.rb
|
112
|
+
- lib/urbit/settings.rb
|
103
113
|
- lib/urbit/ship.rb
|
104
114
|
- 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
|
115
|
+
- lib/urbit/version.rb
|
113
116
|
- urbit-api.gemspec
|
114
117
|
homepage: https://www.ngzax.com
|
115
118
|
licenses:
|
@@ -133,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
136
|
- !ruby/object:Gem::Version
|
134
137
|
version: '0'
|
135
138
|
requirements: []
|
136
|
-
rubygems_version: 3.1.
|
139
|
+
rubygems_version: 3.1.6
|
137
140
|
signing_key:
|
138
141
|
specification_version: 4
|
139
142
|
summary: The Ruby interface to the Urbit HTTP API
|
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
@@ -1 +0,0 @@
|
|
1
|
-
2.7.2
|
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
|
data/README.md
DELETED
@@ -1,237 +0,0 @@
|
|
1
|
-
# Urbit::Api
|
2
|
-
## The Ruby interface to the Urbit HTTP API
|
3
|
-
|
4
|
-
This library wraps the Urbit ship http interface exposing it as a Ruby gem.
|
5
|
-
|
6
|
-
[](https://github.com/urbit/awesome-urbit)
|
7
|
-
|
8
|
-
## Installation
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
gem 'urbit-api'
|
14
|
-
```
|
15
|
-
|
16
|
-
And then execute:
|
17
|
-
|
18
|
-
$ bundle install
|
19
|
-
|
20
|
-
Or install it yourself as:
|
21
|
-
|
22
|
-
$ gem install urbit-api
|
23
|
-
|
24
|
-
## Usage
|
25
|
-
|
26
|
-
```sh
|
27
|
-
> bin/console
|
28
|
-
|
29
|
-
# This will instantiate a ship that connects to the fake `~zod` dev server by default
|
30
|
-
# See Urbit docs for more info: https://urbit.org/using/develop/
|
31
|
-
[1] pry(main)> ship = Urbit.new
|
32
|
-
=> #<Urbit::Ship:0x00007fa74b87f920 ...
|
33
|
-
|
34
|
-
OR... with config file...
|
35
|
-
> ship = Urbit.connect(config_file: '_config-barsyr-latreb.yml')
|
36
|
-
|
37
|
-
> ship.logged_in?
|
38
|
-
=> false
|
39
|
-
|
40
|
-
> ship.login
|
41
|
-
=> #<Urbit::Ship:0x00007fa74b87f920 ...
|
42
|
-
|
43
|
-
> ship.logged_in?
|
44
|
-
=> true
|
45
|
-
|
46
|
-
> ship.to_s
|
47
|
-
=> "a Ship(name: '~barsyr-latreb', host: 'http://localhost', port: '8080')"
|
48
|
-
|
49
|
-
> channel = ship.subscribe(app: 'graph-store', path: '/updates')
|
50
|
-
=> a Channel (Open) on ~barsyr-latreb(name: 'Channel-0', key: '1622836437b540b4')
|
51
|
-
|
52
|
-
# Subscribing works by opening a Channel. Your ships has a collection of all it's open Channels.
|
53
|
-
> channel = ship.open_channels.first
|
54
|
-
=> a Channel (Open) on ~barsyr-latreb(name: 'Channel-0', key: '1622836437b540b4')
|
55
|
-
|
56
|
-
# Notice that it's the same one.
|
57
|
-
|
58
|
-
# Every Channel has a unique key to identify it.
|
59
|
-
> channel.key
|
60
|
-
=> "16142890875c348d"
|
61
|
-
|
62
|
-
# The Channel has a Receiver that will now be listening on the app and path you specified. Each time an event is sent in it will be stored in the receiver's facts collection.
|
63
|
-
> channel.receiver.facts.count
|
64
|
-
=> 12
|
65
|
-
|
66
|
-
# Perform any action through landscape that would initiate an update into %graph-store...
|
67
|
-
# In this case I have added a comment to a local notebook.
|
68
|
-
> channel.receiver.facts.last
|
69
|
-
=> a Fact({:ship=>{:name=>"~barsyr-latreb", :host=>"http://localhost", :port=>"8080"}, :resource=>"~barsyr-latreb/test0-996", :acknowleged=>true, :is_graph_update=>true})
|
70
|
-
|
71
|
-
# Your ship keeps a collection of all the messages sent to urbit:
|
72
|
-
> channel.sent_messages.collect {|m| m.to_s}
|
73
|
-
=> [
|
74
|
-
"a Message({:action=>"poke", :app=>"hood", :id=>1, :json=>"Opening Airlock", :mark=>"helm-hi", :ship=>"barsyr-latreb"})",
|
75
|
-
"a Message({:action=>"subscribe", :app=>"graph-store", :id=>2, :path=>"/updates", :ship=>"barsyr-latreb"})",
|
76
|
-
"a Message({"id"=>3, "action"=>"ack", "event-id"=>"0"})",
|
77
|
-
"a Message({"id"=>4, "action"=>"ack", "event-id"=>"1"})",
|
78
|
-
"a Message({"id"=>5, "action"=>"ack", "event-id"=>"2"})"
|
79
|
-
]
|
80
|
-
|
81
|
-
#
|
82
|
-
# --------------------------------------------------------------------
|
83
|
-
# Poke
|
84
|
-
# --------------------------------------------------------------------
|
85
|
-
#
|
86
|
-
> ship.poke(app: 'hood', mark: 'helm-hi', message: 'Opening Airlock')
|
87
|
-
=> a Channel (Open) on ~barsyr-latreb(name: 'Channel-0', key: '1630355920a717e1')
|
88
|
-
|
89
|
-
#
|
90
|
-
# --------------------------------------------------------------------
|
91
|
-
# Scry
|
92
|
-
# --------------------------------------------------------------------
|
93
|
-
#
|
94
|
-
# Retrieving your ship's base hash using scry....
|
95
|
-
> ship.scry(app: 'file-server', path: '/clay/base/hash')
|
96
|
-
# => {:status=>200, :code=>"ok", :body=>"\"e75k5\""}
|
97
|
-
|
98
|
-
#
|
99
|
-
# --------------------------------------------------------------------
|
100
|
-
# Spider
|
101
|
-
# --------------------------------------------------------------------
|
102
|
-
#
|
103
|
-
# Creating a new Notebook in "My Channels" using %spider....
|
104
|
-
> create_json = %Q(
|
105
|
-
{"create": {"resource": { "ship": "~zod", "name": "random_name"},
|
106
|
-
"title": "Testing",
|
107
|
-
"description": "Testing Un-Managed Graph Creation",
|
108
|
-
"associated" : {"policy": {"invite": {"pending": []}}},
|
109
|
-
"module": "publish", "mark": "graph-validator-publish"}}
|
110
|
-
)
|
111
|
-
> ship.spider(mark_in: 'graph-view-action', mark_out: 'json', thread: 'graph-create', data: create_json)
|
112
|
-
# => {:status=>200, :code=>"ok", :body=>"\"e75k5\""}
|
113
|
-
|
114
|
-
#
|
115
|
-
# --------------------------------------------------------------------
|
116
|
-
# %graph-store
|
117
|
-
# --------------------------------------------------------------------
|
118
|
-
#
|
119
|
-
> puts ship.graph_names
|
120
|
-
~barsyr-latreb/dm-inbox
|
121
|
-
~darlur/announce
|
122
|
-
~bitbet-bolbel/urbit-community-5.963
|
123
|
-
~winter-paches/top-shelf-6391
|
124
|
-
~winter-paches/the-great-north-7.579
|
125
|
-
~barsyr-latreb/test0-996
|
126
|
-
~fabled-faster/test-chat-a-5919
|
127
|
-
~barsyr-latreb/test1-4287
|
128
|
-
~darrux-landes/welcome-to-urbit-community
|
129
|
-
~millyt-dorsen/finance-2.962
|
130
|
-
~fabled-faster/interface-testing-facility-683
|
131
|
-
~darlur/help-desk-4556
|
132
|
-
=>
|
133
|
-
|
134
|
-
# Reference a graph by name and return a single node.
|
135
|
-
> puts ship.graph(resource: '~winter-paches/top-shelf-6391').node(index: "170.141.184.505.207.751.870.046.689.877.378.990.080")
|
136
|
-
a Node({:index=>"170.141.184.505.207.751.870.046.689.877.378.990.080", :author=>"witfyl-ravped", :contents=>[{"text"=>"the patches don't really bother me though tbh"}], :time_sent=>1629316468195, :is_parent=>false, :child_count=>0})
|
137
|
-
=>
|
138
|
-
|
139
|
-
# You can also reference a graph by its index in the graphs collection.
|
140
|
-
> puts ship.graphs[3].node(index: "170.141.184.505.207.751.870.046.689.877.378.990.080")
|
141
|
-
a Node({:index=>"170.141.184.505.207.751.870.046.689.877.378.990.080", :author=>"witfyl-ravped", :contents=>[{"text"=>"the patches don't really bother me though tbh"}], :time_sent=>1629316468195, :is_parent=>false, :child_count=>0})
|
142
|
-
=>
|
143
|
-
|
144
|
-
# Return the contents of the 5 oldest nodes of a graph
|
145
|
-
> graph = ship.graph(resource: '~winter-paches/top-shelf-6391')
|
146
|
-
> graph.oldest_nodes(count: 5).sort.each {|n| p n.contents};nil
|
147
|
-
[{"text"=>"watching the 2020 stanley cup finals (tampa (sigh) just went up 2-0 in game 3) and i thought: \"the great north has to have a hockey chat, eh?\""}]
|
148
|
-
[{"text"=>"we'll see if this has legs. ;)"}]
|
149
|
-
[{"text"=>"shortie! now 2-1 tampa."}]
|
150
|
-
[{"text"=>"looks like tampa's going to go up 2-1. as a canadian this geographically depresses me. :/"}]
|
151
|
-
[{"text"=>"anyone in the stands?"}]
|
152
|
-
=>
|
153
|
-
|
154
|
-
# A single Node. In this case, the 3rd oldest node in the graph.
|
155
|
-
> puts graph.nodes[2].contents
|
156
|
-
{"text"=>"shortie! now 2-1 tampa."}
|
157
|
-
=>
|
158
|
-
|
159
|
-
# Getting the next newer Node. Remember that it always returns an Array, hence the '#first'.
|
160
|
-
> puts graph.nodes[2].next.first.contents
|
161
|
-
{"text"=>"looks like tampa's going to go up 2-1. as a canadian this geographically depresses me. :/"}
|
162
|
-
=>
|
163
|
-
|
164
|
-
# Return the indexes of the newest 5 nodes of a graph
|
165
|
-
> ship.graph(resource: '~winter-paches/top-shelf-6391').newest_nodes(count: 5).sort.each {|n| p n.index};nil
|
166
|
-
"170.141.184.505.209.257.330.601.508.862.548.770.816"
|
167
|
-
"170.141.184.505.209.375.247.350.471.711.992.578.048"
|
168
|
-
"170.141.184.505.209.545.972.004.310.065.795.301.376"
|
169
|
-
"170.141.184.505.209.627.337.970.761.265.544.429.568"
|
170
|
-
"170.141.184.505.209.644.102.846.398.558.514.446.336"
|
171
|
-
=>
|
172
|
-
|
173
|
-
# Fetching nodes older relative to another node. (See indexes above)
|
174
|
-
> puts (node = ship.graph(resource: '~winter-paches/top-shelf-6391').node(index: "170.141.184.505.209.644.102.846.398.558.514.446.336"))
|
175
|
-
a Node({:index=>"170.141.184.505.209.644.102.846.398.558.514.446.336", :author=>"winter-paches", :contents=>[{"text"=>"yep. that's how i did it as a kid. harry caray was the white sox announcer before he turned traitor and went to the cubs."}], :time_sent=>1629419046028, :is_parent=>false, :child_count=>0})
|
176
|
-
=>
|
177
|
-
|
178
|
-
> puts node.previous
|
179
|
-
a Node({:index=>"170.141.184.505.209.627.337.970.761.265.544.429.568", :author=>"pathus-hiddyn", :contents=>[{"text"=>"Lol oh man I haven’t listened to a baseball game on the radio in forever. It is great isn’t it. "}], :time_sent=>1629418137668, :is_parent=>false, :child_count=>0})
|
180
|
-
=>
|
181
|
-
|
182
|
-
> node.previous(count: 4).each {|n| p n.index};nil
|
183
|
-
"170.141.184.505.209.257.330.601.508.862.548.770.816"
|
184
|
-
"170.141.184.505.209.375.247.350.471.711.992.578.048"
|
185
|
-
"170.141.184.505.209.545.972.004.310.065.795.301.376"
|
186
|
-
"170.141.184.505.209.627.337.970.761.265.544.429.568"
|
187
|
-
```
|
188
|
-
### Configuration
|
189
|
-
|
190
|
-
Configure your ship using a config file or constructor keyword arguments. Either or both can be used; the keyword args will override any values set via config file.
|
191
|
-
|
192
|
-
Supported keys:
|
193
|
-
- `code` - the auth code
|
194
|
-
- `host` - the ship's host (e.g., 'localhost' or 'myship.net')
|
195
|
-
- `name` - the ship's name (e.g, '~zod')
|
196
|
-
- `port` - the open www port on your ship ('80' by default)
|
197
|
-
|
198
|
-
#### Config File
|
199
|
-
|
200
|
-
See [`_config.yml`](_config.yml) for an example config file. This will connect to a local fake zod, see creation instructions below.
|
201
|
-
|
202
|
-
```rb
|
203
|
-
ship = Urbit.new(config_file: 'my-moon.yml')
|
204
|
-
```
|
205
|
-
|
206
|
-
#### Constructor Keyword Arguments
|
207
|
-
|
208
|
-
```rb
|
209
|
-
ship = Urbit.new(host: '127.0.0.1', port: '8080')
|
210
|
-
```
|
211
|
-
|
212
|
-
## Testing
|
213
|
-
|
214
|
-
```sh
|
215
|
-
bin/test
|
216
|
-
```
|
217
|
-
Tests assume that an instance of a ["fake" development Urbit ship](https://urbit.org/using/develop/) (one not connected to the live network) will be running, available at `http://localhost:8080`.
|
218
|
-
### "fake" ~zod
|
219
|
-
|
220
|
-
To create this development ship:
|
221
|
-
```sh
|
222
|
-
./urbit -F zod
|
223
|
-
```
|
224
|
-
## Development
|
225
|
-
|
226
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
227
|
-
|
228
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
229
|
-
|
230
|
-
## Contributing
|
231
|
-
|
232
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/urbit-api.
|
233
|
-
|
234
|
-
|
235
|
-
## License
|
236
|
-
|
237
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
DELETED
data/_config.yml
DELETED