Class: Intercom::UserResource

Inherits:
Object
  • Object
show all
Extended by:
RequiresParameters
Includes:
UnixTimestampUnwrapper
Defined in:
lib/intercom/user_resource.rb

Overview

Base class for resources tied off a User, all of which are scoped by either the users :email or :user_id.

Direct Known Subclasses

Impression, MessageThread, Note, User

Instance Method Summary (collapse)

Methods included from RequiresParameters

requires_parameters

Methods included from UnixTimestampUnwrapper

#set_time_at, #time_at

Constructor Details

- (UserResource) initialize(attributes = {})

A new instance of UserResource



10
11
12
# File 'lib/intercom/user_resource.rb', line 10

def initialize(attributes={})
  self.attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block) (private)



77
78
79
80
# File 'lib/intercom/user_resource.rb', line 77

def method_missing(method, *args, &block)
  return @attributes[method.to_s] if @attributes.has_key?(method.to_s)
  super
end

Instance Method Details

- (String) email

Email address

Returns:

  • (String)

    email address



20
21
22
# File 'lib/intercom/user_resource.rb', line 20

def email
  @attributes["email"]
end

- (String) email=(email)

Parameters:

  • email (String)

Returns:

  • (String)


26
27
28
# File 'lib/intercom/user_resource.rb', line 26

def email=(email)
  @attributes["email"] = email
end

- (Hash) to_hash

Hash of all the attributes in the structure they will be sent to the api

Returns:

  • (Hash)

    hash of all the attributes in the structure they will be sent to the api



15
16
17
# File 'lib/intercom/user_resource.rb', line 15

def to_hash
  UserResource.for_wire(@attributes)
end

- (UserResource) update_from_api_response(api_response)

updates the internal state of this Intercom::UserResource based on the response from the API

Returns:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/intercom/user_resource.rb', line 43

def update_from_api_response(api_response)
  api_response.each do |key, value|
    setter_method = "#{key.to_s}="
    if self.respond_to?(setter_method)
      self.send(setter_method, value)
    else
      @attributes[key.to_s] = value
    end
  end
  self
end

- (String) user_id

User_id

Returns:

  • (String)

    user_id



31
32
33
# File 'lib/intercom/user_resource.rb', line 31

def user_id
  @attributes["user_id"]
end

- (String) user_id=(user_id)

Parameters:

  • user_id (String)

Returns:

  • (String)


37
38
39
# File 'lib/intercom/user_resource.rb', line 37

def user_id=(user_id)
  @attributes["user_id"] = user_id
end