Class: Curldown::BitBucket

Inherits:
Object
  • Object
show all
Includes:
Curldown
Defined in:
lib/curldown.rb

Constant Summary collapse

CORE_URL =
"https://api.bitbucket.org/2.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Curldown

#get, render

Constructor Details

#initialize(u, r) ⇒ BitBucket

Returns a new instance of BitBucket.



103
104
105
106
# File 'lib/curldown.rb', line 103

def initialize(u, r)
  @user= u
  @repo_name= r
end

Instance Attribute Details

#commitObject

Returns the value of attribute commit.



102
103
104
# File 'lib/curldown.rb', line 102

def commit
  @commit
end

#readme_fileObject

Returns the value of attribute readme_file.



102
103
104
# File 'lib/curldown.rb', line 102

def readme_file
  @readme_file
end

#readme_mdObject

Returns the value of attribute readme_md.



102
103
104
# File 'lib/curldown.rb', line 102

def readme_md
  @readme_md
end

#repo_nameObject

Returns the value of attribute repo_name.



102
103
104
# File 'lib/curldown.rb', line 102

def repo_name
  @repo_name
end

#repo_objectObject

Returns the value of attribute repo_object.



102
103
104
# File 'lib/curldown.rb', line 102

def repo_object
  @repo_object
end

#treeObject

Returns the value of attribute tree.



102
103
104
# File 'lib/curldown.rb', line 102

def tree
  @tree
end

#userObject

Returns the value of attribute user.



102
103
104
# File 'lib/curldown.rb', line 102

def user
  @user
end

Instance Method Details

#get_last_commitObject



119
120
121
122
123
# File 'lib/curldown.rb', line 119

def get_last_commit
  commits_url = repo_object['links']['commits']['href']
  commits = get(commits_url)
  @commit= commits['values'][0]['hash']
end

#get_readme_fileObject



127
128
129
130
131
132
133
134
135
136
# File 'lib/curldown.rb', line 127

def get_readme_file
  tree['values'].each{|v|
    if v['path'].match?(/readme.md/i)
      @readme_file= v['path']
    end
  }
  if !readme_file
    raise RuntimeError.new("No readme file in repository")
  end
end

#get_readme_mdObject



137
138
139
# File 'lib/curldown.rb', line 137

def get_readme_md
  @readme_md= get("https://bitbucket.org/#{@user}/#{@repo_name}/raw/#{@commit}/#{@readme_file}", json: false)
end

#get_repoObject



114
115
116
117
118
# File 'lib/curldown.rb', line 114

def get_repo
  @repo_object= get("#{CORE_URL}/repositories/#{@user}/#{@repo_name}")
  @repo_name= repo_object['name']
  @repo_slug= repo_object['slug']
end

#get_tree_objectObject



124
125
126
# File 'lib/curldown.rb', line 124

def get_tree_object
  @tree= get("#{CORE_URL}/repositories/#{@user}/#{@repo_slug}/src/#{@commit}/")
end

#performObject



107
108
109
110
111
112
113
# File 'lib/curldown.rb', line 107

def perform
  get_repo
  get_last_commit
  get_tree_object
  get_readme_file
  get_readme_md
end