Skip to content

Instantly share code, notes, and snippets.

@charleyhine
Created July 31, 2014 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charleyhine/abf228e3b9e680cbcb46 to your computer and use it in GitHub Desktop.
Save charleyhine/abf228e3b9e680cbcb46 to your computer and use it in GitHub Desktop.
Chain webhooks -> Ruby
class HomeController < ApplicationController
skip_before_filter :verify_authenticity_token, only: [:callback]
def register_callback
register_url = 'https://api.chain.com/v1/webhooks?key=GUEST-TOKEN'
callback_url = 'http://chain-hooks.herokuapp.com/callback'
callback_alias = 'charley'
response = HTTParty.post(register_url,
body: { url: callback_url,
alias: callback_alias }.to_json,
headers: { 'Content-Type' => 'application/json' } )
puts response.body, response.code, response.message, response.headers.inspect
@response = response.body
respond_to do |format|
format.html { render template: "home/index" }
end
end
def register_event
event_url = 'https://api.chain.com/v1/webhooks/charley/events?key=GUEST-TOKEN'
response = HTTParty.post(event_url,
body: { event: 'address-transaction',
block_chain: 'testnet3',
address: 'moVqN4C1cLgp88WtDkKLYg8aPMac68os1q',
confirmations: 1 }.to_json,
headers: { 'Content-Type' => 'application/json' } )
puts response.body, response.code, response.message, response.headers.inspect
@response = response.body
respond_to do |format|
format.html { render template: "home/index" }
end
end
def callback
puts request.body.read
respond_to do |format|
format.all { render text: request.body.read }
end
end
def index
@response = "Here we are!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment