Module: StartupStats::Countdb::Counts
- Included in:
- Client
- Defined in:
- lib/startupstats/countdb/counts.rb
Instance Method Summary collapse
-
#counts_for_day(date) ⇒ StartupStats::ApiResult
Returns all the counts for.
-
#counts_for_key(key) ⇒ StartupStats::ApiResult
Returns all the counts for a key.
-
#delete_count(key, date) ⇒ Object
Deletes a count for a date.
-
#delete_counts(key) ⇒ Object
Deletes all counts for a key.
-
#increment_key(key, count) ⇒ Boolean
Increments the value for a key.
-
#increment_key_for_date(key, count, date) ⇒ Boolean
Increments the key for a specific date.
-
#update_key(orig_key, new_key) ⇒ Object
Updates all keys to a new key.
Instance Method Details
#counts_for_day(date) ⇒ StartupStats::ApiResult
Returns all the counts for
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
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]
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]
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
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
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]
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 |