supportpal 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +71 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/supportpal.rb +118 -0
- data/lib/supportpal/config.rb +44 -0
- data/lib/supportpal/version.rb +3 -0
- data/supportpal.gemspec +45 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9904edb7c7891fe8166aaa215af16c51e29101f9
|
4
|
+
data.tar.gz: 26ae545b047d0b35f912e71bf205865466c3c94b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29d7917c10182eca350ab4a2467eaefd6a563decc96aac49441f1798cacd9411f8453aa41644ef69c9e6eb96f4e590c15a2594dfd7f735073ef71bdeec3edd58
|
7
|
+
data.tar.gz: c1fb941b967e3a7c7a96eff06aa3334ec9fe504f06810c9908adc17e820f4a96fd8bcd4139271f836f95f478341d6df94ababf92bf8ddf4fd806bbd9be670d42
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Andrew White
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# supportpal-ruby
|
2
|
+
|
3
|
+
This gem provides direct calls to the SupportPal REST APIs.
|
4
|
+
|
5
|
+
Current functions:
|
6
|
+
|
7
|
+
* Open a new ticket
|
8
|
+
* Add a note to a ticket (by ID)
|
9
|
+
* Close a ticket (by ID)
|
10
|
+
|
11
|
+
Other features may be added later as needed by me, however pull requests are always welcomne.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'supportpal-ruby'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install supportpal-ruby
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Basic example:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'supportpal'
|
35
|
+
|
36
|
+
cwd = File.expand_path('../', __FILE__)
|
37
|
+
|
38
|
+
supportpal = SupportPal::Session.new({
|
39
|
+
'base_uri' => 'https://supportpal.local',
|
40
|
+
'config' => "#{cwd}/config.yml"
|
41
|
+
})
|
42
|
+
puts "Loaded SupportPal API version #{SupportPal::VERSION}"
|
43
|
+
|
44
|
+
ticket = supportpal.open_new_ticket(
|
45
|
+
"Ticket subject",
|
46
|
+
"This is a <strong>Ticket message!</strong>"
|
47
|
+
)
|
48
|
+
|
49
|
+
if ticket[:status] == 'success' then
|
50
|
+
note = supportpal.add_ticket_note(ticket[:ticket_id], 'This is a test note')
|
51
|
+
supportpal.close_ticket_by_id(ticket[:ticket_id])
|
52
|
+
else
|
53
|
+
puts "Error opening new ticket - #{ticket[:message]}"
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
```yaml
|
58
|
+
ticket_user_id: 5
|
59
|
+
ticket_department_id: 3
|
60
|
+
auth_token: 2YpXPZ9BDYo6S9Unp5uQ4FH4q
|
61
|
+
```
|
62
|
+
|
63
|
+
`config` can be passed as path to yaml file, hash, or left blank for default options to be used.
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/WhiteyDude/supportpal-ruby.
|
68
|
+
|
69
|
+
## License
|
70
|
+
|
71
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "supportpal"
|
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 "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/supportpal.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require "supportpal/version"
|
2
|
+
require 'supportpal/config'
|
3
|
+
require "httparty"
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module SupportPal
|
7
|
+
# Errors
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class Session
|
11
|
+
include HTTParty
|
12
|
+
# Uncomment to debug output
|
13
|
+
#debug_output $stdout
|
14
|
+
|
15
|
+
def initialize(options)
|
16
|
+
# Make a class variable
|
17
|
+
@options = options
|
18
|
+
|
19
|
+
# Load config
|
20
|
+
if @options['config'] then # Can be hash with values, or path to yaml
|
21
|
+
config = SupportPal::Configure.new(@options['config'])
|
22
|
+
else
|
23
|
+
config = SupportPal::Configure.new
|
24
|
+
end
|
25
|
+
@config = config.config
|
26
|
+
|
27
|
+
# Check to ensure required options exist
|
28
|
+
raise Error, 'You must provide a base_uri option!' if ! @options['base_uri']
|
29
|
+
self.class.base_uri @options['base_uri']
|
30
|
+
|
31
|
+
raise Error, 'You must provide an auth token in config!' if ! @config[:auth_token]
|
32
|
+
|
33
|
+
# Default headers
|
34
|
+
@auth = { username: @config[:auth_token], password: 'X' }
|
35
|
+
@http_options = { basic_auth: @auth }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test
|
39
|
+
puts "Base URI is #{self.class.base_uri}"
|
40
|
+
res = self.class.get('/api/selfservice/type', @http_options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def open_new_ticket(subject, message, options = {})
|
44
|
+
params = {}
|
45
|
+
params['subject'] = subject
|
46
|
+
params['text'] = message
|
47
|
+
|
48
|
+
params['user'] = @config[:ticket_user_id]
|
49
|
+
params['user'] = options['operator_id'] if options['operator_id']
|
50
|
+
params['user'] = options['user_id'] if options['user_id']
|
51
|
+
|
52
|
+
params['department'] = (options['department']) ? options['department'] : @config[:ticket_department_id]
|
53
|
+
params['status'] = (options['status']) ? options['status'] : @config[:ticket_status]
|
54
|
+
params['priority'] = (options['priority']) ? options['priority'] : @config[:ticket_priority]
|
55
|
+
|
56
|
+
@http_options.merge!({ body: params })
|
57
|
+
res = self.class.post('/api/ticket/ticket', @http_options)
|
58
|
+
response = res.parsed_response
|
59
|
+
if response['status'] == 'success' then
|
60
|
+
return {
|
61
|
+
:status => 'success',
|
62
|
+
:ticket_id => response['data']['id']
|
63
|
+
}
|
64
|
+
else
|
65
|
+
return {
|
66
|
+
:status => 'failure',
|
67
|
+
:message => response['message']
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_ticket_note(ticket_id, message, options = {})
|
73
|
+
params = {}
|
74
|
+
params['text'] = message
|
75
|
+
|
76
|
+
params['user_id'] = @config[:ticket_user_id]
|
77
|
+
params['user_id'] = options['operator_id'] if options['operator_id']
|
78
|
+
params['user_id'] = options['user_id'] if options['user_id']
|
79
|
+
|
80
|
+
params['ticket_id'] = ticket_id
|
81
|
+
params['message_type'] = 1 # 1 = note, 0 = reply
|
82
|
+
|
83
|
+
@http_options.merge!({ body: params })
|
84
|
+
res = self.class.post("/api/ticket/message", @http_options)
|
85
|
+
response = res.parsed_response
|
86
|
+
if response['status'] == 'success' then
|
87
|
+
return {
|
88
|
+
:status => 'success',
|
89
|
+
:message => response['message']
|
90
|
+
}
|
91
|
+
else
|
92
|
+
return {
|
93
|
+
:status => 'failure',
|
94
|
+
:message => response['message']
|
95
|
+
}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def close_ticket_by_id(ticket_id)
|
100
|
+
# Check if ticket_id is an integer
|
101
|
+
@http_options.merge!({ body: { status: 2 } })
|
102
|
+
res = self.class.put("/api/ticket/ticket/#{ticket_id}", @http_options)
|
103
|
+
response = res.parsed_response
|
104
|
+
if response['status'] == 'success' then
|
105
|
+
return {
|
106
|
+
:status => 'success',
|
107
|
+
:message => response['message']
|
108
|
+
}
|
109
|
+
else
|
110
|
+
return {
|
111
|
+
:status => 'failure',
|
112
|
+
:message => response['message']
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SupportPal
|
2
|
+
class Configure
|
3
|
+
# Concept from https://stackoverflow.com/a/10112179
|
4
|
+
|
5
|
+
def default_config
|
6
|
+
@config = {
|
7
|
+
:ticket_status => 1, # Open
|
8
|
+
:ticket_priority => 1, # Low
|
9
|
+
:ticket_user_id => nil, # Operator or user
|
10
|
+
:ticket_department_id => nil,
|
11
|
+
:auth_token => nil, # SupportPal token
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(opts = {})
|
16
|
+
opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
|
17
|
+
end
|
18
|
+
|
19
|
+
def configure_with(path_to_yaml_file)
|
20
|
+
begin
|
21
|
+
config = YAML::load(IO.read(path_to_yaml_file))
|
22
|
+
rescue Errno::ENOENT
|
23
|
+
puts "YAML configuration file couldn't be found. Using defaults."; return
|
24
|
+
rescue Psych::SyntaxError
|
25
|
+
puts "YAML configuration file contains invalid syntax. Using defaults."; return
|
26
|
+
end
|
27
|
+
configure(config)
|
28
|
+
end
|
29
|
+
|
30
|
+
def config
|
31
|
+
@config
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(config = nil)
|
35
|
+
default_config
|
36
|
+
@valid_config_keys = @config.keys
|
37
|
+
if config.class == Hash then
|
38
|
+
configure(config)
|
39
|
+
elsif config.class == String then
|
40
|
+
configure_with(config)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/supportpal.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "supportpal/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "supportpal"
|
8
|
+
spec.version = SupportPal::VERSION
|
9
|
+
spec.authors = ["Andrew White"]
|
10
|
+
spec.email = ["github@and.rew.ninja"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides ruby functions to natively call SupportPal APIs directly without adding cURL or HTTP call gems to your code}
|
13
|
+
spec.description = %q{Native SupportPal API calls}
|
14
|
+
spec.homepage = "https://github.com/WhiteyDude/supportpal"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/WhiteyDude/supportpal"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/WhiteyDude/supportpal"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "dotenv", "~> 2.7"
|
42
|
+
|
43
|
+
# Runtime dependancies
|
44
|
+
spec.add_runtime_dependency "httparty", "~> 0.17.0"
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: supportpal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew White
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-28 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dotenv
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.17.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.17.0
|
69
|
+
description: Native SupportPal API calls
|
70
|
+
email:
|
71
|
+
- github@and.rew.ninja
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/supportpal.rb
|
84
|
+
- lib/supportpal/config.rb
|
85
|
+
- lib/supportpal/version.rb
|
86
|
+
- supportpal.gemspec
|
87
|
+
homepage: https://github.com/WhiteyDude/supportpal
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata:
|
91
|
+
allowed_push_host: https://rubygems.org
|
92
|
+
homepage_uri: https://github.com/WhiteyDude/supportpal
|
93
|
+
source_code_uri: https://github.com/WhiteyDude/supportpal
|
94
|
+
changelog_uri: https://github.com/WhiteyDude/supportpal
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.2.3
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Provides ruby functions to natively call SupportPal APIs directly without
|
115
|
+
adding cURL or HTTP call gems to your code
|
116
|
+
test_files: []
|