Nest API, what are STRING1 and STRING2 for - nest-api

On several of the fields in the nest api docs, I see examples with "STRING1" and "STRING2" in the URL which are described as "do not change", do I need to include those in requests, or what are those for?
Example

In most cases, STRING1/2 are returned when you read the device values. You'll pass them along when you use the URL.
For example, when I read my camera, I get this response:
"image_url": "https://www.dropcam.com/api/wwn.get_image/CjZRcWll.../OwKxchf...?auth=c.twC2qlu...",
In this example, STRING1 = CjZRcWll... and DEVICE_ID = OwKxchf
I can copy the "https://..." string, paste it into a web browser and see the image that was captured.

Related

Can i put Many Pictures links in dialogflow and send only one Randomly

I am new to dialogflow. I learned some things the previous month, but I am still searching for how to put a lot of pictures in intent and sending only one to the user, not all of them, and randomly, such as text responses as a kind of entertainment inside the Agent ...
Note :
I linked the client to Facebook Messenger and I want to send the photo there
Can i do this?
Assuming you're using Dialogflow-fulfillment library to respond to webhook requests this should do the trick.
You can store whatever type of response that you want to send in an array...
For example, I'll choose an array of plain text responses
const responses = [
"I didn't get that. Can you say it again?",
'I missed what you said. What was that?',
'Sorry, could you say that again?',
'Sorry, can you say that again?',
'Can you say that again?',
"Sorry, I didn't get that. Can you rephrase?",
'Sorry, what was that?',
'One more time?',
'What was that?',
'Say that one more time?',
"I didn't get that. Can you repeat?",
'I missed that, say that again?'
]
Given the array you can generate a random number between 0 (most programming languages index from 0) and the length of the array.
const index = Math.floor((Math.random() * responses.length) + 1)
In the above case, index is assigned to any number between 0 and 11. You can then pass this index into the array to randomly choose 1 value.
agent.add(responses[index])
You can take this concept and apply it to any response type you want.
Hope this does the trick for you!

Best practice to pass query conditions in ajax request

