bitbucket 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ module Bitbucket
2
+
3
+ autoload :Configuration, 'bitbucket/configuration'
4
+ autoload :Base, 'bitbucket/base'
5
+ autoload :User, 'bitbucket/user'
6
+ autoload :Repository, 'bitbucket/repository'
7
+ autoload :Changesets, 'bitbucket/changesets'
8
+
9
+ def config
10
+ Bitbucket::Configuration.instance
11
+ end
12
+
13
+ def default_auth_options
14
+ if self.config.token.nil?
15
+ return {username: self.config.username, password: self.config.password}
16
+ else
17
+ return {token: self.config.token, secret: self.config.secret}
18
+ end
19
+ end
20
+
21
+ module_function :config, :default_auth_options
22
+ end
@@ -0,0 +1,60 @@
1
+ require 'oauth'
2
+ require 'json'
3
+
4
+ class Bitbucket::Base
5
+ attr_reader :access_token
6
+
7
+ def initialize options = nil
8
+ if options.nil?
9
+ options = Bitbucket.default_auth_options
10
+ end
11
+ if options[:token] && options[:secret]
12
+ @access_token = OAuth::AccessToken.new(
13
+ Bitbucket.config.oauth_consumer,
14
+ options[:token], options[:secret]
15
+ )
16
+ else
17
+ # TODO for basic auth method...
18
+ @usernaem = options[:username]
19
+ @password = options[:password]
20
+ end
21
+ if @username.nil? && @access_token.nil?
22
+ raise Error
23
+ end
24
+ end
25
+
26
+ #
27
+ def get path, data = nil, raw = false
28
+ if !data.nil? && data.is_a?(Hash)
29
+ path = path + '?' +
30
+ data.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
31
+ end
32
+ res = @access_token.get(path)
33
+ # value() raise Net::HTTPError
34
+ res.value
35
+ unless raw
36
+ return JSON.parse(res.body)
37
+ else
38
+ return res.body
39
+ end
40
+ end
41
+
42
+ def post path, data = nil, raw = false
43
+ res = @access_token.post(path,data)
44
+ # value() raise Net::HTTPError
45
+ res.value
46
+ unless raw
47
+ return JSON.parse(res.body)
48
+ else
49
+ return res.body
50
+ end
51
+ end
52
+
53
+ def delete path
54
+ res = @access_token.delete(path)
55
+ # value() raise Net::HTTPError
56
+ res.value
57
+ return res.body
58
+ end
59
+
60
+ end
@@ -0,0 +1,7 @@
1
+ class Bitbucket::Changesets < Bitbucket::Base
2
+ def changesets username, reponame, headname = 'master', limit = 15
3
+ data = {start: headname, limit: limit}
4
+ self.get("/api/1.0/repositories/#{username}"+
5
+ "/#{reponame}/changesets", data)
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ require 'singleton'
2
+ require 'oauth'
3
+
4
+ class Bitbucket::Configuration
5
+ include Singleton
6
+
7
+ @@oauth_options = {:signature_method=>"HMAC-SHA1",
8
+ :request_token_path=>"/api/1.0/oauth/request_token",
9
+ :authorize_path=>"/api/1.0/oauth/authenticate",
10
+ :access_token_path=>"/api/1.0/oauth/access_token",
11
+ :proxy=>nil,
12
+ # :proxy=>"http://localhost:8080/",
13
+ :scheme=>:header,
14
+ :http_method=>:post,
15
+ :oauth_version=>"1.0",
16
+ :site=>"https://bitbucket.org"}
17
+
18
+ def self.oauth_options
19
+ @@oauth_options
20
+ end
21
+
22
+ def oauth_consumer
23
+ @oauth_consumer ||= OAuth::Consumer.new(
24
+ self.consumer_key,
25
+ self.consumer_secret,
26
+ @@oauth_options
27
+ )
28
+ end
29
+
30
+ attr_accessor :consumer_key, :consumer_secret, :token, :secret, :username, :password
31
+ end
@@ -0,0 +1,22 @@
1
+ class Bitbucket::Repository < Bitbucket::Base
2
+ def repositories
3
+ self.get('/api/1.0/user/repositories/')
4
+ end
5
+
6
+ def repository username, reponame
7
+ self.get("/api/1.0/repositories/#{username}/#{reponame}/")
8
+ end
9
+
10
+ def create reponame, is_private = true, scm = 'git'
11
+ data = {
12
+ name: reponame,
13
+ scm: scm,
14
+ is_private: is_private ? 'True' : 'False',
15
+ }
16
+ self.post("/api/1.0/repositories/", data)
17
+ end
18
+
19
+ def destroy username, reponame
20
+ self.delete("/api/1.0/repositories/#{username}/#{reponame}/")
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ class Bitbucket::User < Bitbucket::Base
2
+ def emails
3
+ self.get('/api/1.0/emails/')
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitbucket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sowawa (Keisuke SOGAWA)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: using Bitbucket api via OAuth access token.
15
+ email: keisuke.sogawa+gems@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/bitbucket.rb
21
+ - lib/bitbucket/base.rb
22
+ - lib/bitbucket/configuration.rb
23
+ - lib/bitbucket/user.rb
24
+ - lib/bitbucket/repository.rb
25
+ - lib/bitbucket/changesets.rb
26
+ homepage: http://rubygems.org/gems/bitbucket
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.24
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Bitbucket
50
+ test_files: []