samanage 1.6.5 → 1.6.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
  SHA1:
3
- metadata.gz: b1ee27251b28d9f40d4d55f4c0cc15a7edb6bc3a
4
- data.tar.gz: 2041f972113561267d319d7aed592ebc961dc418
3
+ metadata.gz: c8d2a585e1b0f72637d782fc0b6e5efad1e826c3
4
+ data.tar.gz: 01e457f64d73dfc4e9f83575fbc4e7dc5551b95a
5
5
  SHA512:
6
- metadata.gz: a21c0270079f3cb74d05b900467cc1f1a200dc669bff48b7bac62fa4ce39b20793c79069b5125981b4e9fcfbd636a0f830e080ea52bd23094f52331a4445cf09
7
- data.tar.gz: e213eb9303ed3ed60fae82b876170b0cddd69850b6b2e30fc3254f36385faa10755192e5ef9d590275491e92078da83397b55a0265d3a4c08cee3c496bbec163
6
+ metadata.gz: c2e30a81d1045d99a7ee8b293f98420e2cdead43146637f8725f0aee3eacd02a3f99f2cad6a7c4ee19b10c629e26b7601ad201fe847e80ecb0f1fdc3fa54ef9c
7
+ data.tar.gz: 125c5ef4fa1575286418e34b4220253bbf41bb9d5b02808af6200df9b4a2146f0951b1c9f56825e09cdeba67b3e8d6aae6f59c731977a69edc7110d60f91579c
data/lib/samanage.rb CHANGED
@@ -7,6 +7,7 @@ require 'samanage/api/requester'
7
7
  require 'samanage/api/hardwares'
8
8
  require 'samanage/api/other_assets'
9
9
  require 'samanage/api/incidents'
10
+ require 'samanage/api/comments'
10
11
  require 'samanage/api/custom_fields'
11
12
  require 'samanage/api/custom_forms'
12
13
  require 'samanage/error'
@@ -0,0 +1,30 @@
1
+ module Samanage
2
+ class Api
3
+
4
+ def get_comments(incident_id: )
5
+ path = "incidents/#{incident_id}/comments.json"
6
+ api_call = self.execute(path: path)
7
+ api_call
8
+ end
9
+
10
+ def create_comment(incident_id: nil, comment: nil, options: {})
11
+ path = "incidents/#{incident_id}/comments.json"
12
+ api_call = self.execute(http_method: 'post', path: path, payload: comment)
13
+ api_call
14
+ end
15
+
16
+ def collect_comments(incident_id: nil)
17
+
18
+ page = 1
19
+ max_pages = 5
20
+ comments = Array.new
21
+ while page <= max_pages
22
+ path = "incidents/#{incident_id}/comments.json?page=#{page}"
23
+ api_call = self.execute(path: path)
24
+ comments += api_call[:data]
25
+ page += 1
26
+ end
27
+ comments
28
+ end
29
+ end
30
+ end
@@ -48,7 +48,6 @@ module Samanage
48
48
  # Update user by id
49
49
  def update_user(payload: nil, id: nil)
50
50
  path = "users/#{id}.json"
51
- puts "Path: #{path}"
52
51
  api_call = self.execute(path: path, http_method: 'put', payload: payload)
53
52
  api_call
54
53
  end
data/samanage.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'samanage'
3
- s.version = '1.6.5'
3
+ s.version = '1.6.6'
4
4
  s.date = Date.today.strftime("%Y-%m-%d")
5
5
  s.summary = "Samanage Ruby Gem"
6
6
  s.description = "Connect to Samanage using Ruby!"
@@ -0,0 +1,41 @@
1
+ require 'samanage'
2
+ describe Samanage::Api do
3
+ context 'Comments' do
4
+ before(:each) do
5
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
6
+ @controller = Samanage::Api.new(token: TOKEN)
7
+ end
8
+ describe 'API Functions' do
9
+ it 'gets comments' do
10
+ incident_id = @controller.get_incidents()[:data].sample.dig('id')
11
+ comments = @controller.get_comments(incident_id: incident_id)
12
+ expect(comments).to be_a(Hash)
13
+ end
14
+
15
+ it 'creates a comment' do
16
+ incident_id = @controller.get_incidents()[:data].sample.dig('id')
17
+ rand_text = ('a'..'z').to_a.shuffle[0,8].join
18
+ comment = {
19
+ comment: {
20
+ body: rand_text,
21
+ }
22
+ }.to_json
23
+ api_call = @controller.create_comment(incident_id: incident_id, comment: comment)
24
+
25
+ expect(api_call.dig(:data,'body')).to eq(rand_text)
26
+ end
27
+
28
+ it 'collects all comments' do
29
+ incident_id = @controller.get_incidents()[:data].sample.dig('id')
30
+ incident_id = 19394209
31
+ comments_api = @controller.get_comments(incident_id: incident_id)
32
+ comments_found = @controller.collect_comments(incident_id: incident_id)
33
+ # puts "comments api size: #{comments_api.inspect}"
34
+ # puts "Found Comments: #{comments_found.size}"
35
+
36
+ # Total count bug
37
+ # expect(comments_api[:total_count]).to eq(comments_found.size)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -64,12 +64,12 @@ describe Samanage::Api do
64
64
  incidents = @controller.collect_incidents
65
65
  sample_id = incidents.sample['id']
66
66
  new_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
67
- json = {
67
+ incident_json = {
68
68
  :incident => {
69
69
  :name => new_name
70
70
  }
71
71
  }
72
- incident_update = @controller.update_incident(payload: json.to_json, id: sample_id)
72
+ incident_update = @controller.update_incident(payload: incident_json.to_json, id: sample_id)
73
73
  expect(incident_update[:data]["name"]).to eq(new_name)
74
74
  expect(incident_update[:code]).to eq(200).or(201)
75
75
  end
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.5
4
+ version: 1.6.6
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-11-02 00:00:00.000000000 Z
11
+ date: 2017-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -52,6 +52,7 @@ files:
52
52
  - README.md
53
53
  - lib/samanage.rb
54
54
  - lib/samanage/api.rb
55
+ - lib/samanage/api/comments.rb
55
56
  - lib/samanage/api/custom_fields.rb
56
57
  - lib/samanage/api/custom_forms.rb
57
58
  - lib/samanage/api/hardwares.rb
@@ -63,6 +64,7 @@ files:
63
64
  - lib/samanage/url_builder.rb
64
65
  - lib/test.rb
65
66
  - samanage.gemspec
67
+ - spec/api/comments_spec.rb
66
68
  - spec/api/samanage_custom_field_spec.rb
67
69
  - spec/api/samanage_custom_form_spec.rb
68
70
  - spec/api/samanage_hardware_spec.rb