samanage 1.6.2 → 1.6.5

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
  SHA1:
3
- metadata.gz: 6a868afa190497ef5e1ea3933c827800c6a0b872
4
- data.tar.gz: 1795e4fc05003d145f8e4c20fd73240cac497a6e
3
+ metadata.gz: b1ee27251b28d9f40d4d55f4c0cc15a7edb6bc3a
4
+ data.tar.gz: 2041f972113561267d319d7aed592ebc961dc418
5
5
  SHA512:
6
- metadata.gz: 55118de925fb9e075bcb4d318076f56a8410c1aa30e99ea6949afd5a7a0b5b977450cb5dfb1df1ca594bd084e11e8cdb14e7636ebb23173e630af4234fb83021
7
- data.tar.gz: b504e6330c69bfc77db8c6ed614e8c27e0a60eb5d70a5d31da464de1d728ee4cecba7e6597b0284013c3727c79b07b6196e1dcb3fda17cf4f027f90166284ee6
6
+ metadata.gz: a21c0270079f3cb74d05b900467cc1f1a200dc669bff48b7bac62fa4ce39b20793c79069b5125981b4e9fcfbd636a0f830e080ea52bd23094f52331a4445cf09
7
+ data.tar.gz: e213eb9303ed3ed60fae82b876170b0cddd69850b6b2e30fc3254f36385faa10755192e5ef9d590275491e92078da83397b55a0265d3a4c08cee3c496bbec163
data/.gitignore CHANGED
@@ -1,3 +1,7 @@
1
1
  tmp/*
2
2
  ./test.rb
3
- *.gem
3
+ *.gem
4
+ .gitignore
5
+ .DS_STORE
6
+ *.DS_STORE
7
+ */**.DS_STORE
data/README.md CHANGED
@@ -18,21 +18,34 @@
18
18
  ## Usage
19
19
  ### Basic Queries
20
20
 
21
+ Initialize API controller
21
22
  ```ruby
22
- api_controller = Samanage::Api.new(token: api_token)
23
- user_query = api_controller.execute(http_method: 'get', path: 'users.json')
23
+ api_controller = Samanage::Api.new(token: 'abc123')
24
24
  ```
25
25
 
26
+ - Find a user by email
27
+ ```ruby
28
+ user_query = api_controller.execute(http_method: 'get', path: 'users.json?email=example@gmail.com')
29
+ ```
30
+
31
+
32
+ - Update incident by ID
26
33
  ```ruby
27
34
  incident_data = {incident: { priority: 'Critical' }}.to_json
28
35
  incident_update = api_controller.execute(http_method: 'put', path: 'incidents/123.json', payload: incident_data)
29
36
  ```
30
37
 
38
+ - Update hardware
39
+ ```ruby
40
+ hardware = {'hardware':{'name':'My Computer'}}
41
+ result = api_controller.update_hardware(id: 123, payload: hardware)
42
+ ```
43
+
31
44
 
32
45
 
33
46
 
34
47
 
35
- Returns query returns a Hash with keys:
48
+ Executing an api query will return a Hash with the following keys:
36
49
  - `:response`*:* unparsed http response
37
50
  - `:code`*:* http status code
38
51
  - `:json`*:* Samanage API json response
@@ -43,15 +56,4 @@ Returns query returns a Hash with keys:
43
56
 
44
57
 
45
58
 
46
- ### Function examples
47
- #### Return all Samanage Users
48
- ```ruby
49
- users = api_controller.collect_users
50
- ```
51
-
52
- #### Update hardware
53
- ```ruby
54
- hardware = {'hardware':{'name':'My Computer'}}
55
- result = api_controller.update_hardware(id: 123, payload: hardware)
56
- ```
57
59
 
@@ -30,6 +30,12 @@ module Samanage
30
30
  api_call
31
31
  end
32
32
 
33
+ def find_hardwares_by_serial(serial_number: nil)
34
+ path = "hardwares.json?serial_number[]=#{serial_number}"
35
+ api_call = self.execute(path: path)
36
+ api_call
37
+ end
38
+
33
39
  def check_hardware(options: {})
34
40
  url = Samanage::UrlBuilder.new(path: PATHS[:hardware], options: options).url
35
41
  puts "Url: #{url}"
@@ -1,6 +1,6 @@
1
1
  module Samanage
2
2
  class Api
3
- def get_requester_id(value: nil)
3
+ def get_requester_id(value: nil, name: nil, email: nil)
4
4
  api_call = self.execute(path: "requesters.json?name=#{value}")
5
5
  requester = api_call[:data].size == 1 ? api_call[:data][0] : nil
6
6
  requester
@@ -6,7 +6,7 @@ module Samanage
6
6
  api_call = self.execute(path: url)
7
7
  api_call
8
8
  end
9
-
9
+
10
10
  # Returns all users in the account
11
11
  def collect_users
12
12
  page = 1
@@ -24,7 +24,7 @@ module Samanage
24
24
  api_call = self.execute(path: PATHS[:user], http_method: 'post', payload: payload)
25
25
  api_call
26
26
  end
27
-
27
+
28
28
  # Find user by id
29
29
  def find_user(id: nil)
30
30
  path = "users/#{id}.json"
@@ -32,6 +32,12 @@ module Samanage
32
32
  api_call
33
33
  end
34
34
 
