bazil_client 1.0.2 → 2.0.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.
- data/ChangeLog.md +6 -0
- data/VERSION +1 -1
- data/lib/bazil/client.rb +7 -5
- data/lib/bazil/rest.rb +13 -1
- metadata +4 -4
data/ChangeLog.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/lib/bazil/client.rb
CHANGED
@@ -13,7 +13,7 @@ module Bazil
|
|
13
13
|
extend Forwardable
|
14
14
|
|
15
15
|
class Options
|
16
|
-
attr_reader :host, :port, :scheme, :ca_file, :ssl_version, :verify_mode, :api_key, :secret_key
|
16
|
+
attr_reader :host, :port, :scheme, :api_root, :ca_file, :ssl_version, :verify_mode, :api_key, :secret_key
|
17
17
|
|
18
18
|
def initialize(options)
|
19
19
|
if options.kind_of? String
|
@@ -36,6 +36,8 @@ module Bazil
|
|
36
36
|
@port = url.port or raise "Failed to obtain port number from given url: url = #{url.to_s}"
|
37
37
|
@scheme = url.scheme or raise "Failed to obtain scheme from given url: url = #{url.to_s}"
|
38
38
|
raise "Unsupported scheme '#{@scheme}'" unless AVAILABLE_SCHEMA.include? @scheme
|
39
|
+
@api_root = url.path
|
40
|
+
@api_root += '/' unless @api_root.end_with? '/'
|
39
41
|
end
|
40
42
|
|
41
43
|
def load_ca_file_option(options)
|
@@ -97,9 +99,9 @@ module Bazil
|
|
97
99
|
DEFAULT_SKIP_VERIFY = false
|
98
100
|
|
99
101
|
BAZIL_CONFIG_DIRS = [
|
100
|
-
File::join(ENV['PWD'], '.bazil'),
|
101
|
-
File::join(ENV['HOME'], '.bazil')
|
102
|
-
]
|
102
|
+
(File::join(ENV['PWD'], '.bazil') if ENV['PWD']),
|
103
|
+
(File::join(ENV['HOME'], '.bazil') if ENV['HOME']),
|
104
|
+
].compact
|
103
105
|
|
104
106
|
API_KEYS_FILE_KEY = :api_keys
|
105
107
|
DEFAULT_API_KEYS_FILES = BAZIL_CONFIG_DIRS.map{|dir| File::join(dir, 'api_keys') }
|
@@ -119,7 +121,7 @@ module Bazil
|
|
119
121
|
http = Net::HTTP.new(opt.host, opt.port)
|
120
122
|
set_ssl_options(http,opt)
|
121
123
|
|
122
|
-
@http_cli = REST.new(http)
|
124
|
+
@http_cli = REST.new(http, api_root: opt.api_root)
|
123
125
|
set_api_keys(opt.api_key, opt.secret_key)
|
124
126
|
end
|
125
127
|
|
data/lib/bazil/rest.rb
CHANGED
@@ -5,13 +5,16 @@ require 'json'
|
|
5
5
|
require 'time'
|
6
6
|
require 'net/http'
|
7
7
|
require 'digest/md5'
|
8
|
+
require 'pathname'
|
8
9
|
|
9
10
|
module Bazil
|
10
11
|
class REST
|
11
12
|
extend Forwardable
|
12
13
|
|
13
|
-
def initialize(http)
|
14
|
+
def initialize(http, options = {})
|
14
15
|
@http = http
|
16
|
+
@api_root = options[:api_root] || '/'
|
17
|
+
@api_root += '/' unless @api_root.end_with? '/'
|
15
18
|
end
|
16
19
|
|
17
20
|
def_delegators :@http, :read_timeout, :read_timeout=
|
@@ -23,6 +26,7 @@ module Bazil
|
|
23
26
|
end
|
24
27
|
|
25
28
|
def get(uri)
|
29
|
+
uri = gen_path(uri)
|
26
30
|
uri, header = add_api_signature(uri, nil)
|
27
31
|
@http.get(uri, header)
|
28
32
|
rescue Errno::ECONNREFUSED => e
|
@@ -30,6 +34,7 @@ module Bazil
|
|
30
34
|
end
|
31
35
|
|
32
36
|
def put(uri, data, header = {})
|
37
|
+
uri = gen_path(uri)
|
33
38
|
uri, header = add_api_signature(uri, data, header)
|
34
39
|
@http.put(uri, data, header)
|
35
40
|
rescue Errno::ECONNREFUSED => e
|
@@ -37,6 +42,7 @@ module Bazil
|
|
37
42
|
end
|
38
43
|
|
39
44
|
def post(uri, data, header = {})
|
45
|
+
uri = gen_path(uri)
|
40
46
|
uri, header = add_api_signature(uri, data, header)
|
41
47
|
@http.post(uri, data, header)
|
42
48
|
rescue Errno::ECONNREFUSED => e
|
@@ -44,6 +50,7 @@ module Bazil
|
|
44
50
|
end
|
45
51
|
|
46
52
|
def delete(uri)
|
53
|
+
uri = gen_path(uri)
|
47
54
|
uri, header = add_api_signature(uri, nil)
|
48
55
|
@http.delete(uri, header)
|
49
56
|
rescue Errno::ECONNREFUSED => e
|
@@ -51,6 +58,11 @@ module Bazil
|
|
51
58
|
end
|
52
59
|
|
53
60
|
private
|
61
|
+
def gen_path(path)
|
62
|
+
# Pathname#+ cannot append absolute path, so use String#+ then canonicalize it
|
63
|
+
Pathname.new(@api_root + path).cleanpath.to_s
|
64
|
+
end
|
65
|
+
|
54
66
|
def add_api_signature(uri, data, header = {})
|
55
67
|
return uri, header unless @api_key and @secret_key
|
56
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bazil_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -102,10 +102,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
segments:
|
104
104
|
- 0
|
105
|
-
hash:
|
105
|
+
hash: 2357737480406686873
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.8.23
|
108
|
+
rubygems_version: 1.8.23.2
|
109
109
|
signing_key:
|
110
110
|
specification_version: 3
|
111
111
|
summary: Ruby client of Bazil
|