hummer-client 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13da03a90d431a06a5ffc8e6a8d3ba3d35189e5a
4
- data.tar.gz: 523bbc21d6160174a89194d0e60f4fc568680652
3
+ metadata.gz: c9a1ce8193cbeaf1076d8406935558b5b9f03bd9
4
+ data.tar.gz: e13d5a293af67e24946b05adedc1a1716601e1ea
5
5
  SHA512:
6
- metadata.gz: 407a0745f83406bb42a9fde1832700ee108fc806a3587b3848152bcc693e1038c1b5eca363d5fe2019b3f9be7c0b23b0832feb544d64392d37f1c621c52a60f2
7
- data.tar.gz: eb750a26d1f2d09acb87af448960618fd1f9284824c754de66d34e297d47156c22991174def24201a048dda01f4b29500c63866281e63fa041667a0199874a82
6
+ metadata.gz: 4a922452a387805059e369646a8481c1f8d9b7fc6f78457168f1931605d2adfbe4e3460a9893c25b3c610b1e410917dee2ed523e33cca4245e715bb576ab45b4
7
+ data.tar.gz: 01f4a8ca1039cf3b878660e2d778be746495082aa464ddf61c4ee3150d3f51ba0196319c087db4b67ff57aed5af4b08ca55d03bbeb72277f3b00cf6f7c07fc72
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_dependency "terminal-table"
24
+ spec.add_dependency "json"
24
25
  spec.add_dependency "mime-types", "<2.0"
25
26
  spec.add_dependency "rest-client"
26
27
  end
data/lib/hummer/client.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "hummer/client/version"
2
2
  require "hummer/client/command"
3
- require "hummer/client/api"
3
+ require "hummer/client/model"
4
4
 
5
5
  module Hummer
6
6
  module Client
@@ -3,11 +3,16 @@ require 'optparse'
3
3
  require 'yaml'
4
4
  require 'readline'
5
5
 
6
+ require 'hummer/client/model'
7
+
6
8
  module Hummer::Client
7
9
  class Command
10
+ include Hummer::Client::Model
8
11
  def initialize(config = nil)
9
12
  @options = {
10
- :server => "http://0.0.0.0:3000"
13
+ :server => "http://0.0.0.0:3000",
14
+ :user => "00000000-0000-0000-0000-000000000000",
15
+ :token => ""
11
16
  }
12
17
  if config
13
18
  config = File.expand_path(config)
@@ -25,7 +30,7 @@ module Hummer::Client
25
30
  parser = OptionParser.new do|opts|
26
31
  opts.banner = "Usage: hummer [options] [command]"
27
32
  opts.separator ""
28
- opts.separator "Specific commands: projects suites post"
33
+ opts.separator "Commands: projects suites features post"
29
34
  opts.separator ""
30
35
  opts.separator "Specific options:"
31
36
  opts.on('--help', 'Display help' ) do
@@ -46,15 +51,28 @@ module Hummer::Client
46
51
  opts.on('--suite ID', 'Suite ID' ) do |id|
47
52
  @options[:suite] = id
48
53
  end
54
+ opts.on('--features NAMEs', 'Feature name, separeted by \',\'' ) do |features|
55
+ @options[:features] = features
56
+ end
57
+ opts.on('--build name', 'Build for new post' ) do |build|
58
+ @options[:build] = build
59
+ end
49
60
  opts.on('--json', 'Output in JSON format' ) do
50
61
  @options[:json] = true
51
62
  end
52
63
  opts.on('--file FILE', 'XML file with test results') do |file|
53
64
  @options[:file] = file
54
65
  end
66
+ opts.on('--version', 'Display version') do
67
+ @options[:version] = true
68
+ end
55
69
  end
56
70
  begin
57
71
  parser.parse ARGV
72
+ if @options[:version]
73
+ puts "Version: #{Hummer::Client::VERSION}"
74
+ exit(0)
75
+ end
58
76
  if @options[:help] or ARGV.empty?
59
77
  puts parser
60
78
  exit(0)
@@ -63,64 +81,65 @@ module Hummer::Client
63
81
  puts e.message
64
82
  end
65
83
  end
