haveapi-go-client 0.20.0 → 0.21.0

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: db88d2729b86152d843b5714fe2e55dcf5eb33382b6d50196eb3c04a5c7549b4
4
- data.tar.gz: 7505c745f672b7d2aa09f5ccc38aaa70c34dfc86a68b59bf732d5aab22f440e3
3
+ metadata.gz: 7a7636a78332b0aa0b89c5eb21f0d3d0944629c006165e899670677ee3e8e83e
4
+ data.tar.gz: d1cb9bcd4d094670197d613aaa8775724e02304ed5b073292423056ec33a4621
5
5
  SHA512:
6
- metadata.gz: c7680dd117b5ee738e72f66f6652ffeca053da2904173a924667ecd51789be4cde6c7821182698de0f26365e8d816813175d842a3fa72e845d9466589fa6d0d9
7
- data.tar.gz: 9f56f3b3e8b470a3ca87df671a0ac18c0bc87b852c7bfc9d377d689680f51cea92d1b7ecc0bbd43f0a63632b481f647466594574be7c8ce9256dcad249698a00
6
+ metadata.gz: 8b67cc15963852f808c5554acdd668b6813e2b06d6ff721d3157fc348de8bd466399fd14bd73e5c8571b678305ad4198b31db0b284070acef090172f3186e7e4
7
+ data.tar.gz: f9932502872003d594552901d06895a62869abb4feb2e289546e4c7659c73fbb98180d85fbe9c867dd8e09416d20dca16736925c42f1c6fc1c23a0e030e004f3
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'haveapi-client', path: '../ruby'
5
+
6
+ group :development do
7
+ gem 'bundler'
8
+ gem 'rake'
9
+ end
@@ -1,6 +1,5 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
1
+ lib = File.expand_path('lib', __dir__)
2
+ $:.unshift(lib) unless $:.include?(lib)
4
3
  require 'haveapi/go_client/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
@@ -9,17 +8,15 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ['Jakub Skokan']
10
9
  spec.email = ['jakub.skokan@vpsfree.cz']
11
10
  spec.summary =
12
- spec.description = 'Go client generator'
11
+ spec.description = 'Go client generator'
13
12
  spec.homepage = ''
14
13
  spec.license = 'MIT'
15
14
 
15
+ spec.required_ruby_version = ">= #{File.read('../../.ruby-version').strip}"
16
+
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler'
22
- spec.add_development_dependency 'rake'
23
-
24
- spec.add_runtime_dependency 'haveapi-client', '~> 0.20.0'
21
+ spec.add_runtime_dependency 'haveapi-client', '~> 0.21.0'
25
22
  end
@@ -59,12 +59,12 @@ module HaveAPI::GoClient
59
59
  @name = name.to_s
60
60
  @prefix = prefix
61
61
  @aliases = desc[:aliases]
62
- @full_dot_name = resource.full_dot_name + '#' + @name.capitalize
62
+ @full_dot_name = "#{resource.full_dot_name}##{@name.capitalize}"
63
63
  @go_name = camelize(name)
64
64
  @go_type = full_go_type
65
- @go_invocation_type = go_type + 'Invocation'
66
- @go_request_type = go_type + 'Request'
67
- @go_response_type = go_type + 'Response'
65
+ @go_invocation_type = "#{go_type}Invocation"
66
+ @go_request_type = "#{go_type}Request"
67
+ @go_response_type = "#{go_type}Response"
68
68
  @input = desc[:input] && InputOutput.new(self, :io, :input, desc[:input])
69
69
  @output = desc[:output] && InputOutput.new(self, :io, :output, desc[:output])
70
70
  @http_method = desc[:method]
@@ -96,7 +96,7 @@ module HaveAPI::GoClient
96
96
  end
97
97
 
98
98
  def input_output
99
- %i(input output).select do |v|
99
+ %i[input output].select do |v|
100
100
  send(v) && send(v).parameters.any?
101
101
  end.map { |v| send(v) }
102
102
  end
@@ -106,9 +106,7 @@ module HaveAPI::GoClient
106
106
  end
107
107
 
108
108
  def resolve_associations
109
- input_output.each do |io|
110
- io.resolve_associations
111
- end
109
+ input_output.each(&:resolve_associations)
112
110
 
113
111
  metadata && metadata.resolve_associations
114
112
  end
@@ -118,6 +116,7 @@ module HaveAPI::GoClient
118
116
  end
119
117
 
120
118
  protected
119
+
121
120
  attr_reader :prefix
122
121
 
123
122
  def full_go_type
@@ -126,7 +125,7 @@ module HaveAPI::GoClient
126
125
  names << 'Action'
127
126
  names.concat(resource.resource_path.map(&:go_name))
128
127
  names << go_name
129
- names.join('')
128
+ names.join
130
129
  end
131
130
  end
