-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
423 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Api | ||
module Helper | ||
module ProjectsHelper | ||
include ::Tinybucket::Api::Helper::ApiHelper | ||
|
||
private | ||
|
||
def path_to_list(owner) | ||
base_path(owner) | ||
end | ||
|
||
def path_to_find(owner, project_key) | ||
build_path(base_path(owner), | ||
[project_key, 'project_key']) | ||
end | ||
|
||
def base_path(owner) | ||
build_path('/teams', | ||
[owner, 'owner'], | ||
'projects', | ||
'/') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Api | ||
class ProjectsApi < BaseApi | ||
include Tinybucket::Api::Helper::ProjectsHelper | ||
attr_accessor :owner | ||
|
||
def list(options = {}) | ||
get_path( | ||
path_to_list(owner), | ||
options, | ||
Tinybucket::Parser::ProjectsParser | ||
) | ||
end | ||
|
||
def find(project_key, options = {}) | ||
get_path( | ||
path_to_find(owner, project_key), | ||
options, | ||
Tinybucket::Parser::ProjectParser | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ module Model | |
:ErrorResponse, | ||
:Page, | ||
:Profile, | ||
:Project, | ||
:PullRequest, | ||
:Repository, | ||
:Team | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Model | ||
class Project < Base | ||
acceptable_attributes \ | ||
:type, :description, :links, :uuid, :created_on, | ||
:key, :updated_on, :is_private, :name, :owner | ||
|
||
# Update this project | ||
# | ||
# @param _params [Hash] | ||
# @raise [NotImplementedError] to be implemented | ||
def update(_params) | ||
raise NotImplementedError | ||
end | ||
|
||
# Destroy this project | ||
# | ||
# @raise [NotImplementedError] to be implemented. | ||
def destroy | ||
raise NotImplementedError | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Parser | ||
class ProjectParser < BaseParser | ||
def convert(json) | ||
Tinybucket::Model::Project.new(json) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Parser | ||
class ProjectsParser < BaseParser | ||
def convert(json) | ||
Tinybucket::Model::Page.new(json, Tinybucket::Model::Project) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ module Resource | |
:Commits, | ||
:Forks, | ||
:OwnersRepos, | ||
:Projects, | ||
:PublicRepos, | ||
:PullRequests, | ||
:Repos, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Resource | ||
class Projects < Base | ||
attr_accessor :owner | ||
|
||
# Initialize | ||
# | ||
# @param owner_name [String] | ||
# @param options [Hash] | ||
def initialize(owner_name, options = {}) | ||
@owner = owner_name | ||
@args = [options] | ||
end | ||
|
||
# Find the project | ||
# | ||
# @param project_key [String] | ||
# @param options [Hash] | ||
# @return [Tinybucket::Model::Project] | ||
def find(project_key, options = {}) | ||
projects_api.find(project_key, options) | ||
end | ||
|
||
# Create a new project | ||
# | ||
# NOTE: Not Implemented yet. | ||
# | ||
# @param _params [Hash] | ||
# @raise [NotImplementedError] to be implemented | ||
def create(_params) | ||
raise NotImplementedError | ||
end | ||
|
||
private | ||
|
||
def projects_api | ||
create_api('Projects').tap do |api| | ||
api.owner = @owner | ||
end | ||
end | ||
|
||
def enumerator | ||
create_enumerator(projects_api, :list, *@args) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ | ||
"pagelen": 10, | ||
"values": [ | ||
{ | ||
"uuid": "{45d24c3d-efa0-4c2a-be4e-78c1b30a30d0}", | ||
"links": { | ||
"self": { | ||
"href": "https://api.bitbucket.org/2.0/teams/test_team/projects/TEST" | ||
}, | ||
"html": { | ||
"href": "https://bitbucket.org/account/user/test_team/projects/TEST" | ||
}, | ||
"repositories": { | ||
"href": "https://api.bitbucket.org/2.0/repositories/test_team?q='project.key=\"TEST\"'" | ||
}, | ||
"avatar": { | ||
"href": "https://bitbucket.org/account/user/test_team/projects/TEST/avatar/32" | ||
} | ||
}, | ||
"description": null, | ||
"created_on": "2016-03-19T03:34:27.792230+00:00", | ||
"key": "TEST", | ||
"owner": { | ||
"username": "test_team", | ||
"display_name": "test team", | ||
"type": "team", | ||
"uuid": "{e0f17982-effb-43eb-8589-7bacabb37cab}", | ||
"links": { | ||
"self": { | ||
"href": "https://api.bitbucket.org/2.0/teams/test_team" | ||
}, | ||
"html": { | ||
"href": "https://bitbucket.org/test_team/" | ||
}, | ||
"avatar": { | ||
"href": "https://bitbucket.org/account/test_team/avatar/32/" | ||
} | ||
} | ||
}, | ||
"updated_on": "2016-03-19T03:34:27.792256+00:00", | ||
"type": "project", | ||
"is_private": false, | ||
"name": "test" | ||
}, | ||
{ | ||
"uuid": "{59278b96-1238-4418-a2b9-8f438234ae45}", | ||
"links": { | ||
"self": { | ||
"href": "https://api.bitbucket.org/2.0/teams/test_team/projects/PROJ" | ||
}, | ||
"html": { | ||
"href": "https://bitbucket.org/account/user/test_team/projects/PROJ" | ||
}, | ||
"repositories": { | ||
"href": "https://api.bitbucket.org/2.0/repositories/test_team?q='project.key=\"PROJ\"'" | ||
}, | ||
"avatar": { | ||
"href": "https://bitbucket.org/account/user/test_team/projects/PROJ/avatar/32" | ||
} | ||
}, | ||
"description": "Project created by Bitbucket for test", | ||
"created_on": "2015-12-04T02:27:25.909083+00:00", | ||
"key": "PROJ", | ||
"owner": { | ||
"username": "test_team", | ||
"display_name": "test team", | ||
"type": "team", | ||
"uuid": "{e0f17982-effb-41cb-8589-7bacabb37cab}", | ||
"links": { | ||
"self": { | ||
"href": "https://api.bitbucket.org/2.0/teams/test_team" | ||
}, | ||
"html": { | ||
"href": "https://bitbucket.org/test_team/" | ||
}, | ||
"avatar": { | ||
"href": "https://bitbucket.org/account/test_team/avatar/32/" | ||
} | ||
} | ||
}, | ||
"updated_on": "2015-12-04T02:27:25.909123+00:00", | ||
"type": "project", | ||
"is_private": false, | ||
"name": "Untitled project" | ||
} | ||
], | ||
"page": 1, | ||
"size": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"uuid": "{45234c3d-efa0-4c2a-be4e-78c1b30a30d0}", | ||
"links": { | ||
"self": { | ||
"href": "https://api.bitbucket.org/2.0/teams/test_team/projects/myprj" | ||
}, | ||
"html": { | ||
"href": "https://bitbucket.org/account/user/test_team/projects/myprj" | ||
}, | ||
"repositories": { | ||
"href": "https://api.bitbucket.org/2.0/repositories/test_team?q='project.key=\"myprj\"'" | ||
}, | ||
"avatar": { | ||
"href": "https://bitbucket.org/account/user/test_team/projects/myprj/avatar/32" | ||
} | ||
}, | ||
"description": null, | ||
"created_on": "2016-03-19T03:34:27.792230+00:00", | ||
"key": "myprj", | ||
"owner": { | ||
"username": "test_team", | ||
"display_name": "test team", | ||
"type": "team", | ||
"uuid": "{e0f17982-efab-43cb-8589-7bacabb37cab}", | ||
"links": { | ||
"self": { | ||
"href": "https://api.bitbucket.org/2.0/teams/test_team" | ||
}, | ||
"html": { | ||
"href": "https://bitbucket.org/test_team/" | ||
}, | ||
"avatar": { | ||
"href": "https://bitbucket.org/account/test_team/avatar/32/" | ||
} | ||
} | ||
}, | ||
"updated_on": "2016-03-19T03:34:27.792256+00:00", | ||
"type": "project", | ||
"is_private": false, | ||
"name": "myprj" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Tinybucket::Api::ProjectsApi do | ||
include ApiResponseMacros | ||
|
||
let(:api) { Tinybucket::Api::ProjectsApi.new } | ||
let(:owner) { 'test_team' } | ||
let(:request_path) { nil } | ||
before do | ||
api.owner = owner | ||
stub_apiresponse(:get, request_path) if request_path | ||
end | ||
|
||
it { expect(api).to be_a_kind_of(Tinybucket::Api::BaseApi) } | ||
|
||
describe 'list' do | ||
subject { api.list() } | ||
let(:request_path) { '/teams/test_team/projects/' } | ||
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Page) } | ||
end | ||
|
||
describe 'find' do | ||
let(:project_key) { 'myprj' } | ||
subject { api.find(project_key) } | ||
|
||
let(:request_path) { "/teams/test_team/projects/#{project_key}" } | ||
it { expect(subject).to be_an_instance_of(Tinybucket::Model::Project) } | ||
end | ||
end |
Oops, something went wrong.