Skip to content

Instantly share code, notes, and snippets.

window.location.href = <%= root_url %>
class BankacctsController < ApplicationController
def addbank
@account_uri = (params['account_uri'])
current_user.customer_uri = @account_uri
current_user.save!
end
end
def current_path
current_url = request.original_url
end_of_string = current_url.length
regex_index = (Rails.env.production?) ? /.\.com\// : /:\d\d\d\d\//
regex_after_index = (regex_index =~ current_url) + 5 # production 7
path= end_of_string - regex_after_index
if path == 0
"/"
else
current_url[-path..-1]
def render_option(url_options)
custom_render = false
url_options[:custom][:urls].each do |url|
if current_path == url
custom_render = true
break
elsif [current_path] == url_options[:custom][:other_urls]
custom_render = "other"
break
elsif [current_path] == ["/articles"] or current_path[0,17] == "/carbon_projects/" or current_path[0,10] == "/articles/"
def create_button(id)
button = {
:name => 'test',
:type => 'buy_now',
:price_string => '1.23',
:price_currency_iso => "USD",
:custom => 'Order123',
:callback_url => 'http://www.example.com/my_custom_button_callback',
:description => 'sample description',
:style => 'custom_large',
uri = URI.parse("https://coinbase.com/api/v1/buttons")
button = { :name => 'test', :type => 'buy_now', :description => 'sample description', :include_email => true }
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = Net::HTTP.post_form(uri,button)
response
#<Net::HTTPBadRequest 400 Bad Request readbody=true>
@alaingoldman
alaingoldman / POST
Last active January 24, 2017 13:29
uri = URI.parse("https://coinbase.com/api/v1/buttons")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-Type', 'application/json')
button = { :name => 'test', :type => 'buy_now', :description => 'sample description', :include_email => true }
request.body = button.to_json
uri = URI.parse("https://coinbase.com/api/v1/buttons")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
request.add_field('Content-Type', 'application/json')
button = { :name => 'test', :type => 'buy_now', :description => 'sample description', :include_email => true }
request.body = button.to_json
@API_KEY = 'asdfghj'
@API_SECRET = 'asdfghjklfrgh'
def get_http(url, body=nil)
@nonce = (Time.now.to_f * 1e6).to_i
@message = @nonce.to_s + url + body.to_s
@signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha256'), @API_SECRET, @message)
@headers = {"ACCESS_KEY" => @API_KEY, "ACCESS_SIGNATURE" => @signature, "ACCESS_NONCE" => @nonce}
begin
if body.nil?
require "net/http"
require "uri"
require "json"
require 'openssl'
uri = URI.parse("https://coinbase.com/api/v1/buttons")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true