Module: Backblaze::B2

Defined in:
lib/backblaze/b2.rb,
lib/backblaze/b2/base.rb,
lib/backblaze/b2/file.rb,
lib/backblaze/b2/bucket.rb,
lib/backblaze/b2/file_version.rb

Defined Under Namespace

Classes: Base, Bucket, File, FileVersion

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.account_idObject (readonly)

Returns the value of attribute account_id.



11
12
13
# File 'lib/backblaze/b2.rb', line 11

def 
  @account_id
end

.api_pathObject (readonly)

Returns the value of attribute api_path.



11
12
13
# File 'lib/backblaze/b2.rb', line 11

def api_path
  @api_path
end

.api_urlObject (readonly)

Returns the value of attribute api_url.



11
12
13
# File 'lib/backblaze/b2.rb', line 11

def api_url
  @api_url
end

.download_urlObject (readonly)

Returns the value of attribute download_url.



11
12
13
# File 'lib/backblaze/b2.rb', line 11

def download_url
  @download_url
end

.tokenObject (readonly)

Returns the value of attribute token.



11
12
13
# File 'lib/backblaze/b2.rb', line 11

def token
  @token
end

Class Method Details

.bearer(options) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/backblaze/b2.rb', line 46

def bearer(options)
   = options.fetch(:account_id)
  application_key = options.fetch(:application_key)
  token = Base64.strict_encode64("#{account_id}:#{application_key}")

  "Basic #{token}"
end

.login(options) ⇒ void

This method returns an undefined value.

Authenticates with the server to get the authorization data. Raises an error if there is a problem

Parameters:

  • account_id (#to_s)

    the account id

  • application_key (#to_s)

    the private app key

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/backblaze/b2.rb', line 20

def (options)
  api_path = options.fetch(:api_path) { '/b2api/v1/' }

  params = {
    headers: {
      'Content-Type' => 'application/json',
      'Accept' => 'application/json',
      'Authorization' => bearer(options)
    }
  }
  api_path = "/#{api_path}/".gsub(/\/+/, '/')

  response = HTTParty.get("https://api.backblazeb2.com#{api_path}b2_authorize_account", params)

  raise Backblaze::AuthError, response unless response.success?

  @account_id = response['accountId']
  @token = response['authorizationToken']
  @api_url = response['apiUrl']
  @download_url = response['downloadUrl']
  @api_path = api_path
  Backblaze::B2::Base.base_uri("#{@api_url}#{api_path}")
  Backblaze::B2::Base.headers('Authorization' => token,
                              'Content-Type' => 'application/json')
end