sappy 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Rakefile +24 -11
  2. data/VERSION +1 -1
  3. data/lib/sappy.rb +1 -2
  4. data/lib/sappy/account.rb +18 -17
  5. data/lib/sappy/monitor.rb +9 -1
  6. data/lib/sappy/response.rb +32 -10
  7. data/lib/sappy/responses/account_info.rb +4 -4
  8. data/lib/sappy/responses/add_monitor.rb +3 -8
  9. data/lib/sappy/responses/annual_statistics.rb +2 -2
  10. data/lib/sappy/responses/auth.rb +4 -3
  11. data/lib/sappy/responses/daily_statistics.rb +2 -2
  12. data/lib/sappy/responses/disable_monitor.rb +1 -8
  13. data/lib/sappy/responses/edit_monitor.rb +1 -8
  14. data/lib/sappy/responses/enable_monitor.rb +1 -8
  15. data/lib/sappy/responses/monitors.rb +2 -2
  16. data/lib/sappy/responses/monthly_statistics.rb +2 -2
  17. data/lib/sappy/responses/remove_monitor.rb +1 -8
  18. data/lib/sappy/responses/summary_statistics.rb +5 -4
  19. data/spec/credentials.integrity.rb +1 -0
  20. data/spec/sappy/{account_bacon.rb → account_spec.rb} +8 -11
  21. data/spec/sappy/monitor_spec.rb +73 -0
  22. data/spec/spec_helper.rb +45 -0
  23. data/spec/xml/accountinfo.xml +15 -0
  24. data/spec/xml/accountinfo_1.xml +15 -0
  25. data/spec/xml/addmonitor.xml +15 -0
  26. data/spec/xml/annualstatistics.xml +16 -0
  27. data/spec/xml/dailystatistics.xml +16 -0
  28. data/spec/xml/disablemonitor.xml +13 -0
  29. data/spec/xml/enablemonitor.xml +13 -0
  30. data/spec/xml/invalid_account.xml +12 -0
  31. data/spec/xml/monitors.xml +16 -0
  32. data/spec/xml/monitors_1.xml +17 -0
  33. data/spec/xml/monitors_12.xml +17 -0
  34. data/spec/xml/monthlystatistics.xml +16 -0
  35. data/spec/xml/removemonitor.xml +13 -0
  36. data/spec/xml/summarystatistics.xml +15 -0
  37. data/spec/xml/valid_account.xml +15 -0
  38. metadata +28 -10
  39. data/lib/sappy/responses/error.rb +0 -22
  40. data/spec/helper.rb +0 -38
  41. data/spec/sappy/monitor_bacon.rb +0 -73
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
+ require 'bundler'
2
+ require 'jeweler'
3
+
1
4
  begin
2
- require 'jeweler'
3
5
  Jeweler::Tasks.new do |gemspec|
4
6
  gemspec.name = "sappy"
5
7
  gemspec.summary = "Wrapping that shit!"
@@ -7,22 +9,33 @@ begin
7
9
  gemspec.email = ["dylanegan@gmail.com", "tim@spork.in"]
8
10
  gemspec.homepage = "http://github.com/abcde/sappy"
9
11
  gemspec.authors = ["Dylan Egan", "Tim Carey-Smith"]
10
- gemspec.files = %w(README.markdown Rakefile VERSION) + Dir.glob("{lib,bacon}/**/*")
12
+ # reject people's local copies of credentials
13
+ project_files = Dir.glob("{lib,spec}/**/*").reject { |file| file =~ %r!spec/credentials.rb! }
14
+ gemspec.files = %w(README.markdown Rakefile VERSION) + project_files
11
15
  gemspec.rubyforge_project = 'abcde'
12
- gemspec.add_dependency "rack", "1.0.0"
13
- gemspec.add_dependency "rest-client", "1.0.3"
14
- gemspec.add_dependency "xml-simple", "1.0.12"
16
+ manifest = Bundler::Environment.load(File.dirname(__FILE__) + '/Gemfile')
17
+ manifest.dependencies.each do |d|
18
+ next unless d.only && d.only.include?('release')
19
+ gemspec.add_dependency(d.name, d.version)
20
+ end
15
21
  end
16
22
 
17
23
  Jeweler::RubyforgeTasks.new
