Class: SafeNet::DataId
- Inherits:
-
Object
- Object
- SafeNet::DataId
- Defined in:
- lib/safenet.rb
Instance Method Summary collapse
- #deserialize(contents) ⇒ Object
- #drop_handle(handle_id) ⇒ Object
- #get_data_id_ad(name, is_private = false) ⇒ Object
- #get_data_id_sd(name, type_tag = 500) ⇒ Object
-
#initialize(client_obj) ⇒ DataId
constructor
A new instance of DataId.
- #serialize(handle_id) ⇒ Object
Constructor Details
#initialize(client_obj) ⇒ DataId
Returns a new instance of DataId.
1260 1261 1262 |
# File 'lib/safenet.rb', line 1260 def initialize(client_obj) @client = client_obj end |
Instance Method Details
#deserialize(contents) ⇒ Object
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 |
# File 'lib/safenet.rb', line 1336 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
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 |
# File 'lib/safenet.rb', line 1308 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
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 |
# File 'lib/safenet.rb', line 1286 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
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 |
# File 'lib/safenet.rb', line 1264 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
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 |
# File 'lib/safenet.rb', line 1322 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 |