module Bitbucket

Constants

VERBOSE

Public Class Methods

create_and_sync(path, name = nil) click to toggle source
# File lib/simple_bitbucket.rb, line 4
def create_and_sync path, name = nil
  name = path.split('/')[-1].sub(/\.git$/i, '') if name.nil?
  curl_command "/repositories", {:method => :post, :params => {:name => name} }

  FileUtils.chdir path
  `git remote add origin git@bitbucket.org:#{Username}/#{name}.git`
  `git push origin master`
end
curl_command(path, opts = {}) click to toggle source
# File lib/simple_bitbucket.rb, line 18
def curl_command path, opts = {}
  method = opts.delete(:method) || :get

  addition = case method.to_sym
  when :get
  when :post
    d = opts[:params].map {|k, v| "#{k}=#{v}" }.join("&")
    "-k -X POST -d #{d}"
  end
  vebose_str = VERBOSE ? '-v' : ''
  `curl #{addition} --user #{Email}:#{Password} https://api.bitbucket.org/1.0#{path} #{vebose_str}`
end
list() click to toggle source
# File lib/simple_bitbucket.rb, line 13
def list
  str = curl_command("/user/repositories")
  JSON.parse(str)
end

Private Instance Methods

create_and_sync(path, name = nil) click to toggle source
# File lib/simple_bitbucket.rb, line 4
def create_and_sync path, name = nil
  name = path.split('/')[-1].sub(/\.git$/i, '') if name.nil?
  curl_command "/repositories", {:method => :post, :params => {:name => name} }

  FileUtils.chdir path
  `git remote add origin git@bitbucket.org:#{Username}/#{name}.git`
  `git push origin master`
end
curl_command(path, opts = {}) click to toggle source
# File lib/simple_bitbucket.rb, line 18
def curl_command path, opts = {}
  method = opts.delete(:method) || :get

  addition = case method.to_sym
  when :get
  when :post
    d = opts[:params].map {|k, v| "#{k}=#{v}" }.join("&")
    "-k -X POST -d #{d}"
  end
  vebose_str = VERBOSE ? '-v' : ''
  `curl #{addition} --user #{Email}:#{Password} https://api.bitbucket.org/1.0#{path} #{vebose_str}`
end
list() click to toggle source
# File lib/simple_bitbucket.rb, line 13
def list
  str = curl_command("/user/repositories")
  JSON.parse(str)
end