bitzlato 0.1.3 → 0.1.9

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: 52ac8eed7ada8363c97899f1c8919916150c7647cebcc42be4c5156b84e51c39
4
- data.tar.gz: 85f143d37881b374f5c7ba20ffa617c43ba256cbb337319924e583ebfcb4adde
3
+ metadata.gz: 0a89268c8cb7ff848c3d653f7e3e2adae06630b834896f8057123983317a9556
4
+ data.tar.gz: 2e49d78b376fdb0e2f52b5c6b1d0e019b1c08ed9c7bc51fa43de73385ac17ca3
5
5
  SHA512:
6
- metadata.gz: a640a87353032fb04d49dd597621fd41bec3fe067eaf58fc4839a30ad106a504efc7acbdf8cd954460edc5b1cb0fae02744b67651aa73b91d050f76d75b685ce
7
- data.tar.gz: 62feabf34dca0199eb56b3f79fa65a8f836660d7b89fd9c7e194f2d9c410f76c45bd12f268207dc4966a70cf26c0557e6f410159ee904108e7f36591d929455c
6
+ metadata.gz: 187352800cc314d3b6462b65912a37ab112215241b7ce159e7ff426e7c856171378dca31c7e6c09915b823e02dfc7b038559fadbb99e6e0a021851c36270fa04
7
+ data.tar.gz: 8c4b547b3370949fdf52dadaf0fc5289dfaf483a267398f567acedb12d4cb8ffec6ae8d1a2c963d421df96aaff22cc41d4c0ecbdea85c1d26b8249ff34f351db
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- bitzlato (0.1.3)
10
+ bitzlato (0.1.8)
11
11
  faraday (>= 0.17)
12
12
  json (~> 2.0)
13
13
  jwt (~> 2.3.0.dev)
@@ -44,4 +44,4 @@ DEPENDENCIES
44
44
  rake (~> 12.0)
45
45
 
46
46
  BUNDLED WITH
47
- 2.1.4
47
+ 2.2.15
data/exe/bitzlato-cli CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
4
+ require 'bundler/setup'
3
5
  require 'bitzlato'
4
6
 
5
7
  key = JSON.parse(ENV.fetch('BITZLATO_API_KEY')).transform_keys(&:to_sym)
@@ -10,9 +12,11 @@ client = Bitzlato::Client
10
12
  if ARGV.length == 1
11
13
  puts JSON.pretty_generate(client.get ARGV[0] || '/api/auth/whoami')
12
14
  elsif ARGV.length == 2
13
- puts JSON.pretty_generate(client.send(ARGV[0], ARGV[1]))
15
+ puts JSON.pretty_generate(client.send(ARGV[0].downcase, ARGV[1]))
14
16
  elsif ARGV.length == 3
15
- puts JSON.pretty_generate(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])))
16
18
  else
17
- 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"
18
22
  end
data/lib/bitzlato.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "bitzlato/version"
2
2
 
3
3
  module Bitzlato
4
- class Error < StandardError; end
5
4
  require "bitzlato/client"
6
5
  end
@@ -6,16 +6,23 @@ 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
 
12
+ attr_reader :uid, :email, :jwk, :home_url
13
+
11
14
  def initialize(home_url: , key: , logger: false, email: nil, uid: nil, adapter: nil)
12
15
  raise ArgumentError, 'email or uid must be presented' if uid.nil? && email.nil?
13
16
  @email = email
14
17
  @uid = uid
15
18
  @jwk = JWT::JWK.import key
16
19
  @home_url = home_url
17
- @logger = logger
18
20
  @adapter = adapter || Faraday.default_adapter
21
+ if logger == true
22
+ @logger = Faraday::Response::Logger.new(STDOUT)
23
+ else
24
+ @logger = logger
25
+ end
19
26
  end
20
27
 
21
28
  def get(path, params = {})
@@ -29,8 +36,9 @@ module Bitzlato
29
36
  private
30
37
 
31
38
  def parse_response(response)
32
- raise WrongResponse, "Wrong response status (#{response.status})" unless response.success?
33
- raise WrongResponse, "Wrong content type (#{response['content-type']})" unless response['content-type'] == 'application/json'
39
+ raise WrongResponse, "Wrong response status (#{response.status}) with body #{response.body}" unless response.success?
40
+ return nil if response.body.empty?
41
+ raise WrongResponse, "Wrong content type (#{response['content-type']})" if response['content-type'] != 'application/json'
34
42
  JSON.parse response.body
35
43
  end
36
44
 
@@ -45,13 +53,15 @@ module Bitzlato
45
53
  }
46
54
  end
47
55
 
56
+ # Every time build new connection to have fresh jwt token
48
57
  def connection
49
- @connection ||= Faraday.new url: @home_url do |c|
50
- c.use Faraday::Response::Logger if @logger
58
+ Faraday.new url: @home_url do |c|
59
+ c.use Faraday::Response::Logger unless @logger.nil?
51
60
  c.headers = {
52
61
  'Content-Type' => 'application/json',
53
62
  'Accept' => 'application/json'
54
63
  }
64
+ c.request :curl, @logger, :warn if ENV['BITZLATO_CURL_LOGGER']
55
65
  c.authorization :Bearer, bearer
56
66
  c.adapter @adapter
57
67
  end
@@ -1,3 +1,3 @@
1
1
  module Bitzlato
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.9"
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.3
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danil Pismenny
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -98,7 +98,7 @@ metadata:
98
98
  homepage_uri: https://github.com/finfex/bitzlato
99
99
  source_code_uri: https://github.com/finfex/bitzlato
100
100
  changelog_uri: https://github.com/finfex/bitzlato/blob/main/CHANGELOG.md
101
- post_install_message:
101
+ post_install_message:
102
102
  rdoc_options: []
103
103
  require_paths:
104
104
  - lib
@@ -113,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.0.3
117
- signing_key:
116
+ rubygems_version: 3.2.15
117
+ signing_key:
118
118
  specification_version: 4
119
119
  summary: Ruby HTTP API client library and cli for bitzlato.bz
120
120
  test_files: []