forked from ppworks/hello-esa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_files.rb
37 lines (30 loc) · 897 Bytes
/
upload_files.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'esa'
require 'json'
require 'pry'
require './lib/retryable'
access_token = ARGV[0]
team_name = ARGV[1]
file_path = ARGV[2]
qiita_team_cookie = ARGV[3]
client = Esa::Client.new(
access_token: access_token,
current_team: team_name, # 移行先のチーム名(サブドメイン)
)
class ImageUploader
include Retryable
attr_accessor :client, :files, :qiita_team_cookie
def initialize(client, file_path, qiita_team_cookie)
@client = client
@files = File.read(file_path).split("\n")
@qiita_team_cookie = qiita_team_cookie
end
def upload!
files.each.with_index do |file, index|
response_body = wrap_response { client.upload_attachment([file, qiita_team_cookie]) }
esa_url = response_body['attachment']['url']
puts "#{file} #{esa_url}"
end
end
end
uploader = ImageUploader.new(client, file_path, qiita_team_cookie)
uploader.upload!