netbox-client-ruby 0.3.1 → 0.4.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
  SHA1:
3
- metadata.gz: 980c41479f9ebc620b9d44319b03a301bb88558b
4
- data.tar.gz: 5bd503c8ca0adb4c868b779f92d42f62301858f6
3
+ metadata.gz: b208caa12086d6501f332d3b8569158d4d63ad5a
4
+ data.tar.gz: ce322b1cba7805f739b5fa2b79de2ba6c75455a9
5
5
  SHA512:
6
- metadata.gz: 4c17ce3c8d947d50c35e6d408dd74aaabce5d915d16de620ad834232337303241a2fe79da356f7ffec71180b4fa2b9d4773b08d1ddde38e3f07e2768e3d918fd
7
- data.tar.gz: 650212f2c20e238ff5ffcdfa827f3062fc64d3af52a048e0e26a172ea49d584f03a6496c9187b710c012cbf9c84922beae25d38ecd417740f618f30cac8d239e
6
+ metadata.gz: 9bbe1c52549ca8f5257aefab0dca882c926a31af88c6bb47a8fae616c6d6a975822ef6975a367de0ce5dde50d6e134c063f6cf93036361d09fee27642b9df3f0
7
+ data.tar.gz: affbc19283cb620529178f35c66dd426e3879e40febb66818927c21a075192d95d83087c5c96456f9185de3f430c82ef4b3e932c97d1acbd4b1b7fa4b75b0723
data/README.md CHANGED
@@ -68,7 +68,7 @@ sites = NetboxClientRuby.dcim.sites
68
68
  puts "There are #{sites.total} sites in your Netbox instance."
69
69
 
70
70
  # get the first site of the result set
71
- first_site = sites[0]
71
+ first_site = sites.first
72
72
  puts "The first site is called #{first_site.name}."
73
73
 
74
74
  # filter devices by site
@@ -76,6 +76,15 @@ puts "The first site is called #{first_site.name}."
76
76
  devices_of_site = NetboxClientRuby.dcim.devices.filter(site: first_site.slug)
77
77
  puts "#{devices_of_site.total} devices belong to the site. #{devices_of_site}.length devices have been fetched."
78
78
 
79
+ # Finds a specific device
80
+ NetboxClientRuby.dcim.devices.find_by(name: 'my-device', other_field: 'other-value')
81
+
82
+ # Finds a specific device with a certain custom field
83
+ NetboxClientRuby.dcim.devices.find_by(cf_custom_url: 'https://google.com')
84
+
85
+ # Or a mix of regular and custom fields
86
+ NetboxClientRuby.dcim.devices.find_by(name: 'my-device', cf_custom_field: 'custom-value')
87
+
79
88
  # get a site by id
80
89
  s = NetboxClientRuby.dcim.site(1)
81
90
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -75,8 +75,28 @@ module NetboxClientRuby
75
75
  end
76
76
  end
77
77
 
78
+ def find_by(attributes)
79
+ fail ArgumentError, '"attributes" expects a hash' unless attributes.is_a? Hash
80
+
81
+ filter(attributes).find do |netbox_object|
82
+ attributes.all? do |filter_key, filter_value|
83
+ if filter_key.to_s.start_with?('cf_')
84
+ custom_field = filter_key.to_s.sub('cf_', '')
85
+
86
+ netbox_object.custom_fields[custom_field] == filter_value
87
+ else
88
+ if netbox_object.respond_to?(filter_key)
89
+ netbox_object.public_send(filter_key) == filter_value
90
+ else
91
+ false
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+
78
98
  def filter(filter)
79
- raise ArgumentError, '"filter" expects a hash' unless filter.is_a? Hash
99
+ fail ArgumentError, '"filter" expects a hash' unless filter.is_a? Hash
80
100
 
81
101
  @filter = filter
82
102
  reset
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netbox-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Mäder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-22 00:00:00.000000000 Z
11
+ date: 2018-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable