How to recognize a bot in rails [duplicate] - ruby-on-rails

This question already has answers here:
Rails Browser Detection Methods
(3 answers)
Closed 8 years ago.
I'm trying to record visits to my site, but I keep getting crawlers accidentally setting off my code. Is there any way in rails controllers to determine whether a user is a bot such as googlebot, etc?

You can check HTTP headers, particularly the user agent string.
http://www.useragentstring.com/pages/Googlebot/
Most friendly bots have "bot" in their user agent.
Another suggestion is to use something like Google Analytics to track your visits. It's way better than implementing your own.

Related

Phone number based Devise authentication for mobile apps [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
We all know that Devise is de facto standard for implementing authentication on rails based apps.
By default it uses email as ID but also allows you to use usernames instead. It also has "Confirmable" module which lets you confirm the email address by sending an email and clicking through the link to verify your email.
I was looking for something similar for phone numbers--basically accepting phone numbers as primary ID instead of emails, and then confirm the phone number by sending an auth code as SMS message to the user's number via something like Twilio, and then let the user confirm it by entering the code (or even let the user click through a generated link to verify just like they do with emails)
The reason I was expecting there to be a popular devise module for this functionality was because it seems as if most mobile social apps accept phone numbers and confirm the number nowadays. There's gotta be someone who thought this was a problem and open-sourced a module for this. However I couldn't find any popular ones. Actually to be precise, here are the only three relevant links I've found on this:
https://github.com/giano/devise_sms_activable
https://github.com/baranov-sv/devise_sms_confirmable
Rails register User using phone number and confirmation
None of them leads to a working solution (I've tried devise_sms_activable but it doesn't work for rails 4, plus I'm wary of the low number of stars) So I wanted to ask if there's any viable solution to this. Am I missing something? Has this topic been brought up among the Devise developer community? I'm curious about the solution but if there is none, I would at least appreciate any answer on why this is not readily available.
[UPDATE]
I think the question might have been a bit misleading. While I can just build it myself, I don't like to re-invent the wheel.
Basically my intention with this question was:
If there's any package that does this (like all the modules such as confirmable, token_authentcatable, etc. Maybe not even a Devise module and it could be entirely a different thing)
Or, if there is no such pre-built solution, why there isn't one. I just can't comprehend why there is no such solution I can find when everyone seems to be doing this.
I will gladly accept when I get an answer to either #1 or #2. Thanks!
i've looked into that before... but the project requirements changed... so all of the following are relative links found on the devise wiki
this how to allows you to sign in and authenticate with different fields other than the email address
A Simple Token Authentication Service for Mobile Devices Using Rails 3 and Devise.
you can use the previous tuts in conjunction with some thing like Twilio to send the created custom auth token and authenticate user with phone number other than email.
[UPDATE]
since you mentioned an already working solution, I think this is what you are looking for. Active Model OTP and this blog post it's new and i didn't have the chance to test drive it :D
I also found Two factor authentication Devise extension
[UPDATE Aug/2017]
Based on a project that I was recently working on, I found that Tinfoil/devise-two-factor provides a really good/extensible integration with devise (and is highly customizable)... using the internal ROTP gem, you can provide different length codes based on different authentication methods (APP/SMS) and different window/drift allowed per method without having to write the whole thing from the ground up. (highly recommended if you want full power over complex workflow)
I'm the OP, and since I asked this question, I've come across a gem called active_model_opt https://github.com/heapsource/active_model_otp
This gem is not exactly a devise plugin but it does exactly what i was looking for. Basically by adding it to your user model it generates one time passwords that are valid for a certain amount of time. It even has a built-in function to "authenticate" using the one time password.
Anyway I hope anyone who stumbled upon this question may find this answer useful.
Probably not exactly what the OP was looking for, but for Rails developers in China, now there's a gem called china_sms which automatically integrates various Chinese SMS sending services into your Rails app. I'll just add it here in case anybody shall find it useful.
https://github.com/saberma/china_sms
https://ruby-china.org/topics/12407

What is the best way to save Iphone user data in a server? [duplicate]

This question already has answers here:
Best way to save data on the iPhone
(7 answers)
Closed 9 years ago.
I want to start an iPhone app for an E-learning recommendation system which does the following:
Let the user register or log in the app.
After logging in the app ask the user questions.
My question:
What is the best way to manage users to be able to log/register and save/retrieve user questions and answers?
I feel like I've answered this question many times before, but the alleged duplicate recommends using NSUserDefaults and I think that's poor advice for saving the data that your app manages. (The dupe is from back in 2008, BTW; the iOS landscape was somewhat different back then, but even so I still don't think the most popular answer gives very good advice.)
Since you're looking at having your users log in, there may be a server that they're logging into. If so, saving the data on the server is the right thing to do. Exactly how that work will depend on your infrastructure, but you'll probably GET and POST data to a web server using HTTP. There's a LOT of information on the net about how to go about that (lack of research is probably why you're getting down votes), but you'll either use NSURLConnection and NSURLRequest directly, or you'll use a third party library like AFNetworking that makes it even easier to access a web server.

Tweet counter button showing zero (Addthis plugin for blogspot) [duplicate]

This question already has answers here:
Dealing with < in tw:counturl addthis plugin
(2 answers)
Closed 3 years ago.
I have added a Addthis plugin for blogspot for social networking sharing. The tweet count button for some reason is showing zero always, though the link has been tweeted multiple times.
I have verified using http://cdn.api.twitter.com/1/urls/count.json?url=
My blog website is http://rohit-cricket.blogspot.in/2012/10/turning-twenty-three-and-counting.html
There is no point of pasting code here, as Addthis expands when the page is loaded. It can be seen using Inspect element of google chrome.
Please help
Twitter describes a couple possibilities as to why your count may not be incrementing:
To improve performance we cache the count before displaying it. The cache is updated frequently but on some occasions it may look like your count is not increasing while the cache is updated. In addition, the count only includes public Tweets meaning a Tweet from a protected account will not cause an increase.
Additionally, there is currently a requirement that your server support HTTP HEAD requests in order to update the count properly. An easy way to check this is to use the command-line curl program, passing the -I (capital i) flag. A successful request should have a HTTP 200 OK response
Source: https://dev.twitter.com/docs/tweet-button/faq#count-api-increment
Also, try updating the link to tweet:
<a class="addthis_button_tweet" tw:counturl="http://yoururltocount.com/">
Found answer here: http://www.addthis.com/forum/viewtopic.php?f=4&t=30188

What's this new `#!` in URL convention? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What's the shebang/hashbang (#!) in Facebook and new Twitter URLs for?
I noticed that some popular sites started switching to a new URL (convention?), in which a URI segment is no longer prefixed by / but rather by #!/.
For example, if you type into Twitter http://twitter.com/stackoverflow, it will immediately redirect to http://twitter.com/#!/stackoverflow.
Had I seen this on Twitter only, I wouldn't have thought twice about this, but now I am seeing this in other sites.
Is this a new convention for URL redirection? Where can I learn more about this?
It was started by Google ( http://code.google.com/web/ajaxcrawling/ )
If you're running an AJAX application
with content that you'd like to appear
in search results, we have a new
process that, when implemented, can
help Google (and potentially other
search engines) crawl and index your
content. Historically, AJAX
applications have been difficult for
search engines to process because AJAX
content is produced dynamically by the
browser and thus not visible to
crawlers. While there are existing
methods for dealing with this problem,
they involve regular manual
maintenance to keep the content
up-to-date.
Look at this answer here:
What's the shebang/hashbang (#!) in Facebook and new Twitter URLs for?
The opinion on using this is split - Gawker had major issues after taking this up : http://www.webmonkey.com/2011/02/gawker-learns-the-hard-way-why-hash-bang-urls-are-evil/
It's how Google should index the page when dealing with AJAX

Update Facebook Page Wall via API [duplicate]

This question already has answers here:
Easy way of posting on Facebook page (not a profile but a fanpage)
(2 answers)
Closed 2 years ago.
I am having difficulty both publishing content to a Facebook Page wall, and also finding up to date documentation about how to accomplish this (the Facebook pages that I have found links to in other questions asked here either are missing or broken).
The application I am writing would periodically push content on a schedule basis from a ruby on rails application via a cron job/rake task to the fan page wall. I am hoping that someone may have an up to date guide or instructions on how to push content to Facebook page walls.
Any help would be appreciated.
Koala rocks my world!
Assuming you have asked for write permission to their wall (first read this: http://developers.facebook.com/docs/authentication/ [pay attention to the 'scope' parameter] refer to this for the permissions: http://developers.facebook.com/docs/authentication/permissions/ [you'll need to ask for publish_stream permisson], then read https://github.com/arsduo/koala/wiki/OAuth), and have a valid oauth token, its as simple as:
#graph.put_wall_post("hey, i'm learning koala")
https://github.com/arsduo/koala/wiki/Graph-API
Also, read https://github.com/arsduo/koala/wiki/Koala-on-Rails for Koala on ROR.
See the oauth examples at:http://oauth.twoalex.com/ (Source code: https://github.com/arsduo/oauth_playground)

Resources