Class: Userlist::Push::Relationship

Inherits:
Resource
  • Object
show all
Includes:
Operations::Create, Operations::Delete
Defined in:
lib/userlist/push/relationship.rb

Instance Attribute Summary

Attributes inherited from Resource

#config, #payload

Instance Method Summary collapse

Methods included from Operations::Delete

#delete?, included

Methods included from Operations::Create

#create?, included

Methods inherited from Resource

#attribute_names, endpoint, #eql?, from_payload, #hash, #identifier, relationship_names, #relationship_names, relationships, resource_name, #respond_to_missing?, #to_hash, #to_json

Constructor Details

#initialize(payload = {}, config = Userlist.config) ⇒ Relationship

Returns a new instance of Relationship.



10
11
12
13
14
15
16
# File 'lib/userlist/push/relationship.rb', line 10

def initialize(payload = {}, config = Userlist.config)
  raise Userlist::ArgumentError, 'Missing required payload' unless payload
  raise Userlist::ArgumentError, 'Missing required parameter :user' unless payload[:user]
  raise Userlist::ArgumentError, 'Missing required parameter :company' unless payload[:company]

  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Userlist::Push::Resource

Instance Method Details

#push?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/userlist/push/relationship.rb', line 25

def push?
  user&.push? && company&.push?
end

#urlObject

Raises:



18
19
20
21
22
23
# File 'lib/userlist/push/relationship.rb', line 18

def url
  raise Userlist::Error, "Cannot generate url for #{self.class.name} without a user" unless user
  raise Userlist::Error, "Cannot generate url for #{self.class.name} without a company" unless company

  "#{self.class.endpoint}/#{user.identifier}/#{company.identifier}"
end