rs_service_now 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rs_service_now.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 nemski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # RsServiceNow
2
+
3
+ A Ruby Soap ServiceNow interface.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rs_service_now'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rs_service_now
20
+
21
+ ## Usage
22
+
23
+ sn = RsServiceNow::Company.new user, password, instance
24
+
25
+ ### Retrieve
26
+ # Get every field from matching records. This is a quick way to retrieve any number of records, 250 at a time.
27
+
28
+ # Using an encodedQuery. This can be easily retrieved by conducting a search in Service-Now, right clicking the very end of the search string and selecting "Copy query"
29
+ sn.request :encoded_query => "active=true"
30
+
31
+ ### Export
32
+ # Retrieve a data export from Service-Now. Should be more efficient than Retrieve as by default it can export 10000 records at a time, instead of 250.
33
+ sn.export :encoded_query => "active=true"
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/nemski/rs_service_now/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,7 @@
1
+ require "rs_service_now/version"
2
+ require "rs_service_now/record"
3
+ require "rs_service_now/company"
4
+
5
+ module RsServiceNow
6
+
7
+ end
@@ -0,0 +1,11 @@
1
+ class RsServiceNow::Ci < RsServiceNow::Record
2
+ TABLE = 'cmdb_ci'
3
+
4
+ def request encoded_query
5
+ self._request TABLE, encoded_query
6
+ end
7
+
8
+ def export encoded_query, max_export = 10000
9
+ self._export TABLE, encoded_query, max_export
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class RsServiceNow::Company < RsServiceNow::Record
2
+ TABLE = 'core_company'
3
+
4
+ def request encoded_query
5
+ self._request TABLE, encoded_query
6
+ end
7
+
8
+ def export encoded_query, max_export = 10000
9
+ self._export TABLE, encoded_query, max_export
10
+ end
11
+ end
@@ -0,0 +1,78 @@
1
+ require 'savon'
2
+ require 'open-uri'
3
+ require 'active_support/core_ext/hash/conversions'
4
+
5
+ class RsServiceNow::Record
6
+
7
+ def initialize user, password, instance
8
+ @user = user
9
+ @password = password
10
+ @url = "https://#{instance}.service-now.com"
11
+ end
12
+
13
+ def _request table, encoded_query
14
+ client = setup_client table
15
+ num_entries = get_keys(client, encoded_query)[:count].to_i
16
+ index = 0
17
+ result = []
18
+
19
+ while index < num_entries
20
+ response = client.call(:get_records, :message => {:__encoded_query => encoded_query, :__first_row => index, :__last_row => (index + 250)})
21
+ index = index + 250
22
+
23
+ records = response.hash[:envelope][:body][:get_records_response][:get_records_result]
24
+ if records.is_a? Array
25
+ result.push *records
26
+ else
27
+ result.push records
28
+ end
29
+ end
30
+
31
+ result
32
+ end
33
+
34
+ def _export table, encoded_query, max_export
35
+ client = setup_client table
36
+ get_keys_result = get_keys(client, encoded_query)
37
+ num_entries = get_keys_result[:count].to_i
38
+ keys = get_keys_result[:sys_id].split(/,/)
39
+ index = 0
40
+ export = []
41
+
42
+ while index < num_entries
43
+ # Use a URL to retrieve an XML export as documented at http://wiki.servicenow.com/index.php?title=Exporting_Data
44
+ xml = open("#{@url}/#{table}.do?XML&" +
45
+ "sysparm_order_by=sys_id&" +
46
+ "sysparm_query=#{CGI.escape(encoded_query + '^')}" +
47
+ "sys_id#{CGI.escape('>=') + keys[index]}&" +
48
+ "sysparm_record_count=#{max_export}",
49
+ :http_basic_authentication => [@user, @password]
50
+ ).read
51
+
52
+ records = Hash.from_xml(xml)["xml"][table]
53
+ if records.is_a? Array
54
+ export.push *records
55
+ else
56
+ export.push records
57
+ end
58
+
59
+ index = index + max_export
60
+ end
61
+
62
+ export
63
+ end
64
+
65
+ def get_keys client, encoded_query
66
+ response = client.call(:get_keys, :message => {:__encoded_query => encoded_query, :__order_by => "sys_id"})
67
+ response.hash[:envelope][:body][:get_keys_response]
68
+ end
69
+
70
+ def setup_client table
71
+ Savon.client do |globals|
72
+ globals.wsdl "#{@url}/#{table}.do?WSDL"
73
+ globals.basic_auth [@user, @password]
74
+ globals.convert_request_keys_to :none
75
+ globals.namespace_identifier :u
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module RsServiceNow
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rs_service_now/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rs_service_now"
8
+ spec.version = RsServiceNow::VERSION
9
+ spec.authors = ["nemski"]
10
+ spec.email = ["nemski.rabbit@gmail.com"]
11
+ spec.summary = %q{A Ruby Soap ServiceNow interface.}
12
+ spec.description = %q{A library for exporting data from ServiceNow}
13
+ spec.homepage = "https://github.com/nemski/rs_service_now"
14
+ spec.license = "BSD"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_runtime_dependency "savon", "~> 2.0"
25
+ spec.add_runtime_dependency "activesupport"
26
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rs_service_now
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - nemski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.7'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.7'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: savon
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: A library for exporting data from ServiceNow
79
+ email:
80
+ - nemski.rabbit@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - lib/rs_service_now.rb
91
+ - lib/rs_service_now/ci.rb
92
+ - lib/rs_service_now/company.rb
93
+ - lib/rs_service_now/record.rb
94
+ - lib/rs_service_now/version.rb
95
+ - rs_service_now.gemspec
96
+ homepage: https://github.com/nemski/rs_service_now
97
+ licenses:
98
+ - BSD
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.28
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: A Ruby Soap ServiceNow interface.
121
+ test_files: []