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

#blocksObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/layer/user.rb', line 8

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