bitzlato 0.1.2 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26408b56dadbb4cca23a9227bde63308729f7393c35adb982d5d83b8fe97f4d3
4
- data.tar.gz: 02bc9776579bd77f49d6fc92dd9d086b8e4430503d53f486e97ae629d12f9951
3
+ metadata.gz: 9f7d7f7beafdecadd6bd2400c04a7961c8d502f4878d05cf9006cce4ee15c19c
4
+ data.tar.gz: c1df825aa3a3d40891c4f48e4c4d44ceb0a341527c6f2d354fe04a3de902ca25
5
5
  SHA512:
6
- metadata.gz: 8ec6dce0334d287c64cffb23ada0de56fa932b449203301023262e2f7447e142e1994ed75ad0df253938fc760e49b837571b538f2ae04e0b283b5ab5af145b10
7
- data.tar.gz: 771a02c15844d6d592fa4450ebf14d61f1f2cde83be62e9624ef016cefd2fe203e148eec497cf415692f9c7dbc29290aaf99cee1d1d9089f93a17d744826bd08
6
+ metadata.gz: f72fd5d74a97800162e8dcc639c415ac7a3e585d9cdf3259bb6ed656d4bac1efdd202cc72f3e92a6c0784e4e12f3de116ba2be5b8b293639440832afdd9ad22e
7
+ data.tar.gz: 5208f0055f0f42cf38ac847d8b1b01ff2f61247411130d2635f1db97a60fe8ea57e3557ec7a44ba0b863b9746e6bee7ae79f22690692923db4e62a2c1791def8
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- bitzlato (0.1.2)
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,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,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
 
11
- def initialize(home_url: , key: , logger: false, email: nil, uid: nil)
12
+ attr_reader :uid, :email, :jwk, :home_url
13
+
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
20
+ @adapter = adapter || Faraday.default_adapter
21
+ if logger == true
22
+ @logger = Faraday::Response::Logger.new(STDOUT)
23
+ else
24
+ @logger = logger
25
+ end
18
26
  end
19
27
 
20
28
  def get(path, params = {})
@@ -29,7 +37,8 @@ module Bitzlato
29
37
 
30
38
  def parse_response(response)
31
39
  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'
40
+ return nil if response.body.empty?
41
+ raise WrongResponse, "Wrong content type (#{response['content-type']})" if response['content-type'] != 'application/json'
33
42
  JSON.parse response.body
34
43
  end
35
44
 
@@ -44,14 +53,17 @@ module Bitzlato
44
53
  }
45
54
  end
46
55
 
56
+ # Every time build new connection to have fresh jwt token
47
57
  def connection
48
- @connection ||= Faraday.new url: @home_url do |c|
49
- c.use Faraday::Response::Logger if @logger
58
+ Faraday.new url: @home_url do |c|
59
+ c.use Faraday::Response::Logger unless @logger.nil?
50
60
  c.headers = {
51
61
  'Content-Type' => 'application/json',
52
62
  'Accept' => 'application/json'
53
63
  }
64
+ c.request :curl, @logger, :warn if ENV['BITZLATO_CURL_LOGGER']
54
65
  c.authorization :Bearer, bearer
66
+ c.adapter @adapter
55
67
  end
56
68
  end
57
69
 
@@ -1,3 +1,3 @@
1
1
  module Bitzlato
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.8"
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.2
4
+ version: 0.1.8
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-04-14 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: []