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
-
.account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
.api_path ⇒ Object
readonly
Returns the value of attribute api_path.
-
.api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
.download_url ⇒ Object
readonly
Returns the value of attribute download_url.
-
.token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
- .bearer(options) ⇒ Object
-
.login(options) ⇒ void
Authenticates with the server to get the authorization data.
Class Attribute Details
.account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
11 12 13 |
# File 'lib/backblaze/b2.rb', line 11 def account_id @account_id end |
.api_path ⇒ Object (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_url ⇒ Object (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_url ⇒ Object (readonly)
Returns the value of attribute download_url.
11 12 13 |
# File 'lib/backblaze/b2.rb', line 11 def download_url @download_url end |
.token ⇒ Object (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() account_id = .fetch(:account_id) application_key = .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
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 login() api_path = .fetch(:api_path) { '/b2api/v1/' } params = { headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => bearer() } } 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 |