18
24
  rescue LoadError
19
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
20
26
  end
21
27
 
22
- desc 'Run bacon'
23
- task :bacon do
24
- puts `bacon #{Dir["spec/**/*_bacon.rb"].join(" ")}`
28
+ require 'spec/rake/spectask'
29
+ desc "Run specs"
30
+ Spec::Rake::SpecTask.new do |t|
31
+ t.spec_files = FileList['spec/**/*_spec.rb']
32
+ t.spec_opts = %w(-fs --color)
33
+
34
+ t.rcov = ENV['RCOV'] == "true"
35
+ t.rcov_opts << '--exclude' << 'spec'
36
+ t.rcov_opts << '--text-summary'
37
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
25
38
  end
26
39
 
27
- desc 'Default: Runs spec'
28
- task :default => :bacon
40
+ desc 'Default: Runs rspec'
41
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -1,6 +1,5 @@
1
- require 'xmlsimple'
2
-
3
1
  require File.dirname(__FILE__) + '/core_ext'
2
+ require 'nokogiri'
4
3
 
5
4
  $:.unshift File.dirname(__FILE__)
6
5
 
@@ -49,24 +49,25 @@ module Sappy
49
49
  Request.perform(self, action, parameters)
50
50
  end
51
51
 
52
- private
53
- def authenticate
54
- response = request('auth', "Email" => @username, "Password" => @password)
55
- @authkey = response.key
56
- end
52
+ private
53
+
54
+ def authenticate
55
+ response = request('auth', "Email" => @username, "Password" => @password)
56
+ @authkey = response.key
57
+ end
57
58
 
58
- def refresh_account_info
59
- response = request('accountinfo')
60
- @available_monitors = response.available_monitors
61
- @setup_monitors = response.setup_monitors
62
- @sms_alerts = response.sms_alerts
63
- end
59
+ def refresh_account_info
60
+ response = request('accountinfo')
61
+ @available_monitors = response.available_monitors
62
+ @setup_monitors = response.setup_monitors
63
+ @sms_alerts = response.sms_alerts
64
+ end
64
65
 
65
- def refresh_summary_statistics
66
- response = request('summarystatistics')
67
- @up_monitors = response.up
68
- @down_monitors = response.down
69
- @inactive_monitors = response.inactive
70
- end
66
+ def refresh_summary_statistics
67
+ response = request('summarystatistics')
68
+ @up_monitors = response.up
69
+ @down_monitors = response.down
70
+ @inactive_monitors = response.inactive
71
+ end
71
72
  end
72
73
  end
@@ -107,11 +107,19 @@ module Sappy
107
107
  @active = 0
108
108
  end
109
109
 
110
+ def disabled?
111
+ @active != 1
112
+ end
113
+
110
114
  def enable!
111
115
  @account.request('enablemonitor', "MonitorId" => id)
112
116
  @active = 1
113
117
  end
114
118
 
119
+ def enabled?
120
+ @active == 1
121
+ end
122
+
115
123
  def new_record?
116
124
  id.nil?
117
125
  end
@@ -121,7 +129,7 @@ module Sappy
121
129
  end
122
130
 
123
131
  def create
124
- @id = @account.request("addmonitor", attributes).id
132
+ self.id = @account.request("addmonitor", attributes).id
125
133
  end
126
134
 
127
135
  def update
@@ -9,16 +9,33 @@ module Sappy
9
9
  r
10
10
  end
11
11
 
12
- def initialize(xml)
13
- @xml = xml
12
+ attr_reader :data, :xml
13
+
14
+ def initialize(data)
15
+ @data = data.to_s
16
+ @xml = Nokogiri::XML.parse(data)
17
+ end
18
+
19
+ def error_response?
20
+ resp = xml.xpath('//rsp')
21
+ resp && resp.first['stat'] == 'fail'
22
+ end
23
+
24
+ def error_response
25
+ resp = xml.xpath('//err')
26
+ resp && resp.first
27
+ end
28
+
29
+ def first_xpath(path)
30
+ node = xml.xpath(path)
31
+ node && node.first
14
32
  end
15
33
 
16
34
  def parse
