Accessing a django function/module in iOS - ios

Here is what I am trying to do:
I'm implementing a search function in python that would be used in this sort of fashion:
search(query)
I'm using a Django + TastyPie JSON api to link a PostgreSQL db to an iOS app. It's been easy (so far) to perform CRUD operations on my tables, but now I want to do something decidedly more complex.
What would be the best way to implement this? I want instant search, which I could do in-browser with backbone or the like. Something like google instant search.
I thought that I could, potentially, connect the function to a view at http://search.example.com/query, which would return some JSON aligned with the query 'query'. The problem is, doing this via http seems inefficient:
http://search.example.com/q
http://search.example.com/qu
http://search.example.com/que
http://search.example.com/quer
http://search.example.com/query
Thanks for the help!

Related

Getting many models in one Rails API endpoint

I'm sifting through a few Rails 5 API tutorials and all the endpoints are as you would expect: /todos for getting all todos, /todos/:id/items for getting a todo item, etc.
I'm building an API where a Site has Tutorials and TutorialItems. I am first wondering if with a Rails API it is possible to create a custom endpoint like /init_tutorials that would get a site's tutorials and tutorial items OR does it instead make sense to have the endpoint /site/:id that would pull Site's tutorials and tutorial items all in one go like so in app/controllers/sites_controller.rb:
# GET /sites/:id
def show
# get #Site.tutorial.tutorial_items
end
Either way is obviously possible. One option is to do have the /site/:id endpoint accept a parameter, something like /sites/1?tutorials=true. This works well for simple APIs but can quickly get out of had for larger APIs with more diverse clients and many potential options.
If you are likely to be doing something more complex you might want to start out using an API style more like Facebook's FQL or Netflix's Falcor API style. There are a few Gems which can help you with either one.

how to use external API with rails

After making a bunch of CRUD-like apps, I've decided to venture out a bit and play with APIS. The Riot game API seems pretty simple to implement, as it is just a link follow by my API key.
ex: https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/RiotSchmick?api_key=<key>
after googling for quite a while yesterday, I am still at lost how I can integrate this information.
Where should I put the above link, how do I store the information from the JSON, and how exactly does the MVC structure fit into this?
If I'm not storing any data (no users, just instant display of info based on API) Do I even need a database?

Display all tweets with a certain hashtag with simple design

I'm developing some website using Rails. I want to add "our users' tweets" part to the main page. I need an advice how I can do it better. I hoped to get standard way to do it, may be some Twitter widget or something else. I used Google, but I've found nothing. Please, point me to the right path. Sorry if my questions is very simple, but I don't really know how to do it. I hope that I needn't parse JSON and add styles independently; I need simple design from Twitter :)
To answer your [ambiguous] question, there are a number of things to consider:
How will you retrieve the tweets?
How will you store / access them?
How will the data be displayed on front-end?
The two methods you have are either to use the Twitter gem, or the TwitterFetcher JS plugin:
Gem
The Twitter gem uses the Twitter API to pull data from the official Twitter API. This means you've got the throttling & authentication to build into your app
The benefits of using this gem is it gives you a HUGE amount of flexibility with the data. You can pull as much data as you need / want, in whatever format you want - all formatted in JSON & can be displayed on your site
This gem is best suited to storing your tweets, either in a DB or in Redis etc, otherwise you'll have massive synchronous dependency on Twitter's API - which is never good for performance
JS
The TwitterFetcher JS plugin is epic - basically takes a Twitter widget & strips out the HTML, allowing you to style it how you like
This is the most effective way to retrieve Twitter data on-the-fly, as it's asynchronous, relies on Twitter's widget system (far more robust than API), and stores no data locally

How best to aggregate site statistics (especially search demand)

I am working on a rails application that uses sunspot solr for search. I have been asked to log (or capture in some way) each search that happens on the site; the query, the user that did the search, the result count that resulted from their search...etc, so that the company can report on what people are searching on (demand), and other things.
Before I go and make a table, that will receive an ever-growing number of rows of search data, I'm wondering if anyone has done this in a better way? Can I use analytics (google?) in some way for this? Is there some kind of service I can send this information too, such that we could easily pull reports, or create reports from?
In short, is there some better/smarter way than creating my own table and storing this all in our own DB?
I had never done this, but here are some thoughts.
If you just need to store that data I think you should do it yourself.
If you need to also provide a way to analyse the data yes, see if there is anything already done (I'm not sure but it seems google analytics only support internal search using their search bar).
If your client already have some BI tool they just need a way to access the data, and it would be easier to have it in a owned DB wich you can easily be query instead of using a provider api.

Aggregating feeds in Rails application

I am thinking of writing a daemon to loop through feeds and then add them into the database as ActiveRecord objects.
Firstly, one problem I am facing is that I cannot reliably retrieve the author/user of a story using the feed-normalizer gem. It appears that some times, it does not recognize the tag (I don't know if anyone else has faced this problem).
Secondly, I haven't seen anyone convert RSS feeds back into database entries. I need to do this as each entry will have associations with other ActiveRecord objects. I can't find any gems to do this specifically, but could I somehow hack something like acts_as_feed to do that?
Don't use SimpleRSS. It won't decode HTML entities for you, and it occasionally ignores the structure of the feed.
I've found it easiest to parse the feed as XML with XMLSimple, but you can use any XML parser.
SimpleRSS exposes a very simple API and works pretty well on most feeds. I recommend not looking at the implementation as its "parser" is a bunch of regexes (which is so wrong on so many levels), but it works well.
Daemons is a good gem for running it in the background.
If you are using active record, you should follow the instructions for using AR outside of rails and then inline define the model classes. This will cut down on bloat a bit.
RSS feeds are pretty inconsistent, this is the fall through we use
date = i[:pubDate] || i[:published] || i[:updated]
body = i[:description] || i[:content] || i[:summary] || ""
url = i[:guid] || i[:link]
Also, from experience, make sure you try to rescue everything (and remember that timeouts are not caught by normal rescue). It sucks to have to constantly bounce RSS daemons that get bad data.
The best approach is to use a Rails Engine connected to a Feed API like Superfeedr's.
Polling RSS feeds implies that you'll need to run your own asynchronous workers and/or a queue system which can be fairly complex to build and maintain overtime. You'll also have to handle hundreds of formats and inconsistencies. Here's a blog post that shows how to consume RSS feeds in a Rails application.

Resources