lib/gist_updater/content.rb in gist_updater-0.3.0 vs lib/gist_updater/content.rb in gist_updater-0.3.1
- old
+ new
@@ -1,18 +1,27 @@
# frozen_string_literal: true
require 'octokit'
module GistUpdater
+ # A content related to a gist file
class Content
+ # @param user [String] GitHub username
+ # @param access_token [String] GitHub personal access token
+ # @param gist_id [String] A gist id
+ # @param file_path [String] A relative file path
def initialize(user:, access_token:, gist_id:, file_path:)
@user = user
@access_token = access_token
@gist_id = gist_id
@file_path = file_path
end
+ # Update the content if needed
+ #
+ # @return [Sawyer::Resource] an updated resource
+ # @return [NilClass] isnot updated
def update_if_need
if need_to_update?
result = update
puts "Updated `#{file_path}` to #{result.html_url}"
elsif GistUpdater.debug
@@ -40,9 +49,12 @@
def local
@local ||= File.read(file_path)
end
+ # Update a Gist file
+ #
+ # @return [Sawyer::Resource]
def update
client.edit_gist(
gist_id,
files: { file_name => { 'content' => local } }
)