class Event

Event Class (イベント クラス)

@!attribute [r] name

@return [String] event name (イベント名)

@!attribute [r] goal_id

@return [String] goal id (ゴールID)

@!attribute [r] timestamp

@return [String] time stamp (タイム・スタンプ)

@!attribute [r] client_id

@return [String] client id (クライアントID)

@!attribute [r] value

@return [String] optional info of event (イベントの追加情報)

Attributes

client_id[R]
goal_id[R]
name[R]
timestamp[R]
value[R]

Public Class Methods

new(client, name, value=nil) click to toggle source

initializer (イニシャライザ) @param [Client] client Client object (クライアント) @param [String] name event name (イベント名) @param [String] value optional info of event (イベントの追加情報)

# File lib/growthpush/event.rb, line 29
def initialize(client, name, value=nil)
  @client = client
  @name = name
  @value = value
end

Public Instance Methods

save(growth_push) click to toggle source

save event (イベントを登録する) @param [GrowthPush] growth_push GrowthPush object (GrowthPushオブジェクト) @raise [GrowthPushException] exception (例外) @return [Event] event (イベント)

# File lib/growthpush/event.rb, line 41
def save(growth_push)
  begin
    if @client.id && @client.code
      http_response = HttpClient.instance.post('events',
                                                   {
                                                       'clientId' => @client.id,
                                                       'code' => @client.code,
                                                       'name' => self.name,
                                                       'value' => self.value
                                                   }
      )
    elsif @client.token
      http_response = HttpClient.instance.post('events',
                                                   {
                                                       'applicationId' => growth_push.application_id,
                                                       'secret' => growth_push.secret,
                                                       'token' => @client.token,
                                                       'name' => self.name,
                                                       'value' => self.value,
                                                   }
      )
    else
      raise GrowthPushException.new('Invalid client')
    end

  rescue GrowthPushException => ex
    raise GrowthPushException.new('Failed to save event: ' << ex.message, ex.code)
  end

  body = http_response.body
  self.attributes = body

  return self
end

Private Instance Methods

attributes=(attributes) click to toggle source

set attributes (属性をセットする) @param [Hash] attributes attributes (属性)

# File lib/growthpush/event.rb, line 80
def attributes=(attributes)
  @goal_id = attributes['goalId'];
  @timestamp = attributes['timestamp'];
  @client_id = attributes['clientId'];
  @value = attributes['value'];
end