Class: TheCity::MetricList

Inherits:
ApiList
  • Object
show all
Includes:
Enumerable
Defined in:
lib/api/metric_list.rb

Instance Attribute Summary

Attributes inherited from ApiList

#current_page, #per_page, #total_entries, #total_pages

Instance Method Summary collapse

Methods inherited from ApiList

load, #next_page, #next_page!, #next_page?

Constructor Details

#initialize(options = {}) ⇒ MetricList

Constructor.

Options:

:page - The page number to get.
:filter -  (optional) The filters are below and only one can be specified.
  ::created_in_the_last_N_PERIOD - A string specifying the period of time to look back for users created. 
                                   N_PERIOD is in days, weeks, months or years.
  ::contact_updated_in_the_last_N_PERIOD - A string specifying the period of time to look back for users created.
                                           N_PERIOD is in days, weeks, months or years.
  ::with_external_id_1 - The external ID to reference.
  ::with_external_id_2 - The external ID to reference.
  ::with_external_id_3 - The external ID to reference.
  ::without_external_id_1 - The external ID to reference.
  ::without_external_id_2 - The external ID to reference.
  ::without_external_id_3 - The external ID to reference.

Examples:

MetricList.new({:filter => :created_in_the_last_7_days})

MetricList.new({:page => 2, :filter => :contact_updated_in_the_last_2_weeks})

Parameters:

  • options (defaults to: {})

    A hash of filters for loading the list.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/api/metric_list.rb', line 31

def initialize(options = {}) 
  @options = options
  @options[:page] ||= 1
  @options[:reader] = TheCity::MetricListReader.new(@options) if @options[:reader].nil?
  @json_data = @options[:reader].load_feed 

  @total_entries = @json_data['total_entries']
  @total_pages = @json_data['total_pages']
  @per_page = @json_data['per_page']
  @current_page = @json_data['current_page']      
end

Instance Method Details

#[](index) ⇒ Metric

Get the specified metric.

Parameters:

  • index

    The index of the user to get.

Returns:



48
49
50
# File 'lib/api/metric_list.rb', line 48

def [](index)  
  Metric.new( @json_data['metrics'][index] ) if @json_data['metrics'][index]
end

#each(&block) ⇒ Object

This method is needed for Enumerable.



54
55
56
# File 'lib/api/metric_list.rb', line 54

def each &block
  @json_data['metrics'].each{ |metric| yield( Metric.new(metric) )}
end

#empty?Boolean

Checks if the list is empty.

Returns:

  • (Boolean)

    True on empty, false otherwise.



65
66
67
# File 'lib/api/metric_list.rb', line 65

def empty?
  @json_data['metrics'].empty?
end