sappy 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,10 @@
4
4
 
5
5
  A ruby library providing a wrapper around the SiteUptime API.
6
6
 
7
+ ## Installation:
8
+
9
+ gem install sappy -s http://gemcutter.org
10
+
7
11
  ## Usage:
8
12
 
9
13
  require 'rubygems'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -13,3 +13,4 @@ require 'sappy/monitor'
13
13
  require 'sappy/request'
14
14
  require 'sappy/response'
15
15
  require 'sappy/responses'
16
+ require 'sappy/statistics'
@@ -132,16 +132,16 @@ module Sappy
132
132
  @account.request('removemonitor', "MonitorId" => id)
133
133
  end
134
134
 
135
- def daily_statistics
136
- raise "Not yet implemented."
135
+ def daily_statistics(year, month, day)
136
+ Statistics::Daily.new(@account.request('dailystatistics', "MonitorId" => id, "Year" => year, "Month" => month, "Day" => day).statistics)
137
137
  end
138
138
 
139
- def monthly_statistics
140
- raise "Not yet implemented."
139
+ def monthly_statistics(year, month)
140
+ Statistics::Monthly.new(@account.request('monthlystatistics', "MonitorId" => id, "Year" => year, "Month" => month).statistics)
141
141
  end
142
142
 
143
- def annual_statistics
144
- raise "Not yet implemented."
143
+ def annual_statistics(year = "")
144
+ Statistics::Annual.new(@account.request('annualstatistics', "MonitorId" => id, "Year" => year).statistics)
145
145
  end
146
146
  end
147
147
  end
@@ -7,6 +7,9 @@ require 'sappy/responses/edit_monitor'
7
7
  require 'sappy/responses/remove_monitor'
8
8
  require 'sappy/responses/enable_monitor'
9
9
  require 'sappy/responses/disable_monitor'
10
+ require 'sappy/responses/daily_statistics'
11
+ require 'sappy/responses/monthly_statistics'
12
+ require 'sappy/responses/annual_statistics'
10
13
 
11
14
  module Sappy
12
15
  module Responses
@@ -19,7 +22,10 @@ module Sappy
19
22
  "editmonitor" => EditMonitor,
20
23
  "removemonitor" => RemoveMonitor,
21
24
  "enablemonitor" => EnableMonitor,
22
- "disablemonitor" => DisableMonitor
25
+ "disablemonitor" => DisableMonitor,
26
+ "dailystatistics" => DailyStatistics,
27
+ "monthlystatistics" => MonthlyStatistics,
28
+ "annualstatistics" => AnnualStatistics
23
29
  }
24
30
 
25
31
  def self.for(action)
@@ -0,0 +1,11 @@
1
+ module Sappy
2
+ module Responses
3
+ class AnnualStatistics < Response
4
+ attr_reader :statistics
5
+
6
+ def success(hash)
7
+ @statistics = hash["monthlystats"].first
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Sappy
2
+ module Responses
3
+ class DailyStatistics < Response
4
+ attr_reader :statistics
5
+
6
+ def success(hash)
7
+ @statistics = hash["checks"].first
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Sappy
2
+ module Responses
3
+ class MonthlyStatistics < Response
4
+ attr_reader :statistics
5
+
6
+ def success(hash)
7
+ @statistics = hash["dailystats"].first
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'sappy/statistics/annual'
2
+ require 'sappy/statistics/daily'
3
+ require 'sappy/statistics/monthly'
@@ -0,0 +1,15 @@
1
+ module Sappy
2
+ module Statistics
3
+ class Annual
4
+ attr_reader :checks, :failures, :timezone, :total, :uptime
5
+
6
+ def initialize(attributes = {})
7
+ @checks = attributes['numchecks']
8
+ @failures = attributes['numfailures']
9
+ @timezone = attributes['timezone']
10
+ @total = attributes['total']
11
+ @uptime = attributes['uptime']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Sappy
2
+ module Statistics
3
+ class Daily
4
+ attr_reader :checks, :failures, :timezone, :total, :uptime
5
+
6
+ def initialize(attributes = {})
7
+ @checks = attributes[:numchecks]
8
+ @failures = attributes[:numfailures]
9
+ @timezone = attributes[:timezone]
10
+ @total = attributes[:total]
11
+ @uptime = attributes[:uptime]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Sappy
2
+ module Statistics
3
+ class Monthly
4
+ attr_reader :checks, :failures, :month, :timezone, :total, :uptime, :year
5
+
6
+ def initialize(attributes = {})
7
+ @checks = attributes[:numchecks]
8
+ @failures = attributes[:numfailures]
9
+ @month = attributes[:month]
10
+ @timezone = attributes[:timezone]
11
+ @total = attributes[:total]
12
+ @uptime = attributes[:uptime]
13
+ @year = attributes[:year]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -45,6 +45,32 @@ module Sappy
45
45
  end
