servicenow-api 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +58 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +93 -0
- data/Rakefile +6 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/lib/service_now.rb +1 -0
- data/lib/servicenow-api.rb +1 -0
- data/lib/servicenow.rb +16 -0
- data/lib/servicenow/api.rb +33 -0
- data/lib/servicenow/client.rb +50 -0
- data/lib/servicenow/client/cmdb.rb +20 -0
- data/lib/servicenow/client/tables.rb +20 -0
- data/lib/servicenow/collection.rb +12 -0
- data/lib/servicenow/configuration.rb +34 -0
- data/lib/servicenow/connection.rb +30 -0
- data/lib/servicenow/exceptions.rb +35 -0
- data/lib/servicenow/http_errors.rb +24 -0
- data/lib/servicenow/response.rb +11 -0
- data/lib/servicenow/result.rb +15 -0
- data/lib/servicenow/version.rb +3 -0
- data/servicenow-api.gemspec +34 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b9db061cd2f5740c25ba39952b76c155a05c51781ce1c809383bdec05772c358
|
4
|
+
data.tar.gz: 2ac0d91d52a68896724fb78ff52814b4477ff8550ffcfe93727de32a4628dd93
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55f0db75b7ec137dfd4136ac7b85eb2dd3b359dcd89c4c56888e2b6db6a5bebe070afd5d31dbd92a04c519e1281674408fe9e04b786233c10a6255c75ba17b10
|
7
|
+
data.tar.gz: fb84b302120d2db816d6ae10a5af70f1d765e796a324f8d9c050a295bc0c7073ed4c82de01e9adc1a3e4093d4d4de105661f20b9c04a55e50bb38802e85d53ee
|
data/.gitignore
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
Gemfile.lock
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at cbisnett@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Huntress Labs and Chris Bisnett
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# ServiceNow
|
2
|
+
|
3
|
+
The ServiceNow Ruby library provides convenient access to the [ServiceNow](https://developer.servicenow.com/app.do#!/document/content/app_store_doc_rest_integrate_newyork_c_RESTAPI?v=newyork) REST API. The library is structured such that it can be used to manage multiple ServiceNow tenants.
|
4
|
+
|
5
|
+
*Note: Not all API endpoints are implemented and more continue to be added as time permits.*
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
API documentation:
|
10
|
+
- [REST Basics](https://developer.servicenow.com/app.do#!/document/content/app_store_doc_rest_integrate_newyork_c_RESTAPI?v=newyork)
|
11
|
+
- [REST API Reference](https://docs.servicenow.com/bundle/newyork-application-development/page/build/applications/concept/api-rest.html)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'servicenow-ruby'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install servicenow-ruby
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
To create a client for a ServiceNow instance using OAuth:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client = ServiceNow.authenticate(
|
35
|
+
"myhost.service-now.com",
|
36
|
+
"client_id",
|
37
|
+
"client_secret",
|
38
|
+
"username",
|
39
|
+
"password"
|
40
|
+
)
|
41
|
+
|
42
|
+
# get all incidents
|
43
|
+
client.incidents.all()
|
44
|
+
```
|
45
|
+
|
46
|
+
API methods are organized in the client based on the record type. For example, methods for creating/modifying/deleting incidents can be accessed through the `incidents` namespace:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# get all incidents
|
50
|
+
client.incidents.all()
|
51
|
+
|
52
|
+
# create a new incident
|
53
|
+
client.incidents.create(
|
54
|
+
short_description: "My First Incident",
|
55
|
+
description: "This incident is the best incident because..."
|
56
|
+
)
|
57
|
+
```
|
58
|
+
|
59
|
+
### Table Access
|
60
|
+
|
61
|
+
Any table can be accessed using the `tables()` method of the client. Simply specify the table name and you can interact with the table through the ServiceNow Tables API methods.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# get a reference to the table
|
65
|
+
mytable = client.tables("my_table")
|
66
|
+
|
67
|
+
# get all the table rows
|
68
|
+
mytable.all()
|
69
|
+
```
|
70
|
+
|
71
|
+
### Filtering, Sorting, Paging
|
72
|
+
|
73
|
+
Not yet implemented.
|
74
|
+
|
75
|
+
## Development
|
76
|
+
|
77
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
78
|
+
|
79
|
+
Run all tests:
|
80
|
+
|
81
|
+
bundle exec rake spec
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/huntresslabs/servicenow-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
90
|
+
|
91
|
+
## Code of Conduct
|
92
|
+
|
93
|
+
Everyone interacting in the servicenow-ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/huntresslabs/servicenow-ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "servicenow"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "byebug"
|
14
|
+
|
15
|
+
require "irb"
|
16
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/service_now.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "servicenow"
|
@@ -0,0 +1 @@
|
|
1
|
+
require "servicenow"
|
data/lib/servicenow.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "servicenow/version"
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/core_ext/hash"
|
5
|
+
|
6
|
+
module ServiceNow
|
7
|
+
require "servicenow/api"
|
8
|
+
require "servicenow/client"
|
9
|
+
require "servicenow/collection"
|
10
|
+
require "servicenow/configuration"
|
11
|
+
require "servicenow/connection"
|
12
|
+
require "servicenow/exceptions"
|
13
|
+
require "servicenow/http_errors"
|
14
|
+
require "servicenow/response"
|
15
|
+
require "servicenow/result"
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ServiceNow
|
2
|
+
class Api
|
3
|
+
attr_reader :connection
|
4
|
+
|
5
|
+
def initialize(connection)
|
6
|
+
@connection = connection
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_many(path, params = {})
|
10
|
+
ServiceNow::Collection.new connection.get(path, params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_one(path, params = {})
|
14
|
+
ServiceNow::Response.new connection.get(path, params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(path, params = {})
|
18
|
+
ServiceNow::Response.new connection.post(path, params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def patch(path, params = {})
|
22
|
+
ServiceNow::Response.new connection.patch(path, params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def put(path, params = {})
|
26
|
+
ServiceNow::Response.new connection.put(path, params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(path)
|
30
|
+
connection.delete(path)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ServiceNow
|
2
|
+
class Client
|
3
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
|
4
|
+
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def authenticate(instance_id, client_id, client_secret, username, password)
|
9
|
+
connection_options = {
|
10
|
+
url: "https://#{instance_id}.service-now.com/"
|
11
|
+
}
|
12
|
+
|
13
|
+
conn = Faraday.new(connection_options) do |faraday|
|
14
|
+
faraday.request :url_encoded
|
15
|
+
faraday.response :json
|
16
|
+
faraday.response :raise_error
|
17
|
+
faraday.adapter Faraday.default_adapter
|
18
|
+
end
|
19
|
+
|
20
|
+
params = {
|
21
|
+
grant_type: "password",
|
22
|
+
client_id: client_id,
|
23
|
+
client_secret: client_secret,
|
24
|
+
username: username,
|
25
|
+
password: password
|
26
|
+
}
|
27
|
+
|
28
|
+
response = conn.post('oauth_token.do', params)
|
29
|
+
connection = Connection.new(instance_id, response.body["access_token"])
|
30
|
+
Client.new(connection)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(connection)
|
35
|
+
@connection = connection
|
36
|
+
end
|
37
|
+
|
38
|
+
def incidents
|
39
|
+
@incidents ||= Client::Tables.new(@connection, "incident")
|
40
|
+
end
|
41
|
+
|
42
|
+
def tables(table_name)
|
43
|
+
Client::Tables.new(@connection, table_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def cmdb_instance(instance_class)
|
47
|
+
Client::CMDB.new(@connection, instance_class)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ServiceNow
|
2
|
+
class Client::CMDB < Api
|
3
|
+
def initialize(connection, instance_class)
|
4
|
+
super(connection)
|
5
|
+
@instance_class = instance_class
|
6
|
+
end
|
7
|
+
|
8
|
+
def all(params = {})
|
9
|
+
get_many "cmdb/instance/#{@instance_class}", params
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(id)
|
13
|
+
get_one "cmdb/instance/#{@instance_class}/#{id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(params = {})
|
17
|
+
post "cmdb/instance/#{@instance_class}", params
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ServiceNow
|
2
|
+
class Client::Tables < Api
|
3
|
+
def initialize(connection, table_name)
|
4
|
+
super(connection)
|
5
|
+
@table_name = table_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def all(params = {})
|
9
|
+
get_many "table/#{@table_name}", params
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(id)
|
13
|
+
get_one "table/#{@table_name}/#{id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def create(params = {})
|
17
|
+
post "table/#{@table_name}", params
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ServiceNow
|
2
|
+
class Collection
|
3
|
+
attr_reader :total, :results
|
4
|
+
|
5
|
+
delegate_missing_to :@results
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
@results = (response.body["result"] || []).map { |r| Result.new r }
|
9
|
+
@total = response.headers["x-total-count"] || @results.size
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ServiceNow
|
2
|
+
module Configuration
|
3
|
+
VALID_OPTIONS_KEYS = [
|
4
|
+
:user_agent,
|
5
|
+
].freeze
|
6
|
+
|
7
|
+
DEFAULT_USER_AGENT = "ServiceNow Ruby Gem #{ServiceNow::VERSION}".freeze
|
8
|
+
|
9
|
+
# Define accessor methods for configuration keys
|
10
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
11
|
+
|
12
|
+
# Convenience method to allow configuration options to be set in a block
|
13
|
+
def configure
|
14
|
+
yield self
|
15
|
+
end
|
16
|
+
|
17
|
+
# When this module is extended, set all configuration options to their default values
|
18
|
+
def self.extended(base)
|
19
|
+
base.reset
|
20
|
+
end
|
21
|
+
|
22
|
+
# Create a hash of options and their values
|
23
|
+
def options
|
24
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
25
|
+
option.merge!(key => send(key))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def reset
|
30
|
+
self.debug = DEFAULT_DEBUG
|
31
|
+
self.user_agent = DEFAULT_USER_AGENT
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
|
4
|
+
module ServiceNow
|
5
|
+
class Connection
|
6
|
+
delegate_missing_to :@connection
|
7
|
+
|
8
|
+
def initialize(instance_id, token)
|
9
|
+
@instance_id = instance_id
|
10
|
+
@token = token
|
11
|
+
|
12
|
+
@connection = Faraday::Connection.new(connection_options) do |conn|
|
13
|
+
conn.use HttpErrors
|
14
|
+
|
15
|
+
conn.authorization :Bearer, @token
|
16
|
+
conn.request :json
|
17
|
+
conn.response :json
|
18
|
+
conn.adapter Faraday.default_adapter
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def connection_options
|
25
|
+
{
|
26
|
+
url: "https://#{@instance_id}.service-now.com/api/now/"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ServiceNow
|
2
|
+
class ApiError < StandardError
|
3
|
+
attr_reader :response, :message, :detail, :status
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
if response&.body
|
8
|
+
@message = response.body.dig("error", "message")
|
9
|
+
@detail = response.body.dig("error", "detail")
|
10
|
+
@status = response.body["status"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# HTTP 400
|
16
|
+
class BadRequestError < ApiError; end
|
17
|
+
|
18
|
+
# HTTP 401
|
19
|
+
class UnauthorizedError < ApiError; end
|
20
|
+
|
21
|
+
# HTTP 403
|
22
|
+
class ForbiddenError < ApiError; end
|
23
|
+
|
24
|
+
# HTTP 404
|
25
|
+
class NotFoundError < ApiError; end
|
26
|
+
|
27
|
+
# HTTP 405
|
28
|
+
class MethodNotAllowedError < ApiError; end
|
29
|
+
|
30
|
+
# HTTP 406
|
31
|
+
class NotAcceptableError < ApiError; end
|
32
|
+
|
33
|
+
# HTTP 415
|
34
|
+
class UnsupportedMediaTypeError < ApiError; end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ServiceNow
|
2
|
+
class HttpErrors < Faraday::Response::Middleware
|
3
|
+
def on_complete(env)
|
4
|
+
case env[:status].to_i
|
5
|
+
when 400
|
6
|
+
raise BadRequestError, env.response
|
7
|
+
when 401
|
8
|
+
raise UnauthorizedError, env.response
|
9
|
+
when 403
|
10
|
+
raise ForbiddenError, env.response
|
11
|
+
when 404
|
12
|
+
raise NotFoundError, env.response
|
13
|
+
when 405
|
14
|
+
raise MethodNotAllowedError, env.response
|
15
|
+
when 406
|
16
|
+
raise NotAcceptableError, env.response
|
17
|
+
when 415
|
18
|
+
raise UnsupportedMediaTypeError, env.response
|
19
|
+
when 500..600
|
20
|
+
raise ApiError, env.response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "servicenow/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "servicenow-api"
|
8
|
+
spec.version = ServiceNow::VERSION
|
9
|
+
spec.authors = ["Chris Bisnett"]
|
10
|
+
spec.email = ["cbisnett@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby wrapper for the ServiceNow REST API"
|
13
|
+
spec.description = "Ruby wrapper for the ServiceNow REST API (formerly servicenow-ruby)"
|
14
|
+
spec.homepage = "https://github.com/huntresslabs/servicenow-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", ">= 1.16"
|
27
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "byebug"
|
30
|
+
|
31
|
+
spec.add_dependency "faraday", "< 1.0"
|
32
|
+
spec.add_dependency "faraday_middleware", "< 1.0"
|
33
|
+
spec.add_dependency "activesupport", ">= 5.0"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: servicenow-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Bisnett
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "<"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday_middleware
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "<"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "<"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '5.0'
|
111
|
+
description: Ruby wrapper for the ServiceNow REST API (formerly servicenow-ruby)
|
112
|
+
email:
|
113
|
+
- cbisnett@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- CODE_OF_CONDUCT.md
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/console
|
125
|
+
- bin/setup
|
126
|
+
- lib/service_now.rb
|
127
|
+
- lib/servicenow-api.rb
|
128
|
+
- lib/servicenow.rb
|
129
|
+
- lib/servicenow/api.rb
|
130
|
+
- lib/servicenow/client.rb
|
131
|
+
- lib/servicenow/client/cmdb.rb
|
132
|
+
- lib/servicenow/client/tables.rb
|
133
|
+
- lib/servicenow/collection.rb
|
134
|
+
- lib/servicenow/configuration.rb
|
135
|
+
- lib/servicenow/connection.rb
|
136
|
+
- lib/servicenow/exceptions.rb
|
137
|
+
- lib/servicenow/http_errors.rb
|
138
|
+
- lib/servicenow/response.rb
|
139
|
+
- lib/servicenow/result.rb
|
140
|
+
- lib/servicenow/version.rb
|
141
|
+
- servicenow-api.gemspec
|
142
|
+
homepage: https://github.com/huntresslabs/servicenow-ruby
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubygems_version: 3.0.3
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: Ruby wrapper for the ServiceNow REST API
|
165
|
+
test_files: []
|