Module: B2::Authentication

Defined in:
lib/b2/authentication.rb

Class Method Summary collapse

Class Method Details

.authorizeObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/b2/authentication.rb', line 4

def authorize
  options = {
    basic_auth: {username: B2., password: B2.application_key}
  }

  response = HTTParty.get("#{BASE_URI}b2_authorize_account", options)

  B2::Base.base_uri "#{response['apiUrl']}/b2api/v1/"
  B2::Base.headers 'Authorization' => response['authorizationToken'], 'Content-Type' => 'application/json'
  B2::Base.cookies.merge!(download_url: response['downloadUrl'])
  B2::Base.cookies.merge!(expired: Time.now + 3600 * 23)
end