From aa9a3d4b364be776f32331d9ea9986b2956fb136 Mon Sep 17 00:00:00 2001 From: Eduardo Ozores Date: Thu, 12 Dec 2024 17:14:04 +0100 Subject: [PATCH 1/7] Update copyright --- error.rb | 2 +- example/example.rb | 2 +- latch.rb | 2 +- latch_app.rb | 2 +- latch_auth.rb | 2 +- latch_response.rb | 2 +- latch_user.rb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/error.rb b/error.rb index 47921b5..16d170e 100644 --- a/error.rb +++ b/error.rb @@ -1,5 +1,5 @@ #Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. -#Copyright (C) 2023 Telefonica Digital +#Copyright (C) 2024 Telefonica Innovación Digital # #This library is free software; you can redistribute it and/or #modify it under the terms of the GNU Lesser General Public diff --git a/example/example.rb b/example/example.rb index 30b719b..cf22e5c 100644 --- a/example/example.rb +++ b/example/example.rb @@ -1,5 +1,5 @@ #Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. -#Copyright (C) 2023 Telefonica Digital +#Copyright (C) 2024 Telefonica Innovación Digital # #This library is free software; you can redistribute it and/or #modify it under the terms of the GNU Lesser General Public diff --git a/latch.rb b/latch.rb index 9ddbd28..76cb518 100644 --- a/latch.rb +++ b/latch.rb @@ -1,5 +1,5 @@ #Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. -#Copyright (C) 2023 Telefonica Digital +#Copyright (C) 2024 Telefonica Innovación Digital # #This library is free software; you can redistribute it and/or #modify it under the terms of the GNU Lesser General Public diff --git a/latch_app.rb b/latch_app.rb index c263644..3179a02 100644 --- a/latch_app.rb +++ b/latch_app.rb @@ -1,5 +1,5 @@ #Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. -#Copyright (C) 2023 Telefonica Digital +#Copyright (C) 2024 Telefonica Innovación Digital # #This library is free software; you can redistribute it and/or #modify it under the terms of the GNU Lesser General Public diff --git a/latch_auth.rb b/latch_auth.rb index b4fa52c..9916297 100644 --- a/latch_auth.rb +++ b/latch_auth.rb @@ -1,5 +1,5 @@ #Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. -#Copyright (C) 2023 Telefonica Digital +#Copyright (C) 2024 Telefonica Innovación Digital # #This library is free software; you can redistribute it and/or #modify it under the terms of the GNU Lesser General Public diff --git a/latch_response.rb b/latch_response.rb index 0d1882a..a433ce5 100644 --- a/latch_response.rb +++ b/latch_response.rb @@ -1,5 +1,5 @@ #Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. -#Copyright (C) 2023 Telefonica Digital +#Copyright (C) 2024 Telefonica Innovación Digital # #This library is free software; you can redistribute it and/or #modify it under the terms of the GNU Lesser General Public diff --git a/latch_user.rb b/latch_user.rb index 651c6d9..9011ae0 100644 --- a/latch_user.rb +++ b/latch_user.rb @@ -1,5 +1,5 @@ #Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. -#Copyright (C) 2023 Telefonica Digital +#Copyright (C) 2024 Telefonica Innovación Digital # #This library is free software; you can redistribute it and/or #modify it under the terms of the GNU Lesser General Public From 049a66ae9041664b342c7208f408e1a13ef5a322 Mon Sep 17 00:00:00 2001 From: Eduardo Ozores Date: Thu, 12 Dec 2024 17:15:27 +0100 Subject: [PATCH 2/7] Update urls to latch.tu.com --- README.md | 4 ++-- latch_auth.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b0c8c24..e3c1221 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ * Ruby 1.9.3 or above. -* Read API documentation (https://latch.telefonica.com/www/developers/doc_api). +* Read API documentation (https://latch.tu.com/www/developers/doc_api). -* To get the "Application ID" and "Secret", (fundamental values for integrating Latch in any application), it’s necessary to register a developer account in Latch's website: https://latch.telefonica.com. On the upper right side, click on "Developer area". +* To get the "Application ID" and "Secret", (fundamental values for integrating Latch in any application), it’s necessary to register a developer account in Latch's website: https://latch.tu.com. On the upper right side, click on "Developer area". #### USING THE SDK IN RUBY #### diff --git a/latch_auth.rb b/latch_auth.rb index 9916297..96c0273 100644 --- a/latch_auth.rb +++ b/latch_auth.rb @@ -24,7 +24,7 @@ class LatchAuth attr_accessor :api_host - API_HOST = 'https://latch.telefonica.com' + API_HOST = 'https://latch.tu.com' API_VERSION = '1.1' # Application API From 3c3739eb23d728b55851ab8769b81a3da3f792b3 Mon Sep 17 00:00:00 2001 From: Eduardo Ozores Date: Thu, 12 Dec 2024 17:16:45 +0100 Subject: [PATCH 3/7] Add new endpoints --- latch_app.rb | 67 ++++++++++++++++++++++++++++++++++++++++++++++++--- latch_auth.rb | 2 ++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/latch_app.rb b/latch_app.rb index 3179a02..2a6f1d9 100644 --- a/latch_app.rb +++ b/latch_app.rb @@ -26,14 +26,43 @@ def initialize(app_id, secret_key) super(app_id, secret_key) end - def pairWithId(account_id) - http_get_proxy(API_PAIR_WITH_ID_URL + '/' + account_id) + def pair(token, web3_wallet = nil, web3_signature = nil, common_name = nil) + data = { + 'wallet' => CGI.escape(web3_wallet.to_s), + 'signature' => CGI.escape(web3_signature.to_s), + 'commonName' => CGI.escape(common_name.to_s) + } + + # Filter empty or nil + data = data.reject { |_, v| v.nil? || v.empty? } + + if data.empty? + http_get_proxy(API_PAIR_URL + '/' + token) + else + http_post_proxy(API_PAIR_URL + '/' + token, data) + end end - def pair(token) - http_get_proxy(API_PAIR_URL + '/' + token) + def pairWithId(account_id, web3_wallet = nil, web3_signature = nil, common_name = nil) + data = { + 'wallet' => CGI.escape(web3_wallet.to_s), + 'signature' => CGI.escape(web3_signature.to_s), + 'commonName' => CGI.escape(common_name.to_s) + } + + # Filtrar datos (eliminar valores nil o vacíos) + data = data.reject { |_, v| v.nil? || v.empty? } + + # Realizar la solicitud dependiendo de si 'data' está vacío + if data.empty? + http_get_proxy(API_PAIR_WITH_ID_URL + '/' + account_id) + else + http_post_proxy(API_PAIR_WITH_ID_URL + '/' + account_id, data) + end end + # Deprecated: Use 'pairWithId' instead of 'pairWithIdWeb3' + # This method will be removed in a future release. def pairWithIdWeb3(account_id, web3Wallet, web3Signature) if web3Wallet.nil? || web3Signature.nil? http_get_proxy(API_PAIR_WITH_ID_URL + '/' + account_id) @@ -43,6 +72,8 @@ def pairWithIdWeb3(account_id, web3Wallet, web3Signature) end end + # Deprecated: Use 'pair' instead of 'pairWithCodeWeb3' + # This method will be removed in a future release. def pairWithCodeWeb3(token, web3Wallet, web3Signature) if web3Wallet.nil? || web3Signature.nil? http_get_proxy(API_PAIR_URL + '/' + token) @@ -174,4 +205,32 @@ def getOperations(operation_id=nil) end end + def create_totp(id, name) + data = { + 'userId' => CGI.escape(id.to_s), + 'commonName' => CGI.escape(name.to_s) + } + http_post_proxy(API_TOTP_URL, data) + end + + def get_totp(totp_id) + http_get_proxy(API_TOTP_URL + '/' + totp_id) + end + + # Validar un TOTP + def validate_totp(totp_id, code) + data = { 'code' => CGI.escape(code.to_s) } + http_post_proxy(API_TOTP_URL + '/' + totp_id + '/validate', data) + end + + # Eliminar un TOTP + def delete_totp(totp_id) + http_delete_proxy(API_TOTP_URL + '/' + totp_id) + end + + # Comprobar el estado del control + def check_control_status(control_id) + http_get_proxy(API_CONTROL_STATUS_CHECK_URL + '/' + control_id) + end + end diff --git a/latch_auth.rb b/latch_auth.rb index 96c0273..d6e7ef9 100644 --- a/latch_auth.rb +++ b/latch_auth.rb @@ -37,6 +37,8 @@ class LatchAuth API_HISTORY_URL = '/api/' + API_VERSION + '/history' API_OPERATIONS_URL = '/api/' + API_VERSION + '/operation' API_INSTANCE_URL = '/api/' + API_VERSION + '/instance' + API_TOTP_URL= '/api/' + API_VERSION + '/totps'; + API_CONTROL_STATUS_CHECK_URL = '/api/' + API_VERSION + '/control-status'; # User API API_APPLICATION_URL = '/api/' + API_VERSION + '/application' From 657def42675a81d582616c1945524e429cf3874e Mon Sep 17 00:00:00 2001 From: Eduardo Ozores Date: Thu, 12 Dec 2024 17:18:02 +0100 Subject: [PATCH 4/7] Fix LatchResponse when response is empty --- latch_response.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/latch_response.rb b/latch_response.rb index a433ce5..9751d30 100644 --- a/latch_response.rb +++ b/latch_response.rb @@ -33,7 +33,9 @@ class LatchResponse # @param jsonString a json string received from one of the methods of the Latch API def initialize(jsonString) - json = JSON.parse(jsonString) + if jsonString != nil + json = JSON.parse(jsonString) + end if json != nil if json.has_key?('data') From 57e46056ff97dd670407e1e398edcd701b0f61cf Mon Sep 17 00:00:00 2001 From: Eduardo Ozores Date: Thu, 12 Dec 2024 17:18:13 +0100 Subject: [PATCH 5/7] Update version api --- latch_auth.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/latch_auth.rb b/latch_auth.rb index d6e7ef9..ef4bc50 100644 --- a/latch_auth.rb +++ b/latch_auth.rb @@ -25,7 +25,7 @@ class LatchAuth attr_accessor :api_host API_HOST = 'https://latch.tu.com' - API_VERSION = '1.1' + API_VERSION = '3.0' # Application API API_CHECK_STATUS_URL = '/api/' + API_VERSION + '/status' From 3f89cb5cd18fee612e63df4cb7c9fa7e77511f4c Mon Sep 17 00:00:00 2001 From: Eduardo Ozores Date: Thu, 12 Dec 2024 18:29:30 +0100 Subject: [PATCH 6/7] Update examples --- example/example.rb | 116 --------------------------------------- example/example_basic.rb | 114 ++++++++++++++++++++++++++++++++++++++ example/example_totp.rb | 113 ++++++++++++++++++++++++++++++++++++++ example/example_web3.rb | 97 ++++++++++++++++++++++++++++++++ 4 files changed, 324 insertions(+), 116 deletions(-) delete mode 100644 example/example.rb create mode 100644 example/example_basic.rb create mode 100644 example/example_totp.rb create mode 100644 example/example_web3.rb diff --git a/example/example.rb b/example/example.rb deleted file mode 100644 index cf22e5c..0000000 --- a/example/example.rb +++ /dev/null @@ -1,116 +0,0 @@ -#Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. -#Copyright (C) 2024 Telefonica Innovación Digital -# -#This library is free software; you can redistribute it and/or -#modify it under the terms of the GNU Lesser General Public -#License as published by the Free Software Foundation; either -#version 2.1 of the License, or (at your option) any later version. -# -#This library is distributed in the hope that it will be useful, -#but WITHOUT ANY WARRANTY; without even the implied warranty of -#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -#Lesser General Public License for more details. -# -#You should have received a copy of the GNU Lesser General Public -#License along with this library; if not, write to the Free Software -#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -require_relative '../latch_app' -require_relative '../latch_response' - -# We define the credentials of our app in Latch -app_id = "APP_ID" -secret_key = "SECRET_KEY" - -clientWallet = "YOUR_WALLET_ADDRESS" -clientSignature = "YOUR_SIGNATURE" - -# Create a LatchApp instance with our credentials -latch = LatchApp.new(app_id, secret_key) - -# We start the pairing process by entering the app token -responsePair = latch.pair("pairingCode") - -# Return the response -if responsePair.error != nil - puts "Error: #{responsePair.error.message}" -else - puts "Pairing successful" - puts responsePair.data -end - - -responsePairId = latch.pairWithId("test@email.com") - -# Return the response -if responsePairId.error != nil - puts "Error: #{responsePairId.error.message}" -else - puts "Pairing successful" - puts responsePairId.data -end - - -# USING THE SDK IN NODEJS FOR WEB3 SERVICES - -responsePairCodeWeb3 = latch.pairWithCodeWeb3("pairingCode", clientWallet, clientSignature) -# Return the response - if responsePairCodeWeb3.error != nil - puts "Error: #{responsePairCodeWeb3.error.message}" -else - puts "Pairing successful" - puts responsePairCodeWeb3.data -end - - -responsePairIdWeb3 = latch.pairWithIdWeb3("test@email.com", clientWallet, clientSignature) - -# Return the response -if responsePairIdWeb3.error != nil - puts "Error: #{responsePairIdWeb3.error.message}" -else - puts "Pairing successful" - puts responsePairIdWeb3.data -end - -# We lock the account - -responseLockWeb3 = latch.lock("accountId") - -# Return the response -if responseLock.error != nil - puts "Error: #{responseLock.error.message}" -else - puts "Lock successful" -end - -# We unlock the account -responseUnlock = latch.unlock("accountId") - -# Return the response -if responseUnlock.error != nil - puts "Error: #{responseUnlock.error.message}" -else - puts "Unlock successful" -end - - -# We check the status of the account -responseStatus = latch.status("accountId") - -# Return the response -if responseStatus.error != nil - puts "Error: #{responseStatus.error.message}" -else - puts "Status: #{responseStatus.data}" -end - -# We unpair the account -responseUnpair = latch.unpair("accountId") - -# Return the response -if responseUnpair.error != nil - puts "Error: #{responseUnpair.error.message}" -else - puts "Unpair successful" -end \ No newline at end of file diff --git a/example/example_basic.rb b/example/example_basic.rb new file mode 100644 index 0000000..1ec14f4 --- /dev/null +++ b/example/example_basic.rb @@ -0,0 +1,114 @@ +#Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. +#Copyright (C) 2024 Telefonica Innovación Digital +# +#This library is free software you can redistribute it and/or +#modify it under the terms of the GNU Lesser General Public +#License as published by the Free Software Foundation either +#version 2.1 of the License, or (at your option) any later version. +# +#This library is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +#Lesser General Public License for more details. +# +#You should have received a copy of the GNU Lesser General Public +#License along with this library if not, write to the Free Software +#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require_relative '../latch_app' +require_relative '../latch_response' + +# We define the credentials of our app in Latch +#app_id = "APP_ID" +#secret_key = "SECRET_KEY" +app_id = "Dnc4ftijVZrpyzj9RpWA" +secret_key = "dBUs8Rgbxk8DPX8uyV2JrMnTvVTYghuNtiQTLWzN" + + +def read_input(message, default_value = nil) + print "#{message}: " + input = gets.chomp + input.empty? ? default_value : input +end + +def print_response(response) + puts "Data:" + data_response = response.data + puts data_response.inspect +end + +def check_error_response(response, method_name) + error_response = response.error + result = !error_response.nil? + + if result + error_code = error_response.code + error_message = error_response.message + puts "Error in #{method_name} request with error_code: #{error_code} and message: #{error_message}" + end + + result +end + +def exit_if_error_response(response, method_name) + if check_error_response(response, method_name) + exit(1) + end +end + +def check_status(api, account_id, element_id) + # Fetch the response + response = api.status(account_id) + + # Check for errors + exit_if_error_response(response, "check_status") + + response_data = response.data + + # Evaluate the status + case response_data["operations"][element_id]["status"] + when 'on' + puts "Your latch is open and you are able to perform action" + when 'off' + puts "Your latch is locked and you cannot be allowed to perform action" + else + puts "Error processing the response" + exit(1) + end +end + +# Create a LatchApp instance with our credentials +latch = LatchApp.new(app_id, secret_key) + +puts "* We start the pairing process by entering the app token" +paring_code = read_input("Generated pairing token from the user account") +common_name = read_input('Do you want a alias for the pairing, it will be showed in admin panels like Latch Support Tool (L:ST). Optional, blank if none ', nil) + +response = latch.pair(paring_code, nil, nil, common_name) +exit_if_error_response(response, "pair") +print_response(response) + +puts "Store the accountId for future uses"; +account_id = response.data["accountId"]; + +puts "* Check status account" +#When the state is checked, it can be checked at different levels. Application, Operation or Instance +check_status(latch, account_id, app_id); + +puts "* Lock the account" +response = latch.lock(account_id); +exit_if_error_response(response, "lock"); +#Lock responses is empty if all is correct +check_status(latch, account_id, app_id); + +puts "* Unlock the account" +response = latch.unlock(account_id); +exit_if_error_response(response, "unlock"); +#Unlock responses is empty if all is correct +check_status(latch, account_id, app_id); + +puts "* Unpairing process" +response = latch.unpair(account_id); +exit_if_error_response(response, "unpair"); +#Unpair responses is empty if all is correct +check_status(latch, account_id, app_id); \ No newline at end of file diff --git a/example/example_totp.rb b/example/example_totp.rb new file mode 100644 index 0000000..276a4d8 --- /dev/null +++ b/example/example_totp.rb @@ -0,0 +1,113 @@ +#Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. +#Copyright (C) 2024 Telefonica Innovación Digital +# +#This library is free software you can redistribute it and/or +#modify it under the terms of the GNU Lesser General Public +#License as published by the Free Software Foundation either +#version 2.1 of the License, or (at your option) any later version. +# +#This library is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +#Lesser General Public License for more details. +# +#You should have received a copy of the GNU Lesser General Public +#License along with this library if not, write to the Free Software +#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require_relative '../latch_app' +require_relative '../latch_response' + +# We define the credentials of our app in Latch +#app_id = "APP_ID" +#secret_key = "SECRET_KEY" +app_id = "Dnc4ftijVZrpyzj9RpWA" +secret_key = "dBUs8Rgbxk8DPX8uyV2JrMnTvVTYghuNtiQTLWzN" + + +def read_input(message, default_value = nil) + print "#{message}: " + input = gets.chomp + input.empty? ? default_value : input +end + +def print_response(response) + puts "Data:" + data_response = response.data + puts data_response.inspect +end + +def check_error_response(response, method_name) + error_response = response.error + result = !error_response.nil? + + if result + error_code = error_response.code + error_message = error_response.message + puts "Error in #{method_name} request with error_code: #{error_code} and message: #{error_message}" + end + + result +end + +def exit_if_error_response(response, method_name) + if check_error_response(response, method_name) + exit(1) + end +end + +def check_status(api, account_id, element_id) + # Fetch the response + response = api.status(account_id) + + # Check for errors + exit_if_error_response(response, "check_status") + + response_data = response.data + + # Evaluate the status + case response_data["operations"][element_id]["status"] + when 'on' + puts "Your latch is open and you are able to perform action" + when 'off' + puts "Your latch is locked and you cannot be allowed to perform action" + else + puts "Error processing the response" + exit(1) + end +end + +# Create a LatchApp instance with our credentials +latch = LatchApp.new(app_id, secret_key) + + +id = read_input('Enter the name displayed for the totp') +common_name = read_input('Do you want a alias for the totp. Optional, blank if none ', nil) + +response = latch.create_totp(id, common_name) +exit_if_error_response(response, "create_totp") +print_response(response) + +totp_id = response.data["totpId"] +puts "Totp Id (Save it, you'll need it later): " + totp_id +puts "QR (Scan the QR with the app, you can open it with any browse):\n" + response.data["qr"] + +puts "Get info about a totp" +response = latch.get_totp(totp_id) +exit_if_error_response(response, "get_totp") +print_response(response) + +puts "Validate totp" +code = read_input("Enter the code generated") +response = latch.validate_totp(totp_id, code) +#validate_totp responses is empty if code is valid +is_code_valid = !check_error_response(response, "validate_totp") +puts "Te code is valid: " + (is_code_valid ? 'true' : 'false') + +puts "Deleting totp" +response = latch.delete_totp(totp_id) +#delete_totp responses is empty if all is correct +is_totp_deleted = !check_error_response(response, "delete_totp") +puts "Te totpId has been deleted: " + (is_totp_deleted ? 'true' : 'false') +response = latch.get_totp(totp_id); +check_error_response(response, "get_totp") \ No newline at end of file diff --git a/example/example_web3.rb b/example/example_web3.rb new file mode 100644 index 0000000..190a787 --- /dev/null +++ b/example/example_web3.rb @@ -0,0 +1,97 @@ +#Latch Ruby SDK - Set of reusable classes to allow developers integrate Latch on their applications. +#Copyright (C) 2024 Telefonica Innovación Digital +# +#This library is free software you can redistribute it and/or +#modify it under the terms of the GNU Lesser General Public +#License as published by the Free Software Foundation either +#version 2.1 of the License, or (at your option) any later version. +# +#This library is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +#Lesser General Public License for more details. +# +#You should have received a copy of the GNU Lesser General Public +#License along with this library if not, write to the Free Software +#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require_relative '../latch_app' +require_relative '../latch_response' + +# We define the credentials of our app in Latch +#app_id = "APP_ID" +#secret_key = "SECRET_KEY" +app_id = "Dnc4ftijVZrpyzj9RpWA" +secret_key = "dBUs8Rgbxk8DPX8uyV2JrMnTvVTYghuNtiQTLWzN" + + +def read_input(message, default_value = nil) + print "#{message}: " + input = gets.chomp + input.empty? ? default_value : input +end + +def print_response(response) + puts "Data:" + data_response = response.data + puts data_response.inspect +end + +def check_error_response(response, method_name) + error_response = response.error + result = !error_response.nil? + + if result + error_code = error_response.code + error_message = error_response.message + puts "Error in #{method_name} request with error_code: #{error_code} and message: #{error_message}" + end + + result +end + +def exit_if_error_response(response, method_name) + if check_error_response(response, method_name) + exit(1) + end +end + +def check_status(api, account_id, element_id) + # Fetch the response + response = api.status(account_id) + + # Check for errors + exit_if_error_response(response, "check_status") + + response_data = response.data + + # Evaluate the status + case response_data["operations"][element_id]["status"] + when 'on' + puts "Your latch is open and you are able to perform action" + when 'off' + puts "Your latch is locked and you cannot be allowed to perform action" + else + puts "Error processing the response" + exit(1) + end +end + +# Create a LatchApp instance with our credentials +latch = LatchApp.new(app_id, secret_key) + +paring_code = read_input('Generated pairing token from the user account'); +wallet = read_input('Your public key of your wallet'); +signature = read_input('Sign the message "Latch-Web3" with your wallet'); +common_name = read_input('Do you want a alias for the pairing, it will be showed in admin panels like Latch Support Tool (L:ST). Optional, blank if none ', nil) + +response = latch.pair(paring_code, wallet, signature, common_name) +exit_if_error_response(response, "pair") +print_response(response) + +puts "Store the accountId for future uses"; +account_id = response.data["accountId"]; + +puts "* Check status account" +#When the state is checked, it can be checked at different levels. Application, Operation or Instance +check_status(latch, account_id, app_id); \ No newline at end of file From fd334dbe67aaf203497708ce2696fe87accf30a3 Mon Sep 17 00:00:00 2001 From: Eduardo Ozores Date: Thu, 12 Dec 2024 19:03:27 +0100 Subject: [PATCH 7/7] Revised message when latch is locked --- example/example_basic.rb | 2 +- example/example_totp.rb | 2 +- example/example_web3.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/example_basic.rb b/example/example_basic.rb index 1ec14f4..107ba79 100644 --- a/example/example_basic.rb +++ b/example/example_basic.rb @@ -70,7 +70,7 @@ def check_status(api, account_id, element_id) when 'on' puts "Your latch is open and you are able to perform action" when 'off' - puts "Your latch is locked and you cannot be allowed to perform action" + puts "Your latch is locked and you are not allowed to perform action" else puts "Error processing the response" exit(1) diff --git a/example/example_totp.rb b/example/example_totp.rb index 276a4d8..abadf86 100644 --- a/example/example_totp.rb +++ b/example/example_totp.rb @@ -70,7 +70,7 @@ def check_status(api, account_id, element_id) when 'on' puts "Your latch is open and you are able to perform action" when 'off' - puts "Your latch is locked and you cannot be allowed to perform action" + puts "Your latch is locked and you are not allowed to perform action" else puts "Error processing the response" exit(1) diff --git a/example/example_web3.rb b/example/example_web3.rb index 190a787..029b949 100644 --- a/example/example_web3.rb +++ b/example/example_web3.rb @@ -70,7 +70,7 @@ def check_status(api, account_id, element_id) when 'on' puts "Your latch is open and you are able to perform action" when 'off' - puts "Your latch is locked and you cannot be allowed to perform action" + puts "Your latch is locked and you are not allowed to perform action" else puts "Error processing the response" exit(1)