bucketface2 0.4.0

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.
data/.Rakefile.un~ ADDED
Binary file
Binary file
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+
2
+ *.swp
3
+ pkg/*
4
+ *.gem
5
+ .bundle
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@bucketface --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bucketface.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bucketface (0.3.1)
5
+ hashie (~> 0.3.0)
6
+ httparty (~> 0.6.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ crack (0.1.8)
12
+ diff-lcs (1.1.3)
13
+ fakeweb (1.3.0)
14
+ hashie (0.3.1)
15
+ httparty (0.6.1)
16
+ crack (= 0.1.8)
17
+ jnunemaker-matchy (0.4.0)
18
+ mocha (0.9.10)
19
+ rake
20
+ rake (0.8.7)
21
+ rspec (2.11.0)
22
+ rspec-core (~> 2.11.0)
23
+ rspec-expectations (~> 2.11.0)
24
+ rspec-mocks (~> 2.11.0)
25
+ rspec-core (2.11.1)
26
+ rspec-expectations (2.11.1)
27
+ diff-lcs (~> 1.1.3)
28
+ rspec-mocks (2.11.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bucketface!
35
+ fakeweb (~> 1.3)
36
+ jnunemaker-matchy (~> 0.4.0)
37
+ mocha (~> 0.9)
38
+ rspec (~> 2.11)
data/README.markdown ADDED
@@ -0,0 +1,69 @@
1
+ # bucketface
2
+
3
+ Simple Ruby wrapper for the Bitbucket API. (This code is based on octopussy)
4
+
5
+ ## Installation
6
+
7
+ sudo gem install bucketface
8
+
9
+ ## Some examples
10
+
11
+ ### Show a user
12
+
13
+ Bucketface.user('cored')
14
+ <#Hashie::Mash first_name="Rafael" last_name="George" resource_uri="/1.0/users/cored/" username="cored">
15
+
16
+ ### Show followers for a giving user
17
+
18
+ Bucketface.followers('cored')
19
+ [<#Hashie::Mash _state="<django.db.models.base.ModelState object at 0x66d8590>" avatar_id=nil cname=nil differ="udiff" digest="b0634325ca1a1bb69bd227f521b9b20c" email_notifications=false feature_per_user_pricing=true id=1600 location="Denver, CO" plan_id=7 user_id=1602 website="http://www.percious.com/">, <#Hashie::Mash _state="<django.db.models.base.ModelState object at 0x66d8f90>" avatar_id=nil cname=nil differ="udiff" digest="861e1c2f15e3fc5f55b32a1e10f6ec78" email_notifications=true feature_per_user_pricing=true id=7010 location=nil plan_id=7 user_id=7012 website=nil>, <#Hashie::Mash _state="<django.db.models.base.ModelState object at 0x66d88d0>" avatar_id=nil cname=nil differ="udiff" digest="24c19e325a62a293c26c2f38ee62f6ef" email_notifications=true feature_per_user_pricing=true id=1906 location="Detroit, Michigan, USA" plan_id=7 user_id=1908 website="http://lost-theory.org/">]
20
+
21
+ ### Working with repositories
22
+
23
+ Methods that require a repo argument may be passed in any of the following forms
24
+
25
+ * "cored/test-repo"
26
+ * {:username => 'cored', :name => 'test-repo'}
27
+ * {:username => 'cored', :repo => 'test-repo'}
28
+ * instance of Repo
29
+
30
+ ### Show a repo
31
+
32
+ Bucketface.repo("cored/test-repo")
33
+ <#Hashie::Mash description="Testing ticketmaster with this repo" followers_count=1 name="test-repo" slug="test-repo" website="">
34
+
35
+ ## Authenticated requests
36
+
37
+ Some methods require authentication so you'll need to pass a login and a password.
38
+
39
+ client = Bucketface::Client.new(:login => 'cored', :password => 'hithere')
40
+ client.open_issue('cored/test-repo', 'testing', 'testing')
41
+
42
+ ## TODO
43
+
44
+ * Add documentation to all classes
45
+ * Functionality for the following API resources
46
+ * Privileges
47
+ * Wiki
48
+ * Source
49
+ * Create examples
50
+ * Refactor code to abstract functionality from client class
51
+ * Add bad response handling
52
+
53
+ ## Note on Patches/Pull requests
54
+
55
+ * Fork the project
56
+ * Make your feature addition or bug fix
57
+ * Add tests for it. This is important so I don't break it in a future version unintentionally
58
+ * Commit, do not mess with rakefile, version, or history
59
+ (if you want to have your own version, that is fine but bump version in a commit by itself
60
+ I can ignore when I pull)
61
+ * Send me a pull request. Bonus points for topic branches.
62
+
63
+ ## Credits
64
+
65
+ Bucketface is based and inspired by [Octopussy](http://github.com/pengwynn/octopussy)
66
+
67
+ ## Copyright
68
+
69
+ Copyright (c) 2010 [Rafael George](http://bandw.tumblr.com)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bucketface/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bucketface2"
7
+ s.version = Bucketface::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Rafael George", "Jon Willis"]
10
+ s.email = ["george.rafael@gmail.com", "jondwillis@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Provides a wrapper for Bitbucket API}
13
+ s.description = %q{Provides a wrapper for Bitbucket API}
14
+
15
+ s.rubyforge_project = "bucketface2"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency('fakeweb', '~> 1.3')
23
+ s.add_development_dependency('jnunemaker-matchy', '~> 0.4.0')
24
+ s.add_development_dependency('mocha', '~> 0.9')
25
+ s.add_development_dependency('rspec', '~> 2.11')
26
+ s.add_runtime_dependency('hashie', '~> 0.3.0')
27
+ s.add_runtime_dependency('httparty', '~> 0.6.1')
28
+ end
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+ ## 0.3.1
3
+ * Fixed close issue method it was deleting the issue
4
+ * Fixed opening of issue it was not creating it as new
5
+ * Added a class api method to extract current state of the client data
6
+ ## 0.2.1
7
+ * Downgrade version of Hashie to 0.3.0 it wasn't compatible with ticketmaster
8
+ ## 0.1.1
9
+ * Started the use of the Repository class
10
+ ## 0.0.1 Initial version
11
+ * Bitbucket API
@@ -0,0 +1,136 @@
1
+ module Bucketface
2
+ class Client
3
+ include HTTParty
4
+ format :json
5
+ base_uri "https://api.bitbucket.org/1.0"
6
+
7
+ attr_reader :login
8
+
9
+ def initialize(auth={})
10
+ if auth[:password].nil?
11
+ @login = auth[:login]
12
+ @token = auth[:token]
13
+ self.class.basic_auth(nil, nil)
14
+ else
15
+ @login = auth[:login]
16
+ self.class.basic_auth(@login, auth[:password])
17
+ end
18
+ @@api = self
19
+ end
20
+
21
+ def self.api
22
+ @@api
23
+ end
24
+
25
+ def user(login=self.login)
26
+ get("/users/#{login}/").user
27
+ end
28
+
29
+ def followers(login=self.login)
30
+ get("/users/#{login}/followers/").followers
31
+ end
32
+
33
+ def repo_followers(repo)
34
+ repo = Repository.new(repo)
35
+ get("/repositories/#{repo.user}/#{repo}/followers/").followers
36
+ end
37
+
38
+ def issue_followers(repo, id)
39
+ repo = Repository.new(repo)
40
+ get("/repositories/#{repo.user}/#{repo}/issues/#{id}/followers/").followers
41
+ end
42
+
43
+ def issues(repo)
44
+ repo = Repository.new(repo)
45
+ get("/repositories/#{repo.user}/#{repo}/issues/").issues
46
+ end
47
+
48
+ def issue(repo, id)
49
+ repo = Repository.new(repo)
50
+ get("/repositories/#{repo.user}/#{repo}/issues/#{id}/")
51
+ end
52
+
53
+ def repo(repo)
54
+ repo = Repository.new(repo)
55
+ get("/repositories/#{repo.user}/#{repo}/")
56
+ end
57
+
58
+ def list_repos(login=self.login)
59
+ get("/users/#{login}/").repositories
60
+ end
61
+
62
+ def branches(repo)
63
+ repo = Repository.new(repo)
64
+ get("/repositories/#{repo.user}/#{repo}/branches/")
65
+ end
66
+
67
+ def tags(repo)
68
+ repo = Repository.new(repo)
69
+ get("/repositories/#{repo.user}/#{repo}/tags/")
70
+ end
71
+
72
+ def open_issue(repo, title, body)
73
+ rep = Repository.new(repo)
74
+ post("/repositories/#{rep.user}/#{rep}/issues/", :body => {:title => title, :content => body, :status => 'new'})
75
+ end
76
+
77
+ def delete_issue(repo, id)
78
+ repo = Repository.new(repo)
79
+ delete("/repositories/#{repo.user}/#{repo}/issues/#{id}/")
80
+ end
81
+
82
+ def changesets(repo)
83
+ repo = Repository.new(repo)
84
+ get_resource("/repositories/#{repo.user}/#{repo}/changesets/").changesets
85
+ end
86
+
87
+ def changeset(repo, changeset)
88
+ repo = Repository.new(repo)
89
+ get("/repositories/#{repo.user}/#{repo}/changesets/#{changeset}/")
90
+ end
91
+
92
+ def events(login=self.login)
93
+ get("/users/#{login}/events/").events
94
+ end
95
+
96
+ def repo_events(repo)
97
+ repo = Repository.new(repo)
98
+ get("/repositories/#{repo.user}/#{repo}/events/").events
99
+ end
100
+
101
+ def groups(login=self.login)
102
+ get("/groups/{login}/")
103
+ end
104
+
105
+ private
106
+ def get(path, options = {})
107
+ Hashie::Mash.new(self.class.get(path, options))
108
+ end
109
+
110
+ def post(path, options = {})
111
+ Hashie::Mash.new(self.class.post(path, options))
112
+ end
113
+
114
+ def delete(path, options = {})
115
+ self.class.delete(path, options)
116
+ end
117
+
118
+ def get_resource(path, options ={})
119
+ get(path, {:query => options})
120
+ end
121
+
122
+ def post_resource(path, options = {})
123
+ post(path, options)
124
+ end
125
+
126
+ def self.delete(*args); handle_response super end
127
+
128
+ def self.handle_response(response)
129
+ case response.code
130
+ when 204 then return "Success!"
131
+ else
132
+ response
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,28 @@
1
+ module Bucketface
2
+ class Repository
3
+ attr_accessor :username, :name
4
+
5
+ def initialize(repo)
6
+ case repo
7
+ when String
8
+ repo = repo.split("/")
9
+ @name = repo.pop
10
+ @username = repo.pop
11
+ when Repository
12
+ @username = repo.username
13
+ @name = repo.name
14
+ when Hash
15
+ @name = repo[:repo] ||= repo[:name]
16
+ @username = repo[:username] ||= repo[:user]
17
+ end
18
+ end
19
+
20
+ def user
21
+ @username
22
+ end
23
+
24
+ def to_s
25
+ @name
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Bucketface
2
+ VERSION = "0.4.0"
3
+ end
data/lib/bucketface.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'forwardable'
2
+
3
+ require 'httparty'
4
+ require 'hashie'
5
+ Hash.send :include, Hashie::HashExtensions
6
+
7
+ libdir = File.dirname(__FILE__)
8
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
9
+
10
+ require 'bucketface/repository'
11
+ require 'bucketface/client'
12
+
13
+ module Bucketface
14
+ extend SingleForwardable
15
+
16
+ class BucketfaceError < StandardError
17
+ attr_reader :data
18
+
19
+ def initialize(data)
20
+ @data = data
21
+ super
22
+ end
23
+ end
24
+
25
+ def self.client; Client.new end
26
+
27
+ # Users
28
+ def_delegators :client, :user, :followers
29
+
30
+ # Repositories
31
+ def_delegators :client, :repo_followers, :repo, :list_repos, :branches, :tags
32
+
33
+ # Issues
34
+ def_delegators :client, :issue_followers, :issues, :issue
35
+
36
+ # Changesets
37
+ def_delegators :client, :changesets, :changeset
38
+
39
+ # Events
40
+ def_delegators :client, :events, :repo_events
41
+ end
@@ -0,0 +1,146 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/helper'
2
+
3
+ class BucketfaceTest < MiniTest::Spec
4
+ context "when authenticated" do
5
+ setup do
6
+ @client = Bucketface::Client.new(:login => 'cored', :token => '2U812')
7
+ end
8
+
9
+ should "authenticate via basic auth" do
10
+ stub_get('https://cored:2U812@api.bitbucket.org/1.0/users/cored/?', 'full_user.json')
11
+ client = Bucketface::Client.new(:login => 'cored', :password => '2U812')
12
+ user = client.user
13
+ user.is_private?.should == false
14
+ end
15
+
16
+ should "extract api from Bucketface module" do
17
+ stub_get('https://cored:2U812@api.bitbucket.org/1.0/users/cored/?', 'full_user.json')
18
+ Bucketface::Client.new(:login => 'cored', :password => '2U812')
19
+ api = Bucketface::Client.api
20
+ api.user.username.should be_eql('cored')
21
+ end
22
+
23
+ should "return followers for an user authenticated user" do
24
+ stub_get('/users/cored/followers/?', 'followers.json')
25
+ followers = @client.followers
26
+ followers.size.should == 3
27
+ end
28
+
29
+ should "open an issue" do
30
+ stub_post('/repositories/cored/test-repo/issues/', 'open_issue.json')
31
+ issue = @client.open_issue({:username => 'cored', :repo => 'test-repo'}, "testing", "testing")
32
+ issue.title.should == "new issue"
33
+ end
34
+
35
+ should "delete an issue" do
36
+ stub_delete('/repositories/cored/test-repo/issues/1/', 'close_issue.txt')
37
+ issue = @client.delete_issue({:username => 'cored', :repo => 'test-repo'}, 1)
38
+ issue.should == "Success!"
39
+ end
40
+
41
+ should "reopen an issue"
42
+
43
+ should "close an issue"
44
+
45
+ end
46
+
47
+ context "user resource" do
48
+ should "return user info" do
49
+ stub_get("/users/cored/", "user.json")
50
+ user = Bucketface.user("cored")
51
+ user.username.should == 'cored'
52
+ end
53
+
54
+ should "return followers for a user" do
55
+ stub_get("/users/cored/followers/", "followers.json")
56
+ followers = Bucketface.followers("cored")
57
+ followers.size.should == 3
58
+ end
59
+ end
60
+
61
+ context "changeset resource" do
62
+ should "return a list of changeset for a giving repository" do
63
+ stub_get("/repositories/cored/test-repo/changesets/", "changesets.json")
64
+ changesets = Bucketface.changesets(:username => 'cored', :repo => 'test-repo')
65
+ changesets.size.should == 15
66
+ end
67
+
68
+ should "return an specific changeset for a giving repository" do
69
+ stub_get("/repositories/cored/test-repo/changesets/fa57572a9acf/", "changeset.json")
70
+ changeset = Bucketface.changeset({:username => 'cored', :repo => 'test-repo'}, 'fa57572a9acf')
71
+ changeset.author.should == 'jespern'
72
+ end
73
+ end
74
+
75
+ context "events resource" do
76
+ should "return a list of events for a giving user" do
77
+ stub_get("/users/cored/events/", "events.json")
78
+ events = Bucketface.events('cored')
79
+ events.size.should == 5
80
+ events.first.repository.slug.should == 'test-repo'
81
+ end
82
+
83
+ should "return a list of events for a giving repository" do
84
+ stub_get("/repositories/cored/test-repo/events/", "repo_events.json")
85
+ events = Bucketface.repo_events(:username => 'cored', :repo => 'test-repo')
86
+ events.size.should == 6
87
+ events.first.repository.slug == 'test-repo'
88
+ end
89
+ end
90
+
91
+ context "repository resource" do
92
+ should "return list of followers for a giving repository" do
93
+ stub_get("/repositories/cored/test-repo/followers/", "repo_followers.json")
94
+ repo_followers = Bucketface.repo_followers({:user => "cored", :repo => "test-repo"})
95
+ repo_followers.size.should == 1
96
+ end
97
+
98
+ should "return repository info" do
99
+ stub_get("/repositories/cored/test-repo/", "repo.json")
100
+ repo = Bucketface.repo(:user => "cored", :repo => "test-repo")
101
+ repo.name.should == "test-repo"
102
+ end
103
+
104
+ should "list repositories for an user" do
105
+ stub_get("/users/cored/", "repos.json")
106
+ repos = Bucketface.list_repos("cored")
107
+ repos.first.name.should == "test-repo"
108
+ end
109
+
110
+ should "list branches in a giving repo" do
111
+ stub_get("/repositories/cored/test-repo/branches/", "branches.json")
112
+ branches = Bucketface.branches(:user => "cored", :repo => "test-repo")
113
+ branches.size.should == 1
114
+ assert branches.include?("default")
115
+ end
116
+
117
+ should "list all the tags in a giving repo" do
118
+ stub_get("/repositories/cored/test-repo/tags/", "tags.json")
119
+ tags = Bucketface.tags(:user => "cored", :repo => "test-repo")
120
+ tags.size.should == 6
121
+ assert tags.include?("0.6.4")
122
+ end
123
+ end
124
+
125
+ context "issue resource" do
126
+ should "return the list of followers of an issue" do
127
+ stub_get("/repositories/cored/test-repo/issues/1/followers/", "issue_followers.json")
128
+ issue_followers = Bucketface.issue_followers({:user => "cored", :repo => "test-repo"},"1")
129
+ issue_followers.size.should == 1
130
+ end
131
+
132
+ should "return the list of issues for a giving repository" do
133
+ stub_get("/repositories/cored/test-repo/issues/", "issues.json")
134
+ issues = Bucketface.issues({:user => "cored", :repo => "test-repo"})
135
+ issues.size.should == 2
136
+ issues.first.title.should == "Another issue test"
137
+ end
138
+
139
+ should "return an individual issue" do
140
+ stub_get("/repositories/cored/test-repo/issues/1/", "issue.json")
141
+ issue = Bucketface.issue({:user => "cored", :repo => "test-repo"}, "1")
142
+ issue.title.should == "Test issue"
143
+ end
144
+
145
+ end
146
+ end
@@ -0,0 +1,17 @@
1
+ {
2
+ "default": {
3
+ "node": "10c1068f1171",
4
+ "files": [],
5
+ "author": "elpargo",
6
+ "timestamp": "2009-08-26 17:11:33",
7
+ "raw_node": "10c1068f117163e7c3e98d2a461799481367b727",
8
+ "parents": [
9
+ "041529d47395",
10
+ "b119fb3263f7"
11
+ ],
12
+ "branch": "default",
13
+ "message": "- merging",
14
+ "revision": 132,
15
+ "size": 0
16
+ }
17
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "node": "fa57572a9acf",
3
+ "files": [
4
+ {
5
+ "type": "modified",
6
+ "file": "piston/handler.py"
7
+ }
8
+ ],
9
+ "author": "jespern",
10
+ "timestamp": "2009-09-09 12:55:07",
11
+ "raw_node": "fa57572a9acf7b66aa66f739af6d1391075f9f21",
12
+ "parents": [
13
+ "aaf0c2d64294"
14
+ ],
15
+ "branch": "default",
16
+ "message": "warning in case of a model being registered twice under different handlers, configurable via PISTON_IGNORE_DUPE_MODELS",
17
+ "revision": 207,
18
+ "size": 561
19
+ }