17
- hash = XmlSimple.xml_in(@xml.to_s, 'KeepRoot' => false)
18
- if hash["stat"] == "fail"
19
- error = hash["err"]
20
- message = error.first["msg"]
21
- case code = error.first["code"]
35
+ if error_response?
36
+ error = error_response
37
+ message = error["msg"]
38
+ case code = error["code"]
22
39
  when "AUTH_EXPIRED"
23
40
  raise SessionExpired, "The auth session expired, reconnect to continue using the API"
24
41
  else
@@ -26,16 +43,21 @@ module Sappy
26
43
  raise UnhandledError, "Unhandled error: #{code}, #{message}"
27
44
  end
28
45
  else
29
- success(hash)
46
+ success
30
47
  end
31
48
  end
32
49
 
33
- def success(hash)
50
+ def success
34
51
  raise NotImplementedError, "Overwrite #success in a Response subclass"
35
52
  end
36
53
 
37
54
  def failure(code, message)
38
- raise NotImplementedError, "Overwrite #failure in a Response subclass"
55
+ case code
56
+ when "WRONG_DATA"
57
+ raise ArgumentError, "You didn't provide a correct monitor id: #{message}"
58
+ else
59
+ raise NotImplementedError, "Overwrite #failure in a Response subclass"
60
+ end
39
61
  end
40
62
  end
41
63
  end
@@ -3,11 +3,11 @@ module Sappy
3
3
  class AccountInfo < Response
4
4
  attr_reader :available_monitors, :setup_monitors, :sms_alerts
5
5
 
6
- def success(hash)
7
- accountinfo = hash["accountinfo"].first
6
+ def success
7
+ accountinfo = first_xpath('//accountinfo')
8
+ @sms_alerts = accountinfo["smsalerts"].to_i
9
+ @setup_monitors = accountinfo["setupmonitors"].to_i
8
10
  @available_monitors = accountinfo["availablemonitors"].to_i
9
- @setup_monitors = accountinfo["setupmonitors"].to_i
10
- @sms_alerts = accountinfo["smsalerts"].to_i
11
11
  end
12
12
  end
13
13
  end
@@ -2,15 +2,10 @@ module Sappy
2
2
  module Responses
3
3
  class AddMonitor < Response
4
4
  attr_reader :id
5
- def success(hash)
6
- @id = hash["monitor"].first["id"]
7
- end
8
5
 
9
- def failure(code, message)
10
- case code
11
- when "WRONG_DATA"
12
- raise ArgumentError, "You didn't provide the correct data: #{message}"
13
- end
6
+ def success
7
+ node = first_xpath('//monitor')
8
+ @id = node && node['id']
14
9
  end
15
10
  end
16
11
  end
@@ -3,8 +3,8 @@ module Sappy
3
3
  class AnnualStatistics < Response
4
4
  attr_reader :statistics
5
5
 
6
- def success(hash)
7
- @statistics = hash["monthlystats"].first
6
+ def success
7
+ @statistics = first_xpath('//monthlystats')
8
8
  end
9
9
  end
10
10
  end
@@ -2,10 +2,11 @@ module Sappy
2
2
  module Responses
3
3
  class Auth < Response
4
4
  class LoginFailed < Error; end
5
-
6
5
  attr_reader :key
7
- def success(hash)
8
- @key = hash["session"].first["key"]
6
+
7
+ def success
8
+ node = first_xpath('//session')
9
+ @key = node && node["key"]
9
10
  end
10
11
 
11
12
  def failure(code, message)
@@ -3,8 +3,8 @@ module Sappy
3
3
  class DailyStatistics < Response
4
4
  attr_reader :statistics
5
5
 
6
- def success(hash)
7
- @statistics = hash["checks"].first
6
+ def success
7
+ @statistics = first_xpath('//checks')
8
8
  end
9
9
  end
10
10
  end
@@ -1,14 +1,7 @@
1
1
  module Sappy
2
2
  module Responses
3
3
  class DisableMonitor < Response
4
- def success(hash)
5
- end
6
-
7
- def failure(code, message)
8
- case code
9
- when "WRONG_DATA"
10
- raise ArgumentError, "You didn't provide a correct monitor id: #{message}"
11
- end
4
+ def success
12
5
  end
13
6
  end
14
7
  end
@@ -1,14 +1,7 @@
1
1
  module Sappy
2
2
  module Responses
3
3
  class EditMonitor < Response
