Skip to content

Instantly share code, notes, and snippets.

View herestomwiththeweather's full-sized avatar
🏠
Working from home

Tom Brown herestomwiththeweather

🏠
Working from home
View GitHub Profile
@herestomwiththeweather
herestomwiththeweather / oauth2_mac_client_example.rb
Created March 12, 2012 19:51
Example code to make hmac signed oauth2 requests
require 'uri'
require 'cgi'
require 'net/https'
require 'json'
require 'oauth2_mac_client'
# oauth2_mac_client gem at https://github.com/herestomwiththeweather/oauth2_mac_client
# usage using this test class:
# > client = OAuth2Client.new
# > client.get_token('refresh_token') # get a new MAC type access token
#!/usr/bin/env ruby
require 'rss'
require 'webmention'
require 'time'
string = File.open('latest_time.txt', 'r') { |f| f.read }
latest = string.strip # RSS timestamp of most recent blog post for which webmentions have been sent
latest_found = latest # RSS timestamp of most recent blog post including new ones found
last_time = Time.parse(latest)
from, to, branch = ARGF.read.split " "
if (branch =~ /herestomwiththeweather$/) == nil
puts "Received branch #{branch}, not deploying."
exit
end
deploy_to_dir = '/home/pants/deploy/herestomwiththeweather-jekyll-indieweb'
`unset GIT_DIR && cd "#{deploy_to_dir}" && git pull`
puts "DEPLOY: herestomwiththeweather(#{to}) copied to '#{deploy_to_dir}'"
`cd /home/pants/repositories/herestomwiththeweather-jekyll-indieweb.git/hooks && ./send_webmentions.rb`
Verifying that +herestomwiththeweather is my blockchain ID. https://onename.com/herestomwiththeweather
@herestomwiththeweather
herestomwiththeweather / request_token
Created May 21, 2011 00:31
Single Payment Scope: Request Token
POST /oauth/request_token HTTP/1.1
Accept: */*
Connection: close
User-Agent: OAuth gem v0.4.4
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth oauth_callback="http%3A%2F%2Flocalhost%3A3001%2Foauth_callback", oauth_consumer_key="xBoHeeNNFt3LQ7U1tvAb8BVKr32duE6rdWtpCSFD", oauth_nonce="cde4xVNJBZm6XAy3V6EjMk8gy6uTPf5wEdZgKiMlk", oauth_signature="dyP6m%2FQm%2Bvnes86o6dLvD013Yy4%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1305937625", oauth_version="1.0"
Content-Length: 106
Host: demo.opensourcecurrency.org
scope=http%3a%2f%2fdemo.opensourcecurrency.org%2fscopes%2fsingle_payment.json%3fasset%3dbernalbucks%26amount%3d3
unless (access_token.nil? || access_token.authorized_for?(exchange.amount))
false
def authorized_for?(requested_amount)
['single_payment','recurring_payment'].include?(action_id) && requested_amount <= amount.to_f && !invalidated?
end
{
"action":
{
"_id":"single_payment",
"name":"single payment",
"icon_uri":"/images/icons/switch.gif"
}
}
@herestomwiththeweather
herestomwiththeweather / authorize.html.erb
Created May 21, 2011 03:06
single payment authorization view
<%= check_box_tag 'authorize' %> authorize <span id="scope-action"><%= @token.action_name %></span> <img src="<%= @token.action_icon_uri %>"> of <%= @token.amount %> <%= @token.asset %>
def create_request_token(params={})
if params[:scope]
scope_uri = URI.parse(params[:scope])
# XXX ignoring host:port and assuming it's our host:port
filepath = RAILS_ROOT + '/public' + scope_uri.path
if File.exist?(filepath)
# valid asset is required
asset = CGI::parse(scope_uri.query)['asset'][0]
unless asset.blank?
group = Group.find_by_asset(asset)