class OneDriveForBusiness::Drive

Attributes

access_token[R]
url[R]

Public Class Methods

new(tenant, access_token) click to toggle source

@return Drive

# File lib/onedrive_for_business/drive.rb, line 8
def initialize(tenant, access_token)
  @url = "https://#{tenant}-my.sharepoint.com/_api/v1.0/me/drive"
  @access_token = access_token
end

Public Instance Methods

id() click to toggle source

@return String

# File lib/onedrive_for_business/drive.rb, line 17
def id
  fetch_properties! unless @id
  @id
end
owner() click to toggle source

@return Identity

# File lib/onedrive_for_business/drive.rb, line 23
def owner
  fetch_properties! unless @owner
  @owner
end
quota() click to toggle source

@return Drive::Quota

# File lib/onedrive_for_business/drive.rb, line 29
def quota
  fetch_properties! unless @quota
  @quota
end

Private Instance Methods

fetch_properties!() click to toggle source
# File lib/onedrive_for_business/drive.rb, line 50
def fetch_properties!
  resp = http(url).get(url, 'authorization' => "Bearer #{@access_token}")
  if resp.code.to_i != 200
    # TODO(aj-michael) Add better error.
    fail "Unauthorized request: #{resp.body}."
  end
  resp_hash = JSON.parse(resp.body)
  @id = resp_hash['id']
  @quota = Drive::Quota.new(resp_hash['quota'])
  @owner = Identity.new(resp_hash['owner'])
end