Module: StartupStats::Countdb::Counts

Included in:
Client
Defined in:
lib/startupstats/countdb/counts.rb

Instance Method Summary collapse

Instance Method Details

#counts_for_day(date) ⇒ StartupStats::ApiResult

Returns all the counts for

Parameters:

  • date (Integer)

Returns:

Raises:



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/startupstats/countdb/counts.rb', line 56

def counts_for_day( date )
	res = send( :get , "counts" , { 'date' => date , 'db_id' => @db_id } )
	counts = []
	res[:body][:counts].each{ |count|
		c = StartupStats::Countdb::Count.new
		c.key = count[:key]
		c.db_id = @db_id
		c.count = count[:count]
		c.date = count[:date]
		counts.push( c )
	}
	StartupStats::ApiResult.new( { 'total_count' => counts.length , 'start' => 0 , 'limit' => 0 , 'counts' => counts } )
end

#counts_for_key(key) ⇒ StartupStats::ApiResult

Returns all the counts for a key

Parameters:

  • key (String)

Returns:

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/startupstats/countdb/counts.rb', line 36

def counts_for_key( key )
	res = send( :get , "counts/#{key}" , { 'db_id' => @db_id } )
	# parse the counts
	counts = []
	res[:body][:counts].each{ |count|
		c = StartupStats::Countdb::Count.new
		c.key = key 
		c.db_id = @db_id
		c.count = count[:count]
		c.date = count[:date]
		counts.push( c )
	}
	StartupStats::ApiResult.new( { 'total_count' => counts.length , 'start' => 0 , 'limit' => 0 , 'counts' => counts } )
end

#delete_count(key, date) ⇒ Object

Deletes a count for a date

return [Boolean]

Parameters:

  • key (String)
  • date (Integer)

Raises:



76
77
78
79
# File 'lib/startupstats/countdb/counts.rb', line 76

def delete_count( key , date )
	res = send( :delete , "counts" , { 'key' => key , 'date' => date , 'db_id' => @db_id } )
	( res[:status] == 200 )
end

#delete_counts(key) ⇒ Object

Deletes all counts for a key

return [Boolean]

Parameters:

  • key (String)


85
86
87
88
# File 'lib/startupstats/countdb/counts.rb', line 85

def delete_counts( key )
	res = send( :delete , "counts" , { 'key' => key , 'db_id' => @db_id } )
	( res[:status] == 200 )
end

#increment_key(key, count) ⇒ Boolean

Increments the value for a key

Parameters:

  • key (String)
  • count (Integer)

Returns:

  • (Boolean)

    Whether or not the request was successful

Raises:



12
13
14
15
16
# File 'lib/startupstats/countdb/counts.rb', line 12

def increment_key( key , count )
	raise StartupStats::Error::ParamsError unless key.to_s =~ /^[^\s]+$/ && count.to_s =~ /^\d+$/ && @db_id
	res = send(:post , 'counts' , { 'key' => key , 'count' => count , 'db_id' => @db_id } )
	( res[:status] == 200 )
end

#increment_key_for_date(key, count, date) ⇒ Boolean

Increments the key for a specific date

Parameters:

  • key (String)
  • count (Integer)
  • date (Integer)

Returns:

  • (Boolean)

    Whether or not the request was successful

Raises:



25
26
27
28
29
# File 'lib/startupstats/countdb/counts.rb', line 25

def increment_key_for_date( key , count , date )
	raise StartupStats::Error::ParamsError unless key.to_s =~ /^[^\s]+$/ && count.to_s =~ /^\d+$/ && date.to_s =~ /^\d+$/ && @db_id
	res = send(:post , 'counts' , { 'key' => key , 'count' => count , 'db_id' => @db_id , 'date' => date } )
	( res[:status] == 200 )
end

#update_key(orig_key, new_key) ⇒ Object

Updates all keys to a new key

return [Boolean]

Parameters:

  • orig_key (String)
  • new_key


95
96
97
98
# File 'lib/startupstats/countdb/counts.rb', line 95

def update_key( orig_key , new_key )
	res = send( :put , "counts/#{orig_key}" , { 'count' => { 'key' => "#{new_key}" } , 'db_id' => @db_id } )
	( res[:status] == 200 )
end