Class: GitDuplicator::Services::GithubRepository
- Inherits:
-
GitDuplicator::ServiceRepository
- Object
- Repository
- GitDuplicator::ServiceRepository
- GitDuplicator::Services::GithubRepository
- Defined in:
- lib/git_duplicator/services/github.rb
Constant Summary collapse
- BASE_URI =
'https://api.github.com'
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from GitDuplicator::ServiceRepository
Attributes inherited from Repository
Instance Method Summary collapse
-
#create ⇒ Object
Create the repository.
-
#delete ⇒ Object
Delete the repositroy.
-
#initialize(name, owner, credentials = {}, options = {}) ⇒ GithubRepository
constructor
Initializer.
-
#url ⇒ Object
URL of the repositroy.
Methods inherited from Repository
Constructor Details
#initialize(name, owner, credentials = {}, options = {}) ⇒ GithubRepository
Initializer
20 21 22 23 24 |
# File 'lib/git_duplicator/services/github.rb', line 20 def initialize(name, owner, credentials = {}, = {}) super(name, owner) self.credentials = credentials self. = end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
9 10 11 |
# File 'lib/git_duplicator/services/github.rb', line 9 def credentials @credentials end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/git_duplicator/services/github.rb', line 9 def end |
Instance Method Details
#create ⇒ Object
Create the repository
33 34 35 36 37 38 39 |
# File 'lib/git_duplicator/services/github.rb', line 33 def create request_url = BASE_URI + '/user/repos' response = HTTP.with(headers(:post, request_url)) .post(request_url, json: .merge(name: name)) code, body = response.code.to_i, response.body fail(RepositoryCreationError, body) unless 201 == code end |
#delete ⇒ Object
Delete the repositroy
43 44 45 46 47 48 |
# File 'lib/git_duplicator/services/github.rb', line 43 def delete request_url = BASE_URI + "/repos/#{owner}/#{name}" response = HTTP.with(headers(:delete, request_url)).delete(request_url) code, body = response.code.to_i, response.body fail(RepositoryDeletionError, body) unless [204, 404].include?(code) end |
#url ⇒ Object
URL of the repositroy
27 28 29 |
# File 'lib/git_duplicator/services/github.rb', line 27 def url "[email protected]:#{owner}/#{name}.git" end |