GET request in Rails with big count of params - ruby-on-rails

I want to make some Rails API for a mobile app, and there is the following situation: my app will authorize using a phone number (like Viber / WhatsApp); also it can automatically detect which contacts from a phone book also have my app installed. If I understand right I should create some GET method to take array of numbers and return numbers of users which have been in my system already. There are no problem with GET method for me and arrays in GET params, but phone book of users can be very big, and sending all numbers in GET params is not good solution. How can I do it right? Should I divide numbers in parts and send first 10 numbers, then next 10 numbers etc? Thanks in advance.

Just use a POST request instead. You don't have to always use GET when you're searching for stuff.

You could also optimize your query string:
?ph=5551112222,5552223333...
This at least minimizes the request size. I think Rails should give you params[:ph] as an array. If not then splitting the string on a comma is just one extra line of code.

Related

GET request with long query parameters

I have any API which exports .xlsx data.
The conditions for SQL need 2 ids and I also need to pass the column name/s. I pass the ids via query-parameters along with the column names in a GET request, the column names can be 1 or 10 or 100 depending on the data collected. So it may become a long URL.
Do I modify it to a POST and send the columns in the body or should I send it the way I am right now?
If there is possiblity of URL taking more than 100 characters, you can better go for POST request rather than GET.
you can refer to a similar question asked here:
How long may parameters in a get request be?

Siri Shortcuts how do I sequence the results from JSON in a Siri Shortcut?

I'm using the ptv api call for departures and can successfully return back three results. I'm trying to get Siri to dictate these to me in order but am not having much luck.
When the api is called it returns a bunch of information in an array for however many services you specify (three in my case), but I only want one of the lines to be dictated (scheduled_departure_utc), not the full array.
And I want to pull just this one line out of each of the three blobs of data that are returned so that Siri says...
the next trains to the city are (scheduled_departure_utc),(scheduled_departure_utc),(scheduled_departure_utc). Where (scheduled_departure_utc) is a short form of time (8:28am, 8:38am, 8:58am) as an example.
Any ideas?

Tweepy: Find all tweets in a specific language

I'd like to extract all tweets in the Arabic language in all countries.
I modified the code in this tutorial.
This is my search query.
api.search(q="*", count=tweetsPerQry, lang ['ar'],tweet_mode='extended'). I expect to find a very large number of tweets, but I only collected about 7000 tweets.
I checked the content of some of them and I noticed that they are posted in my country even I did not specify the location/Country (Can anyone explain why this happen??).
I tried to know the reason for finding a limited number of tweets, so I modified the query by replacing the lang parameter by geocode to find tweets in a city. I fetched more than 65,000 Arabic tweets. After that, I used the lang parameter with the geocode and I found a very limited number of tweets.
Can anyone help me to know why I'm not able to get a large number of tweets when I used lang parameter?
The free twitter API's are good for small projects, but keep in mind that they don't display all of the tweets. Twitter has paid API's that are much more powerful, though what you are trying to achieve should be possible. I ran the query attached bellow, it seemed to work I was able to find a considerable amount of tweets. This method also seemed to work for #ebt_dev too I think it was just the structure of your request was set out like the stream listener version not the cursor search.
# Search Query change the X of .items(X) to the amount of tweets you are looking for
for tweet in tweepy.Cursor(api.search, q='*',tweet_mode='extended', lang='de').items(9999999):
# Defining Tweets Creators Name
tweettext = str( tweet.full_text.lower().encode('ascii',errors='ignore')) #encoding to get rid of characters that may not be able to be displayed
# Defining Tweets Id
tweetid = tweet.id
# printing the text of the tweet
print('\ntweet text: '+str(tweettext))
# printing the id of the tweet
print('tweet id: '+str(tweetid))

minimizing parse requests while looping through array

I'm working on a pet project using parse as a back end. I'm setting up a viewcontroller that contains a list of people you can possibly add as "friends"; these are people that
a) exist in your contacts list and
b) have already downloaded the app and signed up.
Different buttons will be displayed depending on their status as a user (invite button if they only exist in your contacts list, add to friends button if they're also using the app already).
I'm trying to keep my Parse account to 30 requests/second so that I'm not out of pocket for a pet app.
One way I've thought to figure out who is registered as a user AND who exists in my contacts list is to loop through the contacts list on my phone and query that phone number on parse. However, this would obviously go over my limit on requests/second.
Is there a way (I've looked through Parse documentation and googled it) to take an array (list of contacts on my phone) and run a PFQuery ON THAT ARRAY, checking each object and returning matches?
Unless you have a quarter million users in your app you shouldn't be much concerned, it doesn't work like: 1 user goes through 30 count for loop with one query each and you get 30 req/s:
How does the requests/second limit translate to concurrent users?
Generally when your user count doubles, your requests per second also double. However, different apps send different numbers of requests per second depending on how frequently they save objects or issue queries. We estimate that the average app's active user will issue 10 requests. Thus, if you had a million users on a particular day, and their traffic was evenly spread throughout the day, you could estimate your app would need about 10,000,000 total API requests, or about 120 requests per second. Every app is different, so we strongly encourage you to measure how many requests your users send.
I have run through loops of requests and I barely hit 1 req/s
Is there a way (I've looked through Parse documentation and googled
it) to take an array (list of contacts on my phone) and run a PFQuery
ON THAT ARRAY, checking each object and returning matches?
Yes there is, use:
query?.whereKey(key: String, containedIn: [AnyObject])

Searching two channels from youtube

I am trying to search for "Food+Show" from two youtube channels. ABCNetwork and FoxBroadcasting. The query I gave is
http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=Food+Show&max-results=3&authors=ABCNetwork,FoxBroadcasting&prettyprint=true
The first result I got was id UKfLsIgJB1g where uploader is wafelsanddinges and not ABC or Fox. Please tell me why my query is not retuning correct result.
The parameter for the v2 data API is "author," not "authors." Unfortunately, fixing that won't solve the problem, as the retrieval of videos from a particular channel can only accept one author at a time. This is also true for v3 of the API.
The reason behind this is that the comma is treated as a concatenator, looking for a video that was published on FoxBroadcasting AND ABCNetwork (the use case for having multiple authors in that parameter is if you are retrieving activity feeds, in which case you want both feeds so having the comma serve as an AND is correct).
So for now, the only solution is two separate calls.

Resources