samanage 1.8.3 → 1.8.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: f1a73bd9d0ecff83e8c95ca29b389260d73eb3e7
4
- data.tar.gz: b2a98bff4c554c017ac670f172981676a3ac9128
3
+ metadata.gz: 8eb0f2b3c57cf1e5b9b79b22c49f0d8e413c9c36
4
+ data.tar.gz: fd23d7f431814e09ca1f354e25fffeca6d1d124b
5
5
  SHA512:
6
- metadata.gz: 0caa861127343267e8c33fe1a730acdf48a722244a2c9464178d9445d60576ed92e85ce9b1dd5cc1db7f53ec24590663cc8c8c35f61a4edbcdf91386f5874ccc
7
- data.tar.gz: ddc7ad10f2e7f6f1642b08dd5d18d745d0956600b24fb6532a46c9049d83197e0098fdbc559aca3048b1874697edffe7dace52c57cc341bc0371d9ad43925a37
6
+ metadata.gz: f7fd9bcaf93c48131728a25c93f038489e993c5f26e53981592e8dfb1483f4baff11755349c9ad309f2309af12d29b502740a75b54c575545ec03a6d0f46a3d5
7
+ data.tar.gz: 9d26eec84dc84809c951f26787cc9781751c70c8f83def1148aa8a3dfef7662b2b3cadff653f056a43325ebc7efbab666e856dad2402f2515a3b2f93585d5821
data/README.md CHANGED
@@ -24,21 +24,28 @@ Initialize API controller
24
24
  api_controller = Samanage::Api.new(token: 'abc123')
25
25
  ```
26
26
 
27
+ - Create a user
28
+ ```ruby
29
+ user = {user: { name: 'John Doe', email: 'john.doe@example.com'}}
30
+ api_controller.create_user(payload: user)
31
+ ```
32
+
33
+
27
34
  - Find a user by email
28
35
  ```ruby
29
- user_query = api_controller.execute(http_method: 'get', path: 'users.json?email=example@gmail.com')
36
+ my_user = api_controller.find_user_by_email(email: 'user@example.com')
30
37
  ```
31
38
 
32
39
 
33
40
  - Update incident by ID
34
41
  ```ruby
35
42
  incident_data = {incident: { priority: 'Critical' }}
36
- incident_update = api_controller.execute(http_method: 'put', path: 'incidents/123.json', payload: incident_data)
43
+ incident_update = api_controller.update_incident(id: 123, payload: incident_data)
37
44
  ```
38
45
 
39
46
  - Update hardware
40
47
  ```ruby
41
- hardware = {'hardware':{'name':'My Computer'}}
48
+ hardware = {hardware: {name: 'My Computer'}}
42
49
  result = api_controller.update_hardware(id: 123, payload: hardware)
