Skip to content

Instantly share code, notes, and snippets.

View nov's full-sized avatar

Nov Matake nov

View GitHub Profile
require 'active_support'
:something.blank?
nov@argentea:~$ oacurl login -p .oacurl.twitter.properties --consumer-key YOUR_CONSUMER_KEY --consumer-secret YOUR_CONSUMER_SECRET --verbose
May 20, 2010 11:30:23 AM org.mortbay.log.Slf4jLog info
INFO: Logging to org.slf4j.impl.JDK14LoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
May 20, 2010 11:30:23 AM org.mortbay.log.Slf4jLog info
INFO: jetty-6.1.x
May 20, 2010 11:30:23 AM org.mortbay.log.Slf4jLog info
INFO: Started SocketConnector@localhost:58227
May 20, 2010 11:30:23 AM com.google.oacurl.Login getAuthorizationUrl
INFO: Fetching request token with parameters: [oauth_callback=http%3A%2F%2Flocalhost%3A58227%2FOAuthCallback]
May 20, 2010 11:30:24 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies
module OpenID
def self.make_kv_post(request_message, server_url)
begin
http_response = self.fetch(server_url, request_message.to_url_encoded)
rescue Exception
raise KVPostNetworkError.new("Unable to contact OpenID server: #{$!.to_s}")
end
puts <<-KV_POST
======
require 'rubygems'
require 'restclient'
RestClient.post('http://api.twitpic.com/1/uploadAndPost.json', {
:key => SET_YOUR_OWN,
:consumer_token => SET_YOUR_OWN,
:consumer_secret => SET_YOUR_OWN,
:oauth_token => SET_YOUR_OWN,
:oauth_secret => SET_YOUR_OWN,
:message => SET_YOUR_OWN,
require 'rubygems'
require 'oauth'
require 'restclient'
consumer = OAuth::Consumer.new(
SET_YOUR_OWN,
SET_YOUR_OWN,
{:site => 'https://api.twitter.com'}
)
nov@argentea:img$ ./script/rails console
Loading development environment (Rails 3.0.0.beta4)
>> person = Person.new(:gender=>:male)
=> #<Person id: nil, gender_id: 1, created_at: nil, updated_at: nil>
>> person.gender
=> :male
>> person.gender_id
=> 1
>>
## OpenID/OAuth Hybrid Sample using rack-openid
require "rubygems"
require "sinatra"
use Rack::Session::Cookie
require "rack/openid"
use Rack::OpenID
# environment.rb
#
# These are models you should define. (you can change the model name, of course)
# * Oauth2::AccessToken
Rails::Initializer.run do |config|
:
require 'rack/oauth2'
oauth2_authenticator = lambda do |request|
access_token = Oauth2::AccessToken.find_by_token(request.access_token)
require 'rubygems'
require 'sinatra'
use Rack::Session::Cookie
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../lib'))
require 'rack/oauth2'
use Rack::OAuth2::Server::Token do |request, response|
# allow everything
# You should define those models. (you can change the model names)
#
# * Oauth2::Client
# * Oauth2::AccessToken
# * Oauth2::RefreshToken
# * Oauth2::AuthorizationCode
class Oauth2Controller < ApplicationController
before_filter :require_authentication, :only => :authorize