Class: SuggestGrid::Action

Inherits:
BaseModel show all
Defined in:
lib/suggestgrid/models/action.rb

Overview

An action object represents a user’s action of a type on an item.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(type = nil, user_id = nil, item_id = nil, rating = nil, timestamp = nil) ⇒ Action

Returns a new instance of Action.



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/suggestgrid/models/action.rb', line 39

def initialize(type = nil,
               user_id = nil,
               item_id = nil,
               rating = nil,
               timestamp = nil)
  @type = type
  @user_id = user_id
  @item_id = item_id
  @rating = rating
  @timestamp = timestamp
end

Instance Attribute Details

#item_idString

The item id of the item the action is performed on.

Returns:



17
18
19
# File 'lib/suggestgrid/models/action.rb', line 17

def item_id
  @item_id
end

#ratingFloat

The optional rating given by the user, if the type is explicit.

Returns:

  • (Float)


21
22
23
# File 'lib/suggestgrid/models/action.rb', line 21

def rating
  @rating
end

#timestampLong

The optional UNIX epoch timestamp of the action. Defaults to the current timestamp.

Returns:

  • (Long)


26
27
28
# File 'lib/suggestgrid/models/action.rb', line 26

def timestamp
  @timestamp
end

#typeString

The type that the action belongs to.

Returns:



9
10
11
# File 'lib/suggestgrid/models/action.rb', line 9

def type
  @type
end

#user_idString

The user id of the performer of the action.

Returns:



13
14
15
# File 'lib/suggestgrid/models/action.rb', line 13

def user_id
  @user_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/suggestgrid/models/action.rb', line 52

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  type = hash['type']
  user_id = hash['user_id']
  item_id = hash['item_id']
  rating = hash['rating']
  timestamp = hash['timestamp']

  # Create object from extracted values.
  Action.new(type,
             user_id,
             item_id,
             rating,
             timestamp)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
35
36
37
# File 'lib/suggestgrid/models/action.rb', line 29

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['type'] = 'type'
  @_hash['user_id'] = 'user_id'
  @_hash['item_id'] = 'item_id'
  @_hash['rating'] = 'rating'
  @_hash['timestamp'] = 'timestamp'
  @_hash
end