132
131
  end
@@ -14,7 +14,7 @@ module HaveAPI::GoClient
14
14
  Resource.new(self, k, v)
15
15
  end.sort!
16
16
 
17
- @resources.each { |r| r.resolve_associations }
17
+ @resources.each(&:resolve_associations)
18
18
 
19
19
  @auth_methods = desc[:authentication].map do |k, v|
20
20
  AuthenticationMethods.new(self, k, v)
@@ -5,6 +5,8 @@ module HaveAPI::GoClient
5
5
  AuthenticationMethods.register(name, self)
6
6
  end
7
7
 
8
+ def initialize(api_version, name, desc); end
9
+
8
10
  # @param dst [String]
9
11
  def generate(dst)
10
12
  raise NotImplementedError
@@ -4,15 +4,11 @@ module HaveAPI::GoClient
4
4
  class Authentication::Basic < Authentication::Base
5
5
  register :basic
6
6
 
7
- def initialize(api_version, name, desc)
8
-
9
- end
10
-
11
7
  def generate(gen)
12
8
  ErbTemplate.render_to_if_changed(
13
9
  'authentication/basic.go',
14
10
  {
15
- package: gen.package,
11
+ package: gen.package
16
12
  },
17
13
  File.join(gen.dst, 'auth_basic.go')
18
14
  )
@@ -13,6 +13,7 @@ module HaveAPI::GoClient
13
13
  attr_reader :revoke_url
14
14
 
15
15
  def initialize(api_version, name, desc)
16
+ super
16
17
  @http_header = desc[:http_header]
17
18
  @revoke_url = desc[:revoke_url]
18
19
  end
@@ -22,7 +23,7 @@ module HaveAPI::GoClient
22
23
  'authentication/oauth2.go',
23
24
  {
24
25
  package: gen.package,
25
- auth: self,
26
+ auth: self
26
27
  },
27
28
  File.join(gen.dst, 'auth_oauth2.go')
28
29
  )
@@ -17,13 +17,14 @@ module HaveAPI::GoClient
17
17
  attr_reader :resource
18
18
 
19
19
  def initialize(api_version, name, desc)
20
+ super
20
21
  @http_header = desc[:http_header]
21
22
  @query_parameter = desc[:query_parameter]
22
23
  @resource = Resource.new(
23
24
  api_version,
24
25
  :token,
25
26
  desc[:resources][:token],
26
- prefix: 'auth_token',
27
+ prefix: 'auth_token'
27
28
  )
28
29
  resource.resolve_associations
29
30
  end
@@ -33,7 +34,7 @@ module HaveAPI::GoClient
33
34
  'authentication/token.go',
34
35
  {
35
36
  package: gen.package,
36
- auth: self,
37
+ auth: self
37
38
  },
38
39
  File.join(gen.dst, 'auth_token.go')
39
40
  )
@@ -49,7 +50,7 @@ module HaveAPI::GoClient
49
50
  # @return [Array<Action>]
50
51
  def custom_actions
51
52
  @custom_actions ||= resource.actions.reject do |a|
52
- %w(request renew revoke).include?(a.name)
53
+ %w[request renew revoke].include?(a.name)
53
54
  end
54
55
  end
55
56
  end
@@ -3,11 +3,10 @@ require 'haveapi/go_client/authentication/base'
3
3
  module HaveAPI::GoClient
4
4
  class Authentication::Unsupported < Authentication::Base
5
5
  def initialize(api_version, name, desc)
6
+ super
6
7
  warn "Ignoring unsupported authentication method #{name}"
7
8
  end
8
9
 
9
- def generate(gen)
10
-
11
- end
10
+ def generate(gen); end
12
11
  end
13
12
  end
@@ -1,5 +1,5 @@
1
1
  module HaveAPI::GoClient
2
- module Authentication ; end
2
+ module Authentication; end
3
3
 
4
4
  module AuthenticationMethods
5
5
  # @param name [Symbol]
@@ -16,9 +16,9 @@ module HaveAPI::GoClient
16
16
 
17
17
  # @param api_version [ApiVersion]
18
18
  # @param name [String]
19
- def self.new(api_version, name, *args)
19
+ def self.new(api_version, name, *)
20
20
  klass = get(name) || Authentication::Unsupported
21
- klass.new(api_version, name, *args)
21
+ klass.new(api_version, name, *)
22
22
  end
23
23
  end
24
24
  end
@@ -5,7 +5,7 @@ module HaveAPI::GoClient
5
5
  class Cli
6
6
  def self.run
7
7
  options = {
8
- package: 'client',
8
+ package: 'client'
9
9
  }
10
10
 
11
11
  parser = OptionParser.new do |opts|
@@ -36,7 +36,7 @@ module HaveAPI::GoClient
36
36
  if self.module
37
37
  ErbTemplate.render_to_if_changed(
38
38
  'go.mod',
39
- {mod: self.module},
39
+ { mod: self.module },
40
40
  File.join(dst, 'go.mod')
41
41
  )
42
42
 
@@ -44,12 +44,12 @@ module HaveAPI::GoClient
44
44
  FileUtils.mkpath(dst)
45
45
  end
46
46
 
47
- %w(client authentication request response types).each do |v|
47
+ %w[client authentication request response types].each do |v|
48
48
  ErbTemplate.render_to_if_changed(
49
49
  "#{v}.go",
50
50
  {
51
- package: package,
52
- api: api,
51
+ package:,
52
+ api:
53
53
  },
54
54
  File.join(dst, "#{v}.go")
55
55
  )
@@ -60,12 +60,13 @@ module HaveAPI::GoClient
60
60
  end
61
61
 
62
62
  def go_fmt
63
- unless system('go', 'fmt', chdir: dst)
64
- fail "go fmt failed"
65
- end
63
+ return if system('go', 'fmt', chdir: dst)
64
+
65
+ raise 'go fmt failed'
66
66
  end
67
67
 
68
68
  protected
69
+
69
70
  attr_reader :api
70
71
  end
71
72
  end
@@ -37,12 +37,12 @@ module HaveAPI::GoClient
37
37
  @parameters = desc[:parameters].map do |k, v|
38
38
  Parameter.new(role, direction, self, k.to_s, v)
39
39
  end.compact.sort!
40
- @go_type = action.go_type + (prefix ? prefix : '') + direction.to_s.capitalize
40
+ @go_type = action.go_type + (prefix || '') + direction.to_s.capitalize
41
41
  @go_namespace = camelize(desc[:namespace])
42
42
  end
43
43
 
44
44
  def resolve_associations
45
- parameters.each { |p| p.resolve }
45
+ parameters.each(&:resolve)
46
46
  end
47
47
  end
48
48
  end
@@ -46,8 +46,8 @@ module HaveAPI::GoClient
46
46
  object && object.resolve_associations
47
47
  end
48
48
 
49
- %i(global object).each do |type|
50
- %i(input output).each do |dir|
49
+ %i[global object].each do |type|
50
+ %i[input output].each do |dir|
51
51
  define_method(:"has_#{type}_#{dir}?") do
52
52
  t = send(type)
53
53
  next(false) unless t
@@ -1,5 +1,5 @@
1
1
  module HaveAPI::GoClient
2
- module Parameters ; end
2
+ module Parameters; end
3
3
 
4
4
  module Parameter
5
5
  # @param klass [Class]
@@ -16,8 +16,8 @@ module HaveAPI::GoClient
16
16
  # @param desc [Hash]
17
17
  # @return [Parameters::Base, nil]
18
18
  def self.new(role, direction, io, name, desc)
19
- klass, _ =
20
- @handlers.select do |klass, block|
19
+ klass, =
20
+ @handlers.select do |_klass, block|
21
21
  block.call(role, direction, name, desc)
22
22
  end.first
23
23
 
@@ -28,6 +28,7 @@ module HaveAPI::GoClient
28
28
  end
29
29
 
30
30
  protected
31
+
31
32
  def find_resource(path)
32
33
  root = parameter.io.action.resource.api_version
33
34
  path = path.clone
@@ -37,7 +38,7 @@ module HaveAPI::GoClient
37
38
  resource = root.resources.detect { |r| r.name == name }
38
39
 
39
40
  if resource.nil?
40
- fail "associated resource '#{name}' not found in "+
41
+ raise "associated resource '#{name}' not found in " +
41
42
  (root.is_a?(ApiVersion) ? 'root' : root.resource_path.map(&:name).join('.'))
42
43
 
43
44
  elsif path.empty?
@@ -48,7 +49,7 @@ module HaveAPI::GoClient
48
49
  end
49
50
  end
50
51
 
51
- fail 'programming error'
52
+ raise 'programming error'
52
53
  end
53
54
  end
54
55
  end
@@ -64,11 +64,10 @@ module HaveAPI::GoClient
64
64
  end
65
65
 
66
66
  protected
67
+
67
68
  # @return [Hash]
68
69
  attr_reader :desc
69
70
 
70
- def do_resolve
71
-
72
- end
71
+ def do_resolve; end
73
72
  end
74
73
  end
@@ -10,6 +10,7 @@ module HaveAPI::GoClient
10
10
  end
11
11
 
12
12
  protected
13
+
13
14
  def do_resolve
14
15
  @go_in_type = @go_out_type = 'string'
15
16
  end
@@ -2,7 +2,7 @@ require 'haveapi/go_client/parameters/base'
2
2
 
3
3
  module HaveAPI::GoClient
4
4
  class Parameters::Resource < Parameters::Base
