What is the best way to access Google Calendar from ruby? - ruby-on-rails

I'm writing an app for a company that uses Google Calendar internally and would need to use events they already have in their calendar in the app. So I need to get read only access to their calendars from the app (namely I need the events title, start and end dates and attendee emails for all future events).
What is the simplest way to do this in ruby (I would need it to work relatively seamlessly on Heroku)?
I tried using the GCal4Ruby gem which seemed the least outdated of the ones I found but I'm unable to even authenticate through the library (HTTPRequestFailed - Captcha required error) let alone get the info I need.
Clarification: What I'm talking about is the Google Apps version of the calendar, not the one at calendar.google.com.

OK I got the api via GCal4Ruby working. I'm not exactly sure what went wrong the first time. Thanks to Mike and James for their suggestions. This is sample code I used for anyone interested:
require "rubygems"
require "gcal4ruby"
serv = GCal4Ruby::Service.new
serv.authenticate "username#example.com", "password"
events = GCal4Ruby::Event.find serv, {'start-min' => Time.now.utc.xmlschema,
:calendar => 'example-cal%40example.com'}
events.each do |event|
puts event.title
puts event.attendees.join ", "
puts event.start_time
puts event.end_time
puts '-----------------------'
end

You should be able to use the Google Calendar private xml address feature to pull out the needed data.
You could then parse it with hpricot or nokogiri to extract whatever fields you need.

Related

How to get ISO currency code by country code in rails?

In my rails app I want to use country-code, currency-code, ISO locale code to fetch some data from API. How can I get this information dynamically when user visit my site from anywhere?
I have used geocoder gem so by request.location I will get location's information and using this gem I can get country-code. Now I am not getting how can I get remaining information such as currency-code & ISO locale code?? Can anyone please help me or guide me??
I have seen this money gem but not sure it will provide me all these information.
Thanks in advance :)
I have tried #Prakash Murthy's answer. But there are many issue in this http://www.currency-iso.org/dam/downloads/table_a1.xml I found there is not proper name of all countries and some country has multiple currency_code which made me confused. But finally I found the solution by this single countries gem without creating any database.
Here is how I achieved the solution:
country_name = request.location.data['country_name'] # got country name
c = Country.find_country_by_name(country_name) # got currency details
currency_code = c.currency['code'] # got currency code
Sorry to answer my own question but I have posted here so in future if anyone stuck like me for the same issue then his/her time not wasted.
I found a way that makes it really easy:
Add currency gem to Gemfile, then bundle install
def currency_for_country(currency_iso_code)
ISO3166::Country.new(currency_iso_code).currency_code
end
Then:
currency_for_country('US')
=> "USD"
currency_for_country('AU')
=> "AUD"
This info is based off the countries gem readme
currency-code & ISO locale code are static data which change very rarely - if at all, and are best handled as static information within the system by storing them within the database tables. Might even be a good idea to provide a CRUD interface for managing these data.
One possible source for Currency code : http://www.currency-iso.org/en/home/tables/table-a1.html
List of All Locales and Their Short Codes? has details about getting the list of all locale codes.

Is there a quicker way to extract data from Sawyer::Resource via Octokit.rb GitHub API call?

I'm using Octokit.rb to search GitHub users and the response returns a Sawyer::Resource object. I'm currently accessing the data this way:
[].tap do |users|
#results.items.each do |item|
user = item.rels[:self].get.data
user = {
location: user.location,
username: user.login,
name: user.name,
email: user.email
}
users << user
end
end
I'd like to iterate over the users array created and display the results, however, right now the method takes extremely long as a result of accessing the data thru #rels[:self].get.data and I'm not sure what to do. Any help would be greatly appreciated!
Hey so I started messing around with the Octokit.rb library yesterday after I saw your question and I actually ran into the same issue as Jason pointed out. You're on the right track about using concurrent requests. I'm not sure about the rate limit being an issue and if it is you could always contact Github and ask if they could up your limit. If you're still having issues I would recommend using the rest-more gem, which uses rest-core to make concurrent requests. Its really simple to setup just read the docs.

Rails TMDB API Browse to Find

