biilabs-client 0.1.1 → 0.1.2
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/README.md +1 -1
- data/lib/biilabs-client.rb +4 -51
- data/lib/string.rb +5 -0
- data/lib/trytes.rb +42 -0
- data/spec/biilabs-client_spec.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4206f66e9bbcde9a87cad33c09a81f7e63247b98cd6a5368aa9decb76fb7577
|
|
4
|
+
data.tar.gz: 510d8be4d7964f8434ae7aa44fd0636f5c0738437bbcd5daab802be13c4e3d71
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54845ebcfd2d0df2151575a282139ca20d000e6f30908942701ac3f751e1f046afa0e8d10cb7048fdfe4fbd5f2bc6323b1817ddc476de849fa93b8b8ee7dfd97
|
|
7
|
+
data.tar.gz: d5f940afe71f7f713aff16ad58b46de11056039e308f976b4811be96594422c34b53e7c1bc083c8335dd01e9a6b239f06a4bc753ff2432253d59fffe50375cff
|
data/README.md
CHANGED
|
@@ -53,7 +53,7 @@ get tangle from IoTA via Biilabs
|
|
|
53
53
|
|
|
54
54
|
get tangles by tag from IoTA via Biilabs
|
|
55
55
|
|
|
56
|
-
irb> BiilabsClient.new.get_tangle_by_tag('
|
|
56
|
+
irb> BiilabsClient.new.get_tangle_by_tag('my tag')
|
|
57
57
|
# {
|
|
58
58
|
# "transactions"=>[{
|
|
59
59
|
# "hash"=>"LTSDZIYLKSLQHCOZPHWWCNUNSFZCVLTZELARIONAGR9RGY9ZXC9J9AYHUZMGEODZXI9AOMJ9PCKB99999",
|
data/lib/biilabs-client.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require 'string'
|
|
2
|
+
require 'trytes'
|
|
3
|
+
|
|
1
4
|
class BiilabsClient
|
|
2
5
|
attr_reader :config
|
|
3
6
|
|
|
@@ -31,7 +34,7 @@ class BiilabsClient
|
|
|
31
34
|
end
|
|
32
35
|
|
|
33
36
|
def get_tangle_by_tag(tag)
|
|
34
|
-
path = "/tag/#{tag}"
|
|
37
|
+
path = "/tag/#{tag.to_trytes.value}"
|
|
35
38
|
resp = connection.get(path)
|
|
36
39
|
response_handler(resp)
|
|
37
40
|
end
|
|
@@ -54,53 +57,3 @@ class BiilabsClient
|
|
|
54
57
|
end
|
|
55
58
|
end
|
|
56
59
|
end
|
|
57
|
-
|
|
58
|
-
class String
|
|
59
|
-
def to_trytes
|
|
60
|
-
Trytes.new(self)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
class Trytes
|
|
65
|
-
attr_reader :value
|
|
66
|
-
|
|
67
|
-
def initialize(string)
|
|
68
|
-
@value = string
|
|
69
|
-
return if trytes?
|
|
70
|
-
@value = ''
|
|
71
|
-
string.each_char do |char|
|
|
72
|
-
asciiValue = char.unpack('c*').first
|
|
73
|
-
return if asciiValue > 255
|
|
74
|
-
firstValue = asciiValue % 27
|
|
75
|
-
secondValue = (asciiValue - firstValue) / 27
|
|
76
|
-
tryte = trytes_chars[firstValue] + trytes_chars[secondValue]
|
|
77
|
-
@value += tryte
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def to_string
|
|
82
|
-
return unless trytes?
|
|
83
|
-
string = ''
|
|
84
|
-
(0..(value.length - 1)).step(2) do |i|
|
|
85
|
-
tryte = value[i] + value[i + 1]
|
|
86
|
-
break if tryte == '99'
|
|
87
|
-
firstValue = trytes_chars.index(tryte[0])
|
|
88
|
-
secondValue = trytes_chars.index(tryte[1])
|
|
89
|
-
decimalValue = firstValue + secondValue * 27
|
|
90
|
-
string += decimalValue.chr
|
|
91
|
-
end
|
|
92
|
-
string
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
private
|
|
96
|
-
|
|
97
|
-
def trytes_chars
|
|
98
|
-
'9ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def trytes?
|
|
102
|
-
return false unless value.kind_of? String
|
|
103
|
-
return false unless /^[9A-Z]*$/.match(value)
|
|
104
|
-
true
|
|
105
|
-
end
|
|
106
|
-
end
|
data/lib/string.rb
ADDED
data/lib/trytes.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
class Trytes
|
|
2
|
+
attr_reader :value
|
|
3
|
+
|
|
4
|
+
def initialize(string)
|
|
5
|
+
@value = string
|
|
6
|
+
return if trytes?
|
|
7
|
+
@value = ''
|
|
8
|
+
string.each_char do |char|
|
|
9
|
+
asciiValue = char.unpack('c*').first
|
|
10
|
+
return if asciiValue > 255
|
|
11
|
+
firstValue = asciiValue % 27
|
|
12
|
+
secondValue = (asciiValue - firstValue) / 27
|
|
13
|
+
tryte = trytes_chars[firstValue] + trytes_chars[secondValue]
|
|
14
|
+
@value += tryte
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_string
|
|
19
|
+
return value unless trytes?
|
|
20
|
+
string = ''
|
|
21
|
+
(0..(value.length - 1)).step(2) do |i|
|
|
22
|
+
tryte = value[i] + value[i + 1]
|
|
23
|
+
break if tryte == '99'
|
|
24
|
+
firstValue = trytes_chars.index(tryte[0])
|
|
25
|
+
secondValue = trytes_chars.index(tryte[1])
|
|
26
|
+
decimalValue = firstValue + secondValue * 27
|
|
27
|
+
string += decimalValue.chr
|
|
28
|
+
end
|
|
29
|
+
string
|
|
30
|
+
end
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def trytes_chars
|
|
34
|
+
'9ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def trytes?
|
|
38
|
+
return false unless value.kind_of? String
|
|
39
|
+
return false unless /^[9A-Z]*$/.match(value)
|
|
40
|
+
true
|
|
41
|
+
end
|
|
42
|
+
end
|
data/spec/biilabs-client_spec.rb
CHANGED
|
@@ -25,7 +25,7 @@ describe BiilabsClient do
|
|
|
25
25
|
|
|
26
26
|
describe '.get_tangle_by_tag' do
|
|
27
27
|
it 'should return tangles with same tag' do
|
|
28
|
-
result = @client.get_tangle_by_tag(@tag
|
|
28
|
+
result = @client.get_tangle_by_tag(@tag)
|
|
29
29
|
expect(result['transactions'].first['tag'].to_trytes.to_string).to eq(@tag)
|
|
30
30
|
end
|
|
31
31
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: biilabs-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ray Lee
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-06-
|
|
11
|
+
date: 2019-06-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -61,6 +61,8 @@ extra_rdoc_files:
|
|
|
61
61
|
files:
|
|
62
62
|
- README.md
|
|
63
63
|
- lib/biilabs-client.rb
|
|
64
|
+
- lib/string.rb
|
|
65
|
+
- lib/trytes.rb
|
|
64
66
|
- spec/biilabs-client_spec.rb
|
|
65
67
|
homepage: https://github.com/redtear1115/biilabs-client
|
|
66
68
|
licenses:
|