rappfirst 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  config.*
2
2
  spec/fixtures/**
3
3
  Gemfile.lock
4
+ *.gem
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/README.md CHANGED
@@ -1,24 +1,123 @@
1
1
  # Rappfirst
2
2
 
3
- TODO: Write a gem description
3
+ A ruby wrapper for the Appfirst API v3. Currently implementing the `/servers/` endpoint. As this is still in beta several parameters are not fully implemented.
4
+
5
+ **Implemented**
6
+ * `/servers/`
7
+ * `/servers/{id}`
8
+ * `/servers/{id}/tags`
9
+ * `/servers/{id}/polled_data_config`
10
+ * `/servers/{id}/outages`
11
+
12
+ **TODO**
13
+ * `/servers/{id}/data`
14
+ * `/servers/{id}/processes`
15
+ * `/servers/{id}/auto_detection`
4
16
 
5
17
  ## Installation
6
18
 
7
19
  Add this line to your application's Gemfile:
8
20
 
9
- gem 'rappfirst'
21
+ ```ruby
22
+ gem 'rappfirst'
23
+ ```
10
24
 
11
25
  And then execute:
12
26
 
13
- $ bundle
27
+ ```bash
28
+ $ bundle
29
+ ```
14
30
 
15
31
  Or install it yourself as:
16
32
 
17
- $ gem install rappfirst
33
+ ```bash
34
+ $ gem install rappfirst
35
+ ```
18
36
 
19
37
  ## Usage
20
38
 
21
- TODO: Write usage instructions here
39
+ All contact with the API starts with connecting via the Client.
40
+ ```ruby
41
+ include 'rappfirst'
42
+ c = Rappfirst::Client.new(username="user@example.com", api_key="1234567890")
43
+ ```
44
+
45
+ Get an array of Server Objects
46
+ ```ruby
47
+ servers = c.servers
48
+ ```
49
+
50
+ Or query for a single server by hostname
51
+ ```ruby
52
+ my_server = c.servers(query_string="?hostname=my-server")
53
+ ```
54
+
55
+ If you know the id, you can just get the server object directly
56
+ ```ruby
57
+ my_first_server = c.server('1')
58
+ ```
59
+
60
+ Once you have a Server Object, it's attributes are immediately accessible
61
+ ```ruby
62
+ my_server.id
63
+ my_server.architecture
64
+ my_server.hostname
65
+ ...
66
+ ```
67
+
68
+ The attributes are a Server Object are read only, except for `nickname` and `description`
69
+ ```ruby
70
+ my_server.id = 2 # Fails
71
+
72
+ my_server.description = "Just an example server"
73
+ # Setting these back on the server is not implemented yet as of 0.1.0
74
+ ```
75
+
76
+ Grab some outage info
77
+ ```ruby
78
+ my_server.outages
79
+ ```
80
+
81
+ Refresh your outage info
82
+ ```ruby
83
+ my_server.outages(refresh=true)
84
+ ```
85
+
86
+ Check out the tags
87
+ ```ruby
88
+ my_server.tags
89
+ my_server.tags(refresh=true)
90
+ ```
91
+
92
+ Set some new tags
93
+ ```ruby
94
+ my_server.tags = ["Prod", "Web"]
95
+ # Setting these back on the server is not implemented yet as of 0.1.0
96
+ ```
97
+
98
+ Get your `polled_data_config`. We can't set the polled data config yet due to some API issues. =(
99
+ ```ruby
100
+ my_server.polled_data_config
101
+ ```
102
+
103
+ Delete your server. This will send the API call, but currently does not modify your local copy of the object.
104
+ ```ruby
105
+ my_server.delete
106
+ ```
107
+
108
+ All information should be cached locally after the first request or object creation.
109
+ ```ruby
110
+ # Cached on creation
111
+ my_server.id
112
+ my_server.hostname
113
+ my_server.architecture
114
+ ...
115
+
116
+ # Cached on method call
117
+ my_server.outages
118
+ my_server.polled_data_config
119
+ my_server.tags
120
+ ```
22
121
 
23
122
  ## Contributing
24
123
 
@@ -27,3 +126,5 @@ TODO: Write usage instructions here
27
126
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
127
  4. Push to the branch (`git push origin my-new-feature`)
29
128
  5. Create new Pull Request
129
+
130
+ NOTE: Since I haven't had a chance to create a 'clean' set of fixtures, I have not committed the fixture data. Therefore tests will reference server id's and hostnames that will not exist in your environment. You will need to fix these to get the tests passing. I should have a set of clean fixtures added soon.
data/Rakefile CHANGED
@@ -1,8 +1,21 @@
1
1
  require 'rake/testtask'
2
-
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Immediately sync all stdout so that tools like buildbot can
5
+ # immediately load in the output.
6
+ $stdout.sync = true
7
+ $stderr.sync = true
8
+
9
+ # Change to the directory of this file.
10
+ Dir.chdir(File.expand_path("../", __FILE__))
11
+
12
+ # This installs the tasks that help with gem creation and
13
+ # publishing.
14
+ Bundler::GemHelper.install_tasks
15
+
3
16
  Rake::TestTask.new do |t|
4
17
  t.test_files = FileList['spec/lib/rappfirst/*_spec.rb']
5
18
  t.verbose = true
6
19
  end
7
-
20
+
8
21
  task :default => :test
@@ -0,0 +1,81 @@
1
+ module Rappfirst
2
+ class Alert
3
+
4
+ include HTTParty
5
+ format :json
6
+
7
+ attr_accessor :id
8
+
9
+ def initialize(id, api_options=nil, json_data=nil)
10
+ if api_options && api_options.keys.include?(:basic_auth)
11
+ username = api_options[:basic_auth][:username]
12
+ api_key = api_options[:basic_auth][:password]
13
+ else
14
+ username = get_config('username')
15
+ api_key = get_config('password')
16
+ end
17
+
18
+ if api_options && api_options.keys.include?(:basic_uri)
19
+ base_uri = api_options[:base_uri]
20
+ else
21
+ base_uri = 'https://wwws.appfirst.com/api/v3'
22
+ end
23
+
24
+ self.class.basic_auth username, api_key
25
+ self.class.base_uri base_uri
26
+
27
+ self.id = id
28
+ set_attributes(json_data=json_data)
29
+ end
30
+
31
+ def delete
32
+ delete_self
33
+ end
34
+
35
+ private
36
+
37
+ def delete_self
38
+ response = self.class.delete("/alerts/#{self.id}/")
39
+ unless response.code == 200
40
+ raise "Unable to delete server, received HTTP code #{response.code}"
41
+ end
42
+ end
43
+
44
+ def set_attributes(json_data=nil)
45
+ if not json_data
46
+ response = get_attributes
47
+ else
48
+ response = json_data
49
+ end
50
+ response.each do |name, v|
51
+ create_method( "#{name}=".to_sym ) { |val|
52
+ if ! instance_variable_get("@" + name)
53
+ instance_variable_set("@" + name, val)
54
+ elsif self.writeable?(name) && instance_variable_get("@" + name)
55
+ instance_variable_set("@" + name, val)
56
+ end
57
+ }
58
+
59
+ create_method( name.to_sym ) {
60
+ instance_variable_get("@" + name)
61
+ }
62
+
63
+ instance_variable_set("@" + name, v)
64
+ end
65
+ end
66
+
67
+ def get_attributes
68
+ return self.class.get("/alerts/#{self.id}/")
69
+ end
70
+
71
+ def create_method(name, &block)
72
+ self.class.send(:define_method, name, &block)
73
+ end
74
+
75
+ def get_config(key)
76
+ config = YAML::load( File.open('config.yml'))
77
+ return config[key]
78
+ end
79
+
80
+ end
81
+ end
@@ -15,7 +15,7 @@ module Rappfirst
15
15
 
16
16
  def servers(query_string=nil)
17
17
  response = get_servers(query_string)
18
- if response.length == 1
18
+ if response.length == 1 && query_string
19
19
  return server(response.first['id'])
20
20
  else
21
21
  s = Array.new
@@ -31,6 +31,20 @@ module Rappfirst
31
31
  Rappfirst::Server.new(id, api_options=api_options)
32
32
  end
33
33
 
34
+ def alerts
35
+ response = get_alerts
36
+ alerts = Array.new
37
+ response.each do |r|
38
+ alerts << alert(r['id'], json_data=r)
39
+ end
40
+ return alerts
41
+ end
42
+
43
+ def alert(id, json_data=nil)
44
+ api_options = self.class.default_options
45
+ Rappfirst::Alert.new(id, api_options=api_options, json_data=json_data)
46
+ end
47
+
34
48
  private
35
49
 
36
50
  def get_servers(query_string=nil)
@@ -40,5 +54,9 @@ module Rappfirst
40
54
  self.class.get("/servers/#{query_string}")
41
55
  end
42
56
 
57
+ def get_alerts
58
+ self.class.get("/alerts/")
59
+ end
60
+
43
61
  end
44
62
  end
@@ -12,7 +12,7 @@ module Rappfirst
12
12
  def initialize(id, api_options=nil)
13
13
  if api_options && api_options.keys.include?(:basic_auth)
14
14
  username = api_options[:basic_auth][:username]
15
- api_key = api_options[:basic_auth][:api_key]
15
+ api_key = api_options[:basic_auth][:password]
16
16
  else
17
17
  username = get_config('username')
18
18
  api_key = get_config('password')
@@ -79,7 +79,7 @@ module Rappfirst
79
79
  def set_attributes
80
80
  response = get_attributes
81
81
  response.each do |name, v|
82
- create_method( "#{name}=".to_sym ) { |val|
82
+ create_method( "#{name}=".to_sym ) { |val|
83
83
  if ! instance_variable_get("@" + name)
84
84
  instance_variable_set("@" + name, val)
85
85
  elsif self.writeable?(name) && instance_variable_get("@" + name)
@@ -87,8 +87,8 @@ module Rappfirst
87
87
  end
88
88
  }
89
89
 
90
- create_method( name.to_sym ) {
91
- instance_variable_get("@" + name)
90
+ create_method( name.to_sym ) {
91
+ instance_variable_get("@" + name)
92
92
  }
93
93
 
94
94
  instance_variable_set("@" + name, v)
@@ -1,3 +1,3 @@
1
1
  module Rappfirst
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,91 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe Rappfirst::Alert do
4
+
5
+ describe "default attributes" do
6
+
7
+ let(:alert) { Rappfirst::Alert.new('114140') }
8
+
9
+ before do
10
+ VCR.insert_cassette 'single_alert', :record => :new_episodes
11
+ end
12
+
13
+ after do
14
+ VCR.eject_cassette
15
+ end
16
+
17
+ it "must include httparty methods" do
18
+ Rappfirst::Alert.must_include HTTParty
19
+ end
20
+
21
+ it "must have the base url set to the Appfirst API" do
22
+ alert.class.base_uri.must_equal 'https://wwws.appfirst.com/api/v3'
23
+ end
24
+
25
+ it "must have API Credentials" do
26
+ alert.class.default_options[:basic_auth].keys.must_include(:username)
27
+ alert.class.default_options[:basic_auth].keys.must_include(:password)
28
+ end
29
+
30
+ end
31
+
32
+
33
+ describe "attributes" do
34
+
35
+ let(:alert) { Rappfirst::Alert.new('114140') }
36
+
37
+ before do
38
+ VCR.insert_cassette 'single_alert', :record => :new_episodes
39
+ end
40
+
41
+ after do
42
+ VCR.eject_cassette
43
+ end
44
+
45
+ describe "retrieve and create methods" do
46
+
47
+ it "must populate the target attribute" do
48
+ alert.must_respond_to :target
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ describe "delete alert" do
56
+
57
+ let(:alert) { Rappfirst::Alert.new('114140') }
58
+
59
+ before do
60
+ VCR.insert_cassette 'single_alert', :record => :new_episodes
61
+ end
62
+
63
+ after do
64
+ VCR.eject_cassette
65
+ end
66
+
67
+ describe "signature" do
68
+
69
+ it "must have a deletion method" do
70
+ alert.must_respond_to :delete
71
+ end
72
+
73
+ end
74
+
75
+ describe "failed deletion" do
76
+
77
+ before do
78
+ stub_request(:any, /wwws.appfirst.com/).
79
+ to_return(:status => [500, "Internal Server Error"])
80
+ end
81
+
82
+ it "must delete itself" do
83
+ lambda { alert.delete }.must_raise RuntimeError
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+
90
+
91
+ end
@@ -1,19 +1,19 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
3
  describe Rappfirst::Client do
4
-
4
+
5
5
  describe "default attributes" do
6
-
6
+
7
7
  it "must include httparty methods" do
8
8
  Rappfirst::Client.must_include HTTParty
9
9
  end
10
-
10
+
11
11
  it "must have the base url set to the Appfirst API" do
12
12
  Rappfirst::Client.
13
13
  instance_variable_get("@default_options")[:base_uri].
14
14
  must_equal 'https://wwws.appfirst.com/api/v3'
15
15
  end
16
-
16
+
17
17
  it "must have API Credentials" do
18
18
  Rappfirst::Client.
19
19
  instance_variable_get("@default_options")[:basic_auth].
@@ -21,9 +21,9 @@ describe Rappfirst::Client do
21
21
  end
22
22
 
23
23
  end
24
-
24
+
25
25
  describe "GET servers" do
26
-
26
+
27
27
  let(:client) { Rappfirst::Client.new }
28
28
 
29
29
  describe "Get all servers" do
@@ -31,18 +31,14 @@ describe Rappfirst::Client do
31
31
  before do
32
32
  VCR.insert_cassette 'servers', :record => :new_episodes
33
33
  end
34
-
34
+
35
35
  after do
36
36
  VCR.eject_cassette
37
37
  end
38
-
38
+
39
39
  it "must have a servers method" do
40
40
  client.must_respond_to :servers
41
41
  end
42
-
43
- it "must parse the api response from JSON to Hash" do
44
- client.servers.must_be_instance_of Array
45
- end
46
42
 
47
43
  it "should return an array of server objects" do
48
44
  client.servers.each { |s| s.must_be_instance_of Rappfirst::Server}
@@ -51,11 +47,11 @@ describe Rappfirst::Client do
51
47
  end
52
48
 
53
49
  describe "Get specific server" do
54
-
50
+
55
51
  before do
56
52
  VCR.insert_cassette 'search_for_server', :record => :new_episodes
57
53
  end
58
-
54
+
59
55
  after do
60
56
  VCR.eject_cassette
61
57
  end
@@ -75,7 +71,7 @@ describe Rappfirst::Client do
75
71
  end
76
72
 
77
73
  describe "Query single server" do
78
-
74
+
79
75
  let(:client) { Rappfirst::Client.new }
80
76
 
81
77
  before do
@@ -96,4 +92,53 @@ describe Rappfirst::Client do
96
92
 
97
93
  end
98
94
 
95
+ describe "Get single alert" do
96
+
97
+ let(:client) { Rappfirst::Client.new }
98
+
99
+
100
+ before do
101
+ VCR.insert_cassette 'single_alert', :record => :new_episodes
102
+ end
103
+
104
+ after do
105
+ VCR.eject_cassette
106
+ end
107
+
108
+ it "must have an alerts method" do
109
+ client.must_respond_to :alert
110
+ end
111
+
112
+ it "must return an alert object" do
113
+ client.alert('114140').must_be_instance_of Rappfirst::Alert
114
+ end
115
+
116
+ end
117
+
118
+ describe "GET alerts" do
119
+
120
+ let(:client) { Rappfirst::Client.new }
121
+
122
+ describe "Get all alerts" do
123
+
124
+ before do
125
+ VCR.insert_cassette 'alerts', :record => :new_episodes
126
+ end
127
+
128
+ after do
129
+ VCR.eject_cassette
130
+ end
131
+
132
+ it "must have an alerts method" do
133
+ client.must_respond_to :alerts
134
+ end
135
+
136
+ it "should return an array of alert objects" do
137
+ client.alerts.each { |s| s.must_be_instance_of Rappfirst::Alert}
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
99
144
  end
@@ -1,29 +1,35 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
3
  describe Rappfirst::Server do
4
-
4
+
5
5
  describe "default attributes" do
6
6
 
7
+ let(:server) { Rappfirst::Server.new('11743') }
8
+
9
+ before do
10
+ VCR.insert_cassette 'server', :record => :new_episodes
11
+ end
12
+
13
+ after do
14
+ VCR.eject_cassette
15
+ end
16
+
7
17
  it "must include httparty methods" do
8
18
  Rappfirst::Server.must_include HTTParty
9
19
  end
10
-
20
+
11
21
  it "must have the base url set to the Appfirst API" do
12
- Rappfirst::Server.
13
- instance_variable_get("@default_options")[:base_uri].
14
- must_equal 'https://wwws.appfirst.com/api/v3'
22
+ server.class.base_uri.must_equal 'https://wwws.appfirst.com/api/v3'
15
23
  end
16
-
24
+
17
25
  it "must have API Credentials" do
18
- Rappfirst::Client.
19
- instance_variable_get("@default_options")[:basic_auth].
20
- keys.must_include(:username)
26
+ server.class.default_options[:basic_auth].keys.must_include(:username)
27
+ server.class.default_options[:basic_auth].keys.must_include(:password)
21
28
  end
22
29
 
23
30
  end
24
31
 
25
32
 
26
-
27
33
  describe "attributes" do
28
34
 
29
35
  let(:server) { Rappfirst::Server.new('11743') }
@@ -31,7 +37,7 @@ describe Rappfirst::Server do
31
37
  before do
32
38
  VCR.insert_cassette 'server', :record => :new_episodes
33
39
  end
34
-
40
+
35
41
  after do
36
42
  VCR.eject_cassette
37
43
  end
@@ -85,7 +91,7 @@ describe Rappfirst::Server do
85
91
  before do
86
92
  VCR.insert_cassette 'server', :record => :new_episodes
87
93
  end
88
-
94
+
89
95
  after do
90
96
  VCR.eject_cassette
91
97
  end
@@ -114,7 +120,7 @@ describe Rappfirst::Server do
114
120
  new_data = current_data.clone
115
121
  new_data['frequency'] = 600
116
122
  server.polled_data = new_data
117
- server.polled_data(refresh=true)['frequency'].wont_equal current_data['frequency']
123
+ server.polled_data(refresh=true)['frequency'].wont_equal current_data['frequency']
118
124
  end
119
125
 
120
126
  before do
@@ -131,13 +137,13 @@ describe Rappfirst::Server do
131
137
 
132
138
 
133
139
  describe "outages" do
134
-
140
+
135
141
  let(:server) { Rappfirst::Server.new('11743') }
136
142
 
137
143
  before do
138
144
  VCR.insert_cassette 'server', :record => :new_episodes
139
145
  end
140
-
146
+
141
147
  after do
142
148
  VCR.eject_cassette
143
149
  end
@@ -178,7 +184,7 @@ describe Rappfirst::Server do
178
184
  before do
179
185
  VCR.insert_cassette 'server', :record => :new_episodes
180
186
  end
181
-
187
+
182
188
  after do
183
189
  VCR.eject_cassette
184
190
  end
@@ -217,13 +223,13 @@ describe Rappfirst::Server do
217
223
  before do
218
224
  VCR.insert_cassette 'server', :record => :new_episodes
219
225
  end
220
-
226
+
221
227
  after do
222
228
  VCR.eject_cassette
223
229
  end
224
230
 
225
231
  describe "signature" do
226
-
232
+
227
233
  it "must have a deletion method" do
228
234
  server.must_respond_to :delete
229
235
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rappfirst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -120,10 +120,12 @@ files:
120
120
  - README.md
121
121
  - Rakefile
122
122
  - lib/rappfirst.rb
123
+ - lib/rappfirst/alert.rb
123
124
  - lib/rappfirst/client.rb
124
125
  - lib/rappfirst/server.rb
125
126
  - lib/rappfirst/version.rb
126
127
  - rappfirst.gemspec
128
+ - spec/lib/rappfirst/alert_spec.rb
127
129
  - spec/lib/rappfirst/client_spec.rb
128
130
  - spec/lib/rappfirst/server_spec.rb
129
131
  - spec/spec_helper.rb
@@ -139,12 +141,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
141
  - - ! '>='
140
142
  - !ruby/object:Gem::Version
141
143
  version: '0'
144
+ segments:
145
+ - 0
146
+ hash: -2428925126903701848
142
147
  required_rubygems_version: !ruby/object:Gem::Requirement
143
148
  none: false
144
149
  requirements:
145
150
  - - ! '>='
146
151
  - !ruby/object:Gem::Version
147
152
  version: '0'
153
+ segments:
154
+ - 0
155
+ hash: -2428925126903701848
148
156
  requirements: []
149
157
  rubyforge_project:
150
158
  rubygems_version: 1.8.23
@@ -152,6 +160,7 @@ signing_key:
152
160
  specification_version: 3
153
161
  summary: Appfirst API v3 Wrapper
154
162
  test_files:
163
+ - spec/lib/rappfirst/alert_spec.rb
155
164
  - spec/lib/rappfirst/client_spec.rb
156
165
  - spec/lib/rappfirst/server_spec.rb
157
166
  - spec/spec_helper.rb