84
+ def display(objects, titles)
85
+ objects = objects.kind_of?(Array) ? objects : objects.to_a
86
+ rows = []
87
+ rows << titles.collect{|_,title| title }
88
+ rows << :separator
89
+ objects.each do |object|
90
+ values = []
91
+ titles.collect{|key,_| key}.each do |attribute|
92
+ value = object.send(attribute)
93
+ if value.kind_of?(Array)
94
+ values << value.join(", ")
95
+ else
96
+ values << value
97
+ end
98
+ end
99
+ rows << values
100
+ end
101
+ puts Terminal::Table.new :rows => rows
102
+ end
66
103
  def run
67
- API.configure(@options)
104
+ Base.configure(@options)
68
105
  command = ARGV.first
69
- if "projects" == command
70
- @projects = API.get()
71
- if @projects.kind_of?(Hash) and @projects.has_key?("error")
72
- puts @projects["error"]
73
- exit(1)
74
- end
75
- if @options[:json]
76
- puts @projects.inspect
77
- else
78
- rows = []
79
- rows << ["ID","Name","Features","Owner"]
80
- rows << :separator
81
- @projects.each do |project|
82
- rows << [project["id"],project["name"],project["feature_list"].join(", "),project["owner_name"]]
106
+ case command
107
+ when "features" then
108
+ display Feature.all, [[:id,"ID"],[:name, "Name"]]
109
+ when "projects" then
110
+ display Project.all, [[:id,"ID"],[:name,"Name"],[:feature_list,"Features"],[:owner_name,"Owner"]]
111
+ when "suites" then
112
+ if @options[:project]
113
+ project = Project.find(@options[:project])
114
+ suites = project.suites
115
+ else
116
+ suites = Suite.all
83
117
  end
84
- table = Terminal::Table.new :rows => rows
85
- puts table
86
- end
87
- elsif "post" == command
88
- if @options[:project] and @options[:file]
89
- API.post(@options[:project], @options[:file], Readline.readline('Build: '), Readline.readline('Tags: '))
90
- else
91
- puts "Need project and file"
92
- end
93
- elsif "upload" == command
94
- if @options.has_key?(:project) and @options.has_key?(:file)
95
- @suite = API.post(@options[:project], @options[:file])
96
- else
97
- puts "Need project and file"
98
- exit(1)
99
- end
100
-
101
- elsif "suites" == command
102
- if @options.has_key?(:project)
103
- @suites = API.get(:project => @options[:project], :suite => nil)
104
- if @suites.kind_of?(Hash) and @suites.has_key?("error")
105
- puts @projects["error"]
106
- exit(1)
118
+ display suites, [[:id,"ID"],[:build,"Build"],[:feature_list,"Features"],[:user_name,"User"],[:total_tests, "Tests"],[:total_errors, "Errors"],[:total_failures, "Failures"],[:total_skip,"Skip"],[:total_passed,"Passed"]]
119
+ when "post" then
120
+ project = @options[:project]
121
+ unless project
122
+ project = Readline.readline('Project> ')
123
+ project = Project.find(project.strip)
107
124
  end
108
- if @options[:json]
109
- puts @suites.inspect
110
- else
111
- rows = []
112
- rows << ["ID","Build","Tests","Errors","Failures","Skip","Passed","Features","Owner"]
113
- rows << :separator
114
- @suites.each do |suite|
115
- rows << [suite["id"],suite["build"],suite["total_tests"],suite["total_errors"],suite["total_failures"],suite["total_skip"],suite["total_passed"],suite["feature_list"].join(", "),suite["user_name"]]
116
- end
117
- table = Terminal::Table.new :rows => rows
118
- puts table
125
+ build = @options[:build]
126
+ unless build
127
+ build = Readline.readline('Build> ')
119
128
  end
129
+ features = @options[:features]
130
+ unless features
131
+ puts "Already exists features: #{Feature.all.collect{|f| f.name}.join(", ")}"
132
+ puts "Default features: #{project.feature_list.join(", ")}"
133
+ features = Readline.readline('Features> ')
134
+ end
135
+ file = @options[:file]
136
+ unless file
137
+ file = Readline.readline('File> ')
138
+ end
139
+ Suite.save(project.id, build, features, file)
120
140
  else
121
- puts "Need project"
141
+ puts "Unknown command: #{command}"
122
142
  exit(1)
123
- end
124
143
  end
125
144
  end
126
145
  end
