tdev_metrics 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/Guardfile +24 -0
- data/LICENSE +22 -0
- data/README.md +91 -0
- data/Rakefile +23 -0
- data/lib/tdev_metrics.rb +21 -0
- data/lib/tdev_metrics/controllers/controller.rb +44 -0
- data/lib/tdev_metrics/controllers/metric_controller.rb +52 -0
- data/lib/tdev_metrics/controllers/project_controller.rb +54 -0
- data/lib/tdev_metrics/metric.rb +42 -0
- data/lib/tdev_metrics/project.rb +16 -0
- data/lib/tdev_metrics/version.rb +8 -0
- data/spec/metric_controller_spec.rb +93 -0
- data/spec/metric_spec.rb +70 -0
- data/spec/project_controller_spec.rb +81 -0
- data/spec/project_spec.rb +31 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/tdev_metrics_spec.rb +78 -0
- data/tdev_metrics.gemspec +22 -0
- metadata +159 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara request specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TotenDev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# TDMetrics
|
2
|
+
|
3
|
+
Ruby gem to send metrics to TDMetrics.
|
4
|
+
|
5
|
+
[![Build Status](https://secure.travis-ci.org/TotenDev/TDMetrics-LibRuby.png?branch=master)](http://travis-ci.org/TotenDev/TDMetrics-LibRuby)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'tdev_metrics'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tdev_metrics
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
require 'tdev_metrics'
|
24
|
+
|
25
|
+
td_metrics = TotenDev::Metrics.new do |c|
|
26
|
+
c.username = 'username'
|
27
|
+
c.password = 'password'
|
28
|
+
c.base_url = 'http://example.com'
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Project Management
|
33
|
+
# create a new project
|
34
|
+
td_metrics.project.create 'MyNewProject'
|
35
|
+
|
36
|
+
# Update a project
|
37
|
+
td_metrics.project.update <PROJECT_ID>, 'NewProjectName'
|
38
|
+
|
39
|
+
# Delete a project
|
40
|
+
td_metrics.project.delete <PROJECT_ID>
|
41
|
+
|
42
|
+
# List all projects
|
43
|
+
td_metrics.project.list
|
44
|
+
|
45
|
+
# List one project
|
46
|
+
td_metrics.project.list <PROJECT_ID>
|
47
|
+
|
48
|
+
|
49
|
+
# Metrics Management
|
50
|
+
# Create a new metric
|
51
|
+
# from hash:
|
52
|
+
metric_hash = {
|
53
|
+
'metric' => 'my metric',
|
54
|
+
'project' => 1,
|
55
|
+
'place' => 'my place',
|
56
|
+
'type' => 'my type',
|
57
|
+
'info' => 'my info',
|
58
|
+
'timestamp' => 1356145931
|
59
|
+
}
|
60
|
+
|
61
|
+
metric = TotenDev::Metric.new metric_hash
|
62
|
+
# you can also set values from attributes
|
63
|
+
# ie:
|
64
|
+
metric.timestamp = Time.new.getutc.to_i
|
65
|
+
# send values to server:
|
66
|
+
td_metrics.metric.create metric
|
67
|
+
|
68
|
+
# Update a metric
|
69
|
+
td_metrics.metric.update <METRIC_ID>, metric
|
70
|
+
|
71
|
+
# Delete a metric
|
72
|
+
td_metrics.metric.delete <METRIC_ID>
|
73
|
+
|
74
|
+
# List all metrics
|
75
|
+
td_metrics.metric.list
|
76
|
+
# you can also set some params for the response:
|
77
|
+
td_metrics.metric.list :all, { :limit => 10, :order => 'desc' }
|
78
|
+
# or list one metric only:
|
79
|
+
td_metrics.metric.list <METRIC_ID>
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
1. Fork it
|
84
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
85
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
86
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
87
|
+
5. Create new Pull Request
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
[MIT](https://github.com/TotenDev/TDMetrics-LibRuby/blob/master/LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
task :default => 'test'
|
5
|
+
|
6
|
+
desc "Run all tests"
|
7
|
+
task :test => [:tlint, :spec] do
|
8
|
+
puts "finished running all tests successfully!"
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Run rspec"
|
12
|
+
task :spec do
|
13
|
+
puts "running rspec..."
|
14
|
+
system "bundle exec rspec spec"
|
15
|
+
raise "rspec failed!" unless $?.exitstatus == 0
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run travis-lint"
|
19
|
+
task :tlint do
|
20
|
+
puts "running travis-lint..."
|
21
|
+
system "travis-lint"
|
22
|
+
raise "lint failed!" unless $?.exitstatus == 0
|
23
|
+
end
|
data/lib/tdev_metrics.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# tdev_metrics.rb — tdev_metrics
|
2
|
+
# today is 7/14/12, it is now 12:24 AM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'tdev_metrics/version'
|
6
|
+
require 'tdev_metrics/metric'
|
7
|
+
require 'tdev_metrics/project'
|
8
|
+
require 'tdev_metrics/controllers/metric_controller'
|
9
|
+
require 'tdev_metrics/controllers/project_controller'
|
10
|
+
|
11
|
+
module TotenDev
|
12
|
+
class Metrics
|
13
|
+
attr_reader :metric, :project
|
14
|
+
|
15
|
+
def initialize( &block )
|
16
|
+
@metric = TotenDev::MetricController.new &block
|
17
|
+
@project = TotenDev::ProjectController.new &block
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# controller.rb — tdev_metrics
|
2
|
+
# today is 7/14/12, it is now 12:16 AM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
module TotenDev
|
9
|
+
class Controller
|
10
|
+
attr_accessor :username
|
11
|
+
attr_accessor :password
|
12
|
+
attr_accessor :base_url
|
13
|
+
|
14
|
+
def initialize( &block )
|
15
|
+
instance_eval &block
|
16
|
+
end
|
17
|
+
|
18
|
+
def get( endpoint, params = {} )
|
19
|
+
uri = URI "#{parsed_base_url}#{endpoint}"
|
20
|
+
uri.query = URI.encode_www_form params unless params.empty?
|
21
|
+
request uri, Net::HTTP::Get.new( uri.request_uri )
|
22
|
+
end
|
23
|
+
|
24
|
+
def post( endpoint, params = {} )
|
25
|
+
uri = URI "#{parsed_base_url}#{endpoint}"
|
26
|
+
req = Net::HTTP::Post.new uri.path
|
27
|
+
req.set_form_data params unless params.empty?
|
28
|
+
request uri, req
|
29
|
+
end
|
30
|
+
|
31
|
+
def request( uri, req )
|
32
|
+
req.basic_auth @username, @password
|
33
|
+
Net::HTTP.start( uri.hostname, uri.port ) {|http| http.request(req) }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def parsed_base_url
|
39
|
+
return @base_url if @base_url.end_with? '/'
|
40
|
+
"#{@base_url}/"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# metric_controller.rb — tdev_metrics
|
2
|
+
# today is 7/14/12, it is now 12:23 AM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'tdev_metrics/controllers/controller'
|
6
|
+
require 'tdev_metrics/metric'
|
7
|
+
|
8
|
+
module TotenDev
|
9
|
+
class MetricController < Controller
|
10
|
+
|
11
|
+
def create( metric )
|
12
|
+
req = post 'info/create', metric.to_hash
|
13
|
+
req.is_a? Net::HTTPSuccess
|
14
|
+
end
|
15
|
+
|
16
|
+
def update( id, metric )
|
17
|
+
req = post "info/update/#{id}", metric.to_hash
|
18
|
+
req.is_a? Net::HTTPSuccess
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete( id )
|
22
|
+
req = post "info/delete/#{id}"
|
23
|
+
req.is_a? Net::HTTPSuccess
|
24
|
+
end
|
25
|
+
|
26
|
+
def list( metric = nil, params = {} )
|
27
|
+
req = get list_endpoint_for_metric( metric ), params
|
28
|
+
return nil unless req.is_a? Net::HTTPSuccess
|
29
|
+
list_parse_response req.body
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# List Helpers
|
35
|
+
def list_endpoint_for_metric( m )
|
36
|
+
return "info/" if m.nil? || m == :all
|
37
|
+
"info/show/#{m}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def list_parse_response( response )
|
41
|
+
parsed_json = JSON.parse response
|
42
|
+
ret_val = []
|
43
|
+
if parsed_json.is_a? Array
|
44
|
+
parsed_json.each { |h| ret_val << TotenDev::Metric.new( h ) }
|
45
|
+
elsif parsed_json.is_a? Hash
|
46
|
+
ret_val << TotenDev::Metric.new( parsed_json )
|
47
|
+
end
|
48
|
+
ret_val
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# project_controller.rb — tdev_metrics
|
2
|
+
# today is 7/14/12, it is now 12:22 AM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'tdev_metrics/controllers/controller'
|
6
|
+
require 'tdev_metrics/project'
|
7
|
+
|
8
|
+
module TotenDev
|
9
|
+
class ProjectController < Controller
|
10
|
+
|
11
|
+
def create( title )
|
12
|
+
req = post 'project/create', { :title => title }
|
13
|
+
req.is_a? Net::HTTPSuccess
|
14
|
+
end
|
15
|
+
|
16
|
+
def update( id, title )
|
17
|
+
req = post "project/update/#{id}", { :title => title }
|
18
|
+
req.is_a? Net::HTTPSuccess
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete( id )
|
22
|
+
req = post "project/delete/#{id}"
|
23
|
+
req.is_a? Net::HTTPSuccess
|
24
|
+
end
|
25
|
+
|
26
|
+
def list( project = nil, params = {} )
|
27
|
+
req = get list_endpoint_for_project( project ), params
|
28
|
+
return nil unless req.is_a? Net::HTTPSuccess
|
29
|
+
list_parse_response req.body
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# List Helpers
|
35
|
+
def list_endpoint_for_project( p )
|
36
|
+
return "project/" if p.nil? || p == :all
|
37
|
+
"project/show/#{p}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def list_parse_response( response )
|
41
|
+
parsed_json = JSON.parse response
|
42
|
+
ret_val = []
|
43
|
+
if parsed_json.is_a? Array
|
44
|
+
parsed_json.each do |obj|
|
45
|
+
ret_val << TotenDev::Project.new( obj['id'], obj['title'])
|
46
|
+
end
|
47
|
+
elsif parsed_json.is_a? Hash
|
48
|
+
ret_val << TotenDev::Project.new( parsed_json['id'], parsed_json['title'])
|
49
|
+
end
|
50
|
+
ret_val
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# metric.rb — tdev_metrics
|
2
|
+
# today is 7/14/12, it is now 12:23 AM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
|
6
|
+
module TotenDev
|
7
|
+
class Metric
|
8
|
+
attr_accessor :id
|
9
|
+
attr_accessor :name
|
10
|
+
attr_accessor :project_id
|
11
|
+
attr_accessor :place
|
12
|
+
attr_accessor :type
|
13
|
+
attr_accessor :info
|
14
|
+
attr_accessor :timestamp
|
15
|
+
|
16
|
+
def initialize( hash = nil )
|
17
|
+
if hash.nil?
|
18
|
+
@timestamp = Time.now.getutc.to_i
|
19
|
+
else
|
20
|
+
@id = hash['id'].to_i
|
21
|
+
@name = hash['metric']
|
22
|
+
@project_id = hash['project'].to_i
|
23
|
+
@place = hash['place']
|
24
|
+
@type = hash['type']
|
25
|
+
@info = hash['info']
|
26
|
+
@timestamp = hash['timestamp'].to_i
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_hash
|
31
|
+
{
|
32
|
+
'metric' => @name,
|
33
|
+
'project' => @project_id,
|
34
|
+
'place' => @place,
|
35
|
+
'type' => @type,
|
36
|
+
'info' => @info,
|
37
|
+
'timestamp' => @timestamp
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# project.rb — tdev_metrics
|
2
|
+
# today is 7/14/12, it is now 12:24 AM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
|
6
|
+
module TotenDev
|
7
|
+
class Project
|
8
|
+
attr_accessor :id, :title
|
9
|
+
|
10
|
+
def initialize( id = nil, title = nil )
|
11
|
+
@id = id
|
12
|
+
@title = title
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# metric_controller_spec.rb — tdev_metrics
|
2
|
+
# today is 7/16/12, it is now 2:16 PM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
RSpec.configure do |c|
|
8
|
+
c.filter_run_excluding :auth_valid => false
|
9
|
+
c.filter_run_excluding :info_only => true
|
10
|
+
end
|
11
|
+
|
12
|
+
describe TotenDev::MetricController do
|
13
|
+
|
14
|
+
# Before
|
15
|
+
before :all do
|
16
|
+
@metric_controller = TotenDev::MetricController.new do |c|
|
17
|
+
c.username = 'username'
|
18
|
+
c.password = 'password'
|
19
|
+
c.base_url = 'http://example.com'
|
20
|
+
end
|
21
|
+
|
22
|
+
@metric_params = {:limit => 5, :order => 'desc' }
|
23
|
+
|
24
|
+
metric_hash = {
|
25
|
+
'metric' => 'my new metric',
|
26
|
+
'project' => 10,
|
27
|
+
'place' => 'my place',
|
28
|
+
'type' => 'my type',
|
29
|
+
'info' => 'my info',
|
30
|
+
'timestamp' => Time.now.getutc.to_i
|
31
|
+
}
|
32
|
+
@metric = TotenDev::Metric.new metric_hash
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# MetricController class
|
37
|
+
describe "#new" do
|
38
|
+
it "returns a MetricController object" do
|
39
|
+
@metric_controller.should be_an_instance_of TotenDev::MetricController
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#username" do
|
44
|
+
it "return username used on creation", :auth_valid => true do
|
45
|
+
@metric_controller.username.should eql 'username'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#password" do
|
50
|
+
it "return password used on creation", :auth_valid => true do
|
51
|
+
@metric_controller.password.should eql 'password'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#base_url" do
|
56
|
+
it "return base_url used on creation", :auth_valid => true do
|
57
|
+
@metric_controller.base_url.should match 'example.com'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Metrics Management
|
63
|
+
describe "#list" do
|
64
|
+
it "list one metric", :auth_valid => false do
|
65
|
+
@metric_controller.list( 1 ).should_not be_nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#list" do
|
70
|
+
it "list all metrics", :auth_valid => false do
|
71
|
+
@metric_controller.list(:all, @metric_params).should_not be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#create" do
|
76
|
+
it "create a metric", :auth_valid => false, :info_only => true do
|
77
|
+
@metric_controller.create( @metric ).should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#update", :auth_valid => false, :info_only => true do
|
82
|
+
it "update a metric" do
|
83
|
+
@metric_controller.update( 3091, @metric ).should be_true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#delete", :auth_valid => false, :info_only => true do
|
88
|
+
it "delete a metric" do
|
89
|
+
@metric_controller.delete( 3086 ).should be_true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/spec/metric_spec.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# metric_spec.rb — tdev_metrics
|
2
|
+
# today is 7/16/12, it is now 2:16 PM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
describe TotenDev::Metric do
|
8
|
+
|
9
|
+
before :all do
|
10
|
+
metric_hash = {
|
11
|
+
'id' => 1,
|
12
|
+
'metric' => 'my metric',
|
13
|
+
'project' => 1,
|
14
|
+
'place' => 'my place',
|
15
|
+
'type' => 'my type',
|
16
|
+
'info' => 'my info',
|
17
|
+
'timestamp' => 1356145931
|
18
|
+
}
|
19
|
+
@metric = TotenDev::Metric.new metric_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#new" do
|
23
|
+
it "returns a Metric object" do
|
24
|
+
@metric.should be_an_instance_of TotenDev::Metric
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#id" do
|
29
|
+
it "return id used on creation" do
|
30
|
+
@metric.id.should eql 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#name" do
|
35
|
+
it "return name used on creation" do
|
36
|
+
@metric.name.should eql 'my metric'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#project_id" do
|
41
|
+
it "return project_id used on creation" do
|
42
|
+
@metric.project_id.should eql 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#place" do
|
47
|
+
it "return place used on creation" do
|
48
|
+
@metric.place.should eql 'my place'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#type" do
|
53
|
+
it "return type used on creation" do
|
54
|
+
@metric.type.should eql 'my type'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#info" do
|
59
|
+
it "return place used on creation" do
|
60
|
+
@metric.info.should eql 'my info'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#timestamp" do
|
65
|
+
it "return timestamp used on creation" do
|
66
|
+
@metric.timestamp.should eql 1356145931
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# project_controller_spec.rb — tdev_metrics
|
2
|
+
# today is 7/16/12, it is now 2:17 PM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
RSpec.configure do |c|
|
8
|
+
c.filter_run_excluding :auth_valid => false
|
9
|
+
c.filter_run_excluding :info_only => true
|
10
|
+
end
|
11
|
+
|
12
|
+
describe TotenDev::ProjectController do
|
13
|
+
|
14
|
+
# Before
|
15
|
+
before :all do
|
16
|
+
@project_controller = TotenDev::ProjectController.new do |c|
|
17
|
+
c.username = 'username'
|
18
|
+
c.password = 'password'
|
19
|
+
c.base_url = 'http://example.com'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# ProjectController class
|
25
|
+
describe "#new" do
|
26
|
+
it "returns a ProjectController object" do
|
27
|
+
@project_controller.should be_an_instance_of TotenDev::ProjectController
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#username" do
|
32
|
+
it "return username used on creation", :auth_valid => true do
|
33
|
+
@project_controller.username.should eql 'username'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#password" do
|
38
|
+
it "return password used on creation", :auth_valid => true do
|
39
|
+
@project_controller.password.should eql 'password'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#base_url" do
|
44
|
+
it "return base_url used on creation", :auth_valid => true do
|
45
|
+
@project_controller.base_url.should match 'example.com'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Metrics Management
|
51
|
+
describe "#list" do
|
52
|
+
it "list one project", :auth_valid => false do
|
53
|
+
@project_controller.list( 1 ).should_not be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#list" do
|
58
|
+
it "list all projects", :auth_valid => false do
|
59
|
+
@project_controller.list.should_not be_nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#create" do
|
64
|
+
it "create a project", :auth_valid => false, :info_only => true do
|
65
|
+
@project_controller.create( 'TDMetricTest' ).should be_true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#update" do
|
70
|
+
it "update a project", :auth_valid => false, :info_only => true do
|
71
|
+
@project_controller.update( 5, 'TDevMetricTest' ).should be_true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#delete" do
|
76
|
+
it "delete a project", :auth_valid => false, :info_only => true do
|
77
|
+
@project_controller.delete( 5 ).should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# project_spec.rb — tdev_metrics
|
2
|
+
# today is 7/16/12, it is now 2:17 PM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
describe TotenDev::Project do
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@project = TotenDev::Project.new 'id', 'title'
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#new" do
|
14
|
+
it "returns a Project object" do
|
15
|
+
@project.should be_an_instance_of TotenDev::Project
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#id" do
|
20
|
+
it "return id used on creation" do
|
21
|
+
@project.id.should eql 'id'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#title" do
|
26
|
+
it "return title used on creation" do
|
27
|
+
@project.title.should eql 'title'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# spec_helper.rb — tdev_metrics
|
2
|
+
# today is 7/16/12, it is now 2:17 PM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
|
6
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
9
|
+
# loaded once.
|
10
|
+
#
|
11
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
|
+
require 'tdev_metrics'
|
13
|
+
require 'tdev_metrics/metric'
|
14
|
+
require 'tdev_metrics/project'
|
15
|
+
require 'tdev_metrics/controllers/metric_controller'
|
16
|
+
require 'tdev_metrics/controllers/project_controller'
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
config.filter_run :focus
|
22
|
+
|
23
|
+
# Run specs in random order to surface order dependencies. If you find an
|
24
|
+
# order dependency and want to debug it, you can fix the order by providing
|
25
|
+
# the seed, which is printed after each run.
|
26
|
+
# --seed 1234
|
27
|
+
config.order = 'random'
|
28
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# tdev_metrics_spec.rb — tdev_metrics
|
2
|
+
# today is 7/16/12, it is now 2:17 PM
|
3
|
+
# created by mtrovilho
|
4
|
+
# see LICENSE for details
|
5
|
+
require 'spec_helper'
|
6
|
+
|
7
|
+
describe TotenDev::Metrics do
|
8
|
+
|
9
|
+
# Before
|
10
|
+
before :all do
|
11
|
+
@metrics = TotenDev::Metrics.new do |c|
|
12
|
+
c.username = 'username'
|
13
|
+
c.password = 'password'
|
14
|
+
c.base_url = 'http://example.com'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# Metrics attributes
|
20
|
+
describe "#new" do
|
21
|
+
it "returns a Metrics object" do
|
22
|
+
@metrics.should be_an_instance_of TotenDev::Metrics
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#metric" do
|
27
|
+
it "return an Metric instance" do
|
28
|
+
@metrics.metric.should be_an_instance_of TotenDev::MetricController
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#project" do
|
33
|
+
it "return an Project instance" do
|
34
|
+
@metrics.project.should be_an_instance_of TotenDev::ProjectController
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# MetricController attributes
|
40
|
+
describe "#metric#username" do
|
41
|
+
it "return the username of the Metric instance" do
|
42
|
+
@metrics.metric.username.should eql 'username'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#metric#password" do
|
47
|
+
it "return the password of the Metric instance" do
|
48
|
+
@metrics.metric.password.should eql 'password'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#metric#base_url" do
|
53
|
+
it "return the base_url of the Metric instance" do
|
54
|
+
@metrics.metric.base_url.should match 'example.com'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# ProjectController attributes
|
60
|
+
describe "#project#username" do
|
61
|
+
it "return the username of the Project instance" do
|
62
|
+
@metrics.project.username.should eql 'username'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#project#password" do
|
67
|
+
it "return the password of the Project instance" do
|
68
|
+
@metrics.project.password.should eql 'password'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#project#base_url" do
|
73
|
+
it "return the base_url of the Project instance" do
|
74
|
+
@metrics.project.base_url.should match 'example.com'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/tdev_metrics/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["TotenDev"]
|
6
|
+
gem.email = ["support@totendev.com"]
|
7
|
+
gem.summary = %q{Ruby gem to send metrics to TDMetrics.}
|
8
|
+
gem.homepage = "https://github.com/TotenDev/TDMetrics-LibRuby"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "tdev_metrics"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = TDevMetrics::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency 'json', '>= 1.7.3'
|
18
|
+
gem.add_development_dependency 'travis-lint'
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
gem.add_development_dependency 'guard-rspec'
|
21
|
+
gem.add_development_dependency 'growl'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tdev_metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- TotenDev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.7.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.7.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: travis-lint
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: growl
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description:
|
95
|
+
email:
|
96
|
+
- support@totendev.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- .travis.yml
|
104
|
+
- Gemfile
|
105
|
+
- Guardfile
|
106
|
+
- LICENSE
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/tdev_metrics.rb
|
110
|
+
- lib/tdev_metrics/controllers/controller.rb
|
111
|
+
- lib/tdev_metrics/controllers/metric_controller.rb
|
112
|
+
- lib/tdev_metrics/controllers/project_controller.rb
|
113
|
+
- lib/tdev_metrics/metric.rb
|
114
|
+
- lib/tdev_metrics/project.rb
|
115
|
+
- lib/tdev_metrics/version.rb
|
116
|
+
- spec/metric_controller_spec.rb
|
117
|
+
- spec/metric_spec.rb
|
118
|
+
- spec/project_controller_spec.rb
|
119
|
+
- spec/project_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
- spec/tdev_metrics_spec.rb
|
122
|
+
- tdev_metrics.gemspec
|
123
|
+
homepage: https://github.com/TotenDev/TDMetrics-LibRuby
|
124
|
+
licenses: []
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: -587469398586136940
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
hash: -587469398586136940
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 1.8.23
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: Ruby gem to send metrics to TDMetrics.
|
153
|
+
test_files:
|
154
|
+
- spec/metric_controller_spec.rb
|
155
|
+
- spec/metric_spec.rb
|
156
|
+
- spec/project_controller_spec.rb
|
157
|
+
- spec/project_spec.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- spec/tdev_metrics_spec.rb
|