growthforecast-client 0.62.4 → 0.80.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/VERSION +1 -1
- data/growthforecast-client.gemspec +2 -1
- data/lib/growthforecast/client.rb +40 -115
- data/spec/growthforecast/client_spec.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8658e5aaffe4bcef2988147166e8bdce538900b
|
4
|
+
data.tar.gz: fc1807ea534cbf097507bcbbd30fc4f04e8090ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2878c8404112b4c25fc7b2994293ee4c1a699098d85c917ee463b67461a8352c754ecb32f4795a50402798eb8da0f50a9ec0894e81e129e5c5acf300f417cf19
|
7
|
+
data.tar.gz: db196f7c978c7854a239bacfe5785297a4011797bec0aa5ba48898e85128ff8217cc162f2f389ef601fdf1b526d8736795847aa912ee6e6d8bb66cb9bd23335b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.80.0
|
@@ -9,6 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.homepage = "https://github.com/sonots/growthforecast-client"
|
10
10
|
gem.summary = "A Ruby Client Library for GrowthForecast API"
|
11
11
|
gem.description = gem.summary
|
12
|
+
gem.licenses = ["MIT"]
|
12
13
|
|
13
14
|
gem.files = `git ls-files`.split($\)
|
14
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -25,5 +26,5 @@ Gem::Specification.new do |gem|
|
|
25
26
|
|
26
27
|
# for debug
|
27
28
|
gem.add_development_dependency "pry"
|
28
|
-
gem.add_development_dependency "
|
29
|
+
gem.add_development_dependency "pry-nav"
|
29
30
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require '
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
3
4
|
require 'json'
|
4
5
|
require 'cgi'
|
5
|
-
require 'pp'
|
6
6
|
|
7
7
|
module GrowthForecast
|
8
8
|
class Error < StandardError; end
|
@@ -10,124 +10,45 @@ module GrowthForecast
|
|
10
10
|
class AlreadyExists < Error; end
|
11
11
|
|
12
12
|
class Client
|
13
|
-
attr_accessor :debug
|
14
13
|
attr_accessor :client
|
15
14
|
attr_reader :base_uri
|
16
|
-
|
15
|
+
attr_reader :debug_dev
|
16
|
+
attr_reader :open_timeout
|
17
|
+
attr_reader :read_timeout
|
18
|
+
attr_reader :keepalive
|
17
19
|
|
18
20
|
# @param [String] base_uri The base uri of GrowthForecast
|
19
21
|
def initialize(base_uri = 'http://127.0.0.1:5125', opts = {})
|
20
|
-
@client = HTTPClient.new
|
21
22
|
@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
|
+
|
22
28
|
opts = stringify_keys(opts)
|
23
|
-
|
24
|
-
self.
|
25
|
-
|
26
|
-
|
27
|
-
# self.
|
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
|
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
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
-
|
36
|
+
def debug_dev=(debug_dev)
|
37
|
+
@debug_dev = debug_dev
|
38
|
+
@client.set_debug_output(debug_dev)
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
|
-
|
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
|
41
|
+
def open_timeout=(open_timeout)
|
42
|
+
@open_time = @client.open_timeout = open_timeout
|
60
43
|
end
|
61
44
|
|
62
|
-
|
63
|
-
|
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)
|
45
|
+
def read_timeout=(read_timeout)
|
46
|
+
@read_timeout = @client.read_timeout = read_timeout
|
121
47
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
def set_cookie_store(filename)
|
126
|
-
@client.set_cookie_store(filename)
|
48
|
+
|
49
|
+
def keepalive=(keepalive)
|
50
|
+
@keepalive = keepalive
|
127
51
|
end
|
128
|
-
attr_proxy_reader :save_cookie_store
|
129
|
-
attr_proxy_reader :cookies
|
130
|
-
attr_proxy_accessor :redirect_uri_callback
|
131
52
|
|
132
53
|
def last_request_uri
|
133
54
|
@request_uri
|
@@ -142,9 +63,8 @@ module GrowthForecast
|
|
142
63
|
# @return [Hash] response body
|
143
64
|
def get_json(path)
|
144
65
|
@request_uri = "#{@base_uri}#{path}"
|
145
|
-
query = nil
|
146
66
|
extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
|
147
|
-
@res = client.get(
|
67
|
+
@res = client.get(path, extheader)
|
148
68
|
handle_error(@res)
|
149
69
|
JSON.parse(@res.body)
|
150
70
|
end
|
@@ -154,11 +74,11 @@ module GrowthForecast
|
|
154
74
|
# @param [Hash] data
|
155
75
|
# @return [Hash] response body
|
156
76
|
def post_json(path, data = {})
|
157
|
-
pp data if @debug
|
158
77
|
@request_uri = "#{@base_uri}#{path}"
|
159
78
|
json = JSON.generate(data)
|
160
79
|
extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
|
161
|
-
|
80
|
+
extheader = extheader.merge({ 'Content-Type' => 'application/json' })
|
81
|
+
@res = client.post(path, json, extheader)
|
162
82
|
handle_error(@res)
|
163
83
|
JSON.parse(@res.body)
|
164
84
|
end
|
@@ -168,10 +88,11 @@ module GrowthForecast
|
|
168
88
|
# @param [Hash] data
|
169
89
|
# @return [String] response body
|
170
90
|
def post_query(path, data = {})
|
171
|
-
pp data if @debug
|
172
91
|
@request_uri = "#{@base_uri}#{path}"
|
92
|
+
form = URI.encode_www_form(data)
|
173
93
|
extheader = @keepalive ? { 'Connection' => 'Keep-Alive' } : {}
|
174
|
-
|
94
|
+
extheader = extheader.merge({ 'Content-Type' => 'application/x-www-form-urlencoded' })
|
95
|
+
@res = client.post(path, form, extheader)
|
175
96
|
handle_error(@res)
|
176
97
|
JSON.parse(@res.body)
|
177
98
|
end
|
@@ -488,11 +409,11 @@ module GrowthForecast
|
|
488
409
|
end
|
489
410
|
|
490
411
|
def handle_error(res)
|
491
|
-
case res.
|
492
|
-
when 200
|
493
|
-
when 404
|
412
|
+
case res.code
|
413
|
+
when '200'
|
414
|
+
when '404'
|
494
415
|
raise NotFound.new(error_message(res))
|
495
|
-
when 409
|
416
|
+
when '409'
|
496
417
|
raise AlreadyExists.new(error_message(res))
|
497
418
|
else
|
498
419
|
raise Error.new(error_message(res))
|
@@ -517,6 +438,10 @@ module GrowthForecast
|
|
517
438
|
updates['meta'] = '' if !params.has_key?('meta')
|
518
439
|
updates
|
519
440
|
end
|
441
|
+
|
442
|
+
def stringify_keys(hash)
|
443
|
+
{}.tap {|h| hash.each {|key, val| h[key.to_s] = val } }
|
444
|
+
end
|
520
445
|
end
|
521
446
|
end
|
522
447
|
|
@@ -162,7 +162,7 @@ describe GrowthForecast::Client do
|
|
162
162
|
include_context "stub_list_graph" if ENV['MOCK'] == 'on'
|
163
163
|
before { @client.list_graph }
|
164
164
|
subject { @client.last_response }
|
165
|
-
it { should be_kind_of
|
165
|
+
it { should be_kind_of Net::HTTPResponse }
|
166
166
|
end
|
167
167
|
|
168
168
|
context "#last_request_uri" do
|
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.
|
4
|
+
version: 0.80.0
|
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-
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: pry-nav
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - '>='
|
@@ -139,7 +139,8 @@ files:
|
|
139
139
|
- spec/support/mock.rb
|
140
140
|
- spec/support/setup.rb
|
141
141
|
homepage: https://github.com/sonots/growthforecast-client
|
142
|
-
licenses:
|
142
|
+
licenses:
|
143
|
+
- MIT
|
143
144
|
metadata: {}
|
144
145
|
post_install_message:
|
145
146
|
rdoc_options: []
|