hudu 0.1.0 → 0.2.0

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: ee8592c8b1e645dcf0b370b7d2661b821f0a411d7bd6675b942d5e2a64d1ec20
4
- data.tar.gz: 13ac2f1bcffab93943e0f3259c2c14f73c98a85cfb00952e181713501c290499
3
+ metadata.gz: 9f48ff08cda4008e20930d883e35caec1e4558ba6ca5a66bb3b0caae36565679
4
+ data.tar.gz: 060e661b7be43f050cf6511728cfadb4a892e582fd56d3ecb588dd89a64e9bf8
5
5
  SHA512:
6
- metadata.gz: 40187b263f4388eea09aed5d54713687afdf8aad57f69c23d2d6e538ef2af0f2449af3c41eb8f5c358576282527c0f09f2e88db205eb06056b9be5b74c276c57
7
- data.tar.gz: a20ac42a0c6aa74e62a2e8dc34a00f73762db7f6d43d62d6c3dde37dd3221181640050bfee855feea66b56c4a437052c3625b53334c6aabe816ae0363573ca28
6
+ metadata.gz: 85010f142ca7b9b2427ca6d654365c949ca4a36de7373029989343cdcb3b83af2668db2500232cd6cca5a95cd2bf52b6092ce203feb1a81595d404fc292cb188
7
+ data.tar.gz: 38323855457d5c411143aa1526d839f007428838e039712dfd76fae9bc23ac06f05f7c249506cd716abc369f55d8d6e40d026aa11355a6d83d4c5027f58ff91c
data/CHANGELOG.md CHANGED
@@ -3,3 +3,6 @@
3
3
  ## [0.1.0] - 2024-02-20
4
4
  - Initial release
5
5
 
6
+ ## [0.2.0] - 2024-03-13
7
+ - update_company_asset added
8
+
data/Gemfile CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in cloudally.gemspec
5
+ # Specify your gem's dependencies in hudu.gemspec
6
6
  gemspec
7
7
 
8
8
  gem 'rake', '~> 13.0'
9
9
  gem 'rubocop', '~> 1.7'
