Skip to content

Instantly share code, notes, and snippets.

@coldfumonkeh
Created October 11, 2012 15:01
Show Gist options
  • Save coldfumonkeh/3873004 to your computer and use it in GitHub Desktop.
Save coldfumonkeh/3873004 to your computer and use it in GitHub Desktop.
Ruby / Sinatra code for PhoneGap Build to automatically force a new request from a Github repository
require 'sinatra'
require 'rest_client'
def get_or_post(path, opts={}, &block)
get(path, opts, &block)
post(path, opts, &block)
end
get '/' do
'Hello world'
end
get_or_post '/:user/:pass/:appid' do
pgURL = 'https://build.phonegap.com/apps/' + params[:appid] + '/push'
private_resource =
RestClient::Resource.new pgURL, params[:user], params[:pass]
private_resource.get{ |response, request, result, &block|
if [301, 302, 307].include? response.code
response.follow_redirection(request, result, &block)
end
}
end
# Handle all other routing
["/", "/:user", "/:user/", "/:user/:pass", "/:user/:pass/"].each do |path|
get_or_post path do
'Ru-roh, you cant do that.'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment