bitzlato 0.1.0 → 0.1.6

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: 8e75020b2c5bf814a55b857cd5a974b084ebaaa3949403019223e32b920b08dc
4
- data.tar.gz: f74c4ffe1b83e7518665a53785f71b69953501a21fbdfe53d7a7681a2b8f123a
3
+ metadata.gz: 2c5615a8307850e0657588e3e5fe2fec0c2512933b8ba15ae86461d3311fcbe7
4
+ data.tar.gz: f9fac4b86cc4ecb7f42fb2f4efc649c27b6d686614cac3e438384fc9adf7cfac
5
5
  SHA512:
6
- metadata.gz: 1dccecf44688d840f6aebd0b1d993fdbe2bc664062a429382ae4d81c99fbd3a4bda5c975fc3c44fa318b9465d693579b2ccbca812af6e58f861ce952571a87c5
7
- data.tar.gz: 757444a2d1324f4c230739449261f72562830aeb94dc5fc5ffb8579857169254766ae0b6c6c8cdd8234b2f4d15ae17eac6976d489c4f10d2d35b625a9384ed0a
6
+ metadata.gz: 007dccd9fb93d607ca4bdee887f2c4486a5867503b995ef848567427c4f14cd2af139390b5f8c8a6ec34cd5272ffebda17ff8e9311328c8d1de2a0245ee0219b
7
+ data.tar.gz: f478a7bc31f8e1010f99c938c9cdd96de4d6bfcb5eebd936ea7166e9ee13b4fa41038b49e458841e6bb72002d64c486daeede97e12d6dfa18994bf33644d9664
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6.6
data/Gemfile.lock CHANGED
@@ -7,10 +7,10 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- bitzlato (0.1.0)
11
- faraday
12
- json
13
- jwt
10
+ bitzlato (0.1.6)
11
+ faraday (>= 0.17)
12
+ json (~> 2.0)
13
+ jwt (~> 2.3.0.dev)
14
14
 
15
15
  GEM
16
16
  remote: https://rubygems.org/
data/bitzlato.gemspec CHANGED
@@ -25,8 +25,8 @@ 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'
29
- spec.add_dependency 'jwt'
30
- spec.add_dependency 'json'
28
+ spec.add_dependency 'faraday', '>= 0.17'
29
+ spec.add_dependency 'jwt', '~> 2.3.0.dev'
30
+ spec.add_dependency 'json', '~> 2.0'
31
31
  spec.add_development_dependency 'pry-nav'
32
32
  end
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,6 +1,5 @@
1
1
  require "bitzlato/version"
2
2
 
3
3
  module Bitzlato
4
- class Error < StandardError; end
5
- # Your code goes here...
4
+ require "bitzlato/client"
6
5
  end
@@ -2,18 +2,25 @@ require 'securerandom'
2
2
  require 'jwt'
3
3
  require 'json'
4
4
  require 'faraday'
5
+ require 'bitzlato'
5
6
 
6
7
  module Bitzlato
7
8
  class Client
9
+ class Error < StandardError; end
8
10
  WrongResponse = Class.new Error
9
11
 
10
- 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)
11
13
  raise ArgumentError, 'email or uid must be presented' if uid.nil? && email.nil?
12
14
  @email = email
13
15
  @uid = uid
14
16
  @jwk = JWT::JWK.import key
15
17
  @home_url = home_url
16
- @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
17
24
  end
18
25
 
19
26
  def get(path, params = {})
@@ -28,7 +35,7 @@ module Bitzlato
28
35
 
29
36
  def parse_response(response)
30
37
  raise WrongResponse, "Wrong response status (#{response.status})" unless response.success?
31
- raise WrongResponse, "Wrong content type (#{response['content-type']})" unless response['content-type'] == 'application/json'
38
+ raise WrongResponse, "Wrong content type (#{response['content-type']})" if !response.body.empty? && response['content-type'] != 'application/json'
32
39
  JSON.parse response.body
33
40
  end
34
41
 
@@ -45,12 +52,14 @@ module Bitzlato
45
52
 
46
53
  def connection
47
54
  @connection ||= Faraday.new url: @home_url do |c|
48
- c.use Faraday::Response::Logger if @logger
55
+ c.use Faraday::Response::Logger unless @logger.nil?
49
56
  c.headers = {
50
57
  'Content-Type' => 'application/json',
51
58
  'Accept' => 'application/json'
52
59
  }
60
+ c.request :curl, logger, :warn if ENV['BITZLATO_CURL_LOGGER']
53
61
  c.authorization :Bearer, bearer
62
+ c.adapter @adapter
54
63
  end
55
64
  end
56
65
 
@@ -1,3 +1,3 @@
1
1
  module Bitzlato
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.6"
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.0
4
+ version: 0.1.6
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,42 +16,42 @@ 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
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.3.0.dev
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.3.0.dev
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-nav
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -76,6 +76,7 @@ extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
78
  - ".gitignore"
79
+ - ".ruby-version"
79
80
  - ".travis.yml"
80
81
  - CODE_OF_CONDUCT.md
81
82
  - Gemfile