46
46
  @account.monitors.size.should == 0
47
47
  end
48
+
49
+ describe "statistics" do
50
+ before do
51
+ unless ENV['LIVE_SPECS']
52
+ FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&Month=11&method=siteuptime.dailystatistics&Day=28&Year=2006&MonitorId=84043", :response => cached_page('dailystatistics'))
53
+ FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&Month=6&method=siteuptime.monthlystatistics&Year=2007&MonitorId=84043", :response => cached_page('monthlystatistics'))
54
+ FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.annualstatistics&Year=&MonitorId=84043", :response => cached_page('annualstatistics'))
55
+ end
56
+ @monitor = @account.add_monitor({:name => "New Monitor", :service => "http", :location => "sf", :host => "engineyard.com", :period => "60"})
57
+ end
58
+
59
+ # it "should provide daily" do
60
+ # @monitor.daily_statistics(2006, 11, 28).should.be.instance_of Statistics::Daily
61
+ # end
62
+ it "should raise error for daily (due to malformed XML from SiteUptime)" do
63
+ lambda { @monitor.daily_statistics(2006, 11, 28) }.should.raise REXML::ParseException
64
+ end
65
+
66
+ it "should provide monthly" do
67
+ @monitor.monthly_statistics(2007, 6).should.be.instance_of Statistics::Monthly
68
+ end
69
+
70
+ it "should provide annual" do
71
+ @monitor.annual_statistics.should.be.instance_of Statistics::Annual
72
+ end
73
+ end
48
74
  end
49
75
  end
50
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sappy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Egan
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-03 00:00:00 +10:00
13
+ date: 2009-10-09 00:00:00 +11:00
14
14
  default_executable: shell
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -52,9 +52,8 @@ executables:
52
52
  extensions: []
53
53
 
54
54
  extra_rdoc_files:
55
- - README.markdown
55
+ - README.md
56
56
  files:
57
- - README.markdown
58
57
  - Rakefile
59
58
  - VERSION
60
59
  - lib/core_ext.rb
@@ -67,14 +66,22 @@ files:
67
66
  - lib/sappy/responses.rb
68
67
  - lib/sappy/responses/account_info.rb
69
68
  - lib/sappy/responses/add_monitor.rb
69
+ - lib/sappy/responses/annual_statistics.rb
70
70
  - lib/sappy/responses/auth.rb
71
+ - lib/sappy/responses/daily_statistics.rb
71
72
  - lib/sappy/responses/disable_monitor.rb
72
73
  - lib/sappy/responses/edit_monitor.rb
73
74
  - lib/sappy/responses/enable_monitor.rb
74
75
  - lib/sappy/responses/error.rb
75
76
  - lib/sappy/responses/monitors.rb
77
+ - lib/sappy/responses/monthly_statistics.rb
76
78
  - lib/sappy/responses/remove_monitor.rb
77
79
  - lib/sappy/responses/summary_statistics.rb
80
+ - lib/sappy/statistics.rb
81
+ - lib/sappy/statistics/annual.rb
82
+ - lib/sappy/statistics/daily.rb
83
+ - lib/sappy/statistics/monthly.rb
84
+ - README.md
78
85
  has_rdoc: true
79
86
  homepage: http://github.com/abcde/sappy
80
87
  licenses: []