Class: RecordsKeeperRubyLib::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/RecordsKeeperRubyLib/stream.rb

Class Method Summary collapse

Class Method Details

.publish(address, stream, key, data) ⇒ Object

Function to publish data into the stream



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/RecordsKeeperRubyLib/stream.rb', line 37

def self.publish address, stream, key, data
 datahex1 = data.to_hex_string
 datahex = datahex1.delete(' ')
 auth = {:username => @user, :password => @password}
		options = {
			:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
			:basic_auth => auth,
			:body => [ {"method":"publishfrom","params":[address, stream, key, datahex],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
		}
		response = HTTParty.get(@url, options)
		out = response.parsed_response

		txid = out[0]['result']

		if txid.nil?
			txid = out[0]['error']['message']
		end

		return txid;
end

.retrieve(stream, txid) ⇒ Object

Function to retrieve data against transaction id from the stream



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/RecordsKeeperRubyLib/stream.rb', line 59

def self.retrieve stream, txid
  auth = {:username => @user, :password => @password}
		options = {
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
:basic_auth => auth,
:body => [ {"method":"getstreamitem","params":[stream, txid],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
		}
		response = HTTParty.get(@url, options)
		out = response.parsed_response
		check = out[0]['result']

		if check.nil?
raw_data = out[0]['error']['message']
		else 
data = out[0]['result']['data']
     	raw_data = data.to_byte_string
    	end
		return raw_data;
end

.retrieveItems(stream, count) ⇒ Object

Function to list stream items on RecordsKeeper Blockchain



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/RecordsKeeperRubyLib/stream.rb', line 186

def self.retrieveItems stream, count
 auth = {:username => @user, :password => @password}
 options = {
   :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
   :basic_auth => auth,
   :body => [ {"method":"liststreamitems","params":[stream, false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
 }
 response = HTTParty.get(@url, options)
 out = response.parsed_response

 check = out[0]['result']

		if check.nil?
			retrieveditems = out[0]['error']['message']
		else 
			address =[]
			key_value = []
			raw_data = []
			txid = []

			for i in 0...check.length
address.push(out[0]['result'][i]['publishers'])		        # returns publisher address
key_value.push(out[0]['result'][i]['key'])			          # returns key value of data
data = out[0]['result'][i]['data']					              # returns hex data
      raw_data.push(data.to_byte_string)                     	  # returns raw data
txid.push(out[0]['result'][i]['txid'])				            # returns tx id
			end
			retrieve = {:address => address,:key_value => key_value,:raw_data => raw_data,:txid => txid}
			retrieveditems = JSON.generate retrieve
		end
		return retrieveditems
end

.retrieveWithAddress(stream, address, count) ⇒ Object

Function to retrieve data against a particular publisher address



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/RecordsKeeperRubyLib/stream.rb', line 80

def self.retrieveWithAddress stream, address, count
 check = []
 auth = {:username => @user, :password => @password}
 options = {
   :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
   :basic_auth => auth,
   :body => [ {"method":"liststreampublisheritems","params":[stream, address, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
 }
 response = HTTParty.get(@url, options)
 out = response.parsed_response


 check = out[0]['result']

 
 if check.empty?
 	retrievedinfo = "No published data found for this address"

 else
			key = []
  raw_data = []
  txid = []
			for i in 0...check.length
key.push(out[0]['result'][i]['key'])           	  #returns key value of the published data
      data = out[0]['result'][i]['data']                #returns hex data
      raw_data.push(data.to_byte_string)    						#returns raw data
      txid.push(out[0]['result'][i]['txid'])            #returns tx id
			end
			retrieve = {:key => key,:raw_data => raw_data,:txid => txid}
			retrievedinfo = JSON.generate retrieve
		end
		return retrievedinfo
end

.retrieveWithKey(stream, key, count) ⇒ Object

Function to retrieve data against a particular key value



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/RecordsKeeperRubyLib/stream.rb', line 115

def self.retrieveWithKey stream, key, count
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"liststreamkeyitems","params":[stream, key, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response
  
  check = out[0]['result']

  if check.nil?
retrievedinfo = out[0]['error']['message']
		
		else

publisher = []
   raw_data = []
   txid = []

for i in 0...check.length
  publisher.push(out[0]['result'][i]['publishers'][0])    	#returns publisher's address of published data
     data = out[0]['result'][i]['data']                        #returns published hex data
     raw_data.push(data.to_byte_string)           				#returns data published
     txid.push(out[0]['result'][i]['txid'])                    #returns transaction id of published data
end
retrieve = {:publisher => publisher,:raw_data => raw_data,:txid => txid}
retrievedinfo = JSON.generate retrieve
return retrievedinfo
		end
end

.verifyData(stream, data, count) ⇒ Object

Function to verify data on RecordsKeeper Blockchain



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/RecordsKeeperRubyLib/stream.rb', line 149

def self.verifyData stream, data, count
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"liststreamitems","params":[stream,false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response

  check = out[0]['result']

  if check.nil?
result = out[0]['error']['message']
		else 
raw_data = []
for i in 0...check.length
	result_data = out[0]['result'][i]['data']						       # returns hex data

   	if result_data.unicode_normalized?
		raw_data.push(result_data.to_byte_string)	                 # returns raw data
		
	else
     		raw_data.push("No data found")
   	end
   end

   if raw_data.include?data
	result = "Data is successfully verified."
else
	result = "Data not found."
   end
		end
		return result;
end