Special character not getting correctly from Searchbar - swift

I'm sending Oven D' word into the search reqeust paramters.
If I'm passing static value (Oven D') into the post alamofire request it's working fine. The request of this paramter is like this
"Keyword" = "Oven D\'"
But if I'm sending it form searchBar.text then it will not work and my request is something like this
"Keyword" = "Oven D'"
Please suggest me why this happening. Is there I need to change something in Search bar property.
Thanks in Advance for suggesting or helping me to sort out this issue.

It was an issue of symbols entering from the search keyboard.
I'm entering ' this but actually it was technically entered , in upwords direction
I used following code and it works:
searchBar.text!.replacingOccurrences(of: "’", with: "'")

Related

Power Query - Populate column through REST API

I have a list of IDs in Power Query and would like to call and API to return some information about each. As there is no direct API that allows me to pull the information for my entire list, I have to call the API for each row in my table.
The API requires a dynamic access token, which I already have a function that takes care of (GetToken()).
I have followed this guide. The guide adds a custom column for which I have written the following code:
Json.Document(
Web.Contents(
Text.Combine({"https://urlthatholdstheinfo.com/", [id]}), [Headers=[Authorization="Bearer "& GetToken()]]))
When I close the editor, I get this classic error:
"Expression.Error: The 'Authorization' header is only supported when connecting anonymously. These headers can be used with all authentication types: Accept, Accept-Charset, Accept-Encoding, Accept-Language, Cache-Control, Content-Type, If-Modified-Since, Prefer, Range, Referer
I have previously mitigated this in the Data Source Settings by setting the Permission to "Anonymous". However, I can not find this query in those settings, so I don't know where to change this.
I have unsuccessfully been looking for a way to parse a parameter to Web.Content, that tells the query to do this with Anonymous settings, but it does not seem to exist.
I have tried this variation as well, but I get the same error
Any thoughts on what I can do?
UPDATE:
The answer for this post works, with a small addition. After implementing the answer, the error still occurred. It was resolved by creating a blank query with a fixed id number instead of parsing the column as an argument to the function. This allowed me to go to "Data source settings" and change the permission for the query to Anonymous, which also fixed the problem for the function and the custom column.
let
Source =
Json.Document(
Web.Contents(
"https://https://urlthatholdstheinfo.com/id",
[Headers=[Authorization="Bearer "& GetToken()]])),
in
Source
Also, be sure to not have the curly brackets that are in the original code of the question.
If you have a list of IDs you can make a custom function that uses appropriate constructors for RelativePath like David suggests. Here is a function you can paste into a blank query, which you can specify using Invoke Custom Function on your list of IDs:
let
Source = (ID as text) =>
Json.Document(
Web.Contents(
"https://urlthatholdstheinfo.com/",
[
Headers=[Authorization="Bearer "& GetToken()] ,
RelativePath=ID
]
]
)
)
in
Source
Make sure your ID column is in text format - or change the custom function above to:
let
Source = (ID as number) =>
Json.Document(
Web.Contents(
"https://urlthatholdstheinfo.com/",
[
Headers=[Authorization="Bearer "& GetToken()] ,
RelativePath=Text.From(ID)
]
]
)
)
in
Source
I'm fairly sure this problem arises because of the way you're constructing your URL using Text.Combine. Can you rewrite your query to use the RelativePath header
https://learn.microsoft.com/en-us/powerquery-m/web-contents

Can't get handlebars to work with dynamic templates

I am very stuck. Tried everything I could think of to solve this issue, but I feel as though it is just something wrong with my JSON. When I build a dynamic template, I'd like to insert some variables for the send. As you can see in the example, simply just adding the first name in the handlebars. However, when I send tests using postman, I can not for the life of me get the first_name to display. I've tried so many different options in the JSON and nothing seems to work. Here is where I am currently at, omitting the first_name obviously. Any help on how to format this I would very much appreciate it.
{
"from": {"email":"example#example.com"},
"template_id":"ID HERE"
"personalizations": [
{
"to": [
{
"email":"recipient#gmail.com"
}
]
}
]
}
I tried 100 different variations of the request.
Twilio developer evangelist here.
I think that using that JSON is mainly for when you're using the API to send an email with a template. You then provide the JSON data as dynamic_template_data and it is populated in the email template.
first_name is a reserved field and substitution tag which lets you use any reserved or custom field data you've added to Marketing Campaigns to dynamically generate unique content for each recipient of your email. One common example is adding a recipient's first name to the body (or even the subject line) of your email.
The data that populates your Substitution Tags will come from the information you have stored about each contact.
You can work with substitution tags with the code editor or design editor.
Let me know if this helps at all!

Is anyone knows how Flutter URI encoding/decoding works?

Is anyone knows how Flutter URI encoding/decoding works?
I have one issue. Let me give you some background on the issue. We have one deep link which will give us the email and access token code to reset the password. We will validate the token on the front end and then allow users to do a reset.
Here is the sample URL from Firebase dynamic link
https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com
Firebase dynamic link will give us this URL in the URI object. The issue is when I try to fetch the query params from this URI object, it removes plus sign from an email and replaces it with the space character instead. E-mail should same as displayed in the above link. This is the email received when I fetch query params: test abc#xyz.com
I have created two dart pads to figure out the issue. Here is the 1st sample where I am parsing (since firebase dynamic link is doing the same) the URL into the URI object and tried printing the output. As expected it removes the plus sign.
Code:
main() {
var httpsUri = Uri.parse("https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com");
print(httpsUri.queryParameters);
}
Output:
{access_token: abcd, email: test abc#xyz.com}
In another sample, I tried creating the URI object from the same parameters and link but manually. Here is the code
Code:
main() {
var httpsUri = Uri(
scheme: 'https',
host: 'example.com',
path: '/auth/resetPassword/',
queryParameters: {
'access_token': 'abcd',
'email': 'test+abc#xyz.com'
});
print(httpsUri.queryParameters);
}
Output:
{access_token: abcd, email: test+abc#xyz.com}
If you see here, the email is correctly displayed.
My exact scenario is matching with the first sample code. Based on my findings it removes the plus sign due to encoding and decoding of the URL as a plus sign has a special meaning in the URL. But on the other hand why it is not happening in 2nd example?
Any help would be appreciated!
+ is a reserved character for URIs and therefore should be encoded to %2B if you want a literal + character.
But on the other hand why it is not happening in 2nd example?
Your second example works because it constructs a Uri object directly, and if you were to convert it to a String, it would perform necessary encodings for you. That is, print(httpsUri) would output:
https://example.com/auth/resetPassword/?access_token=abcd&email=test%2Babc%40xyz.com
rather than original (malformed) URL:
https://example.com/auth/resetPassword/?access_token=abcd&email=test+abc#xyz.com

How to use : colon char in Bottle route

I have simple Bottle route, and URL should contain : (colon) sign. URL should be like /REST/item:128 or /REST/item:89753
My route is
#route('/REST/item:<id:int>')
def icc(id):
return { 'id': id }
Route is not working properly. id contain only last char from url id, not full id.
How to use : (colon) in route?
Wow, this was confusing.
I haven't had time to fully understand what's happening, but I suspect that one of Bottle's route regexes is eating too many characters when there's a colon in the route.
In any case, escaping the colon with a backslash appears to solve the problem:
#route(r'/REST/item\:<id_:int>') # note the "r" prefix there
def icc(id_):
return {'id': id_}
Here's a test request and its response:
=> curl -v 'http://127.0.0.1:8080/REST/item:123'
{"id": 123}
EDIT: Mystery solved.
Bottle currently supports two syntaxes for url wildcards: The
one (since 0.10) and the :old syntax. Both are described here:
http://bottlepy.org/docs/dev/routing.html
In your example, the : triggered the old syntax. The solution is to
escape the colon with a backslash (as described in the SO answer).
Escaping is fully implemented and works as intended, but is
undocumented. This is why I leave this issue open. Pull requests for
better documentation would be welcomed.

Copy specific text from email message to spreadsheet

I get my checking account balance emailed to me once per day. I want to use Google Apps Script to pull the balance from the email message and plug it into my checking account spreadsheet. I am a novice to coding, but so far I have figured out how to do the following, which gets me a log of HTML code of the correct email message:
function myFunction() {
var thread = GmailApp.getUserLabelByName("CHK BAL").getThreads(0,1)[0]; // get first thread in inbox
var message = thread.getMessages()[0]; // get first message
Logger.log(message.getBody()); // log contents of the body
}
However, because this method returns the HTML code for the email message and not the actual message text, it doesn't contain the balance number that shows up in the email itself.
I tried substituting getPlainBody in place of getBody, but it returns a null value in the Log.
The question posted here is pretty much my same question (Google script that find text in my gmail and adds it to a spreadsheet?), but even with Mogsdad's reply and helpful links I haven't been able to figure out what's going wrong.
Can anyone help redirect me on how to get the email content instead of the null value?
(Once that's solved, I can't say that the link on Mogsdad's other reply is very clear about how to identify the currency and copy it into the spreadsheet, but of course I haven't been able to play around yet since I can't even access the content yet.)
Thanks!
EDIT 1
See Serge's answer below for instructions on how to parse the HTML. I used those functions to grab the text of the most recent Bank Account Balance email from a Gmail label/filter and drop it into a cell in my spreadsheet.
Then I was able to use the following equation in an adjacent cell to strip it down to just the currency number:
LEFT(RIGHT(A5,LEN(A5)-FIND("$",A5)),FIND(CHAR(10),RIGHT(A5,LEN(A5)-FIND("$",A5)))-1)+0
Of course, this works for me because the currency number is always preceded by $ (the first, and in my case, only $ to appear in the text) and always followed by CHAR(10). Anyone trying to apply this formula would need similar consistency before and after the value they are seeking to isolate.
You could try this code snippet originally written by Corey G on SO to get the text from the html content. I use it quite often and it works nicely most of the time :) (Thanks Corey)
function getTextFromHtml(html) {
return getTextFromNode(Xml.parse(html, true).getElement());
}
function getTextFromNode(x) {
switch(x.toString()) {
case 'XmlText': return x.toXmlString();
case 'XmlElement': return x.getNodes().map(getTextFromNode).join('');
default: return '';
}
}
And a test function to try it :
function test(){
var html = GmailApp.getInboxThreads()[0].getMessages()[0].getBody();
throw(getTextFromHtml(html));
}
As to why getPlainBody() is returning null, it is most likely due to a bug in Google Apps Script. The issue has been filed at https://code.google.com/p/google-apps-script-issues/issues/detail?id=3980.
From that thread: "It seems the messages affected contain HTML in their content. A possible workaround involves using getBody() instead of getPlainBody() and parsing through the HTML directly."