bitzlato 0.1.1 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/bitzlato.gemspec +1 -1
- data/exe/bitzlato-cli +8 -9
- data/lib/bitzlato.rb +1 -3
- data/lib/bitzlato/client.rb +15 -5
- data/lib/bitzlato/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 707a2f72f5adaeb757672ac13814f34f3267f2ae3684c4ec4b7c020d9b89d401
|
4
|
+
data.tar.gz: 12068b06536e13d3e3879e7e54e20207e922e4837c5b139243f44e650020604f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7d97b43bfd1a6b155fbd2fa987aeb5d391c2a4217d6b0e6f8428639346adcedc9d207385faa3db32b8d49822bfb8b0700ef618701e9709ba1ed82f6f169176c
|
7
|
+
data.tar.gz: b4e46dc07bb667a69977a196833fc0619d7e904354948c8693bb797ad56d757d5e6194dfd5c823ba2aa147df1039215d7c0f8e0747055888924ea3a2520b826b
|
data/Gemfile.lock
CHANGED
data/bitzlato.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.add_dependency 'faraday', '>= 0.
|
28
|
+
spec.add_dependency 'faraday', '>= 0.17'
|
29
29
|
spec.add_dependency 'jwt', '~> 2.3.0.dev'
|
30
30
|
spec.add_dependency 'json', '~> 2.0'
|
31
31
|
spec.add_development_dependency 'pry-nav'
|
data/exe/bitzlato-cli
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
2
3
|
require 'rubygems'
|
3
4
|
require 'bundler/setup'
|
4
|
-
|
5
|
-
Bundler.require(:default)
|
6
|
-
|
7
|
-
require 'bitzlato/client'
|
5
|
+
require 'bitzlato'
|
8
6
|
|
9
7
|
key = JSON.parse(ENV.fetch('BITZLATO_API_KEY')).transform_keys(&:to_sym)
|
10
8
|
|
@@ -12,12 +10,13 @@ client = Bitzlato::Client
|
|
12
10
|
.new(home_url: ENV.fetch('BITZLATO_API_URL'), key: key, uid: ENV.fetch('BITZLATO_API_CLIENT_UID').to_i, logger: ENV.key?('BITZLATO_API_LOGGER'))
|
13
11
|
|
14
12
|
if ARGV.length == 1
|
15
|
-
puts client.get ARGV[0] || '/api/auth/whoami'
|
13
|
+
puts JSON.pretty_generate(client.get ARGV[0] || '/api/auth/whoami')
|
16
14
|
elsif ARGV.length == 2
|
17
|
-
puts client.send(ARGV[0], ARGV[1])
|
15
|
+
puts JSON.pretty_generate(client.send(ARGV[0].downcase, ARGV[1]))
|
18
16
|
elsif ARGV.length == 3
|
19
|
-
puts client.send(ARGV[0], ARGV[1], JSON.parse(ARGV[2]))
|
17
|
+
puts JSON.pretty_generate(client.send(ARGV[0].downcase, ARGV[1], JSON.parse(ARGV[2])))
|
20
18
|
else
|
21
|
-
puts "
|
19
|
+
puts "bitzlato-cli v#{Bitzlato::VERSION}"
|
20
|
+
puts "Usage: bitzlato-cli [get/post] PATH [PARAMS]"
|
21
|
+
puts "Example: bitzlato-cli get /api/auth/whoami"
|
22
22
|
end
|
23
|
-
|
data/lib/bitzlato.rb
CHANGED
data/lib/bitzlato/client.rb
CHANGED
@@ -6,15 +6,21 @@ require 'bitzlato'
|
|
6
6
|
|
7
7
|
module Bitzlato
|
8
8
|
class Client
|
9
|
+
class Error < StandardError; end
|
9
10
|
WrongResponse = Class.new Error
|
10
11
|
|
11
|
-
def initialize(home_url: , key: , logger: false, email: nil, uid: nil)
|
12
|
+
def initialize(home_url: , key: , logger: false, email: nil, uid: nil, adapter: nil)
|
12
13
|
raise ArgumentError, 'email or uid must be presented' if uid.nil? && email.nil?
|
13
14
|
@email = email
|
14
15
|
@uid = uid
|
15
16
|
@jwk = JWT::JWK.import key
|
16
17
|
@home_url = home_url
|
17
|
-
@
|
18
|
+
@adapter = adapter || Faraday.default_adapter
|
19
|
+
if logger == true
|
20
|
+
@logger = Faraday::Response::Logger.new(STDOUT)
|
21
|
+
else
|
22
|
+
@logger = logger
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
def get(path, params = {})
|
@@ -29,7 +35,8 @@ module Bitzlato
|
|
29
35
|
|
30
36
|
def parse_response(response)
|
31
37
|
raise WrongResponse, "Wrong response status (#{response.status})" unless response.success?
|
32
|
-
|
38
|
+
return nil if response.body.emtpy?
|
39
|
+
raise WrongResponse, "Wrong content type (#{response['content-type']})" if response['content-type'] != 'application/json'
|
33
40
|
JSON.parse response.body
|
34
41
|
end
|
35
42
|
|
@@ -44,14 +51,17 @@ module Bitzlato
|
|
44
51
|
}
|
45
52
|
end
|
46
53
|
|
54
|
+
# Every time build new connection to have fresh jwt token
|
47
55
|
def connection
|
48
|
-
|
49
|
-
c.use Faraday::Response::Logger
|
56
|
+
Faraday.new url: @home_url do |c|
|
57
|
+
c.use Faraday::Response::Logger unless @logger.nil?
|
50
58
|
c.headers = {
|
51
59
|
'Content-Type' => 'application/json',
|
52
60
|
'Accept' => 'application/json'
|
53
61
|
}
|
62
|
+
c.request :curl, @logger, :warn if ENV['BITZLATO_CURL_LOGGER']
|
54
63
|
c.authorization :Bearer, bearer
|
64
|
+
c.adapter @adapter
|
55
65
|
end
|
56
66
|
end
|
57
67
|
|
data/lib/bitzlato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitzlato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danil Pismenny
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.17'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jwt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|