growthforecast-client 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc49802fafcfffae9ab1ba873d15a4d5e7d2118a
4
+ data.tar.gz: 16c23fa49c8f1bf380d2adaa37b36a0cf3187329
5
+ SHA512:
6
+ metadata.gz: 091ffcb68fff297f93bdf5c91bb506d41c4e9b16a5e55788518f5cf8f8f35735e2557312ed484e61e71fb39ea73f6d1271361eec256c77d05bc227cf28d3dcdc
7
+ data.tar.gz: 5464d4a3c35988b5f93502bc3c839de730c998f5a3ee2294a2651eb135139f818f378e4a7f7dca027bcaba88527f059afec3221f470d734d8900ca7b8e25d0e0
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  .bundle
6
6
  Gemfile.lock
7
7
  .rbenv-version
8
+ .ruby-version
8
9
  vendor
9
10
  doc/*
10
11
  tmp/*
data/.travis.yml CHANGED
@@ -2,6 +2,6 @@ rvm:
2
2
  # - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- # - ruby-head
5
+ - 2.0.0
6
6
  gemfile:
7
7
  - Gemfile
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- source :rubygems
2
+ source 'https://rubygems.org'
3
3
 
4
4
  gemspec
5
5
  gem 'growthforecast-client', path: '.'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ require 'growthforecast-client'
5
+ CLI::GrowthforecastClient.start(ARGV)
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
 
18
18
  gem.add_runtime_dependency "httpclient"
19
+ gem.add_runtime_dependency "thor"
19
20
 
20
21
  # for testing
21
22
  gem.add_development_dependency "rake"
@@ -24,7 +25,5 @@ Gem::Specification.new do |gem|
24
25
 
25
26
  # for debug
26
27
  gem.add_development_dependency "pry"
27
- gem.add_development_dependency "pry-debugger"
28
- gem.add_development_dependency "rb-readline"
29
28
  gem.add_development_dependency "tapp"
30
29
  end
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'thor'
3
+
4
+ module CLI
5
+ class GrowthforecastClient < Thor
6
+ desc 'delete_graph <url>', 'delete a graph or graphs under a url'
7
+ long_desc <<-LONGDESC
8
+ Delete a graph or graphs under a <url> where <url> is the one obtained from the view, e.g.,
9
+ http://{hostname}:{port}/list/{service_name}/{section_name}?t=sh
10
+ or
11
+ http://{hostname}:{port}/view_graph/{service_name}/{section_name}/{graph_name}?t=sh
12
+ LONGDESC
13
+ def delete_graph(url)
14
+ uri = URI.parse(url)
15
+ client = client(uri)
16
+ service_name, section_name, graph_name = split_path(uri.path)
17
+ graphs = client.list_graph(service_name, section_name, graph_name)
18
+ graphs.each do |graph|
19
+ begin
20
+ client.delete_graph(graph['service_name'], graph['section_name'], graph['graph_name'])
21
+ puts "Deleted #{e graph['service_name']}/#{e graph['section_name']}/#{e graph['graph_name']}"
22
+ rescue => e
23
+ puts "\tclass:#{e.class}\t#{e.message}"
24
+ end
25
+ end
26
+ end
27
+
28
+ no_tasks do
29
+ def e(str)
30
+ URI.escape(str) if str
31
+ end
32
+
33
+ def split_path(path)
34
+ path = path.gsub(/.*list\//, '').gsub(/.*view_graph\//, '')
35
+ path.split('/').map {|p| URI.unescape(p) }
36
+ end
37
+
38
+ def client(uri)
39
+ GrowthForecast::Client.new("#{uri.scheme}://#{uri.host}:#{uri.port}")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1 +1,2 @@
1
1
  require 'growthforecast/client'
2
+ require 'cli/growthforecast-client'
@@ -61,8 +61,12 @@ module GrowthForecast
61
61
  # "section_name"=>"hostname",
62
62
  # "id"=>3},
63
63
  # ]
64
- def list_graph
65
- get_json('/json/list/graph')
64
+ def list_graph(service_name = nil, section_name = nil, graph_name = nil)
65
+ graphs = get_json('/json/list/graph')
66
+ graphs = graphs.select {|g| g['service_name'] == service_name } if service_name
67
+ graphs = graphs.select {|g| g['section_name'] == section_name } if section_name
68
+ graphs = graphs.select {|g| g['graph_name'] == graph_name } if graph_name
69
+ graphs
66
70
  end
67
71
 
68
72
  # A Helper: Get the list of section
@@ -137,7 +141,7 @@ module GrowthForecast
137
141
  # "sllimit"=>-100000,
138
142
  # "md5"=>"3c59dc048e8850243be8079a5c74d079"}
139
143
  def get_graph(service_name, section_name, graph_name)
140
- get_json("/api/#{service_name}/#{section_name}/#{graph_name}")
144
+ get_json("/api/#{e service_name}/#{e section_name}/#{e graph_name}")
141
145
  end
142
146
 
143
147
  # Get the propety of a graph, /json/graph/:id
@@ -176,7 +180,7 @@ module GrowthForecast
176
180
  # @param [String] graph_name
177
181
  # @param [Hash] params The POST parameters. See #get_graph
178
182
  def post_graph(service_name, section_name, graph_name, params)
179
- post_query("/api/#{service_name}/#{section_name}/#{graph_name}", params)
183
+ post_query("/api/#{e service_name}/#{e section_name}/#{e graph_name}", params)
180
184
  end
181
185
 
182
186
  # Delete a graph, POST /delete/:service_name/:section_name/:graph_name
@@ -184,7 +188,7 @@ module GrowthForecast
184
188
  # @param [String] section_name
185
189
  # @param [String] graph_name
186
190
  def delete_graph(service_name, section_name, graph_name)
187
- post_query("/delete/#{service_name}/#{section_name}/#{graph_name}")
191
+ post_query("/delete/#{e service_name}/#{e section_name}/#{e graph_name}")
188
192
  end
189
193
 
190
194
  # Update the property of a graph, /json/edit/graph/:id
@@ -284,6 +288,10 @@ module GrowthForecast
284
288
 
285
289
  private
286
290
 
291
+ def e(str)
292
+ URI.escape(str) if str
293
+ end
294
+
287
295
  def client
288
296
  @client ||= HTTPClient.new
289
297
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe CLI::GrowthforecastClient do
4
+ include_context "setup_growthforecast_client"
5
+ before(:all) { @cli = CLI::GrowthforecastClient.new }
6
+
7
+ context "#split_path" do
8
+ context 'list service url' do
9
+ before { @url = 'http://localhost/list/service_name?t=sh' }
10
+ before { @service_name, @section_name, @graph_name = @cli.split_path(URI.parse(@url).path) }
11
+ it { @service_name.should == 'service_name' }
12
+ it { @section_name.should be_nil }
13
+ it { @graph_name.should be_nil }
14
+ end
15
+
16
+ context 'list section url' do
17
+ before { @url = 'http://localhost/list/service_name/section_name?t=sh' }
18
+ before { @service_name, @section_name, @graph_name = @cli.split_path(URI.parse(@url).path) }
19
+ it { @service_name.should == 'service_name' }
20
+ it { @section_name.should == 'section_name' }
21
+ it { @graph_name.should be_nil }
22
+ end
23
+
24
+ context 'view_graph url' do
25
+ before { @url = 'http://localhost/view_graph/service_name/section_name/graph_name?t=sh' }
26
+ before { @service_name, @section_name, @graph_name = @cli.split_path(URI.parse(@url).path) }
27
+ it { @service_name.should == 'service_name' }
28
+ it { @section_name.should == 'section_name' }
29
+ it { @graph_name.should == 'graph_name' }
30
+ end
31
+ end
32
+
33
+ context "delete_graph" do
34
+ pending
35
+ end
36
+ end
37
+
@@ -10,14 +10,14 @@ shared_context "setup_growthforecast_client" do
10
10
  include_context "stub_post_graph" if ENV['MOCK'] == 'on'
11
11
  include_context "stub_delete_graph" if ENV['MOCK'] == 'on'
12
12
  before(:all) {
13
- @client.delete_graph("app_name", "hostname", "<1sec_count") rescue nil
14
- @client.delete_graph("app_name", "hostname", "<2sec_count") rescue nil
15
- @client.post_graph("app_name", "hostname", "<1sec_count", { 'number' => 0 }) rescue nil
16
- @client.post_graph("app_name", "hostname", "<2sec_count", { 'number' => 0 }) rescue nil
13
+ @client.delete_graph("app name", "host name", "<1sec count") rescue nil
14
+ @client.delete_graph("app name", "host name", "<2sec count") rescue nil
15
+ @client.post_graph("app name", "host name", "<1sec count", { 'number' => 0 }) rescue nil
16
+ @client.post_graph("app name", "host name", "<2sec count", { 'number' => 0 }) rescue nil
17
17
  }
18
18
  after(:all) {
19
- @client.delete_graph("app_name", "hostname", "<1sec_count") rescue nil
20
- @client.delete_graph("app_name", "hostname", "<2sec_count") rescue nil
19
+ @client.delete_graph("app name", "host name", "<1sec count") rescue nil
20
+ @client.delete_graph("app name", "host name", "<2sec count") rescue nil
21
21
  }
22
22
  end
23
23
 
@@ -80,9 +80,9 @@ describe GrowthForecast::Client do
80
80
  include_context "stub_delete_graph" if ENV['MOCK'] == 'on'
81
81
  let(:graph) {
82
82
  {
83
- "service_name" => "app_name",
84
- "section_name" => "hostname",
85
- "graph_name" => "<1sec_count",
83
+ "service_name" => "app name",
84
+ "section_name" => "host name",
85
+ "graph_name" => "<1sec count",
86
86
  }
87
87
  }
88
88
  before { @client.post_graph(graph['service_name'], graph['section_name'], graph['graph_name'], { 'number' => 0 }) }
@@ -143,7 +143,7 @@ describe GrowthForecast::Client do
143
143
  {
144
144
  "service_name" => graphs.first["service_name"],
145
145
  "section_name" => graphs.first["section_name"],
146
- "graph_name" => "complex_graph_test",
146
+ "graph_name" => "complex graph test",
147
147
  "description" => "complex graph test",
148
148
  "sort" => 10
149
149
  }
data/spec/spec_helper.rb CHANGED
@@ -3,8 +3,7 @@ require "bundler/setup"
3
3
 
4
4
  ENV['MOCK'] ||= 'on'
5
5
  require "pry"
6
- require 'debugger'
7
- require 'growthforecast/client'
6
+ require 'growthforecast-client'
8
7
  require 'webmock/rspec' if ENV['MOCK'] == 'on'
9
8
 
10
9
  ROOT = File.dirname(__FILE__)
data/spec/support/mock.rb CHANGED
@@ -5,13 +5,13 @@ base_uri = 'http://localhost:5125'
5
5
  shared_context "stub_list_graph" do
6
6
  let(:list_graph_example) {
7
7
  [
8
- {"service_name"=>"app_name",
9
- "section_name"=>"hostname",
10
- "graph_name"=>"<1sec_count",
8
+ {"service_name"=>"app name",
9
+ "section_name"=>"host name",
10
+ "graph_name"=>"<1sec count",
11
11
  "id"=>1},
12
- {"service_name"=>"app_name",
13
- "section_name"=>"hostname",
14
- "graph_name"=>"<2sec_count",
12
+ {"service_name"=>"app name",
13
+ "section_name"=>"host name",
14
+ "graph_name"=>"<2sec count",
15
15
  "id"=>2},
16
16
  ]
17
17
  }
@@ -33,14 +33,14 @@ shared_context "stub_get_graph" do
33
33
  "stype"=>"AREA",
34
34
  "adjustval"=>"1",
35
35
  "meta"=>"",
36
- "service_name"=>"app_name",
36
+ "service_name"=>"app name",
37
37
  "gmode"=>"gauge",
38
38
  "color"=>"#cc6633",
39
39
  "created_at"=>"2013/02/02 00:41:11",
40
- "section_name"=>"hostname",
40
+ "section_name"=>"host name",
41
41
  "ulimit"=>1000000000,
42
42
  "id"=>1,
43
- "graph_name"=>"<1sec_count",
43
+ "graph_name"=>"<1sec count",
44
44
  "description"=>"",
45
45
  "sulimit"=>100000,
46
46
  "unit"=>"",
@@ -71,14 +71,14 @@ shared_context "stub_get_graph_by_id" do
71
71
  "stype"=>"AREA",
72
72
  "adjustval"=>"1",
73
73
  # "meta"=>"",
74
- "service_name"=>"app_name",
74
+ "service_name"=>"app name",
75
75
  "gmode"=>"gauge",
76
76
  "color"=>"#cc6633",
77
77
  "created_at"=>"2013/02/02 00:41:11",
78
- "section_name"=>"hostname",
78
+ "section_name"=>"host name",
79
79
  "ulimit"=>1000000000,
80
80
  "id"=>1,
81
- "graph_name"=>"<1sec_count",
81
+ "graph_name"=>"<1sec count",
82
82
  "description"=>"",
83
83
  "sulimit"=>100000,
84
84
  "unit"=>"",
@@ -132,9 +132,9 @@ end
132
132
  shared_context "stub_list_complex" do
133
133
  let(:list_complex_example) {
134
134
  [
135
- {"service_name"=>"app_name",
136
- "section_name"=>"hostname",
137
- "graph_name"=>"complex_graph_test",
135
+ {"service_name"=>"app name",
136
+ "section_name"=>"host name",
137
+ "graph_name"=>"complex graph test",
138
138
  "id"=>1},
139
139
  ]
140
140
  }
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ shared_context "setup_growthforecast_client" do
4
+ before(:all) { @client = GrowthForecast::Client.new('http://localhost:5125') }
5
+
6
+ include_context "stub_list_graph" if ENV['MOCK'] == 'on'
7
+ let(:graphs) { @client.list_graph }
8
+ let(:graph) { graphs.first }
9
+
10
+ include_context "stub_post_graph" if ENV['MOCK'] == 'on'
11
+ include_context "stub_delete_graph" if ENV['MOCK'] == 'on'
12
+ before(:all) {
13
+ @client.delete_graph("app name", "host name", "<1sec count") rescue nil
14
+ @client.delete_graph("app name", "host name", "<2sec count") rescue nil
15
+ @client.post_graph("app name", "host name", "<1sec count", { 'number' => 0 }) rescue nil
16
+ @client.post_graph("app name", "host name", "<2sec count", { 'number' => 0 }) rescue nil
17
+ }
18
+ after(:all) {
19
+ @client.delete_graph("app name", "host name", "<1sec count") rescue nil
20
+ @client.delete_graph("app name", "host name", "<2sec count") rescue nil
21
+ }
22
+ end
metadata CHANGED
@@ -1,148 +1,118 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growthforecast-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Naotoshi Seo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
11
+ date: 2013-03-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httpclient
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
- name: rake
28
+ name: thor
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
- type: :development
34
+ type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !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: '2.11'
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: '2.11'
62
- - !ruby/object:Gem::Dependency
63
- name: webmock
42
+ name: rake
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
- - - ! '>='
45
+ - - '>='
68
46
  - !ruby/object:Gem::Version
69
47
  version: '0'
70
48
  type: :development
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
- - - ! '>='
52
+ - - '>='
76
53
  - !ruby/object:Gem::Version
77
54
  version: '0'
78
55
  - !ruby/object:Gem::Dependency
79
- name: pry
56
+ name: rspec
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
58
  requirements:
83
- - - ! '>='
59
+ - - ~>
84
60
  - !ruby/object:Gem::Version
85
- version: '0'
61
+ version: '2.11'
86
62
  type: :development
87
63
  prerelease: false
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
65
  requirements:
91
- - - ! '>='
66
+ - - ~>
92
67
  - !ruby/object:Gem::Version
93
- version: '0'
68
+ version: '2.11'
94
69
  - !ruby/object:Gem::Dependency
95
- name: pry-debugger
70
+ name: webmock
96
71
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
72
  requirements:
99
- - - ! '>='
73
+ - - '>='
100
74
  - !ruby/object:Gem::Version
101
75
  version: '0'
102
76
  type: :development
103
77
  prerelease: false
104
78
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
79
  requirements:
107
- - - ! '>='
80
+ - - '>='
108
81
  - !ruby/object:Gem::Version
109
82
  version: '0'
110
83
  - !ruby/object:Gem::Dependency
111
- name: rb-readline
84
+ name: pry
112
85
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
86
  requirements:
115
- - - ! '>='
87
+ - - '>='
116
88
  - !ruby/object:Gem::Version
117
89
  version: '0'
118
90
  type: :development
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
93
  requirements:
123
- - - ! '>='
94
+ - - '>='
124
95
  - !ruby/object:Gem::Version
125
96
  version: '0'
126
97
  - !ruby/object:Gem::Dependency
127
98
  name: tapp
128
99
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
100
  requirements:
131
- - - ! '>='
101
+ - - '>='
132
102
  - !ruby/object:Gem::Version
133
103
  version: '0'
134
104
  type: :development
135
105
  prerelease: false
136
106
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
107
  requirements:
139
- - - ! '>='
108
+ - - '>='
140
109
  - !ruby/object:Gem::Version
141
110
  version: '0'
142
111
  description: A Ruby Client Library for GrowthForecast API
143
112
  email:
144
113
  - sonots@gmail.com
145
- executables: []
114
+ executables:
115
+ - growthforecast-client
146
116
  extensions: []
147
117
  extra_rdoc_files: []
148
118
  files:
@@ -155,45 +125,44 @@ files:
155
125
  - README.md
156
126
  - Rakefile
157
127
  - VERSION
128
+ - bin/growthforecast-client
158
129
  - examples/create_complex.rb
159
130
  - examples/edit_graph.rb
160
131
  - growthforecast-client.gemspec
132
+ - lib/cli/growthforecast-client.rb
161
133
  - lib/growthforecast-client.rb
162
134
  - lib/growthforecast/client.rb
135
+ - spec/cli/growthforecast-client_spec.rb
163
136
  - spec/growthforecast/client_spec.rb
164
137
  - spec/spec_helper.rb
165
138
  - spec/support/mock.rb
139
+ - spec/support/setup.rb
166
140
  homepage: https://github.com/sonots/growthforecast-client
167
141
  licenses: []
142
+ metadata: {}
168
143
  post_install_message:
169
144
  rdoc_options: []
170
145
  require_paths:
171
146
  - lib
172
147
  required_ruby_version: !ruby/object:Gem::Requirement
173
- none: false
174
148
  requirements:
175
- - - ! '>='
149
+ - - '>='
176
150
  - !ruby/object:Gem::Version
177
151
  version: '0'
178
- segments:
179
- - 0
180
- hash: 503186860326361050
181
152
  required_rubygems_version: !ruby/object:Gem::Requirement
182
- none: false
183
153
  requirements:
184
- - - ! '>='
154
+ - - '>='
185
155
  - !ruby/object:Gem::Version
186
156
  version: '0'
187
- segments:
188
- - 0
189
- hash: 503186860326361050
190
157
  requirements: []
191
158
  rubyforge_project:
192
- rubygems_version: 1.8.23
159
+ rubygems_version: 2.0.0
193
160
  signing_key:
194
- specification_version: 3
161
+ specification_version: 4
195
162
  summary: A Ruby Client Library for GrowthForecast API
196
163
  test_files:
164
+ - spec/cli/growthforecast-client_spec.rb
197
165
  - spec/growthforecast/client_spec.rb
198
166
  - spec/spec_helper.rb
199
167
  - spec/support/mock.rb
168
+ - spec/support/setup.rb