class Activity

Attributes

access[RW]
application_id[RW]
content[RW]
created_at[RW]
data[RW]
href[RW]
id[RW]
latitude[RW]
longitude[RW]
tags[RW]
title[RW]
updated_at[RW]
user_id[RW]

Public Class Methods

destroy(id) click to toggle source
# File lib/restpack_activity/models/activity.rb, line 19
def self.destroy(id)
  service.destroy(id)
  true
end
get(id) click to toggle source
# File lib/restpack_activity/models/activity.rb, line 14
def self.get(id)
  response = service.get(id)
  Activity.new(response.result[:activities].first)
end
list(params = {}) click to toggle source
# File lib/restpack_activity/models/activity.rb, line 24
def self.list(params = {})
  response = service.list(params)

  Page.new(response, :activities) do |activity|
    Activity.new(activity)
  end
end
new(params={}) click to toggle source
Calls superclass method
# File lib/restpack_activity/models/activity.rb, line 8
def initialize(params={})
  @tags = []
  @access = []
  super(params)
end
service() click to toggle source
# File lib/restpack_activity/models/activity.rb, line 89
def self.service
  klass = "RestPack::Activity::Proxies::#{RestPack::Activity.config.service_type.capitalize}"
  klass.classify.constantize
end

Public Instance Methods

access_csv() click to toggle source
# File lib/restpack_activity/models/activity.rb, line 44
def access_csv
  @access.join(',')
end
access_csv=(csv) click to toggle source
# File lib/restpack_activity/models/activity.rb, line 40
def access_csv=(csv)
  @access = csv.split(',')
end
new?() click to toggle source
# File lib/restpack_activity/models/activity.rb, line 69
def new?
  @id.nil?
end
persisted?() click to toggle source
# File lib/restpack_activity/models/activity.rb, line 73
def persisted?
  !new?
end
save() click to toggle source
# File lib/restpack_activity/models/activity.rb, line 48
def save
  if valid?
    response = new? ? service.create(attributes) : service.update(attributes)

    if response.success?
      #TODO: GJ: update model attributes?
      return true
    else
      response.errors.each do |key, messages|
        messages.each do |message|
          errors.add(key, message)
        end
      end

      return false
    end
  end

  nil
end
service() click to toggle source
# File lib/restpack_activity/models/activity.rb, line 94
def service
  self.class.service
end
tags_csv() click to toggle source
# File lib/restpack_activity/models/activity.rb, line 36
def tags_csv
  @tags.join(',')
end
tags_csv=(csv) click to toggle source
# File lib/restpack_activity/models/activity.rb, line 32
def tags_csv=(csv)
  @tags = csv.split(',')
end
update_attributes(params) click to toggle source
# File lib/restpack_activity/models/activity.rb, line 77
def update_attributes(params)
  #TODO: GJ: extract into base class
  #TODO: whitelist updateble params
  @title = params[:title] if params[:title]
  @content = params[:content] if params[:content]
  @latitude = params[:latitude] if params[:latitude]
  @longitude = params[:longitude] if params[:longitude]
  @data = params[:data] if params[:data]
  self.tags_csv = params[:tags_csv] if params[:tags_csv]
  self.access_csv = params[:access_csv] if params[:access_csv]
end

Private Instance Methods

attributes() click to toggle source
# File lib/restpack_activity/models/activity.rb, line 100
def attributes
  #TODO: GJ: extract into base class
  #TODO: GJ: only those that have changed
  hash = {
    id: @id,
    application_id: @application_id,
    user_id: @user_id,
    title: @title,
    content: @content,
    tags: @tags.join(','),
    access: @access.join(',')
  }

  hash[:latitude] = @latitude unless @latitude.blank?
  hash[:longitude] = @longitude unless @longitude.blank?
  hash[:data] = @data unless @data.blank?
  hash
end