Class: Rallio::OwnershipsBase

Inherits:
Base
  • Object
show all
Defined in:
lib/rallio/ownerships_base.rb

Direct Known Subclasses

AccountOwnership, FranchisorOwnership

Class Method Summary collapse

Methods inherited from Base

app_credentials

Class Method Details

.create(user_id:, payload:) ⇒ Rallio::FranchisorOwnership, Rallio::AccountOwnership

Create new ownership.

Parameters:

  • user_id (Integer)

    user id to create ownership for

  • payload (Hash)

Options Hash (payload:):

  • :franchisor_id (Integer)

    franchisor to link to user_id

  • :account_id (Integer)

    account to link to user_id

Returns:



20
21
22
23
# File 'lib/rallio/ownerships_base.rb', line 20

def self.create(user_id:, payload:)
  response = self.post("/users/#{user_id}/#{url_segment}", headers: app_credentials, body: payload)
  new response.parsed_response["#{response_key}"]
end

.destroy(user_id:, object_id:) ⇒ Object

Destroy ownership for user.

Parameters:

  • user_id (Integer)

    user id to destory ownership for

  • object_id (Integer)

    can be either a franchisor_id or an account_id depending on what class this is called from



30
31
32
# File 'lib/rallio/ownerships_base.rb', line 30

def self.destroy(user_id:, object_id:)
  self.delete("/users/#{user_id}/#{url_segment}/#{object_id}", headers: app_credentials)
end

.for(access_token:) ⇒ Object

Ownerships for access_token and url segment defined in class.

Parameters:

  • access_token (String)

    user access token to get ownerships for



6
7
8
9
10
# File 'lib/rallio/ownerships_base.rb', line 6

def self.for(access_token:)
  headers = { 'Authorization' => "Bearer #{access_token}" }
  response = self.get("/#{url_segment}", headers: headers)
  response.parsed_response["#{url_segment}"].map { |a| new(a) }
end