samanage 2.1.0 → 2.1.01

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: 491f7c8b0046101fba0d719ca1393ebafda015d1
4
- data.tar.gz: 228eab3c0d1a702c6dd96935d16425e140907ea8
3
+ metadata.gz: b80680119ee4b58f79e671c7a8f52a8c828a1d9d
4
+ data.tar.gz: 14984ffdcc1356df27c96af099e4def041533820
5
5
  SHA512:
6
- metadata.gz: 6fa55b21df260d27dbb9b6b485a5246b1607dcf69a3aee20d8aaa8c245135064932a8ec35d7adf3ee27a16c0605c6e3a52ca2f31379f06faef1c5713ae718525
7
- data.tar.gz: 866e7890c83bf4c105201320d4e28f07cc4a802d9a440f463c97a62279cafbbb20ec82b21264b8dcb3ad5588a1a4b0cb8c3595a9a66c69bda639223b1741abcf
6
+ metadata.gz: e49c1a93f61074ae57582091a6c28691526e111ac2e7af679d066955e7f82fe2dae50b5893cfbb081e8fc2b271f7907307f47e153c04f4446f812c4718d123df
7
+ data.tar.gz: eced4a164597e9182f54e3e88a16f4c67263fe25952ddaa3b366150aceb6953f2293bfa249ec9fb1a688dfd154fc0b7fd9b402d8ed0e428a8c351fd6c7996eb8
data/changelog.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 2.1.01
2
+ - Added solutions
3
+
1
4
  # 2.1.0
2
5
  - Use `URI#encode_www_form`
3
6
 
data/lib/samanage.rb CHANGED
@@ -17,6 +17,7 @@ require 'samanage/api/mobiles'
17
17
  require 'samanage/api/other_assets'
18
18
  require 'samanage/api/requester'
19
19
  require 'samanage/api/sites'
20
+ require 'samanage/api/solutions'
20
21
  require 'samanage/api/users'
21
22
  require 'samanage/api/utils'
22
23
  require 'samanage/error'
data/lib/samanage/api.rb CHANGED
@@ -17,6 +17,7 @@ module Samanage
17
17
  mobile: 'mobiles.json',
18
18
  other_asset: 'other_assets.json',
19
19
  site: 'sites.json',
20
+ solution: 'solutions.json',
20
21
  user: 'users.json',
21
22
  }
22
23
  attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins, :max_retries
@@ -0,0 +1,40 @@
1
+ module Samanage
2
+ class Api
3
+ def get_solutions(path: PATHS[:solution], options: {})
4
+ url = Samanage::UrlBuilder.new(path: path, options: options).url
5
+ self.execute(path: url)
6
+ end
7
+
8
+ def collect_solutions(options: {})
9
+ solutions = Array.new
10
+ total_pages = self.get_solutions[:total_pages]
11
+ 1.upto(total_pages) do |page|
12
+ options[:page] = page
13
+ params = self.set_params(options: options)
14
+ puts "Collecting Solutions page: #{page}/#{total_pages}" if options[:verbose]
15
+ path = "solutions.json?" + params
16
+ self.execute(http_method: 'get', path: path)[:data].each do |solution|
17
+ if block_given?
18
+ yield solution
19
+ end
20
+ solutions << solution
21
+ end
22
+ end
23
+ solutions
24
+ end
25
+
26
+ def create_solution(payload: , options: {})
27
+ self.execute(path: PATHS[:solution], http_method: 'post', payload: payload)
28
+ end
29
+
30
+ def update_solution(id: ,payload: , options: {})
31
+ self.execute(path: "solutions/#{id}.json", http_method: 'put', payload: payload)
32
+ end
33
+
34
+ def delete_solution(id: )
35
+ self.execute(path: "solutions/#{id}.json", http_method: 'delete')
36
+ end
37
+
38
+ alias_method :solutions, :collect_solutions
39
+ end
40
+ end
@@ -33,6 +33,8 @@ module Samanage
33
33
  url += 'sites'
34
34
  when /department/
35
35
  url += 'departments'
36
+ when /solution/
37
+ url += 'solutions'
36
38
  when /contract/
37
39
  url += 'contracts'
38
40
  when /group/
@@ -1,3 +1,3 @@
1
1
  module Samanage
2
- VERSION = '2.1.0'
2
+ VERSION = '2.1.01'
3
3
  end
@@ -0,0 +1,48 @@
1
+ require 'samanage'
2
+ describe Samanage::Api do
3
+ context 'solution' do
4
+ before(:all) do
5
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
6
+ @samanage = Samanage::Api.new(token: TOKEN)
7
+ @solutions = @samanage.solutions
8
+ end
9
+ it 'get_users: it returns API call of users' do
10
+ api_call = @samanage.get_solutions
11
+ expect(api_call).to be_a(Hash)
12
+ expect(api_call[:total_count]).to be_an(Integer)
13
+ expect(api_call).to have_key(:response)
14
+ expect(api_call).to have_key(:code)
15
+ end
16
+ it 'collects all solutions' do
17
+ solutions = @solutions
18
+ solution_count = @samanage.get_solutions[:total_count]
19
+ expect(solutions).to be_an(Array)
20
+ expect(solutions.size).to eq(solution_count)
21
+ end
22
+ it 'creates a solution' do
23
+ solution_name = "solution ##{(rand*10**4).ceil}"
24
+ solution_description = "Description #{(rand*10**4).ceil}"
25
+ payload = {
26
+ solution: {
27
+ name: solution_name,
28
+ description: solution_description
29
+ }
30
+ }
31
+ solution_create = @samanage.create_solution(payload: payload)
32
+
33
+ expect(solution_create[:data]['id']).to be_an(Integer)
34
+ expect(solution_create[:data]['name']).to eq(solution_name)
35
+ expect(solution_create[:code]).to eq(200)
36
+ end
37
+ it 'updates a valid solution' do
38
+ sample_solution_id = @solutions.sample['id']
39
+ new_description = solution_description = "Description #{(rand*10**4).ceil}"
40
+ payload = {solution: {description: new_description}}
41
+ solution_update = @samanage.update_solution(id: sample_solution_id, payload: payload)
42
+ puts "solution_update: #{solution_update}"
43
+
44
+ expect(new_description).to eq(solution_update.dig(:data,'description'))
45
+ expect(solution_update[:code]).to eq(200)
46
+ end
47
+ end
48
+ 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: 2.1.0
4
+ version: 2.1.01
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Walls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -68,6 +68,7 @@ files:
68
68
  - lib/samanage/api/other_assets.rb
69
69
  - lib/samanage/api/requester.rb
70
70
  - lib/samanage/api/sites.rb
71
+ - lib/samanage/api/solutions.rb
71
72
  - lib/samanage/api/users.rb
72
73
  - lib/samanage/api/utils.rb
73
74
  - lib/samanage/error.rb
@@ -90,6 +91,7 @@ files:
90
91
  - spec/api/samanage_mobile_spec.rb
91
92
  - spec/api/samanage_other_asset_spec.rb
92
93
  - spec/api/samanage_site_spec.rb
94
+ - spec/api/samanage_solution_spec.rb
93
95
  - spec/api/samanage_user_spec.rb
94
96
  - spec/api/samanage_util_spec.rb
95
97
  - spec/samanage_api_spec.rb