jerakia-client 0.5.3 → 1.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.
- checksums.yaml +4 -4
- data/lib/jerakia/client.rb +28 -5
- data/lib/jerakia/client/cli/lookup.rb +11 -1
- data/lib/jerakia/client/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4989cd5cb49bbd373c3fd8e45b8540a0f2966bac
|
4
|
+
data.tar.gz: 71f59ae0a1e0e2624e5d0eabfa4c00725b88d279
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffa938ab9719823a952ef6880b779deb38552a9e8beaf3761a46262eeed1f5a30f4984e8661a8995a389ecf5f6edd608ff038ffe28f6fb3b8ab1cf5b6e313234
|
7
|
+
data.tar.gz: 8cc5df3a87890088bce061da24fee3b0a1988ca36e33ba2db9ef9a5c05c9ce335260e2d8f17082b1f7b351373d30b03fd51cd35dde71a3f1d1db82caf5eafce2
|
data/lib/jerakia/client.rb
CHANGED
@@ -6,6 +6,7 @@ require 'jerakia/client/token'
|
|
6
6
|
require 'uri'
|
7
7
|
require 'json'
|
8
8
|
require 'net/http'
|
9
|
+
require 'msgpack'
|
9
10
|
|
10
11
|
class Jerakia
|
11
12
|
class Client
|
@@ -53,6 +54,7 @@ class Jerakia
|
|
53
54
|
:port => 9843,
|
54
55
|
:api => 'v1',
|
55
56
|
:proto => 'http',
|
57
|
+
:content_type => 'json',
|
56
58
|
}
|
57
59
|
end
|
58
60
|
|
@@ -82,7 +84,11 @@ class Jerakia
|
|
82
84
|
|
83
85
|
case response.code
|
84
86
|
when "200"
|
85
|
-
|
87
|
+
if not @config.key?(:content_type) or @config[:content_type] == 'json'
|
88
|
+
return JSON.parse(response.body)
|
89
|
+
else @config[:content_type] == 'msgpack'
|
90
|
+
return MessagePack.unpack(response.body)
|
91
|
+
end
|
86
92
|
when "401"
|
87
93
|
raise Jerakia::Client::AuthorizationError, "Request not authorized"
|
88
94
|
when "501"
|
@@ -93,22 +99,39 @@ class Jerakia
|
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
102
|
+
def encode_request(request)
|
103
|
+
if not @config.key?(:content_type) or @config[:content_type] == 'json'
|
104
|
+
request.add_field('Content-Type', 'application/json')
|
105
|
+
if request.key?('body')
|
106
|
+
request.body.to_json
|
107
|
+
end
|
108
|
+
elsif @config[:content_type] == 'msgpack'
|
109
|
+
request.add_field('Content-Type', 'application/x-msgpack')
|
110
|
+
if request.key?('body')
|
111
|
+
request.body.to_msgpack
|
112
|
+
end
|
113
|
+
else
|
114
|
+
raise Jerakia::Client::Error, "Invalid setting \"#{@config[:content_type]}\" for \":content_type\" in config - supported is either json or msgpack."
|
115
|
+
exit(false)
|
116
|
+
end
|
117
|
+
return request
|
118
|
+
end
|
96
119
|
|
97
120
|
def get(url_path, params={})
|
98
121
|
uri = URI.parse(url_address + url_path)
|
99
122
|
uri.query = URI.encode_www_form(params)
|
100
123
|
request = Net::HTTP::Get.new(uri.to_s)
|
124
|
+
request = encode_request(request)
|
101
125
|
return http_send(request)
|
102
126
|
end
|
103
127
|
|
104
128
|
def put(url_path, params)
|
105
129
|
uri = URI.parse(url_address + url_path)
|
106
130
|
request = Net::HTTP::Put.new(uri.path)
|
107
|
-
request
|
108
|
-
request.body = params
|
131
|
+
request = set_content_type(request)
|
132
|
+
request.body = params
|
133
|
+
request = encode_request(request)
|
109
134
|
return http_send(request)
|
110
135
|
end
|
111
136
|
end
|
112
137
|
end
|
113
|
-
|
114
|
-
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'yaml'
|
3
|
+
require 'msgpack'
|
3
4
|
|
4
5
|
class Jerakia
|
5
6
|
class Client
|
@@ -80,7 +81,13 @@ class Jerakia
|
|
80
81
|
aliases: :o,
|
81
82
|
type: :string,
|
82
83
|
default: 'json',
|
83
|
-
desc: 'Output format, yaml or
|
84
|
+
desc: 'Output format, yaml, json or msgpack'
|
85
|
+
|
86
|
+
option :content_type,
|
87
|
+
aliases: :c,
|
88
|
+
type: :string,
|
89
|
+
default: 'json',
|
90
|
+
desc: 'Content type, json or msgpack'
|
84
91
|
|
85
92
|
def lookup(key)
|
86
93
|
client = Jerakia::Client.new({
|
@@ -88,6 +95,7 @@ class Jerakia
|
|
88
95
|
:port => options[:port],
|
89
96
|
:api => options[:api],
|
90
97
|
:token => options[:token],
|
98
|
+
:content_type => options[:content_type],
|
91
99
|
})
|
92
100
|
|
93
101
|
lookup_opts = {
|
@@ -118,6 +126,8 @@ class Jerakia
|
|
118
126
|
puts answer.to_json
|
119
127
|
when 'yaml'
|
120
128
|
puts answer.to_yaml
|
129
|
+
when 'msgpack'
|
130
|
+
puts answer.to_msgpack
|
121
131
|
else
|
122
132
|
raise Jerakia::Client::Error, "Unknown output type #{options[:output]}"
|
123
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jerakia-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Dunn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.19'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: msgpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
27
41
|
description: CLI and ruby client libraries for Jerakia Server
|
28
42
|
email:
|
29
43
|
executables:
|