growthforecast-client 0.62.3 → 0.62.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/VERSION +1 -1
- data/bin/growthforecast-client +1 -1
- data/lib/growthforecast-client.rb +2 -2
- data/lib/growthforecast/client.rb +121 -11
- data/spec/growthforecast/client_spec.rb +7 -0
- data/spec/support/setup.rb +12 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5672c5c83ce2b178ace118ac1e6f291346681f41
|
4
|
+
data.tar.gz: 70a5147e382bb3cef90197db057be8ce9d9ede99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f4245db2673db3389d1b99d8ce23dba339fc8979ca56ec6a5493cb2d5bd27f1c041d2e93370b2c78f1674d9973caf9e74177e5e686448674daa844aa3f615dc
|
7
|
+
data.tar.gz: c51644b5a8782c676719e0920c96e858630a116324701b23d5852472c2a9ac4f9d456b0aabdca0f82ba03889abe46e789bec00a35ece9411bff1fc4b1b3f5d86
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GrowthForecast Client [![Build Status](https://secure.travis-ci.org/sonots/growthforecast-client.png?branch=master)](http://travis-ci.org/sonots/growthforecast-client)
|
1
|
+
# GrowthForecast Client [![Build Status](https://secure.travis-ci.org/sonots/growthforecast-client.png?branch=master)](http://travis-ci.org/sonots/growthforecast-client)
|
2
2
|
|
3
3
|
testing ruby: 1.9.2, 1.9.3, 2.0.0; GrowthForecast: >= 0.62 (Jun 27, 2013 released)
|
4
4
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.62.
|
1
|
+
0.62.4
|
data/bin/growthforecast-client
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'growthforecast/client'
|
2
|
+
require_relative 'growthforecast/cli'
|
@@ -12,22 +12,125 @@ module GrowthForecast
|
|
12
12
|
class Client
|
13
13
|
attr_accessor :debug
|
14
14
|
attr_accessor :client
|
15
|
-
attr_reader :debug_dev
|
16
15
|
attr_reader :base_uri
|
16
|
+
attr_accessor :keepalive
|
17
17
|
|
18
18
|
# @param [String] base_uri The base uri of GrowthForecast
|
19
|
-
def initialize(base_uri = 'http://127.0.0.1:5125')
|
19
|
+
def initialize(base_uri = 'http://127.0.0.1:5125', opts = {})
|
20
|
+
@client = HTTPClient.new
|
20
21
|
@base_uri = base_uri
|
22
|
+
opts = stringify_keys(opts)
|
23
|
+
@keepalive = opts.delete('keepalive') # bool
|
24
|
+
self.debug_dev = opts.delete('debug_dev') # IO object such as STDOUT
|
25
|
+
# cf. https://github.com/nahi/httpclient/blob/0a16401e7892fbbd195a0254344bd48ac8a8bb26/lib/httpclient/session.rb#L133-L139
|
26
|
+
# self.connect_timeout = 60
|
27
|
+
# self.connect_retry = 1
|
28
|
+
# self.send_timeout = 120
|
29
|
+
# self.receive_timeout = 60 # For each read_block_size bytes
|
30
|
+
# self.keep_alive_timeout = 15 # '15' is from Apache 2 default
|
31
|
+
# self.read_block_size = 1024 * 16 # follows net/http change in 1.8.7
|
32
|
+
# self.protocol_retry_count = 5
|
21
33
|
end
|
22
34
|
|
23
|
-
def
|
24
|
-
|
35
|
+
def stringify_keys(hash)
|
36
|
+
{}.tap {|h| hash.each {|key, val| h[key.to_s] = val } }
|
25
37
|
end
|
26
38
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
39
|
+
class << self
|
40
|
+
def attr_proxy_reader(symbol)
|
41
|
+
attr_proxy(symbol)
|
42
|
+
end
|
43
|
+
|
44
|
+
def attr_proxy_accessor(symbol)
|
45
|
+
attr_proxy(symbol, true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def attr_proxy(symbol, assignable = false)
|
49
|
+
name = symbol.to_s
|
50
|
+
define_method(name) {
|
51
|
+
@client.__send__(name)
|
52
|
+
}
|
53
|
+
if assignable
|
54
|
+
aname = name + '='
|
55
|
+
define_method(aname) { |rhs|
|
56
|
+
@client.__send__(aname, rhs)
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# cf. https://github.com/nahi/httpclient/blob/0a16401e7892fbbd195a0254344bd48ac8a8bb26/lib/httpclient.rb#L309-L355
|
63
|
+
# cf. https://github.com/nahi/httpclient/blob/0a16401e7892fbbd195a0254344bd48ac8a8bb26/lib/httpclient/session.rb#L89-L158
|
64
|
+
# proxy::SSLConfig:: SSL configurator.
|
65
|
+
attr_proxy_reader :ssl_config
|
66
|
+
# WebAgent::CookieManager:: Cookies configurator.
|
67
|
+
attr_proxy_accessor :cookie_manager
|
68
|
+
# An array of response HTTP message body String which is used for loop-back
|
69
|
+
# test. See test/* to see how to use it. If you want to do loop-back test
|
70
|
+
# of HTTP header, use test_loopback_http_response instead.
|
71
|
+
attr_proxy_reader :test_loopback_response
|
72
|
+
# An array of request filter which can trap HTTP request/response.
|
73
|
+
# See proxy::WWWAuth to see how to use it.
|
74
|
+
attr_proxy_reader :request_filter
|
75
|
+
# proxy::ProxyAuth:: Proxy authentication handler.
|
76
|
+
attr_proxy_reader :proxy_auth
|
77
|
+
# proxy::WWWAuth:: WWW authentication handler.
|
78
|
+
attr_proxy_reader :www_auth
|
79
|
+
# How many times get_content and post_content follows HTTP redirect.
|
80
|
+
# 10 by default.
|
81
|
+
attr_proxy_accessor :follow_redirect_count
|
82
|
+
|
83
|
+
# Set HTTP version as a String:: 'HTTP/1.0' or 'HTTP/1.1'
|
84
|
+
attr_proxy(:protocol_version, true)
|
85
|
+
# Connect timeout in sec.
|
86
|
+
attr_proxy(:connect_timeout, true)
|
87
|
+
# Request sending timeout in sec.
|
88
|
+
attr_proxy(:send_timeout, true)
|
89
|
+
# Response receiving timeout in sec.
|
90
|
+
attr_proxy(:receive_timeout, true)
|
91
|
+
# Reuse the same connection within this timeout in sec. from last used.
|
92
|
+
attr_proxy(:keep_alive_timeout, true)
|
93
|
+
# Size of reading block for non-chunked response.
|
94
|
+
attr_proxy(:read_block_size, true)
|
95
|
+
# Negotiation retry count for authentication. 5 by default.
|
96
|
+
attr_proxy(:protocol_retry_count, true)
|
97
|
+
# if your ruby is older than 2005-09-06, do not set socket_sync = false to
|
98
|
+
# avoid an SSL socket blocking bug in openssl/buffering.rb.
|
99
|
+
attr_proxy(:socket_sync, true)
|
100
|
+
# User-Agent header in HTTP request.
|
101
|
+
attr_proxy(:agent_name, true)
|
102
|
+
# From header in HTTP request.
|
103
|
+
attr_proxy(:from, true)
|
104
|
+
# An array of response HTTP String (not a HTTP message body) which is used
|
105
|
+
# for loopback test. See test/* to see how to use it.
|
106
|
+
attr_proxy(:test_loopback_http_response)
|
107
|
+
# Decompress a compressed (with gzip or deflate) content body transparently. false by default.
|
108
|
+
attr_proxy(:transparent_gzip_decompression, true)
|
109
|
+
# Local socket address. Set HTTPClient#socket_local.host and HTTPClient#socket_local.port to specify local binding hostname and port of TCP socket.
|
110
|
+
attr_proxy(:socket_local, true)
|
111
|
+
|
112
|
+
# cf. https://github.com/nahi/httpclient/blob/0a16401e7892fbbd195a0254344bd48ac8a8bb26/lib/httpclient.rb#L416-L569
|
113
|
+
attr_proxy_accessor :debug_dev
|
114
|
+
attr_proxy_accessor :proxy
|
115
|
+
attr_proxy_accessor :no_proxy
|
116
|
+
def set_auth(domain, user, passwd)
|
117
|
+
@client.set_auth(domain, user, passwd)
|
118
|
+
end
|
119
|
+
def set_basic_auth(domain, user, passwd)
|
120
|
+
@client.set_basic_auth(domain, user, passwd)
|
121
|
+
end
|
122
|
+
def set_proxy_auth(user, passwd)
|
123
|
+
@client.set_proxy_auth(user, passwd)
|
124
|
+
end
|
125
|
+
def set_cookie_store(filename)
|
126
|
+
@client.set_cookie_store(filename)
|
127
|
+
end
|
128
|
+
attr_proxy_reader :save_cookie_store
|
129
|
+
attr_proxy_reader :cookies
|
130
|
+
attr_proxy_accessor :redirect_uri_callback
|
131
|
+
|
132
|
+
def last_request_uri
|
133
|
+
@request_uri
|
31
134
|
end
|
32
135
|
|
33
136
|
def last_response
|
@@ -38,7 +141,10 @@ module GrowthForecast
|
|
38
141
|
# @param [String] path
|
39
142
|
# @return [Hash] response body
|
40
143
|
def get_json(path)
|
41
|
-
@
|
144
|
+
@request_uri = "#{@base_uri}#{path}"
|
145
|
+
query = nil
|
146
|
+
extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
|
147
|
+
@res = client.get(@request_uri, query, extheader)
|
42
148
|
handle_error(@res)
|
43
149
|
JSON.parse(@res.body)
|
44
150
|
end
|
@@ -49,8 +155,10 @@ module GrowthForecast
|
|
49
155
|
# @return [Hash] response body
|
50
156
|
def post_json(path, data = {})
|
51
157
|
pp data if @debug
|
158
|
+
@request_uri = "#{@base_uri}#{path}"
|
52
159
|
json = JSON.generate(data)
|
53
|
-
|
160
|
+
extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
|
161
|
+
@res = client.post(@request_uri, json, extheader)
|
54
162
|
handle_error(@res)
|
55
163
|
JSON.parse(@res.body)
|
56
164
|
end
|
@@ -61,7 +169,9 @@ module GrowthForecast
|
|
61
169
|
# @return [String] response body
|
62
170
|
def post_query(path, data = {})
|
63
171
|
pp data if @debug
|
64
|
-
@
|
172
|
+
@request_uri = "#{@base_uri}#{path}"
|
173
|
+
extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
|
174
|
+
@res = client.post(@request_uri, data, extheader)
|
65
175
|
handle_error(@res)
|
66
176
|
JSON.parse(@res.body)
|
67
177
|
end
|
@@ -164,6 +164,13 @@ describe GrowthForecast::Client do
|
|
164
164
|
subject { @client.last_response }
|
165
165
|
it { should be_kind_of HTTP::Message }
|
166
166
|
end
|
167
|
+
|
168
|
+
context "#last_request_uri" do
|
169
|
+
include_context "stub_list_graph" if ENV['MOCK'] == 'on'
|
170
|
+
before { @client.list_graph }
|
171
|
+
subject { @client.last_request_uri }
|
172
|
+
it { should == "http://localhost:5125/json/list/graph" }
|
173
|
+
end
|
167
174
|
end
|
168
175
|
end
|
169
176
|
|
data/spec/support/setup.rb
CHANGED
@@ -36,14 +36,16 @@ shared_context "setup_growthforecast_client" do
|
|
36
36
|
|
37
37
|
include_context "stub_post_graph" if ENV['MOCK'] == 'on'
|
38
38
|
include_context "stub_delete_graph" if ENV['MOCK'] == 'on'
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
39
|
+
unless ENV['MOCK'] == 'on'
|
40
|
+
before {
|
41
|
+
client.delete_graph("app name", "host name", "<1sec count") rescue nil
|
42
|
+
client.delete_graph("app name", "host name", "<2sec count") rescue nil
|
43
|
+
client.post_graph("app name", "host name", "<1sec count", { 'number' => 0 }) rescue nil
|
44
|
+
client.post_graph("app name", "host name", "<2sec count", { 'number' => 0 }) rescue nil
|
45
|
+
}
|
46
|
+
after {
|
47
|
+
client.delete_graph("app name", "host name", "<1sec count") rescue nil
|
48
|
+
client.delete_graph("app name", "host name", "<2sec count") rescue nil
|
49
|
+
}
|
50
|
+
end
|
49
51
|
end
|
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.62.
|
4
|
+
version: 0.62.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|