4
- def success(hash)
5
- end
6
-
7
- def failure(code, message)
8
- case code
9
- when "WRONG_DATA"
10
- raise ArgumentError, "You didn't provide the correct data: #{message}"
11
- end
4
+ def success
12
5
  end
13
6
  end
14
7
  end
@@ -1,14 +1,7 @@
1
1
  module Sappy
2
2
  module Responses
3
3
  class EnableMonitor < Response
4
- def success(hash)
5
- end
6
-
7
- def failure(code, message)
8
- case code
9
- when "WRONG_DATA"
10
- raise ArgumentError, "You didn't provide a correct monitor id: #{message}"
11
- end
4
+ def success
12
5
  end
13
6
  end
14
7
  end
@@ -3,8 +3,8 @@ module Sappy
3
3
  class Monitors < Response
4
4
  attr_reader :monitors
5
5
 
6
- def success(hash)
7
- @monitors = hash["monitors"].first["monitor"] || []
6
+ def success
7
+ @monitors = xml.xpath('//monitors/monitor')
8
8
  end
9
9
  end
10
10
  end
@@ -3,8 +3,8 @@ module Sappy
3
3
  class MonthlyStatistics < Response
4
4
  attr_reader :statistics
5
5
 
6
- def success(hash)
7
- @statistics = hash["dailystats"].first
6
+ def success
7
+ @statistics = first_xpath('//dailystats')
8
8
  end
9
9
  end
10
10
  end
@@ -1,14 +1,7 @@
1
1
  module Sappy
2
2
  module Responses
3
3
  class RemoveMonitor < Response
4
- def success(hash)
5
- end
6
-
7
- def failure(code, message)
8
- case code
9
- when "WRONG_DATA"
10
- raise ArgumentError, "You didn't provide a correct monitor id: #{message}"
11
- end
4
+ def success
12
5
  end
13
6
  end
14
7
  end
@@ -3,10 +3,11 @@ module Sappy
3
3
  class SummaryStatistics < Response
4
4
  attr_reader :up, :down, :inactive
5
5
 
6
- def success(hash)
7
- hash["summarystatistics"].first.each do |stat,value|
8
- instance_variable_set("@#{stat}", value.to_i)
9
- end
6
+ def success
7
+ node = first_xpath('//summarystatistics')
8
+ @up = node['up'].to_i
9
+ @down = node['down'].to_i
10
+ @inactive = node['inactive'].to_i
10
11
  end
11
12
  end
12
13
  end
@@ -1,2 +1,3 @@
1
1
  USERNAME = "sappy@siteuptime.com"
2
2
  PASSWORD = "password"
3
+ MONITOR_LIMIT = (ENV['SITEUPTIME_MONITOR_LIMIT'] || 1).to_i
@@ -1,21 +1,18 @@
1
- require File.dirname(__FILE__) + '/../helper'
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
3
  module Sappy
4
4
  describe Account do
5
5
  describe "with incorrect credentials" do
6
6
  it "raises an error" do
7
7
  lambda { Account.login("invalid@email.com", "password") }.
8
- should.raise(Responses::Auth::LoginFailed).
9
- message.should.match(/Wrong email or password/)
8
+ should raise_error(Responses::Auth::LoginFailed, 'Wrong email or password')
10
9
  end
11
10
  end
12
11
 
13
12
  describe "with correct credentials" do
14
13
  before do
15
14
  @account = Account.login(USERNAME, PASSWORD)
16
- end
17
-
18
- before do
15
+
19
16
  @account.monitors.each do |m|
20
17
  m.destroy
21
18
  end
@@ -23,7 +20,7 @@ module Sappy
23
20
 
24
21
  it "should obtain an auth key" do
25
22
  if ENV['LIVE_SPECS']
26
- @account.authkey.should.be.kind_of(String)
23
+ @account.authkey.should be_a_kind_of(String)
27
24
  else
28
25
  @account.authkey.should == "b7kks5mh1l300v5segaksm8gh3"
29
26
  end
@@ -44,11 +41,11 @@ module Sappy
44
41
 
45
42
  it "can create a new monitor" do
46
43
  monitor = @account.add_monitor({:name => "New Monitor", :service => "http", :location => "sf", :host => "engineyard.com", :period => "60"})
