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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 480217442cc8094b21e2e3f6796a14acdc40a7f21357b3c3700e14620953e484
4
- data.tar.gz: c017fbd0b13285e18b48367c9d7482e1f708b33399aa8ba81f938f1e079c7848
3
+ metadata.gz: 707a2f72f5adaeb757672ac13814f34f3267f2ae3684c4ec4b7c020d9b89d401
4
+ data.tar.gz: 12068b06536e13d3e3879e7e54e20207e922e4837c5b139243f44e650020604f
5
5
  SHA512:
6
- metadata.gz: 1b760f572865b3fa88340c76b99a2a1efddf8471885e59093275f87ad1ee3e6d872032474be0f5e26153dbed889b86dccaf8bc465b11bc454cb457ff324de5d0
7
- data.tar.gz: 329c6e2fcff57d977acb6f29385ed2d9a61a0b0f374c8cdec78d2984b78631d4a880ccc6fe64f02ec604d173e6039ac40fc37d9348bd46ad0576c4bbf5be10ed
6
+ metadata.gz: e7d97b43bfd1a6b155fbd2fa987aeb5d391c2a4217d6b0e6f8428639346adcedc9d207385faa3db32b8d49822bfb8b0700ef618701e9709ba1ed82f6f169176c
7
+ data.tar.gz: b4e46dc07bb667a69977a196833fc0619d7e904354948c8693bb797ad56d757d5e6194dfd5c823ba2aa147df1039215d7c0f8e0747055888924ea3a2520b826b
data/Gemfile.lock CHANGED
@@ -7,8 +7,8 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- bitzlato (0.1.0)
11
- faraday (>= 0.27)
10
+ bitzlato (0.1.6)
11
+ faraday (>= 0.17)
12
12
  json (~> 2.0)
13
13
  jwt (~> 2.3.0.dev)
14
14
 
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.27'
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 "Run example: #{$0} get /api/auth/whoami"
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
@@ -1,7 +1,5 @@
1
1
  require "bitzlato/version"
2
- require "bitzlato/client"
3
2
 
4
3
  module Bitzlato
5
- class Error < StandardError; end
6
- # Your code goes here...
4
+ require "bitzlato/client"
7
5
  end
@@ -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
- @logger = logger
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
- raise WrongResponse, "Wrong content type (#{response['content-type']})" unless response['content-type'] == 'application/json'
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
- @connection ||= Faraday.new url: @home_url do |c|
49
- c.use Faraday::Response::Logger if @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
 
@@ -1,3 +1,3 @@
1
1
  module Bitzlato
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.7"
3
3
  end
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.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-10 00:00:00.000000000 Z
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.27'
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.27'
26
+ version: '0.17'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jwt
29
29
  requirement: !ruby/object:Gem::Requirement