urbit-api 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a306b64d165415e7a680fd82a20b75de6840ca80d9482be6ceacbd13fd2b4a9f
4
- data.tar.gz: 81ce508aee55fd9cdee15bb56774adf5f226b7f5620d9430f4be8de73cb307f9
3
+ metadata.gz: b57a15f5dfda9e19e863a4fb4760279b98c9d2af55f9865a470be3f6cb23520a
4
+ data.tar.gz: a5442c3e68b634372791bd4ecee3a8a84de201dbe708d94709ddff7fdf20827e
5
5
  SHA512:
6
- metadata.gz: 1cfffd8c6a8f82d701ace0b49266036f17bc481ea75d799d871e7d785899771686d6682a5444a1a20d3b167d7b5415ef4d05b18baa2dc1553000719055b5ca58
7
- data.tar.gz: 561e7976cf6d5b5c07e224079e53f6a6102214d317050fd16d1eb5639befb41b020f88ff50b18a94ffda31eaf85515408e5e85bbf38b3610d59e141c02dfb3de
6
+ metadata.gz: 3e1f0ba98b3ad9cfea824c2b48da18a0123d1a83df844809dcde1bda5e301871477f6c30064e47351c3a0302402482886d709324409e74420078b8c98ecb5e73
7
+ data.tar.gz: 49077ec0705dcbecbe1f758911d982e0101f20c07e2d3638bb99729e57dcbc9e331ee048dcd255f1f729cc1ab6129043a0b79dd1269c350924c3b86a95b8508c
data/lib/urbit/graph.rb CHANGED
@@ -23,6 +23,11 @@ module Urbit
23
23
  @creator
24
24
  end
25
25
 
26
+ def delete
27
+ resp = self.ship.spider(mark_in: 'graph-view-action', mark_out: 'json', thread: 'graph-delete', data: self.delete_graph_json, args: ["NO_RESPONSE"])
28
+ @persistent = !(200 == resp[:status])
29
+ end
30
+
26
31
  def description
27
32
  self.fetch_link if @description.nil?
28
33
  @description
@@ -52,6 +57,19 @@ module Urbit
52
57
  # r = self.ship.scry(app: 'graph-store', path: "/graph/#{self.to_s}/mark")
53
58
  # end
54
59
 
60
+ #
61
+ # Transform this Graph into a PublishGraph.
62
+ #
63
+ # TODO: This is a very crude way to do this since we don't get the type of graph back from
64
+ # our initial call to retrieve the graphs, only later with the metadata.
65
+ #
66
+ # This will need some more thought.
67
+ #
68
+ def molt
69
+ return PublishGraph.new(ship: self.ship, graph_name: self.name, title: self.title, description: self.description, persistent: true) if 'publish' == self.type
70
+ self
71
+ end
72
+
55
73
  #
56
74
  # Finds a single node in this graph by its index.
57
75
  # The index here should be the atom representation (as returned by Node#index).
@@ -120,15 +138,17 @@ module Urbit
120
138
  #
121
139
  # the canonical printed representation of a Graph
122
140
  def to_s
123
- "a Graph(#{self.resource})"
141
+ "a #{self.class.name.split('::').last}(#{self.resource})"
124
142
  end
125
143
 
126
144
  private
127
145
 
146
+ def delete_graph_json
147
+ %Q({"delete": {"resource": {"ship": "#{self.ship.name}", "name": "#{self.name}"}}})
148
+ end
149
+
128
150
  def fetch_all_nodes
129
- self.fetch_nodes("#{self.graph_resource}/",
130
- AddGraphParser,
131
- "add-graph")
151
+ self.fetch_nodes("#{self.graph_resource}/", AddGraphParser, "add-graph")
132
152
  end
133
153
 
134
154
  def fetch_link
@@ -182,4 +202,75 @@ module Urbit
182
202
  "/graph/#{self.resource}"
183
203
  end
184
204
  end
205
+
206
+ class PublishGraph < Graph
207
+
208
+ attr_accessor :description, :title
209
+
210
+ def initialize(ship:, graph_name:, title:, description:, persistent: false)
211
+ super ship: ship, graph_name: graph_name, host_ship_name: ship.untilded_name
212
+ @persistent = persistent
213
+ @title = title
214
+ @description = description
215
+ end
216
+
217
+ def add_post(author:, title:, body:)
218
+ j = self.create_post_json(author, title, body)
219
+ resp = self.ship.spider(mark_in: 'graph-update-3', mark_out: 'graph-view-action', thread: 'graph-add-nodes', data: j)
220
+ (200 == resp[:status])
221
+ end
222
+
223
+ def persist
224
+ # PublishGraph, persist thyself in urbit...
225
+ resp = self.ship.spider(mark_in: 'graph-view-action', mark_out: 'json', thread: 'graph-create', data: self.create_graph_json)
226
+ @persistent = (200 == resp[:status])
227
+ end
228
+
229
+ def persistent?
230
+ @persistent
231
+ end
232
+
233
+ private
234
+
235
+ def create_graph_json
236
+ %Q({"create": {"resource" : {"ship": "#{self.ship.name}", "name": "#{self.name}"},
237
+ "title" : "#{self.title}",
238
+ "description": "#{self.description}",
239
+ "associated" : {"policy": {"invite": {"pending": []}}},
240
+ "module" : "publish",
241
+ "mark" : "graph-validator-publish"
242
+ }
243
+ })
244
+ end
245
+
246
+ def create_post_json(author, title, body)
247
+ time = Time.now.to_i
248
+ index = Urbit::Node.unix_to_da(time)
249
+ %Q({
250
+ "add-nodes": {
251
+ "resource": {"ship": "#{self.host_ship}", "name": "#{self.name}"},
252
+ "nodes": {
253
+ "/#{index}": {
254
+ "post": {"author": "#{author}", "index": "/#{index}", "time-sent": #{time}, "contents": [], "hash": null, "signatures": []},
255
+ "children": {
256
+ "1": {
257
+ "post": { "author": "#{author}", "index": "/#{index}/1", "time-sent": #{time}, "contents": [], "hash": null, "signatures": []},
258
+ "children": {
259
+ "1": {
260
+ "post": {"author": "#{author}", "index": "/#{index}/1/1", "time-sent": #{time}, "contents": [{"text": "#{title}"}, {"text": "#{body}"}], "hash": null, "signatures": []},
261
+ "children": null
262
+ }
263
+ }
264
+ },
265
+ "2": {
266
+ "post": {"author": "#{author}", "index": "/#{index}/2", "time-sent": #{time}, "contents": [], "hash": null, "signatures": []},
267
+ "children": null
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+ })
274
+ end
275
+ end
185
276
  end
data/lib/urbit/node.rb CHANGED
@@ -98,6 +98,10 @@ module Urbit
98
98
  @graph.newer_sibling_nodes(node: self, count: count)
99
99
  end
100
100
 
101
+ def parent?
102
+ !self.children.empty?
103
+ end
104
+
101
105
  #
102
106
  # Answers the previous {count} Nodes relative to this Node.
103
107
  # Defaults to the next Node if no {count} is passed.
@@ -124,7 +128,7 @@ module Urbit
124
128
  author: self.author,
125
129
  sent: self.datetime_sent,
126
130
  contents: self.contents,
127
- is_parent: !self.children.empty?,
131
+ is_parent: self.parent?,
128
132
  child_count: self.children.count
129
133
  }
130
134
  end
data/lib/urbit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Urbit
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daryl Richter
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-29 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -125,7 +125,7 @@ metadata:
125
125
  homepage_uri: https://www.ngzax.com
126
126
  source_code_uri: https://github.com/Zaxonomy/urbit-ruby
127
127
  changelog_uri: https://github.com/Zaxonomy/urbit-ruby/CHANGELOG.md
128
- post_install_message:
128
+ post_install_message:
129
129
  rdoc_options: []
130
130
  require_paths:
131
131
  - lib
@@ -140,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.1.6
144
- signing_key:
143
+ rubygems_version: 3.0.3.1
144
+ signing_key:
145
145
  specification_version: 4
146
146
  summary: The Ruby interface to the Urbit HTTP API
147
147
  test_files: []