growthforecast-client 0.80.0 → 0.80.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8658e5aaffe4bcef2988147166e8bdce538900b
4
- data.tar.gz: fc1807ea534cbf097507bcbbd30fc4f04e8090ee
3
+ metadata.gz: 3006246bf805d5ea28559718454817fd471e552d
4
+ data.tar.gz: 98da2066a4013b894af363388d5a2e52c243c9ce
5
5
  SHA512:
6
- metadata.gz: 2878c8404112b4c25fc7b2994293ee4c1a699098d85c917ee463b67461a8352c754ecb32f4795a50402798eb8da0f50a9ec0894e81e129e5c5acf300f417cf19
7
- data.tar.gz: db196f7c978c7854a239bacfe5785297a4011797bec0aa5ba48898e85128ff8217cc162f2f389ef601fdf1b526d8736795847aa912ee6e6d8bb66cb9bd23335b
6
+ metadata.gz: 95d365a87b8c6e35917484b9e465ccbb6e1d3727ae40c60c6032268a59b86b86512a3b054ba8fd3ce6b045ed0dd9e94f3eb8c087ea294fdba3e440f8ad6c22c6
7
+ data.tar.gz: ceacf17cb3e36e6453a060304521722642a69cdcbfd45fd338ec04b79dd0f4acc4d946466de2361a397c48c750b668d741cabc6e3a43250199163b736748a794
@@ -1,3 +1,9 @@
1
+ # 0.80.1 (2014/02/11)
2
+
3
+ Fixes:
4
+
5
+ - Fixed `net/http` errors
6
+
1
7
  # 0.80.0 (2014/02/03)
2
8
 
3
9
  Changes:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.80.0
1
+ 0.80.1
@@ -8,6 +8,18 @@ class GrowthForecast::CLI < Thor
8
8
  super(args, opts, config)
9
9
  end
10
10
 
11
+ desc 'post <json> <api_url>', 'post a paramter to graph api'
12
+ long_desc <<-LONGDESC
13
+ Post a parameter to graph api
14
+
15
+ ex) growthforecast-client post '{"number":0}' http://{hostname}:{port}/api/{service_name}/{section_name}/{graph_name}
16
+ LONGDESC
17
+ def post(json, url)
18
+ base_uri, service_name, section_name, graph_name = split_url(url)
19
+ @client = client(base_uri)
20
+ puts @client.post_graph(service_name, section_name, graph_name, JSON.parse(json))
21
+ end
22
+
11
23
  desc 'delete <url>', 'delete a graph or graphs under a url'
12
24
  long_desc <<-LONGDESC
13
25
  Delete a graph or graphs under a <url> where <url> is the one obtained from the GrowthForecast URI, e.g.,
@@ -32,7 +44,7 @@ class GrowthForecast::CLI < Thor
32
44
  delete_complexes(complexes, graph_names, section_names)
33
45
  end
34
46
 
35
- desc 'color <url>', 'change the color of graphs'
47
+ desc 'color <url>', 'change the color of graphs under url'
36
48
  long_desc <<-LONGDESC
37
49
  Change the color of graphs
38
50
 
@@ -49,7 +61,7 @@ class GrowthForecast::CLI < Thor
49
61
  setup_colors(colors, graphs)
50
62
  end
51
63
 
52
- desc 'create_complex <url>', 'create complex graphs'
64
+ desc 'create_complex <url>', 'create complex graphs under url'
53
65
  long_desc <<-LONGDESC
54
66
  Create complex graphs under a url
55
67
 
@@ -134,7 +146,7 @@ class GrowthForecast::CLI < Thor
134
146
  end
135
147
 
136
148
  def split_path(path)
137
- path = path.gsub(/.*list\/?/, '').gsub(/.*view_graph\/?/, '')
149
+ path = path.gsub(/.*list\/?/, '').gsub(/.*view_graph\/?/, '').gsub(/.*api\/?/, '')
138
150
  path.split('/').map {|p| CGI.unescape(p.gsub('%20', '+')) }
139
151
  end
140
152
  end
@@ -10,44 +10,57 @@ module GrowthForecast
10
10
  class AlreadyExists < Error; end
11
11
 
12
12
  class Client
13
- attr_accessor :client
14
13
  attr_reader :base_uri
15
- attr_reader :debug_dev
16
- attr_reader :open_timeout
17
- attr_reader :read_timeout
18
- attr_reader :keepalive
14
+ attr_reader :host
15
+ attr_reader :port
16
+ attr_accessor :debug_dev
17
+ attr_accessor :open_timeout
18
+ attr_accessor :read_timeout
19
+ attr_accessor :verify_ssl
20
+ attr_accessor :keepalive
19
21
 
20
22
  # @param [String] base_uri The base uri of GrowthForecast
21
23
  def initialize(base_uri = 'http://127.0.0.1:5125', opts = {})
22
24
  @base_uri = base_uri
23
- URI.parse(base_uri).tap {|uri|
24
- @client = Net::HTTP.new(uri.host, uri.port)
25
- @client.use_ssl = uri.scheme == 'https'
26
- }
27
-
28
25
  opts = stringify_keys(opts)
