urbit-api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a3c9e5915684d444baa066c316ebeafd2cddc0aa731d323b15fec95be932b05
4
- data.tar.gz: 951ddb43e002c92c0490b549de64a2311b42124c09cb499833d58d7c717b088d
3
+ metadata.gz: 466e396f78dad90e05ab4b1010f8c6638ab79468f9adf47f6704ab91f39c4a29
4
+ data.tar.gz: cf2ca6d9f02d70f0a2cd421cc3b1a28d95ba612842ee5a8b6faea6738d3e8e1c
5
5
  SHA512:
6
- metadata.gz: a677021940189cf5e52a969b01d4f77b418dc544d823b47d1dfaf83832c44f00dbe926692d9957f3a01809a8fdda15ba65177b5a57ecb01f310ec800e09d6e75
7
- data.tar.gz: d10188333e23d83a6abee0a44250bdce9641694264fc81970b5de285a973156f00b7b5a342b88e3b4d476d8a363e350012aabcf727cc940b9a2f0fc50ce59918
6
+ metadata.gz: c8012c2739134932ec79654cd9a33edb993dcb88304195574d890bad04bc82e2c6e47ca0f46cae5e3fc288deae7766f173ed7ee25c5f9f9e86fad6a66588cdae
7
+ data.tar.gz: 402992b7ee1782c62025f75d9c1c537ad267db4397346bb04961988c2cfde0d1dc6f233a44f3c8067e0023c22b07c215f9a633d0f33d5325fea4dc6a9650c7dd
data/.ruby-version CHANGED
@@ -1 +1,2 @@
1
- 2.7.2
1
+ 2.7.4
2
+
data/README.md CHANGED
@@ -1,9 +1,12 @@
1
1
  # Urbit::Api
2
+
2
3
  ## The Ruby interface to the Urbit HTTP API
3
4
 
4
5
  This library wraps the Urbit ship http interface exposing it as a Ruby gem.
5
6
 
6
7
  [![awesome urbit badge](https://img.shields.io/badge/~-awesome%20urbit-lightgrey)](https://github.com/urbit/awesome-urbit)
8
+ [![Gem Version](https://badge.fury.io/rb/urbit-api.svg)](https://badge.fury.io/rb/urbit-api)
9
+ [![License](https://img.shields.io/github/license/Zaxonomy/urbit-ruby)](https://github.com/Zaxonomy/urbit-ruby/blob/master/LICENSE.txt)
7
10
 
8
11
  ## Installation
9
12
 
@@ -1,5 +1,5 @@
1
1
  module Urbit
2
2
  module Api
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
data/lib/urbit/graph.rb CHANGED
@@ -14,7 +14,7 @@ module Urbit
14
14
  end
15
15
 
16
16
  def add_node(node:)
17
- @nodes << node
17
+ @nodes << node unless node.deleted?
18
18
  end
19
19
 
20
20
  def host_ship
@@ -56,7 +56,8 @@ module Urbit
56
56
  def newest_nodes(count: 10)
57
57
  count = 1 if count < 1
58
58
  return self.fetch_newest_nodes(count) if @nodes.empty? || @nodes.count < count
59
- self.nodes.reverse[0..(count - 1)]
59
+ last_node = self.nodes.count - 1
60
+ self.nodes[(last_node - count)..last_node]
60
61
  end
61
62
 
62
63
  def oldest_nodes(count: 10)
data/lib/urbit/node.rb CHANGED
@@ -11,8 +11,30 @@ module Urbit
11
11
  @index = nil
12
12
  end
13
13
 
14
+ #
15
+ # Given a bigint representing an urbit date, returns a unix timestamp.
16
+ #
17
+ def self.da_to_unix(da)
18
+ # ported from urbit lib.ts which in turn was ported from +time:enjs:format in hoon.hoon
19
+ da_second = 18446744073709551616
20
+ da_unix_epoch = 170141184475152167957503069145530368000
21
+ offset = da_second / 2000
22
+ epoch_adjusted = offset + (da - da_unix_epoch)
23
+ return (epoch_adjusted * 1000) / da_second
24
+ end
25
+
26
+ #
27
+ # Given a unix timestamp, returns a bigint representing an urbit date
28
+ #
29
+ def self.unix_to_da(unix)
30
+ da_second = 18446744073709551616
31
+ da_unix_epoch = 170141184475152167957503069145530368000
32
+ time_since_epoch = (unix * da_second) / 1000
33
+ return da_unix_epoch + time_since_epoch;
34
+ end
35
+
14
36
  def ==(another_node)
15
- another_node.raw_index == self.raw_index
37
+ another_node.index == self.index
16
38
  end
17
39
 
18
40
  def <=>(another_node)
@@ -20,11 +42,16 @@ module Urbit
20
42
  end
21
43
 
22
44
  def eql?(another_node)
23
- another_node.raw_index == self.raw_index
45
+ another_node.index == self.index
46
+ end
47
+
48
+ def deleted?
49
+ # This is a "deleted" node. Not sure what to do yet, but for now don't create a Node.
50
+ @post_h["index"].nil?
24
51
  end
25
52
 
26
53
  def hash
27
- self.raw_index.hash
54
+ self.index.hash
28
55
  end
29
56
 
30
57
  def author
@@ -47,6 +74,10 @@ module Urbit
47
74
  @post_h['contents']
48
75
  end
49
76
 
77
+ def datetime_sent
78
+ Time.at(self.time_sent / 1000).to_datetime
79
+ end
80
+
50
81
  def persistent?
51
82
  @persistent
52
83
  end
@@ -76,9 +107,13 @@ module Urbit
76
107
  end
77
108
 
78
109
  def raw_index
79
- @post_h["index"].delete_prefix('/')
110
+ return @post_h["index"].delete_prefix('/') unless self.deleted?
111
+ (Node.unix_to_da(Time.now.to_i)).to_s
80
112
  end
81
113
 
114
+ #
115
+ # This is the time sent as recorded by urbit in unix extended format.
116
+ #
82
117
  def time_sent
83
118
  @post_h['time-sent']
84
119
  end
@@ -87,13 +122,17 @@ module Urbit
87
122
  {
88
123
  index: self.index,
89
124
  author: self.author,
125
+ sent: self.datetime_sent,
90
126
  contents: self.contents,
91
- time_sent: self.time_sent,
92
127
  is_parent: !self.children.empty?,
93
128
  child_count: self.children.count
94
129
  }
95
130
  end
96
131
 
132
+ def to_pretty_array
133
+ self.to_h.each.map {|k, v| "#{k}#{(' ' * (12 - k.length))}#{v}"}
134
+ end
135
+
97
136
  def to_s
98
137
  "a Node(#{self.to_h})"
99
138
  end
@@ -108,5 +147,6 @@ module Urbit
108
147
  end
109
148
  subatoms.join('/')
110
149
  end
150
+
111
151
  end
112
152
  end
data/urbit-api.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  spec.name = "urbit-api"
5
5
  spec.version = Urbit::Api::VERSION
6
6
  spec.authors = ["Daryl Richter"]
7
- spec.email = ["daryl@deliverycircle.com"]
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.}
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daryl Richter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-08 00:00:00.000000000 Z
11
+ date: 2021-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '3.10'
69
69
  description: Access your urbit ship the ruby way. It's a Martian gem.
70
70
  email:
71
- - daryl@deliverycircle.com
71
+ - daryl@ngzax.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubygems_version: 3.1.4
136
+ rubygems_version: 3.1.6
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: The Ruby interface to the Urbit HTTP API