35
+ # Email is unique so compare first for exact match only. Return [nil..id]
36
+ def find_user_id_by_email(email: nil)
37
+ api_call = self.check_user(value: email)
38
+ api_call.dig(:data).first.to_h.dig('email').to_s.downcase == email.to_s.downcase ? api_call.dig(:data).first.dig('id') : nil
39
+ end
40
+
35
41
  # Check for user by field (ex: users.json?field=value)
36
42
  def check_user(field: 'email', value: nil)
37
43
  url = "users.json?#{field}=#{value}"
data/samanage.gemspec CHANGED
@@ -1,15 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = 'samanage'
3
- s.version = '1.6.2'
4
- s.date = Date.today.strftime("%Y-%m-%d")
5
- s.summary = "Samanage Ruby Gem"
6
- s.description = "Connect to Samanage using Ruby!"
7
- s.authors = ["Chris Walls"]
8
- s.email = 'cwalls2908@gmail.com'
9
- s.files = `git ls-files`.split("\n")
10
- s.require_paths = ["lib"]
2
+ s.name = 'samanage'
3
+ s.version = '1.6.5'
4
+ s.date = Date.today.strftime("%Y-%m-%d")
5
+ s.summary = "Samanage Ruby Gem"
6
+ s.description = "Connect to Samanage using Ruby!"
7
+ s.authors = ["Chris Walls"]
8
+ s.email = 'cwalls2908@gmail.com'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.homepage = 'https://github.com/cw2908/samanage-ruby'
11
+ s.license = 'MIT'
12
+ s.require_paths = ["lib"]
13
+ s.required_ruby_version = '>= 2.3'
11
14
  s.add_development_dependency 'http', ['~> 2.2']
12
- s.add_runtime_dependency 'http', ["~> 2.2"]
13
- s.homepage = 'https://github.com/cw2908/samanage-ruby'
14
- s.license = 'MIT'
15
+ s.add_runtime_dependency 'http', ['~> 2.2']
15
16
  end
@@ -58,6 +58,19 @@ describe Samanage::Api do
58
58
  sample_id = (0..10).entries.sample
59
59
  expect{@controller.find_hardware(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found hardware
60
60
  end
61
+
62
+ it 'finds_hardwares_by_serial' do
63
+ hardwares = @controller.collect_hardwares
64
+ sample_hardware = hardwares.sample
65
+ sample_serial_number = sample_hardware['serial_number']
66
+ sample_id = sample_hardware['id']
67
+ found_assets = @controller.find_hardwares_by_serial(serial_number: sample_serial_number)
68
+ found_sample = found_assets[:data].sample
69
+ expect(sample_serial_number).not_to be(nil)
70
+ expect(found_sample['serial_number']).not_to be(nil)
71
+ expect(found_sample['serial_number']).to eq(sample_serial_number)
72
+ # expect(sample_id).to eq(found_assets[:data].first.dig('id'))
73
+ end
61
74
  it 'update_hardware: update_hardware by id' do
62
75
  hardwares = @controller.collect_hardwares
63
76
  sample_id = hardwares.sample['id']
@@ -52,10 +52,23 @@ describe Samanage::Api do
52
52
  expect(user[:data]).to have_key('email')
53
53
  expect(user[:data]).to have_key('name')
54
54
  end
55
+
56
+
55
57
  it 'find_user: returns nothing for an invalid id' do
56
58
  sample_id = (0..10).entries.sample
57
59
  expect{@controller.find_user(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found user
58
60
  end
61
+
62
+ it 'finds_user_id_by_email' do
63
+ users = @controller.collect_users
64
+ sample_user = users.sample
65
+ sample_email = sample_user['email']
66
+ sample_id = sample_user['id']
67
+ found_id = @controller.find_user_id_by_email(email: sample_email)
68
+ expect(sample_email).not_to be(nil)
69
+ expect(sample_id).to eq(found_id)
70
+ end
71
+
59
72
  it 'update_user: update_user by id' do
60
73
  users = @controller.collect_users
61
74
  sample_id = users.sample['id']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samanage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Walls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-25 00:00:00.000000000 Z
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -44,16 +44,13 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
- - ".DS_Store"
48
47
  - ".gitignore"
49
48
  - Gemfile
50
49
  - Gemfile.lock
51
50
  - Guardfile
52
51
  - LICENSE
53
52
  - README.md
54
- - lib/.DS_Store
55
53
  - lib/samanage.rb
56
- - lib/samanage/.DS_Store
57
54
  - lib/samanage/api.rb
58
55
  - lib/samanage/api/custom_fields.rb
59
56
  - lib/samanage/api/custom_forms.rb
@@ -88,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
85
  requirements:
89
86
  - - ">="
90
87
  - !ruby/object:Gem::Version
91
- version: '0'
88
+ version: '2.3'
92
89
  required_rubygems_version: !ruby/object:Gem::Requirement
93
90
  requirements:
94
91
  - - ">="
@@ -96,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
93
  version: '0'
97
94
  requirements: []
98
95
  rubyforge_project:
99
- rubygems_version: 2.5.2
96
+ rubygems_version: 2.6.13
100
97
  signing_key:
101
98
  specification_version: 4
102
99
  summary: Samanage Ruby Gem
data/.DS_Store DELETED
Binary file
data/lib/.DS_Store DELETED
Binary file
Binary file