10
+ gem 'simplecov', require: false, group: :test
10
11
  gem 'wrapi'
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Hudu API
2
+ [![Version](https://img.shields.io/gem/v/hudu.svg)](https://rubygems.org/gems/hudu)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/e02c3f2cd2f13261597d/maintainability)](https://codeclimate.com/github/jancotanis/hudu/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/e02c3f2cd2f13261597d/test_coverage)](https://codeclimate.com/github/jancotanis/hudu/test_coverage)
2
5
 
3
- This is a wrapper for the Hudu rest API. You can see the API endpoints here https://www.zabbix.com/documentation/current/en/manual/api/reference/
6
+ This is a wrapper for the Hudu rest API.
4
7
 
5
8
  Currently only the GET requests to get a list of hosts, host groups and problems are implemented.
6
9
 
@@ -75,19 +78,19 @@ end
75
78
  |:--|:--|
76
79
  |.api_info | /api/v1/api_info|
77
80
  |.activity_logs | /api/v1/activity_logs|
78
- |.companies, :company(id) | /api/v1/companies/{id}|
79
- |.articles, :article(id) | /api/v1/articles/{id}|
80
- |.asset_layouts, :asset_layout(id) | /api/v1/asset_layouts/{id}|
81
- |.assets, :asset(id) | /api/v1/assets/{id}|
81
+ |.companies, company(id) | /api/v1/companies/{id}|
82
+ |.articles, article(id) | /api/v1/articles/{id}|
83
+ |.asset_layouts, asset_layout(id) | /api/v1/asset_layouts/{id}|
84
+ |.assets, asset(id) | /api/v1/assets/{id}|
82
85
  |.asset_passwords | /api/v1/asset_passwords/{id}|
83
- |.folders, :folder(id) | /api/v1/folders/{id}|
84
- |.procedures, :procedure(id) | /api/v1/procedures/{id}|
86
+ |.folders, folder(id) | /api/v1/folders/{id}|
87
+ |.procedures, procedure(id) | /api/v1/procedures/{id}|
85
88
  |.expirations | /api/v1/expirations|
86
- |.websites, :website(id) | /api/v1/websites/{id}|
89
+ |.websites, website(id) | /api/v1/websites/{id}|
87
90
  |.relations | /api/v1/relations|
88
- |.company_articles(id) |/api/v1/companies/{id}/articles|
89
- |.company_assets(id) |/api/v1/companies/{id}/assets|
90
- |.company_asset(id,asset_id) |/api/v1/companies/{id}/assets/{asset_id}|
91
+ |.company_articles(id) | /api/v1/companies/{id}/articles|
92
+ |.company_assets(id) | /api/v1/companies/{id}/assets|
93
+ |.company_asset(id,asset_id) | /api/v1/companies/{id}/assets/{asset_id}|
91
94
 
92
95
 
93
96
  ## Publishing
data/Rakefile CHANGED
@@ -1,12 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/gem_tasks'
4
+ require 'dotenv'
4
5
  require 'rake/testtask'
5
6
 
7
+ Dotenv.load
8
+
9
+ system './bin/cc-test-reporter before-build'
10
+
6
11
  Rake::TestTask.new(:test) do |t|
7
12
  t.libs << 'test'
8
13
  t.libs << 'lib'
9
14
  t.test_files = FileList['test/**/*_test.rb']
15
+ at_exit do
16
+ system './bin/cc-test-reporter after-build'
17
+ end
10
18
  end
11
19
 
12
20
  require 'rubocop/rake_task'
Binary file
data/hudu.gemspec CHANGED
@@ -29,8 +29,9 @@ Gem::Specification.new do |s|
29
29
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
30
  s.platform = Gem::Platform::RUBY
31
31
  s.add_runtime_dependency 'faraday'
32
- s.add_runtime_dependency 'wrapi', ">= 0.2.0"
32
+ s.add_runtime_dependency 'wrapi', ">= 0.3.0"
33
33
  s.add_development_dependency 'dotenv'
34
34
  s.add_development_dependency 'minitest'
35
+ s.add_development_dependency 'simplecov'
35
36
  s.add_development_dependency 'rubocop'
36
37
  end
@@ -0,0 +1,20 @@
1
+ module Hudu
2
+
3
+ class AssetHelper
4
+ # Construct asset for updates, assuem it is an entity
5
+ def self.construct_asset asset
6
+ custom_asset = asset.attributes.slice( *%w(
7
+ id company_id asset_layout_id slug name
8
+ primary_serial primary_model primary_mail
9
+ primary_manufacturer )
10
+ )
11
+ custom_asset['custom_fields'] = self.custom_fields(asset.fields)
12
+ { asset: custom_asset }
13
+ end
14
+ private
15
+ def self.custom_fields(fields)
16
+ [fields.map{|field| [field.label.downcase.gsub(' ','_'),field.value]}.to_h]
17
+ end
18
+
19
+ end
20
+ end
data/lib/hudu/client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require File.expand_path('api', __dir__)
2
+ require File.expand_path('asset_helper', __dir__)
2
3
 
3
4
  module Hudu
4
5
  # Wrapper for the Hudu REST API
@@ -17,7 +18,7 @@ module Hudu
17
18
  end
18
19
  # record by id
19
20
  self.send(:define_method, singular_method) do |id, params = {}|
20
- r = get(api_url("#{path}/" + id.to_s), params)
21
+ r = get(api_url("#{path}/#{id}"), params)
21
22
  r = hudu_data(r,singular_method)
22
23
  end
23
24
  else
@@ -26,6 +27,12 @@ module Hudu
26
27
  get(api_url(path), params)
27
28
  end
28
29
  end
30
+ # update
31
+ self.send(:define_method, "update_#{method}") do |id=nil,params = {}|
32
+ r = post(api_url("#{path}/#{id}"), params)
33
+ r = hudu_data(r,method)
34
+ end
35
+
29
36
  end
30
37
 
31
38
  public
@@ -47,11 +54,11 @@ module Hudu
47
54
  api_endpoint :expirations
48
55
  api_endpoint :websites, :website
49
56
  api_endpoint :relations
57
+ api_endpoint :magic_dash
50
58
 
51
59
  def company_articles( company_id, params = {} )
52
- articles({company_id: company_id}.merge(parems))
60
+ articles({company_id: company_id}.merge(params))
53
61
  end
54
-
55
62
  def company_assets(id,params={})
56
63
  get_paged(api_url("companies/#{id}/assets"), params)
57
64
  end
@@ -59,6 +66,10 @@ module Hudu
59
66
  get(api_url("companies/#{id}/assets/#{asset_id}"), params)
60
67
  end
61
68
 
69
+ def update_company_asset(asset)
70
+ put(api_url("companies/#{asset.company_id}/assets/#{asset.id}"), AssetHelper.construct_asset(asset))
71
+ end
72
+
62
73
  # return api path
63
74
  def api_url path
64
75
  "/api/v1/#{path}"
data/lib/hudu/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hudu
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hudu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janco Tanis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-20 00:00:00.000000000 Z
11
+ date: 2024-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.0
33
+ version: 0.3.0
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.2.0
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dotenv
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -92,9 +106,11 @@ files:
92
106
  - Gemfile
93
107
  - README.md
94
108
  - Rakefile
109
+ - bin/cc-test-reporter.exe
95
110
  - hudu.gemspec
96
111
  - lib/hudu.rb
97
112
  - lib/hudu/api.rb
113
+ - lib/hudu/asset_helper.rb
98
114
  - lib/hudu/authentication.rb
99
115
  - lib/hudu/client.rb
100
116
  - lib/hudu/configuration.rb
@@ -122,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
138
  - !ruby/object:Gem::Version
123
139
  version: '0'
124
140
  requirements: []
125
- rubygems_version: 3.2.12
141
+ rubygems_version: 3.2.3
126
142
  signing_key:
127
143
  specification_version: 4
128
144
  summary: A Ruby wrapper for the Hudu APIs (readonly)