Bitcoin Forum

Bitcoin => Project Development => Topic started by: phantastisch on August 23, 2012, 09:36:48 PM



Title: Bitpay RubyGem
Post by: phantastisch on August 23, 2012, 09:36:48 PM
Hi Guys,

since i am learning Ruby i thought it would be cool to create a Ruby Gem for Bitpay.
You can create and request invoices from the Bitpay Api in an easy way.

Here it is :

https://github.com/phanaster/BP-for-Ruby

If you encounter any bugs, have advice, suggestions, or feedback of any kind, i would appreciate it.

Have fun !

Disclaimer : This is an Alpha Release. Keep this in mind, it probably can break or malfunction. Even if my tests did not show any bugs or misbehavior, its not perfect.


Title: Re: Bitpay RubyGem
Post by: davout on August 24, 2012, 09:02:57 AM
Why don't you just call it bitpay ?


Title: Re: Bitpay RubyGem
Post by: phantastisch on August 24, 2012, 09:08:16 AM
Why don't you just call it bitpay ?

I am bad at choosing names.  :'(


Title: Re: Bitpay RubyGem
Post by: Tachikoma on August 24, 2012, 09:35:10 AM
Since you said you are learning ruby I would have some pointers.

1. Ruby uses camel-case for class names and underscores for variables and methods. Also try to use two spaces for tabs and use them consistently.
Code:
class BPLIB > class BpLib
bpCreateInvoice -> bp_create_invoice
etc.

You can read more about the Ruby style in this website (http://www.caliban.org/ruby/rubyguide.shtml).

2. You can make this a one liner if you would want to

Code:
options = @options.merge(options)
options[:price] = price
options[:orderId]= orderid
options[:posData]= posData

options = @options.merge(options).merge({:price => price, :orderId => orderid, :postDate => posData})

3. I would probably rewrite this bit using has_key? since I find it increases readability.

Code:
  postOptions.each_with_index do |opt,index|
    if options.include(opt[index])
      postdata[index] = options[index]
    end
  end

postOptions.each do |key|
  if @options.has_key?(key)
    postdata[key] = @options[key]
  end
end

4. Is the code actually working? It seems you define postdata after you try to fill it.

Hope these tips help :)


Title: Re: Bitpay RubyGem
Post by: phantastisch on August 24, 2012, 01:30:54 PM
Thank you for your nice feedback.  :)

I'm glad someone looked at it.

And yes it's working, the file you've been inspecting is an artifact i forgot in there.
I moved the stuff into the other file because i'm still figuring out method calls.