I'm writing a REST api in node js that will execute a sql query and send the results;
in the request I need to send the WHERE conditions; ex:
GET 127.0.0.1:5007/users //gets the list of users
GET 127.0.0.1:5007/users
id = 1 //gets the user with id 1
Right now the conditions are passed from the client to the rest api in the request's headers.
In the API I'm using sequelize, an ORM that needs to receive WHERE conditions in a particular form (an object); ex: having the condition:
(x=1 AND (y=2 OR z=3)) OR (x=3 AND y=1)
this needs to be formatted as a nested object:
-- x=1
-- AND -| -- y=2
| -- OR ----|
| -- z=3
-- OR -|
|
| -- x=3
-- AND -|
-- y=1
so the object would be:
Sequelize.or (
Sequelize.and (
{x=1},
Sequelize.or(
{y=2},
{z=3}
)
),
Sequelize.and (
{x=3},
{y=1}
)
)
Now I'm trying to pass a simple string (like "(x=1 AND (y=2 OR z=3)) OR (x=3 AND y=1)"), but then I will need a function on the server that can convert the string in the needed object (this method in my opinion has the advantage that the developer writing the client, can pass the where conditions in a simple way, like using sql, and this method is also indipendent from the used ORM, with no need to change the client if we need to change the server or use a different ORM);
The function to read and convert the conditions' string into an object is giving me headache (I'm trying to write one without success, so if you have some examples about how to do something like this...)
What I would like to get is a route capable of executing almost any kind of sql query and give the results:
now I have a different route for everything:
127.0.0.1:5007/users //to get all users
127.0.0.1:5007/users/1 //to get a single user
127.0.0.1:5007/lastusers //to get user registered in the last month
and so on for the other tables i need to query (one route for every kind of request I need in the client);
instead I would like to have only one route, something like:
127.0.0.1:5007/request
(when calling this route I will pass the table name and the conditions' string)
Do you think this solution would be a good solution or you generally use other ways to handle this kind of things?
Do you have any idea on how to write a function to convert the conditions' string into the desired object?
Any suggestion would be appreciated ;)
I would strongly advise you not to expose any part of your database model to your clients. Doing so means you can't change anything you expose without the risk of breaking the clients. One suggestion as far as what you've supplied is that you can and should use query parameters to cut down on the number of endpoints you've got.
GET /users //to get all users
GET /users?registeredInPastDays=30 //to get user registered in the last month
GET /users/1 //to get a single user
Obviously "registeredInPastDays" should be renamed to something less clumsy .. it's just an example.
As far as the conditions string, there ought to be plenty of parsers available online. The grammar looks very straightforward.
IMHO the main disadvantage of your solution is that you are creating just another API for quering data. Why create sthm from scratch if it is already created? You should use existing mature query API and focus on your business logic rather then inventing sthm new.
For example, you can take query syntax from Odata. Many people have been developing that standard for a long time. They have already considered different use cases and obstacles for query API.
Resources are located with a URI. You can use or mix three ways to address them:
Hierarchically with a sequence of path segments:
/users/john/posts/4711
Non hierarchically with query parameters:
/users/john/posts?minVotes=10&minViews=1000&tags=java
With matrix parameters which affect only one path segment:
/users;country=ukraine/posts
This is normally sufficient enough but it has limitations like the maximum length. In your case a problem is that you can't easily describe and and or conjunctions with query parameters. But you can use a custom or standard query syntax. For instance if you want to find all cars or vehicles from Ford except the Capri with a price between $10000 and $20000 Google uses the search parameter
q=cars+OR+vehicles+%22ford%22+-capri+%2410000..%2420000
(the %22 is a escaped ", the %24 a escaped $).
If this does not work for your case and you want to pass data outside of the URI the format is just a matter of your taste. Adding a custom header like X-Filter may be a valid approach. I would tend to use a POST. Although you just want to query data this is still RESTful if you treat your request as the creation of a search result resource:
POST /search HTTP/1.1
your query-data
Your server should return the newly created resource in the Location header:
HTTP/1.1 201 Created
Location: /search/3
The result can still be cached and you can bookmark it or send the link. The downside is that you need an additional POST.

Does amazon provide an API for returning product information for a search term?

If you search on amazon for, say, "Don Quixote Spanish/English" you will find a number of matches or near-matches at http://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=Don%20Quixote%20Spanish%2FEnglish
You can then select any of them, and the URL will contain a designator (ASIN) for the product. For example, if you select a particular item in the result set, its URL might be:
http://www.amazon.com/Don-Quixote-Spanish-English-Complete-ebook/dp/B00JQRGICM/ref=sr_1_4?ie=UTF8&qid=1405527063&sr=8-4&keywords=Don+Quixote+Spanish%2FEnglish
The key piece of data here is the ASIN ("B00JQRGICM"); if you google using that alone, it will find many places where that product is referenced on the Internet.
My question is, does amazon provide an API whereby you can pass a search phrase (such as "Don Quixote Spanish/English") that will return to you an array of ASINs and other relevant data ("B00JQRGICM" and others)?
For example, I would like to call it something like this:
api/Books?SearchStr=Don Quixote Spanish/English
...and get back json such as:
{
Title: "Don Quixote in Spanish and English: Complete (Vol I & Vol II)"
Price: 16.15
ASIN: "B00JQRGICM"
Image: "http://ecx.images-amazon.com/images/I/519dhx-MSOL._SL160_.jpg"
}
. . .
If there is such an API, has anybody here got experience in using it/sample code?
Yes. You can search Amazon and get an XML response with the ASINs using the ListMatchingProducts operation of the MWS Products API.
Here's the documentation with a sample request & response:
http://docs.developer.amazonservices.com/en_US/products/Products_ListMatchingProducts.html
An easy way to test this is using the MWS Scratchpad: https://mws.amazonservices.com/scratchpad/index.html

Tracking a tweeter hashtag (keyword) with stream API

I am trying to track all tweets by given hashtag or keyword. The problem is I can stream the tweets when I use a simple keyword like 'animal' but when I change it to say 'animal4666' then it doesn't work. No reply is received. I am using the code below.
twit.stream('statuses/filter', { track: 'animal4666' }, function(stream) {
stream.on('data', function(data) {
console.log(util.inspect(data));
});
});
I have made two tweets from different account like following:
'#animal4666 a'
'#animal4666 trying to find out what is going on?'
Above tweets are successfully retrieved using search API but because of the rate limitations on search API I need to use stream API so that i can check for new tweets every two seconds with node.js
The addon I am using of node.js: https://github.com/jdub/node-twitter
Can someone please help?
If you look the code of the library you are using, it seems that there is nothing potentially wrong
it only has a workaround when you pass an array in the track param, but is not the case
// Workaround for node-oauth vs. twitter commas-in-params bug
if ( params && params.track && Array.isArray(params.track) ) {
params.track = params.track.join(',')
}
So looking in to the official api docs for track method, I see two caveats that may are relevant.
Each phrase must be between 1 and 60 bytes, inclusive.
I think yours are shorter but is something to take in mind
And what I think is your real problem:
Exact matching of phrases (equivalent to quoted phrases in most search
engines) is not supported.
Punctuation and special characters will be considered part of the term
they are adjacent to. In this sense, "hello." is a different track
term than "hello". However, matches will ignore punctuation present in
the Tweet. So "hello" will match both "hello world" and "my brother
says hello." Note that punctuation is not considered to be part of a
#hashtag or #mention, so a track term containing punctuation will not match either #hashtags or #mentions.
You can check online your tweet text to see if it match here

Twitter search: OR with Tags - but how?

I cannot search the twitter API for tweets which contain one of multiple tags.
Like: q="#tag1 OR #tag2 OR #tag3"
If I leave away the hashes and only search for words, the OR-ing works. For tags they don't.
When I only use spaces, the search terms will be AND-ed, what shrinks the result...
I use the twitter4j library with:
Twitter rest = new TwitterFactory().getInstance();
Query query = new Query();
query.setQuery("#win | #fail");
QueryResult result = rest.search(query);
Isn't it possible, or didn't i use it correctly?
Might just be easier to use twitter's REST API. You'll want to use the search query. Here's an example search url searching for #LA, #NYC or #Boston. Note the spaces and #s are all URL encoded. Just pop a URL like that into a getJSON call like below and you can easily extract your values from the returned JSON object as in the example.
var requestedData = "http://search.twitter.com/search.json?q=%23LA%20OR%20%23NYC%20OR%20%23Boston%22&callback=?"
$.getJSON(requestedData,function(ob)
{
var firstTweet = ob.results[0].text;
var firstTweeter = ob.results[0].from_user;
}
From there it's just a matter of looping through your results and pulling the appropriate fields which are all outlined in the JSON file if you simply visit that example search link in your browser! I don't know this TwitterFactory API but its possible they haven't updated to Twitter's new API or they're just not URL encoding appropriately. Good luck!
Try to use OR operator instead of "|":
query.setQuery("#win OR #fail");
See available Twitter search API operators here:
Using the Twitter Search API

Resources