-
Notifications
You must be signed in to change notification settings - Fork 57
Adding Code Snippets #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3ef5103
55b2f20
4c40f7e
6033357
9a5f870
a57217b
eb59a2b
16f3b68
9786355
05e7a2d
dee9ef3
f51e837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import nexmo, os, getpass | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
|
||
#Load the environment | ||
envpath = join(dirname(__file__),'./.env') | ||
load_dotenv(envpath) | ||
|
||
#Init the client | ||
client = nexmo.Client( | ||
key = os.getenv('NEXMO_API_KEY'), | ||
secret = os.getenv('NEXMO_API_SECRET') | ||
) | ||
|
||
#Get data from user from keyword | ||
api_key = input("Enter your api_key: ") | ||
#Use getpass instead of input to mask secret | ||
new_api_secret = getpass.getpass("Enter secret: ") | ||
|
||
#Create the secret | ||
try: | ||
response = client.create_secret(api_key, new_api_secret) | ||
if "id" in response: | ||
print("Key was created\nId: {}\nCreated at: {}\nLinks: {}".format(response["id"], response["created_at"], response["_links"]["self"]["href"])) | ||
except: | ||
print( | ||
"Error: Secret does not meet complexity requirements. Please check the link below for more details:\n", | ||
"https://developer.nexmo.com/api-errors/account/secret-management#validation" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#Import dependencies | ||
import nexmo, os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
|
||
#Load the environment | ||
envpath = join(dirname(__file__),'./.env') | ||
load_dotenv(envpath) | ||
|
||
#Init the client | ||
client = nexmo.Client( | ||
key = os.getenv('NEXMO_API_KEY'), | ||
secret = os.getenv('NEXMO_API_SECRET'), | ||
signature_secret = os.getenv('NEXMO_SIGNATURE_SECRET'), | ||
signature_method = 'md5' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a difference between md5 hash and HMAC? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, HMAC needs a cryptographic function like md5, sha1 to make the calculations... In other words HMAC depends on a cryptographic functions and other variables like a secret. Is there a specific requirement for either? i just went with md5 as the standard. |
||
) | ||
|
||
#Define variables - replace FROM_NUMBER and TO_NUMBER with actual numbers | ||
from_number = FROM_NUMBER | ||
to_number = TO_NUMBER | ||
text = 'A text message sent using the Nexmo SMS API' | ||
|
||
#Sending the sms | ||
response = client.send_message({ | ||
"from": from_number, | ||
"to": to_number, | ||
"text": text | ||
}) | ||
|
||
if response["messages"][0]["status"] == "0": | ||
print("Message sent successfully.") | ||
else: | ||
print(f"Message failed with error: {response['messages'][0]['error-text']}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They shouldn't need to add an API Secret if they're signing (the signature acts as the auth)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took after the other code snippet models. My bad. Cleaning up