5
- handle do |role, direction, name, desc|
5
+ handle do |_role, _direction, _name, desc|
6
6
  desc[:type] == 'Resource'
7
7
  end
8
8
 
@@ -15,6 +15,7 @@ module HaveAPI::GoClient
15
15
  end
16
16
 
17
17
  protected
18
+
18
19
  def do_resolve
19
20
  @association = Parameters::Association.new(self, desc)
20
21
  @go_in_type = 'int64'
@@ -2,11 +2,12 @@ require 'haveapi/go_client/parameters/base'
2
2
 
3
3
  module HaveAPI::GoClient
4
4
  class Parameters::Typed < Parameters::Base
5
- handle do |role, direction, name, desc|
6
- !%w(Custom Resource).include?(desc[:type])
5
+ handle do |_role, _direction, _name, desc|
6
+ !%w[Custom Resource].include?(desc[:type])
7
7
  end
8
8
 
9
9
  protected
10
+
10
11
  def do_resolve
11
12
  @go_in_type = get_go_type(desc[:type])
12
13
  @go_out_type = get_go_type(desc[:type])
@@ -23,7 +24,7 @@ module HaveAPI::GoClient
23
24
  when 'Boolean'
24
25
  'bool'
25
26
  else
26
- fail "unsupported data type '#{v}'"
27
+ raise "unsupported data type '#{v}'"
27
28
  end
28
29
  end
29
30
  end
@@ -48,7 +48,7 @@ module HaveAPI::GoClient
48
48
  Resource.new(self, k, v)
49
49
  end.sort!
50
50
  @actions = desc[:actions].map do |k, v|
51
- Action.new(self, k.to_s, v, prefix: prefix)
51
+ Action.new(self, k.to_s, v, prefix:)
52
52
  end.sort!
53
53
  end
54
54
 
@@ -78,8 +78,8 @@ module HaveAPI::GoClient
78
78
  end
79
79
 
80
80
  def resolve_associations
81
- actions.each { |a| a.resolve_associations }
82
- resources.each { |r| r.resolve_associations }
81
+ actions.each(&:resolve_associations)
82
+ resources.each(&:resolve_associations)
83
83
  end
84
84
 
85
85
  def generate(gen)
@@ -87,7 +87,7 @@ module HaveAPI::GoClient
87
87
  'resource.go',
88
88
  {
89
89
  package: gen.package,
90
- resource: self,
90
+ resource: self
91
91
  },
92
92
  File.join(gen.dst, prefix_underscore("resource_#{full_name}.go"))
93
93
  )
@@ -99,7 +99,7 @@ module HaveAPI::GoClient
99
99
  'action.go',
100
100
  {
101
101
  package: gen.package,
102
- action: a,
102
+ action: a
103
103
  },
104
104
  File.join(gen.dst, prefix_underscore("resource_#{full_name}_action_#{a.name}.go"))
105
105
  )
@@ -111,6 +111,7 @@ module HaveAPI::GoClient
111
111
  end
112
112
 
113
113
  protected
114
+
114
115
  attr_reader :prefix
115
116
 
116
117
  def prefix_underscore(s)
@@ -133,7 +134,7 @@ module HaveAPI::GoClient
133
134
  names = ['Resource']
134
135
  names.concat(parent_resources.map(&:go_name))
135
136
  names << go_name
136
- prefix_camel(names.join(''))
137
+ prefix_camel(names.join)
137
138
  end
138
139
  end
139
140
  end
@@ -4,7 +4,7 @@ module HaveAPI::GoClient
4
4
  # @param v [String]
5
5
  # @return [String]
6
6
  def camelize(v)
7
- v.to_s.split('_').map(&:capitalize).join('')
7
+ v.to_s.split('_').map(&:capitalize).join
8
8
  end
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module HaveAPI
2
2
  module GoClient
3
- VERSION = '0.20.0'
3
+ VERSION = '0.21.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haveapi-go-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
@@ -10,48 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: haveapi-client
43
15
  requirement: !ruby/object:Gem::Requirement
44
16
  requirements:
45
17
  - - "~>"
46
18
  - !ruby/object:Gem::Version
47
- version: 0.20.0
19
+ version: 0.21.0
48
20
  type: :runtime
49
21
  prerelease: false
50
22
  version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
52
24
  - - "~>"
53
25
  - !ruby/object:Gem::Version
54
- version: 0.20.0
26
+ version: 0.21.0
55
27
  description: Go client generator
56
28
  email:
57
29
  - jakub.skokan@vpsfree.cz
@@ -113,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
85
  requirements:
114
86
  - - ">="
115
87
  - !ruby/object:Gem::Version
116
- version: '0'
88
+ version: 3.2.0
117
89
  required_rubygems_version: !ruby/object:Gem::Requirement
118
90
  requirements:
119
91
  - - ">="