Class: Gitrepox::Gsession
- Inherits:
-
Object
- Object
- Gitrepox::Gsession
- Defined in:
- lib/gitrepox/gsession.rb
Instance Method Summary collapse
- #delete_config_file(fname) ⇒ Object
- #ensure_config_file(fname) ⇒ Object
-
#initialize(config = 'config.json') ⇒ Gsession
constructor
A new instance of Gsession.
- #make_config_file(fname, target, sub_target) ⇒ Object
- #upload_from_string(content, filename, content_type = 'text/tab-separated-values') ⇒ Object
Constructor Details
#initialize(config = 'config.json') ⇒ Gsession
Returns a new instance of Gsession.
7 8 9 10 |
# File 'lib/gitrepox/gsession.rb', line 7 def initialize(config = 'config.json') ensure_config_file(config) @session = GoogleDrive::Session.from_config(config) end |
Instance Method Details
#delete_config_file(fname) ⇒ Object
31 32 33 |
# File 'lib/gitrepox/gsession.rb', line 31 def delete_config_file(fname) File.delete(fname) end |
#ensure_config_file(fname) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/gitrepox/gsession.rb', line 12 def ensure_config_file(fname) pn = Pathname.new(fname) return if pn.exist? target = 'Google' sub_target = 'GCPX' make_config_file(config, target, sub_target) end |
#make_config_file(fname, target, sub_target) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/gitrepox/gsession.rb', line 21 def make_config_file(fname, target, sub_target) home_dir = ENV['HOME'] home_pn = Pathname.new(home_dir) secret_dir_pn = "#{home_pn}secret" sm = Secretmgr::Secretmgr.new(secret_dir_pn) sm.set_setting_for_query(target, sub_target) content = sm.load File.write(fname, content) end |
#upload_from_string(content, filename, content_type = 'text/tab-separated-values') ⇒ Object
35 36 37 38 |
# File 'lib/gitrepox/gsession.rb', line 35 def upload_from_string(content, filename, content_type = 'text/tab-separated-values') obj = @session.upload_from_string(content, filename, content_type: content_type) [obj.title, obj.id].join(',') end |