Class: GitMulticast::RepositoryFetcher::Bitbucket

Inherits:
GitMulticast::RepositoryFetcher show all
Defined in:
lib/git_multicast/repository_fetcher/bitbucket.rb

Constant Summary collapse

REPOS_URI =
'https://bitbucket.org/api/2.0/repositories/%{username}'

Constants inherited from GitMulticast::RepositoryFetcher

FETCHER_ADAPTER_ZIP

Class Method Summary collapse

Methods inherited from GitMulticast::RepositoryFetcher

adapter_by_url, fetcher_by_url, get_repo_parent, zip_by_url

Class Method Details

.get_all_repos_from_user(username) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/git_multicast/repository_fetcher/bitbucket.rb', line 6

def self.get_all_repos_from_user(username)
  uri_str = REPOS_URI % { username: username }
  uri = URI(uri_str)

  response = Net::HTTP.get_response(uri)
  response_json = JSON.parse(response.body)

  # Damn...
  response_json['values'].each do |repo|
    repo['links']['_clone'] = repo['links']['clone']
  end

  response_json['values'].map { |hash| make_struct(hash) }
end

.get_repo(url) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/git_multicast/repository_fetcher/bitbucket.rb', line 21

def self.get_repo(url)
  response = Net::HTTP.get_response(URI(url))
  response_json = JSON.parse(response.body)
  response_json['links']['_clone'] = response_json['links']['clone']

  make_struct(response_json)
end

.make_struct(hash) ⇒ Object



29
30
31
# File 'lib/git_multicast/repository_fetcher/bitbucket.rb', line 29

def self.make_struct(hash)
  RecursiveOpenStruct.new(hash, recurse_over_arrays: true)
end