module Bifubao::Service

Constants

API_HOST
CREATE_EXTERNAL_REQUIRED_OPTIONS

Public Class Methods

check_required_options(options, names) click to toggle source
# File lib/bifubao/service.rb, line 32
def self.check_required_options(options, names)
  names.each do |name|
    raise "Bifubao error: missing required option: #{name}" unless options.has_key?(name)
  end
end
create_external(options) click to toggle source
# File lib/bifubao/service.rb, line 11
def self.create_external(options)
  options = {
      '_app_hash_id_' => Bifubao.app_hash_id,
      '_time_' => Time.now.to_i,
      'price_btc' => 0,
      'price_cny' => 0,
      '_sign_algo_' => 'sha1'
  }.merge(Utils.stringify_keys(options))

  check_required_options(options, CREATE_EXTERNAL_REQUIRED_OPTIONS)
  if options['price_btc'] + options['price_cny'] == 0 || options['price_btc'] * options['price_cny'] != 0
    raise "Bifubao error: price_btc and price_cny should only one above 0"
  end

  JSON.parse RestClient.post("#{API_HOST}/order/createexternal/", sign_query(options))
end
sign_query(options) click to toggle source
# File lib/bifubao/service.rb, line 28
def self.sign_query(options)
  options.merge('_signature_' => Bifubao::Sign.generate(options))
end