@@ -0,0 +1,5 @@
1
+ require 'hummer/client/model/base'
2
+ require 'hummer/client/model/feature'
3
+ require 'hummer/client/model/project'
4
+ require 'hummer/client/model/suite'
5
+
@@ -0,0 +1,46 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ module Hummer::Client::Model
5
+ class Base
6
+ def self.configure(options)
7
+ @@server = RestClient::Resource.new(options[:server],
8
+ :headers => {
9
+ "X-User-ID" => options[:user],
10
+ "X-User-Token" => options[:token],
11
+ "Accept" => "application/json"
12
+ }
13
+ )
14
+ end
15
+ def self.resource res
16
+ @resource = res
17
+ end
18
+ def self.attributes *args
19
+ @attributes = []
20
+ args.each do |arg|
21
+ @attributes << arg
22
+ self.class_eval("def #{arg};@#{arg};end")
23
+ self.class_eval("def #{arg}=(val);@#{arg}=val;end")
24
+ end
25
+ end
26
+ def self.find(id, resource = nil)
27
+ new(JSON(@@server[resource || @resource][id].get))
28
+ rescue => e
29
+ puts "API error: #{e.message}"
30
+ exit(1)
31
+ end
32
+ def self.all(resource = nil)
33
+ JSON(@@server[resource || @resource].get).collect do |params|
34
+ new(params)
35
+ end
36
+ rescue => e
37
+ puts "API error: #{e.message}"
38
+ exit(1)
39
+ end
40
+ def initialize(params = {})
41
+ params.each do |key, value|
42
+ send("#{key}=", value) if respond_to? "#{key}="
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ class Hummer::Client::Model::Feature < Hummer::Client::Model::Base
2
+ attributes :id, :name
3
+ resource "features"
4
+ end
@@ -0,0 +1,7 @@
1
+ class Hummer::Client::Model::Project < Hummer::Client::Model::Base
2
+ attributes :id, :name, :feature_list, :owner_name, :created_at, :updated_at
3
+ resource "projects"
4
+ def suites
5
+ Hummer::Client::Model::Suite.all("projects/#{id}/suites")
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ class Hummer::Client::Model::Suite < Hummer::Client::Model::Base
2
+ attributes :id, :project_id, :build, :total_tests, :total_errors, :total_failures, :total_skip, :total_passed, :feature_list, :user_name
3
+ resource "suites"
4
+ def project
5
+ Hummer::Client::Model::Project.find(project_id)
6
+ end
7
+ def self.save(project, build, feature_list, file)
8
+ @@server["projects/#{project}/suites"].post({
9
+ :tempest => File.open(file),
10
+ :build => build,
11
+ :feature_list => feature_list,
12
+ :multipart => true
13
+ })
14
+ rescue => e
15
+ puts "API error: #{e.message}"
16
+ exit(1)
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Hummer
2
2
  module Client
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hummer-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Evgeniy Shurmin '
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: mime-types
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -97,8 +111,12 @@ files:
97
111
  - hummer-client.gemspec
98
112
  - hummer.yml
99
113
  - lib/hummer/client.rb
100
- - lib/hummer/client/api.rb
101
114
  - lib/hummer/client/command.rb
115
+ - lib/hummer/client/model.rb
116
+ - lib/hummer/client/model/base.rb
117
+ - lib/hummer/client/model/feature.rb
118
+ - lib/hummer/client/model/project.rb
119
+ - lib/hummer/client/model/suite.rb
102
120
  - lib/hummer/client/version.rb
103
121
  homepage: ''
104
122
  licenses:
@@ -1,29 +0,0 @@
1
- require 'json'
2
- require 'net/http'
3
- require 'rest_client'
4
-
5
- module Hummer::Client
6
- class API
7
- def self.configure(options)
8
- @server = RestClient::Resource.new(options[:server],
9
- :headers => {
10
- "X-User-ID" => options[:user],
11
- "X-User-Token" => options[:token],
12
- "Accept" => "application/json"
13
- }
14
- )
15
- end
16
- def self.get(options = {})
17
- if options.has_key?(:project) and options.has_key?(:suite)
18
- JSON @server['projects'][options[:project]]['suites'][options[:suite]].get
19
- elsif options.has_key?(:project)
20
- JSON @server['projects'][options[:project]]['suites'].get
21
- else
22
- JSON @server['projects'].get
23
- end
24
- end
25
- def self.post(project,file,build,feature_list)
26
- JSON @server['projects'][project]['suites'].post :tempest => File.open(file), :build => build, :feature_list => feature_list
27
- end
28
- end
29
- end