AngularJS and Google Ajax Crawler - ajax

So basically I am trying to get angularJs Routes to look like this
www.example.com/ajax.html#!product=1234
instead of like this
www.example.com/ajax.html#/product/1234
is there any hope?

You just have to configure the $location service and call:
$locationProvider.hashPrefix("!")

If your running a ruby app and want to adhere to the google ajax crawling scheme - there's a gem that implements the crawling scheme for any rack app....
gem install google_ajax_crawler
writeup of how to use it is at http://thecodeabode.blogspot.com.au/2013/03/backbonejs-and-seo-google-ajax-crawling.html, source code at https://github.com/benkitzelman/google-ajax-crawler

Related

Moodle with Ruby On Rails

Currently, I am working on a rails application which requires the user to be registered automatically in the moodle. I searched for it and found these gems,
moodle-api: https://github.com/getsmarter/moodle-api
moodle_rb: https://github.com/jobready/moodle-rb/
moodle: https://github.com/robertboloc/moodle
But, nothing seems to work for me. I even searched on youtube but found nothing with the rails.
However, using the moodle_rb gem I was able to create an object which returned me the sites info using the sites_info function. Other than that I am unable to use any of the web services of the moodle. I have created an external service and added some functions like auth_email_get_signup_settings and auth_email_signup_user which accepts none parameters.
May anyone guides me through this? or even a minor help would also be great.
I am using a token to create the object.
Thanks in advance.
Can you show us how you tried to configure your gems? For example, according to the docs the moddle-api gem requires a configuration like:
Moodle::Api.configure do|c|
c.host = 'http://my_moodle_instance.com'
c.token = 'mytoken'
end
If you did configure the gem like the above, can you show some of the code that you tried to call once the gem was installed and configured?

How do I ignore requests to a certain route in Sinatra when using NewRelic?

We're using NewRelic to monitor a Sinatra app. We don't want the probe URL varnish uses to check if the app is online to be instrumented by NewRelic. How do we tell NewRelic to ignore a certain Sinatra route? (The documentation only seems to refer to how to do this in Rails: https://newrelic.com/docs/ruby/blocking-controller-instrumentation)
You could try calling NewRelic::Agent.abort_transaction! within the code path for the probe request. See the API docs for details.
Have you tried what their docs suggest https://newrelic.com/docs/ruby/sinatra-support-in-the-ruby-agent
newrelic_ignore '/ping'
As of version 3.6.3 of the NewRelic gem, you can should be able to use the 'newrelic_ignore' method to ignore endpoints. If you are using Sinatra, you may need to call this class method explicitly, like so:
NewRelic::Agent::Instrumentation::Sinatra::newrelic_ignore('/route/to/ignore')
But, it doesn't work as expected. I am filing a bug report with NewRelic.

Ruby on Rails with chargify

I want to integrate chargify to my rails app. I have user object and I want the user to be able to subscribe for one month and update the boolean column on user object. I prefer to use the API not hosted pages. How can I do that?
Is there any example for chargify on ruby on rails for handling subscriptions but with details about mvc for newbies?
Based on this thread and the Googles it looks like there is not a whole lot out there.
You could try looking at the Rails 2 example here and converting it or use the gem here (gem "chargify", "~> 0.3.0").
I know none of this is aimed at newbies but the info seems to sparse.
This might get you going. It seems that Chartify itself is written in Rails, and therfore their API is ruby code, which you can use...

Ruby: How to screen-scrape the result of an Ajax request

I have written a ruby script to screen scrape something using the 'open-uri' and 'hpricot' gems - everything works great so far.
But now I have to screen scrape something which is returned after a form is submitted via a javascript function (called by an 'onchange' event handler from a drop-down menu):
function submit_form() {
document.list.action="/some/sort/of/path";
document.list.submit();
}
AFAIK, open-uri lets you submit only GET requests. And if I'm not mistaken, a POST request would be needed here.
So my question is: what do I need to install and to 'require' and how would the ruby code then look like (to make that POST request) - sorry, I'm still pretty much of a n00b...
Thank you very much for your help!
Tom
I think you definitely should use Mechanize. It provides a nifty interface to interact with remote pages, forms on them, and so forth (see this example).
The Ruby standard library has the http class, which naturally supports the POST operation.
Net::HTTP.post_form(URI.parse('http://www.example.com/some/sort/of/path')
If you find the API there less than optimal, then take a look at the httparty gem
Finally, while hpricot is a great gem, it isn't actively developed any longer. You should consider moving to nokogiri which practically replaces hpricot and improves upon it.

Twitter/Facebook API for Ruby

I want to write a Ruby application through which:
I can submit tweets to twitter.
I can submit a post to facebook.
I can manage real-time stats of tweets
Is there any twitter/facebook api for Ruby?
I use the Twitter gem and am quite happy with it.
For Facebook, there is the Facebooker gem.
Streams of tweets:
Tweetmon is a great gem for keeping real-time track of tweets. Here's an example of using it to get a stream of tweets on a specific keyword
#!/usr/local/bin/ruby
if ARGV.size==1
keyword = ARGV.shift
else
puts 'tweetmon usage: tweetmon <keyword>'
exit 1
end
require 'yaml'
require 'rubygems'
require 'tweetstream'
config = YAML::load(File.open(File.expand_path('~/.twitter')))
user =config['username']
password =config['password']
TweetStream::Client.new(user,password).track(keyword) do |status|
puts "[#{status.created_at}-#{status.user.screen_name}] #{status.text}"
end
To use this gem you need:
gem sources -a http://gems.github.com
gem install intridea-tweetstream
To submit a tweet is just a HTTP POST - doesn't need any extra libraries to do this.
The Twitter API is a RESTful web service. It's completely language agnostic. Use whatever language you want.
Not sure about Facebook.
Two more libraries that didn't get mentioned yet:
twitter4r: http://twitter4r.rubyforge.org/
Twibot: http://cjohansen.no/en/ruby/twibot_a_microframework_for_twitter_bots_in_ruby
If you're inclined to retain more control over how you use the Twitter and Facebook APIs you can use the Wrest gem.
Take a look at the facebook (http://is.gd/bJspX) and twitter (http://is.gd/bJsqV) examples.
Also, while both the Twitter and Facebook APIs are HTTP APIs, they are not RESTful despite their claims to the contrary.
I would use this gem, it's really helpful https://github.com/moomerman/twitter_oauth
or just gem install twitter_oauth
MiniFB https://github.com/appoxy/mini_fb is excellent for Facebook API. But in both APIs you can do everything through HTTPParty and OAuth.

Resources