47
- monitor.id.should.not.be.nil
48
- if ENV['LIVE_SPECS']
49
- @account.available_monitors.should == 2
44
+ monitor.id.should_not be_nil
45
+ unless mocked?
46
+ @account.available_monitors.should == MONITOR_LIMIT
50
47
  else
51
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.monitors", :response => cached_page('monitors_1'))
48
+ FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.monitors", :response => cached_page("monitors_#{MONITOR_LIMIT}"))
52
49
  end
53
50
  monitors = @account.monitors
54
51
  monitors.size.should == 1
@@ -0,0 +1,73 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Sappy
4
+ describe Monitor do
5
+ before do
6
+ @account = Account.login(USERNAME, PASSWORD)
7
+ end
8
+
9
+ before do
10
+ @account.monitors.each { |m| m.destroy }
11
+ @monitor = @account.add_monitor(:name => "New Monitor", :service => "http", :location => "sf", :host => "engineyard.com", :period => "60")
12
+ end
13
+
14
+ describe "an active monitor" do
15
+ before do
16
+ @monitor.enable!
17
+ end
18
+
19
+ it "can be disabled" do
20
+ @monitor.disable!
21
+ @monitor.should be_disabled
22
+ end
23
+ end
24
+
25
+ describe "an inactive monitor" do
26
+ before do
27
+ @monitor.disable!
28
+ end
29
+
30
+ it "can be enabled" do
31
+ @monitor.enable!
32
+ @monitor.should be_enabled
33
+ end
34
+ end
35
+
36
+ describe "a monitor" do
37
+ it "can be destroyed" do
38
+ if mocked?
39
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.monitors", :response => cached_page('monitors_1'))
40
+ end
41
+ @account.monitors.size.should == 1
42
+ lambda { @monitor.destroy }.should_not raise_error #TODO
43
+ if mocked?
44
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.monitors", :response => cached_page('monitors'))
45
+ end
46
+ @account.monitors.size.should == 0
47
+ end
48
+
49
+ describe "statistics" do
50
+ before do
51
+ if mocked?
52
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&Month=11&method=siteuptime.dailystatistics&Day=28&Year=2006&MonitorId=84043", :response => cached_page('dailystatistics'))
53
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&Month=6&method=siteuptime.monthlystatistics&Year=2007&MonitorId=84043", :response => cached_page('monthlystatistics'))
54
+ FakeWeb.register_uri(:get, "#{api_url}?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_an_instance_of(Statistics::Daily)
61
+ end
62
+
63
+ it "should provide monthly" do
64
+ @monitor.monthly_statistics(2007, 6).should be_an_instance_of(Statistics::Monthly)
65
+ end
66
+
67
+ it "should provide annual" do
68
+ @monitor.annual_statistics.should be_an_instance_of(Statistics::Annual)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,45 @@
1
+ Bundler.require_env(:test)
2
+ require 'cgi'
3
+
4
+ ENV['LIVE_SPECS'] ||= 'false'
5
+
6
+ require File.dirname(__FILE__) + '/../lib/sappy'
7
+
8
+ begin
9
+ require File.dirname(__FILE__) + '/credentials.rb'
10
+ rescue LoadError
11
+ raise "add a spec/credentials.rb that defines USERNAME and PASSWORD constants"
12
+ end
13
+
14
+ Spec::Runner.configure do |config|
15
+ def cached_page(name)
16
+ file = File.dirname(__FILE__) + "/xml/#{name}.xml"
17
+ File.exist?(file) ? file : fail("Unable to find #{file}")
18
+ end
19
+
20
+ def api_url
21
+ 'https://siteuptime.com/api/rest/'
22
+ end
23
+
24
+ def mocked?
25
+ ENV['LIVE_SPECS'] == 'false'
26
+ end
27
+ config.before(:each) do
28
+ if mocked?
29
+ FakeWeb.allow_net_connect = false
30
+ FakeWeb.clean_registry
31
+ FakeWeb.register_uri(:get, "#{api_url}?method=siteuptime.auth&Password=#{PASSWORD}&Email=#{CGI.escape USERNAME}", :response => cached_page('valid_account'))
32
+ FakeWeb.register_uri(:get, "#{api_url}?method=siteuptime.auth&Password=password&Email=invalid%40email.com", :response => cached_page('invalid_account'))
33
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.accountinfo", :response => cached_page('accountinfo'))
34
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.summarystatistics", :response => cached_page('summarystatistics'))
35
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.monitors", :response => cached_page('monitors'))
36
+ FakeWeb.register_uri(:get, "#{api_url}?AddToStatusPage=&AltEmailAlerts=&AuthKey=b7kks5mh1l300v5segaksm8gh3&CheckPeriod=60&Content=&Domain=&DontSendUpAlert=&DownSubject=&EnablePublicStatistics=&Enabled=&HostName=engineyard.com&IP=&Location=sf&Login=&Name=New+Monitor&Password=&PortNumber=&SendAlertAfter=&SendAllDownAlerts=&SendJabberAlert=&SendSms=&SendUrlAlert=&Service=http&Timeout=&UpSubject=&method=siteuptime.addmonitor", :response => cached_page('addmonitor'))
37
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.enablemonitor&MonitorId=84043", :response => cached_page('enablemonitor'))
38
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.disablemonitor&MonitorId=84043", :response => cached_page('disablemonitor'))
39
+ FakeWeb.register_uri(:get, "#{api_url}?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.removemonitor&MonitorId=84043", :response => cached_page('removemonitor'))
40
+ end
41
+ Sappy::Account.login(USERNAME, PASSWORD).monitors.each do |m|
42
+ m.destroy
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:09:43 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 135
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <accountinfo setupmonitors="" availablemonitors="3" smsalerts="0"/>
15
+ </rsp>
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:34:36 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 136
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <accountinfo setupmonitors="1" availablemonitors="2" smsalerts="0"/>
15
+ </rsp>
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:19:02 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 89
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <monitor id="84043"/>
15
+ </rsp>
@@ -0,0 +1,16 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Tue, 06 Oct 2009 22:36:07 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 176
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <monthlystats total="0" timezone="PST+10.0" numchecks="0" numfailures="0" uptime="n/a">
15
+ </monthlystats>
16
+ </rsp>
@@ -0,0 +1,16 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Tue, 06 Oct 2009 22:35:48 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 165
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <checks total="0" timezone="PST+10.0" numchecks="0" numfailures="0" uptime="n/a">
15
+ </checks>
16
+ </rsp>
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:23:19 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 55
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok"/>
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:24:51 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 55
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok"/>
@@ -0,0 +1,12 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:00:31 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Content-Length: 126
6
+ Connection: close
7
+ Content-Type: text/xml
8
+
9
+ <?xml version="1.0" encoding="utf-8"?>
10
+ <rsp stat="fail">
11
+ <err code="WRONG_DATA" msg="Wrong email or password" />
12
+ </rsp>
@@ -0,0 +1,16 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:16:46 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 101
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <monitors total="0">
15
+ </monitors>
16
+ </rsp>
@@ -0,0 +1,17 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:29:31 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 465
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <monitors total="1">
15
+ <monitor id="84043" active="no" name="New Monitor" host="new-sf-monitor.com" service="http" port="0" period="60" location="sf" timeout="25" downsubject="" upsubject="" altemailalerts="" sendalertafter="1" dontsendupalert="no" sendurlalert="no" sendjabberalert="no" sendalldownalerts="no" enablepublicstatistics="no" addtostatuspage="no" current_status="n/a"/>
16
+ </monitors>
17
+ </rsp>
@@ -0,0 +1,17 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:29:31 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 465
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <monitors total="1">
15
+ <monitor id="84043" active="no" name="New Monitor" host="new-sf-monitor.com" service="http" port="0" period="60" location="sf" timeout="25" downsubject="" upsubject="" altemailalerts="" sendalertafter="1" dontsendupalert="no" sendurlalert="no" sendjabberalert="no" sendalldownalerts="no" enablepublicstatistics="no" addtostatuspage="no" current_status="n/a"/>
16
+ </monitors>
17
+ </rsp>
@@ -0,0 +1,16 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Tue, 06 Oct 2009 22:35:16 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 195
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <dailystats year="2009" month="10" total="0" timezone="PST+10.0" numchecks="0" numfailures="0" uptime="n/a">
15
+ </dailystats>
16
+ </rsp>
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:26:12 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 55
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok"/>
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:15:44 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 116
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <summarystatistics up="0" down="0" inactive="0"/>
15
+ </rsp>
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 24 Aug 2009 05:00:02 GMT
3
+ Server: Apache/2.2.3 (Red Hat)
4
+ X-Powered-By: PHP/5.1.6
5
+ Expires: Thu, 19 Nov 1981 08:52:00 GMT
6
+ Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
7
+ Pragma: no-cache
8
+ Content-Length: 110
9
+ Connection: close
10
+ Content-Type: text/xml
11
+
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <rsp stat="ok">
14
+ <session key="b7kks5mh1l300v5segaksm8gh3"/>
15
+ </rsp>
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.4
4
+ version: 0.1.5
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-11 00:00:00 +11:00
13
+ date: 2009-12-07 00:00:00 -08:00
14
14
  default_executable: shell
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -29,19 +29,19 @@ dependencies:
29
29
  version_requirement:
30
30
  version_requirements: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "="
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
34
  version: 1.0.3
35
35
  version:
36
36
  - !ruby/object:Gem::Dependency
37
- name: xml-simple
37
+ name: nokogiri
38
38
  type: :runtime
39
39
  version_requirement:
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - "="
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 1.0.12
44
+ version: "0"
45
45
  version:
46
46
  description: A wrapper for the SiteUptime API
47
47
  email:
@@ -72,7 +72,6 @@ files:
72
72
  - lib/sappy/responses/disable_monitor.rb
73
73
  - lib/sappy/responses/edit_monitor.rb
74
74
  - lib/sappy/responses/enable_monitor.rb
75
- - lib/sappy/responses/error.rb
76
75
  - lib/sappy/responses/monitors.rb
77
76
  - lib/sappy/responses/monthly_statistics.rb
78
77
  - lib/sappy/responses/remove_monitor.rb
@@ -81,6 +80,25 @@ files:
81
80
  - lib/sappy/statistics/annual.rb
82
81
  - lib/sappy/statistics/daily.rb
83
82
  - lib/sappy/statistics/monthly.rb
83
+ - spec/credentials.integrity.rb
84
+ - spec/sappy/account_spec.rb
85
+ - spec/sappy/monitor_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/xml/accountinfo.xml
88
+ - spec/xml/accountinfo_1.xml
89
+ - spec/xml/addmonitor.xml
90
+ - spec/xml/annualstatistics.xml
91
+ - spec/xml/dailystatistics.xml
92
+ - spec/xml/disablemonitor.xml
93
+ - spec/xml/enablemonitor.xml
94
+ - spec/xml/invalid_account.xml
95
+ - spec/xml/monitors.xml
96
+ - spec/xml/monitors_1.xml
97
+ - spec/xml/monitors_12.xml
98
+ - spec/xml/monthlystatistics.xml
99
+ - spec/xml/removemonitor.xml
100
+ - spec/xml/summarystatistics.xml
101
+ - spec/xml/valid_account.xml
84
102
  - README.md
85
103
  has_rdoc: true
86
104
  homepage: http://github.com/abcde/sappy
@@ -112,6 +130,6 @@ specification_version: 3
112
130
  summary: Wrapping that shit!
113
131
  test_files:
114
132
  - spec/credentials.integrity.rb
115
- - spec/helper.rb
116
- - spec/sappy/account_bacon.rb
117
- - spec/sappy/monitor_bacon.rb
133
+ - spec/sappy/account_spec.rb
134
+ - spec/sappy/monitor_spec.rb
135
+ - spec/spec_helper.rb
@@ -1,22 +0,0 @@
1
- module Sappy
2
- module Responses
3
- class ErrorResponse
4
- class Error < StandardError; end
5
- class AuthenticationError < Error; end
6
-
7
- def initialize(xml)
8
- err = xml["err"]
9
- message = err.first["msg"]
10
-
11
- case code = err.first["code"]
12
- when "AUTH_EXPIRED"
13
- raise AuthenticationExpired, message
14
- when "AUTH_ERR"
15
- raise AuthenticationError, message
16
- else
17
- raise Error, "Unknown error[#{code}]: #{message}"
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,38 +0,0 @@
1
- require File.dirname(__FILE__) + '/../tmp/vendor/environment'
2
- Bundler.require_env(:test)
3
- require 'cgi'
4
-
5
- require File.dirname(__FILE__) + '/../lib/sappy'
6
- begin
7
- require File.dirname(__FILE__) + '/credentials.rb'
8
- rescue LoadError
9
- raise "add a spec/credentials.rb that defines USERNAME and PASSWORD constants"
10
- end
11
-
12
- SPEC_DIR = File.dirname(__FILE__) unless defined? SPEC_DIR
13
- $:<< SPEC_DIR
14
-
15
- def cached_page(name)
16
- SPEC_DIR + "/xml/#{name}.xml"
17
- end
18
-
19
- unless ENV['LIVE_SPECS']
20
- # Don't allow real web requests
21
- FakeWeb.allow_net_connect = false
22
-
23
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?method=siteuptime.auth&Password=#{PASSWORD}&Email=#{CGI.escape USERNAME}", :response => cached_page('valid_account'))
24
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?method=siteuptime.auth&Password=password&Email=invalid%40email.com", :response => cached_page('invalid_account'))
25
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.accountinfo", :response => cached_page('accountinfo'))
26
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.summarystatistics", :response => cached_page('summarystatistics'))
27
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.monitors", :response => cached_page('monitors'))
28
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AddToStatusPage=&AltEmailAlerts=&AuthKey=b7kks5mh1l300v5segaksm8gh3&CheckPeriod=60&Content=&Domain=&DontSendUpAlert=&DownSubject=&EnablePublicStatistics=&Enabled=&HostName=engineyard.com&IP=&Location=sf&Login=&Name=New+Monitor&Password=&PortNumber=&SendAlertAfter=&SendAllDownAlerts=&SendJabberAlert=&SendSms=&SendUrlAlert=&Service=http&Timeout=&UpSubject=&method=siteuptime.addmonitor", :response => cached_page('addmonitor'))
29
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.enablemonitor&MonitorId=84043", :response => cached_page('enablemonitor'))
30
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.disablemonitor&MonitorId=84043", :response => cached_page('disablemonitor'))
31
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.removemonitor&MonitorId=84043", :response => cached_page('removemonitor'))
32
- end
33
-
34
- at_exit do
35
- Sappy::Account.login(USERNAME, PASSWORD).monitors.each do |m|
36
- m.destroy
37
- end
38
- end
@@ -1,73 +0,0 @@
1
- require File.dirname(__FILE__) + '/../helper'
2
-
3
- module Sappy
4
- describe Monitor do
5
- before do
6
- @account = Account.login(USERNAME, PASSWORD)
7
- end
8
-
9
- before do
10
- @account.monitors.each { |m| m.destroy }
11
- @monitor = @account.add_monitor({:name => "New Monitor", :service => "http", :location => "sf", :host => "engineyard.com", :period => "60"})
12
- end
13
-
14
- describe "an active monitor" do
15
- before do
16
- @monitor.enable!
17
- end
18
-
19
- it "can be disabled" do
20
- @monitor.disable!
21
- @monitor.should.not.be.active
22
- end
23
- end
24
-
25
- describe "an inactive monitor" do
26
- before do
27
- @monitor.disable!
28
- end
29
-
30
- it "can be enabled" do
31
- @monitor.enable!
32
- @monitor.should.be.active
33
- end
34
- end
35
-
36
- describe "a monitor" do
37
- it "can be destroyed" do
38
- unless ENV['LIVE_SPECS']
39
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.monitors", :response => cached_page('monitors_1'))
40
- end
41
- @account.monitors.size.should == 1
42
- lambda { @monitor.destroy }.should.not.raise
43
- unless ENV['LIVE_SPECS']
44
- FakeWeb.register_uri(:get, "https://siteuptime.com/api/rest/?AuthKey=b7kks5mh1l300v5segaksm8gh3&method=siteuptime.monitors", :response => cached_page('monitors'))
45
- end
46
- @account.monitors.size.should == 0
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
-
63
- it "should provide monthly" do
64
- @monitor.monthly_statistics(2007, 6).should.be.instance_of Statistics::Monthly
65
- end
66
-
67
- it "should provide annual" do
68
- @monitor.annual_statistics.should.be.instance_of Statistics::Annual
69
- end
70
- end
71
- end
72
- end
73
- end