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.

Options Hash (payload:):

  • :franchisor_id (Integer)

    franchisor to link to user_id

  • :account_id (Integer)

    account to link to user_id


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.


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.


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