Class: SafeNet::DataId

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

Instance Method Summary collapse

Constructor Details

#initialize(client_obj) ⇒ DataId

Returns a new instance of DataId.



1220
1221
1222
# File 'lib/safenet.rb', line 1220

def initialize(client_obj)
  @client = client_obj
end

Instance Method Details

#deserialize(contents) ⇒ Object



1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
# File 'lib/safenet.rb', line 1296

def deserialize(contents)
  # entry point
  url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id"

  # api call
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  headers = {
    'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
    'Content-Type': 'text/plain'
  }
  headers["Content-Length"] = contents.size.to_s
  req = Net::HTTP::Post.new(uri.path, headers)
  req.body = contents
  res = http.request(req)
  res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
end

#drop_handle(handle_id) ⇒ Object



1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
# File 'lib/safenet.rb', line 1268

def drop_handle(handle_id)
  # entry point
  url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id/#{handle_id}"

  # api call
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  req = Net::HTTP::Delete.new(uri.path, {
    'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
  })
  res = http.request(req)
  res.code == "200" ? true : JSON.parse(res.body)
end

#get_data_id_ad(name, is_private = false) ⇒ Object



1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# File 'lib/safenet.rb', line 1246

def get_data_id_ad(name, is_private = false)
  # Entry point
  url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id/appendable-data"

  # Payload
  payload = {
    name: name,
    isPrivate: is_private
  }

  # API call
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  req = Net::HTTP::Post.new(uri.path, {
    'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
    'Content-Type' => 'application/json'
  })
  req.body = payload.to_json
  res = http.request(req)
  res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
end

#get_data_id_sd(name, type_tag = 500) ⇒ Object



1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
# File 'lib/safenet.rb', line 1224

def get_data_id_sd(name, type_tag = 500)
  # Entry point
  url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id/structured-data"

  # Payload
  payload = {
    name: name,
    typeTag: type_tag
  }

  # API call
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  req = Net::HTTP::Post.new(uri.path, {
    'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}",
    'Content-Type' => 'application/json'
  })
  req.body = payload.to_json
  res = http.request(req)
  res.code == "200" ? JSON.parse(res.body)['handleId'] : JSON.parse(res.body)
end

#serialize(handle_id) ⇒ Object



1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
# File 'lib/safenet.rb', line 1282

def serialize(handle_id)
  # entry point
  url = "#{@client.app_info[:launcher_server]}#{API_VERSION}/data-id/#{handle_id}"

  # api call
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  req = Net::HTTP::Get.new(uri.path, {
    'Authorization' => "Bearer #{@client.key_helper.get_valid_token()}"
  })
  res = http.request(req)
  res.code == "200" ? res.body : JSON.parse(res.body)
end