Class: Ruboty::YMCrawl::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/ymcrawl/main.rb

Overview

ファイルをアップロードする先を抽象化したクラス

Instance Method Summary collapse

Constructor Details

#initialize(name, app_key, app_secret, access_token = nil) ⇒ Uploader



127
128
129
130
131
132
133
# File 'lib/ruboty/ymcrawl/main.rb', line 127

def initialize(name, app_key, app_secret, access_token = nil)
  @name         = name
  @app_key      = app_key
  @app_secret   = app_secret
  @access_token = access_token
  @c_uploader   = create_uploader
end

Instance Method Details

#access_token?Boolean



145
# File 'lib/ruboty/ymcrawl/main.rb', line 145

def access_token?; @access_token != "" and @access_token != nil end

#create_uploaderObject

引数に応じてアップロード先のインスタンスを返す



136
137
138
139
140
141
142
143
# File 'lib/ruboty/ymcrawl/main.rb', line 136

def create_uploader
  return @c_uploader unless @c_uploader == nil
  if @name == "dropbox"
    @c_uploader = DropboxManager.new(@app_key, @app_secret) 
    return @c_uploader
  end
  raise ArgumentError("uploader #{@name} is not found")
end

#get_access_token_urlObject



158
159
160
161
162
# File 'lib/ruboty/ymcrawl/main.rb', line 158

def get_access_token_url
  error = "---- YMCrawl publishing new access token url. But you already have access token. ----" 
  puts error if @access_token != nil and @access_token != ""
  @c_uploader.get_auth_code_url
end

#get_nameObject



164
# File 'lib/ruboty/ymcrawl/main.rb', line 164

def get_name;    @name                    end


166
# File 'lib/ruboty/ymcrawl/main.rb', line 166

def get_share_link(path) @c_uploader.get_share_link(path) end

#login(token = nil) ⇒ Object



151
152
153
154
155
156
# File 'lib/ruboty/ymcrawl/main.rb', line 151

def (token = nil)
  @access_token = (token == nil) ? @access_token : token
  puts "access token: #{@access_token}"
  puts "---- access token isn't set when login!!!! ----" if token ==nil
  @c_uploader.(token)
end

#put(command) ⇒ Object



165
# File 'lib/ruboty/ymcrawl/main.rb', line 165

def put(command) @c_uploader.put(command) end

#verify_auth_code(auth_code) ⇒ Object



147
148
149
# File 'lib/ruboty/ymcrawl/main.rb', line 147

def verify_auth_code(auth_code)
  @access_token = @c_uploader.get_access_token(auth_code)
end