Ruby on Rails Google API - ruby-on-rails

I'm currently doing a Ruby on Rails project where I try to query from the Google Calendar API. I'm using this line of code:
service = Google::Apis::CalendarV3::CalendarService.new
and I have the gem google-api-client in my Gemfile. However, when I try to run the app with this line, it fails saying that it is Unknown Constant: Google Apis. If I try to put in the line that I've seen on StackOverflow, where I put require 'google/apis/calendar_v3' in the ruby file, it fails. I've spent 4 hours online trying to find anyone with a similar solution. If I try another API, like require 'google/apis/drive_v2', it works fine, just calendar. :(

The following works for me on Rails 4.2.1 -- Note that there are two requires.
require 'google/apis'
=> true
require 'google/apis/calendar_v3'
=> true
service = Google::Apis::CalendarV3::CalendarService.new
=> #<Google::Apis::CalendarV3::CalendarService:0x007fca01ae60a0 #root_url="https://www.googleapis.com/", #base_path="calendar/v3/", #upload_path="upload/calendar/v3/", #batch_path="batch", #client_options=#<struct Google::Apis::ClientOptions application_name="unknown", application_version="0.0.0", proxy_url=nil, use_net_http=false>, #request_options=#<struct Google::Apis::RequestOptions authorization=nil, retries=0, header=nil, timeout_sec=nil, open_timeout_sec=20>>
My gem file contains:
gem 'google-api-client', '0.9'

Related

uninitialized constant Google::Cloud::Vision::ImageAnnotator

Running this example
https://cloud.google.com/vision/docs/face-tutorial?hl=zh-tw
by rails on 'google-cloud-vision', '~> 0.31.0'
got the error
uninitialized constant Google::Cloud::Vision::ImageAnnotator
here's the code
require "google/cloud/vision"
project_id = 'xxxxxx'
vision = Google::Cloud::Vision.new project: project_id
image_annotator = Google::Cloud::Vision::ImageAnnotator.new
Did you added google-cloud-ruby gem in your Gemfile and other google related authentication details into your ruby project.
It turns out that the error was caused because I haven't use the latest version of gcloud-vision(0.32.x)
the way to do what I wanna do in gcloud-vision(0.31.0) is
image = vision.image "path/to/face.jpg"
face = image.face
instead of using class
Google::Cloud::Vision::ImageAnnotator

Different result from rails and irb for YoutubeDL.get

I'm using gem 'youtube-dl.rb'.
From irb, I can get full result, about video, but at the rails 4.2 - I can't.
irb
require 'youtube-dl.rb'
a = YoutubeDL.get "https://www.youtube.com/watch?v=5dsGWM5XGdg", {skip_download: true}
Result https://pastebin.com/9SLbs5GF (With a lot of data).
rails c
require 'youtube-dl.rb'
a = YoutubeDL.get "https://www.youtube.com/watch?v=5dsGWM5XGdg", {skip_download: true}
Result from rails console have only this:
=> #<YoutubeDL::Video:0x007fbc29de1498 #url="https://www.youtube.com/watch?v=5dsGWM5XGdg", #options=#<YoutubeDL::Options:0x007fbc29de1448 #store={:skip_download=>true}>, #download_options=#<YoutubeDL::Options:0x007fbc29de1150 #store={:color=>false, :progress=>false, :skip_download=>true}>, #last_download_output="[youtube] 5dsGWM5XGdg: Downloading webpage\n[youtube] 5dsGWM5XGdg: Downloading video info webpage\n[youtube] 5dsGWM5XGdg: Extracting video information\n[youtube] 5dsGWM5XGdg: Downloading MPD manifest\n">
How I Can get the same result for RoR?
Try to check youtube-dl.rb version inside your rails app and inside your machine enviro

MessageBus.callbackInterval does not work in production

I've been using the message_bus gem for a few months as a more simplified alternative to a websocket solution. The default MessageBus.callbackIntervalis too wide, so I want to narrow it. I've done this successfully in my development env. However, when deploying to production it seems that the second line below is ignored:
MessageBus.start();
MessageBus.callbackInterval = 1800; # this should change the interval frequency, but it doesn't
MessageBus.subscribe("/some_id", function(status) {
// work
});
Any idea how I could debug this?
I haven't personally encountered this problem before, but like with many JavaScript libraries/files in Rails it is probably something in the assets pipeline.
Are you certain that you included JavaScript required for message bus to work in your view with:
<script src="message-bus.js" type="text/javascript"></script>
and in assets
//= require message-bus
If you're using a Ruby version of this gem, you can always try to set this using Ruby instead of JavaScript.
client = MessageBus::Client.new('http://127.0.0.1/8000') #port is optional
#you should be able to do
client.callbackInterval = 1800
#after that you should be able to do
client.subscribe('/message') do |payload|
# Do stuff
end
For more info refer to https://github.com/lowjoel/message_bus-client

how to install and use angularJS plugin in rails

I wanted to use this angular-number-picker plugin in my rails project.
I downloaded the .min.js file and the .js file and put the in the plugins folder. Then I also included the js in
/global_plugins.js
//= require global/plugins/angular-number-picker/angular-number-picker.min.js
and then I also inject it to the dependency of my app
/app.js
var app = angular.module('fotograft', ['ngResource', 'angular-loading-bar', 'cgBusy', 'ngFileUpload', 'MessageCenterModule', 'rails', 'Devise', 'google.places', 'ui.sortable','checklist-model',
'textAngular', 'angularMoment', '720kb.socialshare', 'ngSanitize', '720kb.tooltips', 'angular-md5', 'angularUtils.directives.dirPagination', 'infinite-scroll', 'datatables', 'datatables.bootstrap',
'ngResource', 'frapontillo.bootstrap-switch', 'angular-bootstrap-select','angular-number-picker', 'angular-bootstrap-select.extra', 'ngTextTruncate', 'chart.js', 'timer', 'siyfion.sfTypeahead'])
The problem is when I tried to load any page, the page will not respond. So I tried to view the console and debug, the error was that
Error: [$injector:modulerr] http://errors.angularjs.org/1.3.16/$injector/modulerr?
I truncated the rest of the error messages, because they are kind of long and look gibberish.
So, I would like to ask what am I missing here? I saw from the author's webpage that I need to include the src to the plugin in the html page, but I have no idea which page I should include it in.
Appreciate it if any rails and angularJS developer can help me out here. Thank you very much.
If you double check the link in the source code you provided, it looks like the module name that you have to register is supposed to be angularNumberPicker instead of angular-number-picker.
So you want your app.js module registry to look like this:
var app = angular.module('fotograft', ['ngResource', 'angular-loading-bar', 'cgBusy', 'ngFileUpload', 'MessageCenterModule', 'rails', 'Devise', 'google.places', 'ui.sortable','checklist-model',
'textAngular', 'angularMoment', '720kb.socialshare', 'ngSanitize', '720kb.tooltips', 'angular-md5', 'angularUtils.directives.dirPagination', 'infinite-scroll', 'datatables', 'datatables.bootstrap',
'ngResource', 'frapontillo.bootstrap-switch', 'angular-bootstrap-select','angularNumberPicker', 'angular-bootstrap-select.extra', 'ngTextTruncate', 'chart.js', 'timer', 'siyfion.sfTypeahead']);

Need to load the URL from excel and need to execute using Ruby script

I am very new to ruby, i wanted to learn the ruby code. I have basic knowledge.
I have list of pages(URL), I saved in an excel. I wanted to get those pages and needs to load in browser. Please find below basic script which I wrote for page loading.
require 'rubygems'
require 'watir'
ie = Watir::IE.new
ie.goto("http://google.com")
ie.goto("http://www.softwaretestinghelp.com/")
ie.goto("http://www.onestoptesting.com/manual-testing/")
ie.goto("https://facebook.com")
Please help to get it done.
Thanks and Regards,
Vinayaka M N
You can do it with Nokogiri gem and xml/ json file.
For exmaple:
require 'watir-webdriver'
require 'nokogiri'
browser = Watir::Browser.new :firefox
doc = Nokogiri::XML(File.open('your_file.xml'))
url = doc.at('//url').text
browser.goto(url)
And you must have xml like this:
<url>http://google.com</url>

Resources