43
50
  ```
44
51
 
data/changelog.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 1.8.6
2
+ - Removing layout=long verbosity
3
+
4
+ # 1.8.5
5
+ - Adding option for incidents layout=long
6
+
7
+ # 1.8.3
8
+ - Additional Request Timeout retry support
9
+ - Support for non-parsed responseq
10
+ - Moving non object specific methods to samanage/api/utils
11
+ - Added activation emails
12
+
1
13
  # 1.8.2
2
14
  - Adding Category support
3
15
 
data/lib/samanage.rb CHANGED
@@ -15,7 +15,9 @@ require 'samanage/api/other_assets'
15
15
  require 'samanage/api/requester'
16
16
  require 'samanage/api/sites'
17
17
  require 'samanage/api/users'
18
+ require 'samanage/api/utils'
18
19
  require 'samanage/error'
20
+ require 'samanage/language'
19
21
  require 'samanage/url_builder'
20
22
  require 'samanage/version'
21
23
 
data/lib/samanage/api.rb CHANGED
@@ -87,7 +87,7 @@ module Samanage
87
87
  when 'put'
88
88
  api_call = self.class.put(full_path, query: payload, headers: headers)
89
89
  end
90
- rescue Errno::ECONNREFUSED => e
90
+ rescue Errno::ECONNREFUSED, Net::OpenTimeout => e
91
91
  puts "#{e} - #{e.class}"
92
92
  puts "Retry: #{self.retries}/#{self.max_retries}"
93
93
  self.retries += 1
@@ -109,7 +109,13 @@ module Samanage
109
109
  # Error cases
110
110
  case response[:code]
111
111
  when 200..201
112
- response[:data] = JSON.parse(api_call.body)
112
+ begin
113
+ response[:data] = JSON.parse(api_call.body)
114
+ rescue JSON::ParserError => e
115
+ response[:data] = api_call.body
116
+ puts "** Warning **#{e.class}"
117
+ puts e
118
+ end
113
119
  response
114
120
  when 401
115
121
  response[:data] = api_call.body
@@ -9,12 +9,13 @@ module Samanage
9
9
 
10
10
 
11
11
  # Returns all incidents
12
- def collect_incidents
12
+ def collect_incidents(options: {})
13
13
  page = 1
14
14
  incidents = Array.new
15
15
  total_pages = self.get_incidents[:total_pages]
16
+ layout = options[:layout] == 'long' ? '&layout=long' : nil
16
17
  while page <= total_pages
17
- incidents += self.execute(http_method: 'get', path: "incidents.json?page=#{page}")[:data]
18
+ incidents += self.execute(http_method: 'get', path: "incidents.json?page=#{page}#{layout}")[:data]
18
19
  page += 1
19
20
  end
20
21
  incidents
@@ -0,0 +1,10 @@
1
+ module Samanage
2
+ class Api
3
+ # returns
4
+ def send_activation_email(email: )
5
+ user_id = self.find_user_id_by_email(email: email)
6
+ raise Samanage::Error.new(error: 'Invalid Email', response: {}) unless user_id
7
+ self.execute(http_method: 'put', path: "users/#{user_id}.json?send_activation_email=1&add_callbacks=1")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ module Samanage
2
+ LANGUAGE = {
3
+ 'arabic' => 'ar',
4
+ 'belarusian' => 'be',
5
+ 'bulgarian' => 'bg',
6
+ 'catalan' => 'ca',
7
+ 'chinese simplified' => 'zh-cn',
8
+ 'chinese traditional' => 'zh-tw',
9
+ 'croatian' => 'hr',
10
+ 'czech' => 'cs',
11
+ 'danish' => 'da',
12
+ 'dutch' => 'nl',
13
+ 'english' => 'en',
14
+ 'estonian' => 'et',
15
+ 'finnish' => 'fi',
16
+ 'french' => 'fr',
17
+ 'german' => 'de',
18
+ 'greek' => 'el',
19
+ 'hebrew' => 'he',
20
+ 'hindi' => 'hi-in',
21
+ 'hungarian' => 'hu',
22
+ 'bahasa indonesia (indonesian)' => 'id',
23
+ 'italian' => 'it',
24
+ 'japanese' => 'ja',
25
+ 'korean' => 'ko',
26
+ 'latvian' => 'lv',
27
+ 'lithuanian' => 'lt',
28
+ 'malay' => 'ms',
29
+ 'macedonian' => 'mk',
30
+ 'norwegian' => 'nb',
31
+ 'persian' => 'fa',
32
+ 'polish' => 'pl',
33
+ 'portuguese (brazil)' => 'pt-br',
34
+ 'portuguese (portugal)' => 'pt-pt',
35
+ 'romanian' => 'ro',
36
+ 'russian' => 'ru',
37
+ 'serbian' => 'sr',
38
+ 'slovak' => 'sk',
39
+ 'slovenian' => 'sl',
40
+ 'spanish' => 'es',
41
+ 'spanish (latin america)' => 'es-419',
42
+ 'swedish' => 'sv',
43
+ 'thai' => 'th',
44
+ 'turkish' => 'tr',
45
+ 'ukrainian' => 'uk',
46
+ 'vietnamese' => 'vi',
47
+ }
48
+ def self.lookup_language(language)
49
+ return LANGUAGE[language.to_s.downcase] ||= (language.to_s.downcase if LANGUAGE.values.include?(language.to_s.downcase))
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module Samanage
2
- VERSION = '1.8.3'
2
+ VERSION = '1.8.6'
3
3
  end
@@ -73,6 +73,11 @@ describe Samanage::Api do
73
73
  expect(incident_update[:data]['description']).to eq(description)
74
74
  expect(incident_update[:code]).to eq(200).or(201)
75
75
  end
76
+ it 'finds more data for option[:layout] = "long"' do
77
+ basic_incident_keys = @controller.incidents.sample.keys
78
+ full_incident_keys = @controller.incidents(options: {layout: 'long'}).sample.keys
79
+ expect(basic_incident_keys.size).to be < full_incident_keys.size
80
+ end
76
81
  end
77
82
  end
78
83
  end
@@ -0,0 +1,20 @@
1
+ require 'samanage'
2
+ describe Samanage::Api do
3
+ context 'Utils' do
4
+ describe 'API Functions' do
5
+ before(:each) do
6
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
7
+ @controller = Samanage::Api.new(token: TOKEN)
8
+ end
9
+ it 'sends an activation email' do
10
+ valid_email = @controller.users.sample['email']
11
+ send_email = @controller.send_activation_email(email: valid_email)
12
+ expect(send_email[:code]).to be(200)
13
+ end
14
+ it 'fails for invalid email' do
15
+ invalid_email = @controller.users.sample['email'].gsub!('@','$')
16
+ expect{@controller.send_activation_email(email: invalid_email)}.to raise_error(Samanage::Error)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ describe Samanage do
3
+ describe 'Language' do
4
+ context 'when looking up language' do
5
+ it 'should find case-insensitive valid language codes' do
6
+ valid_lang = 'Czech'
7
+ valid_lang_code = 'cs'
8
+ expect(Samanage.lookup_language(valid_lang)).to eq(valid_lang_code)
9
+ expect(Samanage.lookup_language(valid_lang_code.upcase)).to eq(valid_lang_code)
10
+ end
11
+ it 'should return nil for invalid language codes' do
12
+ invalid_lang = 'Mandalorian'
13
+ invalid_lang_code = 'zzzzzzzzz'
14
+ expect(Samanage.lookup_language(invalid_lang)).to be(nil)
15
+ expect(Samanage.lookup_language(invalid_lang_code)).to be(nil)
16
+ end
17
+ end
18
+ end
19
+ 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.8.3
4
+ version: 1.8.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-12-18 00:00:00.000000000 Z
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -67,7 +67,9 @@ files:
67
67
  - lib/samanage/api/requester.rb
68
68
  - lib/samanage/api/sites.rb
69
69
  - lib/samanage/api/users.rb
70
+ - lib/samanage/api/utils.rb
70
71
  - lib/samanage/error.rb
72
+ - lib/samanage/language.rb
71
73
  - lib/samanage/url_builder.rb
72
74
  - lib/samanage/version.rb
73
75
  - samanage.gemspec
@@ -83,8 +85,10 @@ files:
83
85
  - spec/api/samanage_other_asset_spec.rb
84
86
  - spec/api/samanage_site_spec.rb
85
87
  - spec/api/samanage_user_spec.rb
88
+ - spec/api/samanage_util_spec.rb
86
89
  - spec/samanage_api_spec.rb
87
90
  - spec/samanage_category_spec.rb
91
+ - spec/samanage_language_spec.rb
88
92
  - spec/samanage_url_builder_spec.rb
89
93
  - spec/spec_helper.rb
90
94
  homepage: https://github.com/cw2908/samanage-ruby