is there a pure command-line oauth flow for installed apps? - google-api-ruby-client

I'm trying to get a pure command line oauth flow for an installed app and it's not easy to piece this together... Docs are sorely lacking... I started with the drive example (https://github.com/google/google-api-ruby-client-samples/tree/master/drive) but when it gets to client.authorization = flow.authorize(file_storage) it tries to start webrick to put up a web page. I need something that works similarly to the CLI tools provided by google: it needs to print out the URL I need to visit and then read in the response that I can copy&paste. Is this possible with the google ruby client?

Looks like the following monkey-patch works:
module Google
class APIClient
class InstalledAppFlow
def authorize_cli(storage)
puts "Please visit: #{#authorization.authorization_uri.to_s}"
printf "Enter the code: code="
code = gets
#authorization.code = code
#authorization.fetch_access_token!
if #authorization.access_token
if storage.respond_to?(:write_credentials)
storage.write_credentials(#authorization)
end
#authorization
else
nil
end
end
end
end
end

Related

validating only itunes app store and play store url in rails

I am having a simple problem that is to validating url using ruby on rails technology.There are alot of solution for validating url but none works for me.As i want to allow only play store and app store url to save in database.
Say i have a play store app link.
here is my model:
class AppStore < ActiveRecord::Base
validate :custom
private
def custom
if self.url_name.match /paly.google.com|itunes.apple.com/
else
self.errors.add(:url_name, 'must be app store url or paly store url')
end
end
end
Now the is when i enter url like "http://play.google.com" also the full url of the app then the validation is failling.
A sample url would be like https://play.google.com/store/apps/details?id=com.viber.voip
Please help me to solve this problem as.I am new to rails technology.
Thank you guys.
Please try the following:
class AppStore < ActiveRecord::Base
VALID_STORES = ['play.google.com', 'itunes.apple.com']
validate :store_url_format
private
def store_url_format
unless VALID_STORES.any? { |host| url_name.includes?(host) }
errors.add(:url_name, 'must be an AppStore or a PlayStore url')
end
end
end

LinkedIn Gem Ruby: OAuth (permission_unknown)

I am trying to use the LinkedIn gem to access LinkedIn. I can't seem to get past getting access.
My code is this:
#client = LinkedIn::Client.new(API_KEY, SECRET)
#rtoken = client.request_token.token
#rsecret = client.request_token.secret
puts "token: #{#rtoken} secret #{#rsecret}"
#authorize_url = client.request_token.authorize_url
puts "authorize url: #{#authorize_url}"
#pin = #authorize_url.split("oauth_token=").last.strip
puts "pin #{#pin}"
#keys = #client.authorize_from_request(#rtoken, #rsecret, #pin)
#client.authorize_from_access(#keys)
And that produces the error:
token: sdklghsdgksdghskdhg secret shdlgkshdgshsdk
authorize url: https://www.linkedin.com/uas/oauth/authorize?oauth_token=sdkghskldghsdkg
pin fslkdghskdghdsgkhsdkhg
OAuth::Problem: permission_unknown
Not really sure where to start on this. I've tried to find what permission is missing, but I'm at a loss.
Thoughts?
I've just started playing with this myself. I hit this same issue unless I manually paste the authorize URL into my browser, and then click Accept to allowing the requested permissions to my account. Then a pin is printed on the screen which I enter in for the authorize_from_request call.
So this line in your code is incorrect - the last part of the URL is a generated_token as the README indicates, not a pin. I'm not sure of a programmatic way to do this.
#pin = #authorize_url.split("oauth_token=").last.strip
I discovered the issue. It turns out request_token.authorize_url does not return the pin. It just gives you a URL to visit where you can authenticate and generate a pin. Then you'll have to copy the pin into your application. A more elegant solution is this:
puts request_token.authorize_url
puts "Access the URL above. Authenticate. Enter the PIN here:"
pin = gets.strip
access_keys = client.authorize_from_request(rtoken, rsecret, pin)
This prints the URL and directs the user to authenticate, then enter the pin into the application.

How do I control my dropbox account from Ruby?

I read the documentation of the Dropbox SDK for Ruby, and couldn't find an example about using my own dropbox account. The examples I saw require that I get an ACCESS_TOKEN from a random user that validates the session for me.
I am the user! I just want to start uploading and deleting files; nothing more.
How do I achieve that?
EDIT:
snippet
require 'dropbox_sdk'
APP_KEY = '******'
APP_SECRET = '*****'
ACCESS_TYPE = :dropbox
session = DropboxSession.new(APP_KEY, APP_SECRET)
#I don't want to do this, I just want to know the way of authenticate
#myself with some method that don't need authorization
#-------------------------------------------
session.get_request_token
authorize_url = session.get_authorize_url
puts "AUTHORIZING", authorize_url
puts "Please visit that website and hit 'Allow', then hit Enter here."
gets
session.get_access_token
client = DropboxClient.new(session, ACCESS_TYPE)
puts "linked account:", client.account_info().inspect

How to debug/test email transfers in Sinatra/Ruby

Im using Pony to send email withing my sinatra applications. But the problem - i cant figure out how to debug or test it. Lest say, in php you can configure sendmail fake app (in php.ini) that will store all outgoing email as plain textfiles with all data in it.
How about ruby apps? Is it possible?
You surely found the solution already yourself
In the pony.rb file there is this code part which sends the mail:
def self.transport(tmail)
..
end
You can simply add a method to return the env:
def debug?
true #false
end
and do something special if debug mode is on
def self.transport(tmail)
puts "Debug message" if debug?
if File.executable? sendmail_binary
transport_via_sendmail(tmail)
else
transport_via_smtp(tmail)
end
end

How do I generate a WSDL using Ruby?

I starting to work with Ruby and Soap and had some questions:
How do I generate a WSDL file for the service I created?
Will it be compatible with an .NET client ?
begin
class MyServer < SOAP::RPC::StandaloneServer
# Handler methods
def add(a, b)
return a + b
end
def div(a, b)
return a / b
end
# Expose our services
def initialize(*args)
add_method(self, 'add', 'a', 'b')
add_method(self, 'div', 'a', 'b')
end
end
server = MyServer.new("MyServer",
'urn:ruby:calculation', 'localhost', 8080)
trap('INT'){
server.shutdown
}
server.start
rescue => err
puts err.message
end
ActionWebService (previously in Rails core, now a gem) has tools to generate WSDL files. You can use the tools even if you're not running your service within Rails.
http://www.datanoise.com/articles/2008/7/2/actionwebservice-is-back
As for whether it will work with a .NET client, the answer is maybe. Many .NET clients seem to expect Microsoft's "extended" SOAP info, which .NET webservices provide by default. If the client is also able to consume a service without that extra stuff, then sure.
UPDATE #1
The above link no longer appears to work. There are however forks of ActionWebService that have popped up over on github. You can see a pretty good list of them here. Here are a couple of links to some key versions:
original datanoise version
clevertechru's port, works w/ Rails 3.1.* & Ruby 1.9

Resources