Class: Bard::Github

Inherits:
Struct
  • Object
show all
Defined in:
lib/bard/github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#project_nameObject

Returns the value of attribute project_name

Returns:

  • (Object)

    the current value of project_name



6
7
8
# File 'lib/bard/github.rb', line 6

def project_name
  @project_name
end

Instance Method Details

#add_deploy_key(title:, key:) ⇒ Object



35
36
37
# File 'lib/bard/github.rb', line 35

def add_deploy_key title:, key:
  post("keys", title:, key:)
end

#create_repoObject



39
40
41
42
43
44
# File 'lib/bard/github.rb', line 39

def create_repo
  post("https://api.github.com/orgs/botandrosedesign/repos", {
    name: project_name,
    private: true,
  })
end

#delete(path, params = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/bard/github.rb', line 22

def delete path, params={}
  request(path) do |uri|
    Net::HTTP::Delete.new(uri).tap do |r|
      r.body = JSON.dump(params)
    end
  end
end

#delete_repoObject



46
47
48
# File 'lib/bard/github.rb', line 46

def delete_repo
  delete("https://api.github.com/repos/botandrosedesign/#{project_name}")
end

#get(path, params = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/bard/github.rb', line 7

def get path, params={}
  request(path) do |uri|
    uri.query = URI.encode_www_form(params)
    Net::HTTP::Get.new(uri)
  end
end

#post(path, params = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/bard/github.rb', line 14

def post path, params={}
  request(path) do |uri|
    Net::HTTP::Post.new(uri).tap do |r|
      r.body = JSON.dump(params)
    end
  end
end

#read_file(path, branch: "master") ⇒ Object



30
31
32
33
# File 'lib/bard/github.rb', line 30

def read_file path, branch: "master"
   = get("contents/#{path}", ref: branch)
  Base64.decode64(["content"])
end