Class: Layer::User

Inherits:
Resource show all
Defined in:
lib/layer/user.rb

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

class_name, from_response, #id, #initialize, #respond_to_missing?, url, #url

Constructor Details

This class inherits a constructor from Layer::Resource

Dynamic Method Handling

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

Class Method Details

.find(id, client = self.client) ⇒ Object



4
5
6
# File 'lib/layer/user.rb', line 4

def self.find(id, client = self.client)
  from_response({ 'url' => "/users/#{id}" }, client)
end

Instance Method Details

#blocksLayer::RelationProxy

Note:

This is only available via the Platform API.

Returns the users blocked by this user

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/layer/user.rb', line 12

def blocks
  RelationProxy.new(self, Block, [Operations::Create, Operations::List, Operations::Delete]) do
    def from_response(response, client)
      response['url'] ||= "#{base.url}#{resource_type.url}/#{response['user_id']}"
      super
    end

    def create(attributes, client = self.client)
      response = client.post(url, attributes)
      from_response({ 'user_id' => attributes['user_id'] }, client)
    end
  end
end

#conversationsLayer::RelationProxy

Note:

This is only available via the Platform API.

Returns the user’s conversations

Returns:



52
53
54
# File 'lib/layer/user.rb', line 52

def conversations
  RelationProxy.new(self, Conversation, [Operations::List, Operations::Find])
end

#identityLayer::RelationProxy

Note:

This is only available via the Platform API.

Returns the identity object for this user

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/layer/user.rb', line 30

def identity
  SingletonRelationProxy.new(self, Layer::Identity) do
    def from_response(response, client)
      response['url'] ||= "#{base.url}#{resource_type.url}"
      super
    end

    def create(attributes, client = self.client)
      client.post(url, attributes)
      fetch
    end

    def delete(client = self.client)
      client.delete(url)
    end
  end
end

#messagesLayer::RelationProxy

Note:

This is only available via the Platform API.

Returns the user’s messages

Returns:



60
61
62
# File 'lib/layer/user.rb', line 60

def messages
  RelationProxy.new(self, Message, [Operations::Find])
end