Class: Layer::Resources::User

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

Instance Attribute Summary

Attributes inherited from Layer::Resource

#attributes, #client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layer::Resource

class_name, create, #destroy, #initialize, #inspect, list, #method_missing, pluralized_name, #respond_to_missing?, #update, url, #uuid

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(client, url, id) ⇒ Object



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

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

Instance Method Details

#badgeObject



49
50
51
# File 'lib/layer/resources/user.rb', line 49

def badge
  client.get("#{url}/badge")
end

#blocksObject



8
9
10
# File 'lib/layer/resources/user.rb', line 8

def blocks
  Layer::ResourceProxy.new(client, self, Layer::Resources::Block)
end

#conversationsObject



12
13
14
# File 'lib/layer/resources/user.rb', line 12

def conversations
  Layer::ResourceProxy.new(client, self, Layer::Resources::Conversation)
end

#create_identity(params) ⇒ Object



20
21
22
# File 'lib/layer/resources/user.rb', line 20

def create_identity(params)
  client.post(identity_url,  body: params.to_json)
end

#destroy_identityObject



40
41
42
# File 'lib/layer/resources/user.rb', line 40

def destroy_identity
  client.delete(identity_url)
end

#identityObject



24
25
26
# File 'lib/layer/resources/user.rb', line 24

def identity
  client.get(identity_url)
end

#messagesObject



16
17
18
# File 'lib/layer/resources/user.rb', line 16

def messages
  Layer::ResourceProxy.new(client, self, Layer::Resources::Message)
end

#replace_identity(params) ⇒ Object



36
37
38
# File 'lib/layer/resources/user.rb', line 36

def replace_identity(params)
  client.put(identity_url, body: params.to_json)
end

#set_badge(badge_count) ⇒ Object



44
45
46
47
# File 'lib/layer/resources/user.rb', line 44

def set_badge(badge_count)
  body = { external_unread_count: badge_count }
  client.put("#{url}/badge", body: body.to_json)
end

#update_identity(params) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/layer/resources/user.rb', line 28

def update_identity(params)
  client.patch(
    identity_url,
    body: params.to_json,
    headers: client.layer_patch_header
  )
end