TMDB.org recently made a change to their API which removes the capability to browse their database.
My Rails app used to use the tmdb-ruby gem to browse the TMDB database, but this gem only worked with v2.0 of the API, which is now defunct.
TMDB.org recommends using this gem, and since it is forked from the gem I previously used, it makes it a bit easier.
My PostgreSQL database is already populated with data imported from TMDB when v2.0 was still extant and when I could use the browse feature.
How can I now use the find feature (ie: #movie = TmdbMovie.find(:title => "Iron Man", :limit => 1) ) to find a random movie, without supplying the title of the Movie.
This is my rake file which worked with the older gem.
I would like to know how to have it work the same way but whilst using the find instead of the browse.
Thanks
I don't think find is what you need in order to get what you want (getting the oldest movies in the database and working its way up to the newest movie). Looking at the TMDb API documentation, it looks like they now have discover that may have replaced the browse that you used to use.
I don't see discover anywhere in Irio's ruby-tmdb fork, but it looks like most of the specific methods they have (like TmdbMovie.find) call a generic method Tmdb.api_call.
You should be able to use the generic method to do something like:
api_return = Tmdb.api_call(
"discover/movie",
{
page: 1,
sort_by: 'release_date.asc',
query: '' # Necessary because Tmdb.api_call throws a nil error if you don't specify a query param value
},
"en"
)
results = api_return["results"]
results.flatten!(1)
results.uniq!
results.delete_if &:nil?
results.map!{|m| TmdbMovie.new(m, true)} # `true` tells TmdbMovie.new to expand results
If this works, you could even fork Irio's fork, implement a TmdbMovie.discover method supporting all the options and handling edge cases like TmdbMovie.find does, and send them a pull request since it just looks like they haven't gotten around to implementing this yet and I'm sure other people would like to have this method as well :)

Rails 3 able to import/export to/from Microsoft Access?

this question has been asked here already but it's quite some time ago. Does anyone know if Rails has any support for Microsoft Access? I'd need to import and export data every few weeks and would really like to avoid exporting/importing csv files.
Thanks!
It's worth noting that there's an mdb gem for Ruby. It requires mdbtools to be installed.
Add to your Gemfile:
gem 'mdb'
Usage is pretty straightforward, tables are basically lists of hashes:
require 'mdb'
database = Mdb.open('workshops_handouts_inactive_database.mdb')
table = database[:MainData]
results = table.select { |rec| rec[:"Schedule Type"] == "MU1" }
puts results.first
{:"Container Number"=>"17", :Location=>"1f6", :Department=>"tx", ...
I don't think ActiveRecord support exists for MS Access, though.
the win32OLE class allows you to retrieve data from Microsoft Acess you can find the docs here
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/win32ole/rdoc/WIN32OLE.html

Ruby on Rails 3 and Google Book Search

I'm trying to get started using the Google Data API for Google Book Search in my Ruby on Rails 3 application, and I don't even understand how to get started. What gems do I need? What do I need to do in order to do something simple like searching for books with a title of Foobar?
Following up on the deprecation issue: I've just published GoogleBooks, a Ruby wrapper that enables users to query for books precisely in the manner described.
It's updated to hook into the present-day Google API, so it's not affected by the recent deprecation of the Google Book Search API.
If you're looking to use Google Books to retrieve information about books, you can use their data API: http://code.google.com/apis/books/docs/gdata/developers_guide_protocol.html
Making requests to a URL like http://books.google.com/books/feeds/volumes?q=isbn:9780974514055 will return XML with the book's information. You could use the Nokogiri gem to parse the result ( http://nokogiri.org/ ).
One thing to be aware of is that, to get the full descriptions for books, you need to get the entry instead of just the feed results.
Here's a short example of how you could get a book's information from Google:
require 'open-uri'
require 'nokogiri'
class Book
attr_accessor :title, :description
def self.from_google(title)
book = self.new
entry = Nokogiri::XML(open "http://books.google.com/books/feeds/volumes?q=#{title}").css("entry id").first
xml = Nokogiri::XML(open entry.text) if entry
return book unless xml
book.title = xml.css("entry dc|title").first.text unless xml.css("entry dc|title").empty?
book.description = xml.css("entry dc|description").first.text unless xml.css("entry dc|description").empty?
book
end
end
b = Book.from_google("Ruby")
p b
if you want to use the api, i think you will have to use jruby and their java api. no ruby api exists for the book search, according to this: http://code.google.com/apis/books/docs/gdata/code.html
for connecting with google, try using the gdata gem.
http://code.google.com/apis/gdata/articles/gdata_on_rails.html#SetupRails

Resources