29
- self.debug_dev = opts['debug_dev'] # IO object such as STDOUT
30
- self.open_timeout = opts['open_timeout'] || 5
31
- self.read_timeout = opts['read_timeout'] || 30
32
- self.keepalive = opts['keepalive']
33
- # self.verify_mode = OpenSSL::SSL::VERIFY_NONE
34
- end
35
26
 
36
- def debug_dev=(debug_dev)
37
- @debug_dev = debug_dev
38
- @client.set_debug_output(debug_dev)
27
+ URI.parse(base_uri).tap {|uri|
28
+ @host = uri.host
29
+ @port = uri.port
30
+ @use_ssl = uri.scheme == 'https'
31
+ }
32
+ @debug_dev = opts['debug_dev'] # IO object such as STDOUT
33
+ @open_timeout = opts['open_timeout'] # 60
34
+ @read_timeout = opts['read_timeout'] # 60
35
+ @verify_ssl = opts['verify_ssl']
36
+ @keepalive = opts['keepalive']
39
37
  end
40
38
 
41
- def open_timeout=(open_timeout)
42
- @open_time = @client.open_timeout = open_timeout
39
+ def http_connection
40
+ Net::HTTP.new(@host, @port).tap {|http|
41
+ http.use_ssl = @use_ssl
42
+ http.open_timeout = @open_timeout if @open_timeout
43
+ http.read_timeout = @read_timeout if @read_timeout
44
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @verify_ssl
45
+ http.set_debug_output(@debug_dev) if @debug_dev
46
+ }
43
47
  end
44
48
 
45
- def read_timeout=(read_timeout)
46
- @read_timeout = @client.read_timeout = read_timeout
49
+ def get_request(path, extheader = {})
50
+ Net::HTTP::Get.new(path).tap {|req|
51
+ req['Host'] = @host
52
+ req['Connection'] = 'Keep-Alive' if @keepalive
53
+ extheader.each {|key, value| req[key] = value }
54
+ }
47
55
  end
48
56
 
49
- def keepalive=(keepalive)
50
- @keepalive = keepalive
57
+ def post_request(path, body, extheader = {})
58
+ Net::HTTP::Post.new(path).tap {|req|
59
+ req['Host'] = @host
60
+ req['Connection'] = 'Keep-Alive' if @keepalive
61
+ extheader.each {|key, value| req[key] = value }
62
+ req.body = body
63
+ }
51
64
  end
52
65
 
53
66
  def last_request_uri
@@ -63,8 +76,8 @@ module GrowthForecast
63
76
  # @return [Hash] response body
64
77
  def get_json(path)
65
78
  @request_uri = "#{@base_uri}#{path}"
66
- extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
67
- @res = client.get(path, extheader)
79
+ req = get_request(path)
80
+ @res = http_connection.start {|http| http.request(req) }
68
81
  handle_error(@res)
69
82
  JSON.parse(@res.body)
70
83
  end
@@ -75,10 +88,10 @@ module GrowthForecast
75
88
  # @return [Hash] response body
76
89
  def post_json(path, data = {})
77
90
  @request_uri = "#{@base_uri}#{path}"
78
- json = JSON.generate(data)
79
- extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
80
- extheader = extheader.merge({ 'Content-Type' => 'application/json' })
81
- @res = client.post(path, json, extheader)
91
+ body = JSON.generate(data)
92
+ extheader = { 'Content-Type' => 'application/json' }
93
+ req = post_request(path, body, extheader)
94
+ @res = http_connection.start {|http| http.request(req) }
82
95
  handle_error(@res)
83
96
  JSON.parse(@res.body)
84
97
  end
@@ -89,10 +102,10 @@ module GrowthForecast
89
102
  # @return [String] response body
90
103
  def post_query(path, data = {})
91
104
  @request_uri = "#{@base_uri}#{path}"
92
- form = URI.encode_www_form(data)
93
- extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
94
- extheader = extheader.merge({ 'Content-Type' => 'application/x-www-form-urlencoded' })
95
- @res = client.post(path, form, extheader)
105
+ body = URI.encode_www_form(data)
106
+ extheader = { 'Content-Type' => 'application/x-www-form-urlencoded' }
107
+ req = post_request(path, body, extheader)
108
+ @res = http_connection.start {|http| http.request(req) }
96
109
  handle_error(@res)
97
110
  JSON.parse(@res.body)
98
111
  end
@@ -153,10 +153,6 @@ describe GrowthForecast::Client do
153
153
 
154
154
  describe 'http://blog.64p.org/?page=1366971426' do
155
155
  before { @client ||= client }
156
- context "#client=" do
157
- before { @client.client = HTTPClient.new(agent_name: 'TestAgent/0.1') }
158
- it { @client.client.agent_name.should == 'TestAgent/0.1' }
159
- end
160
156
 
161
157
  context "#last_response" do
162
158
  include_context "stub_list_graph" if ENV['MOCK'] == 'on'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growthforecast-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.80.0
4
+ version: 0.80.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-03 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient