Class: Zine::UploaderGitHub

Inherits:
Object
  • Object
show all
Defined in:
lib/zine/uploader_github.rb

Overview

Upload a file to GitHub using its REST API

Instance Method Summary collapse

Constructor Details

#initialize(build_dir, options, credentials, delete_file_array, upload_file_array) ⇒ UploaderGitHub

Requires zine.yaml to have a path to a credentials yaml file with access_token: … For instructions on how to create an access token: help.github.com/articles/creating-an-access-token-for-command-line-use/



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/zine/uploader_github.rb', line 15

def initialize(build_dir, options, credentials, delete_file_array,
               upload_file_array)
  unless options['method'] == 'github'
    @no_upload = true
    return
  end
  @build_dir = build_dir
  @repo_full_name = options['path_or_repo']
  @client = Octokit::Client.new(access_token: credentials['access_token'])
  @verbose = options['verbose']
  @credentials = credentials
  @delete_file_array = delete_file_array
  @upload_file_array = upload_file_array
end

Instance Method Details

#uploadObject

Duplicates within & between the files already removed in Zine::Upload then .each… upload & delete - uses @build_dir to create relative paths



32
33
34
35
36
37
38
39
40
41
# File 'lib/zine/uploader_github.rb', line 32

def upload
  return if @no_upload

  @delete_file_array.each do |file_pathname|
    delete_file file_pathname
  end
  @upload_file_array.each do |file_pathname|
    upload_file file_pathname
  end
end