sirportly 1.0.4 → 1.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.
- data/lib/sirportly.rb +24 -8
- data/lib/sirportly/client.rb +91 -0
- data/lib/sirportly/data_object.rb +67 -0
- data/lib/sirportly/data_set.rb +36 -0
- data/lib/sirportly/request.rb +16 -8
- metadata +5 -6
- data/lib/sirportly/knowledge_base.rb +0 -53
- data/lib/sirportly/objects.rb +0 -47
- data/lib/sirportly/public_token.rb +0 -19
- data/lib/sirportly/ticket.rb +0 -27
data/lib/sirportly.rb
CHANGED
@@ -1,24 +1,39 @@
|
|
1
|
+
require 'time'
|
1
2
|
require 'uri'
|
2
3
|
require 'net/https'
|
3
4
|
require 'json'
|
4
5
|
|
6
|
+
require 'sirportly/client'
|
5
7
|
require 'sirportly/request'
|
6
|
-
require 'sirportly/
|
7
|
-
require 'sirportly/
|
8
|
-
|
9
|
-
require 'sirportly/
|
8
|
+
require 'sirportly/data_set'
|
9
|
+
require 'sirportly/data_object'
|
10
|
+
|
11
|
+
require 'sirportly/data_objects/brand'
|
12
|
+
require 'sirportly/data_objects/customer'
|
13
|
+
require 'sirportly/data_objects/customer_contact_method'
|
14
|
+
require 'sirportly/data_objects/department'
|
15
|
+
require 'sirportly/data_objects/escalation_path'
|
16
|
+
require 'sirportly/data_objects/priority'
|
17
|
+
require 'sirportly/data_objects/filter'
|
18
|
+
require 'sirportly/data_objects/sla'
|
19
|
+
require 'sirportly/data_objects/status'
|
20
|
+
require 'sirportly/data_objects/team'
|
21
|
+
require 'sirportly/data_objects/ticket'
|
22
|
+
require 'sirportly/data_objects/ticket_update'
|
23
|
+
require 'sirportly/data_objects/user'
|
10
24
|
|
11
25
|
module Sirportly
|
12
26
|
class << self
|
13
27
|
|
14
28
|
## Returns the current version number for the Sirportly API client.
|
15
29
|
def version
|
16
|
-
"1.0
|
30
|
+
"1.1.0"
|
17
31
|
end
|
18
32
|
|
19
|
-
## Stores
|
20
|
-
|
21
|
-
|
33
|
+
## Stores the application token if one has been provided. This can be nil if no
|
34
|
+
## application token exists, however if nil, you cannot authenticate using user
|
35
|
+
## tokens.
|
36
|
+
attr_accessor :application
|
22
37
|
|
23
38
|
## Allow the domain to be changed
|
24
39
|
attr_writer :domain
|
@@ -37,6 +52,7 @@ module Sirportly
|
|
37
52
|
class AccessDenied < Error; end
|
38
53
|
class NotFound < Error; end
|
39
54
|
class CommunicationError < Error; end
|
55
|
+
class ValidationError < Error; end
|
40
56
|
end
|
41
57
|
|
42
58
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Sirportly
|
2
|
+
class Client
|
3
|
+
|
4
|
+
attr_reader :token, :secret
|
5
|
+
|
6
|
+
def initialize(token, secret)
|
7
|
+
@token, @secret = token, secret
|
8
|
+
end
|
9
|
+
|
10
|
+
## Make a request using this client's authentication token and return the request.
|
11
|
+
def request(*args)
|
12
|
+
Request.request(self, *args)
|
13
|
+
end
|
14
|
+
|
15
|
+
## Return all brands
|
16
|
+
def brands
|
17
|
+
Brand.all(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
## Return all customers
|
21
|
+
def customers(opts = {})
|
22
|
+
Customer.all(self, opts)
|
23
|
+
end
|
24
|
+
|
25
|
+
## Return a specific customer
|
26
|
+
def customer(q)
|
27
|
+
Customer.find(self, q)
|
28
|
+
end
|
29
|
+
|
30
|
+
## Return all departments
|
31
|
+
def departments
|
32
|
+
Department.all(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
## Return all escalation paths
|
36
|
+
def escalation_paths
|
37
|
+
EscalationPath.all(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
## Return all filters
|
41
|
+
def filters
|
42
|
+
Filter.all(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
## Return all priorities
|
46
|
+
def priorities
|
47
|
+
Priority.all(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
## Return all SLAs
|
51
|
+
def slas
|
52
|
+
SLA.all(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
## Return all statuses
|
56
|
+
def statuses
|
57
|
+
Status.all(self)
|
58
|
+
end
|
59
|
+
|
60
|
+
## Return all teams
|
61
|
+
def teams
|
62
|
+
Team.all(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
## Return all tickets
|
66
|
+
def tickets
|
67
|
+
Ticket.all(self)
|
68
|
+
end
|
69
|
+
|
70
|
+
## Return a specific ticket
|
71
|
+
def ticket(q)
|
72
|
+
Ticket.find(self, q)
|
73
|
+
end
|
74
|
+
|
75
|
+
## Return a set of tickets for given search term
|
76
|
+
def ticket_search(query, page = 1)
|
77
|
+
Ticket.search(self, query, page)
|
78
|
+
end
|
79
|
+
|
80
|
+
## Return all users
|
81
|
+
def users(opts = {})
|
82
|
+
User.all(self, opts)
|
83
|
+
end
|
84
|
+
|
85
|
+
## Return a specific user
|
86
|
+
def user(q)
|
87
|
+
User.find(self, q)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Sirportly
|
2
|
+
class DataObject
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :collection_path
|
6
|
+
attr_accessor :member
|
7
|
+
attr_accessor :maps
|
8
|
+
|
9
|
+
def all(client, options = {})
|
10
|
+
raise Sirportly::Error, "This object does not support a full list" if collection_path.nil?
|
11
|
+
result = client.request(collection_path, :page => options[:page] || 1)
|
12
|
+
DataSet.new(client, result, self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def find(client, query)
|
16
|
+
raise Sirportly::Error, "This object does not support finding objects" unless member.is_a?(Hash)
|
17
|
+
result = client.request(member[:path], {member[:param] => query})
|
18
|
+
self.new(client, result)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :attributes
|
24
|
+
attr_reader :client
|
25
|
+
|
26
|
+
def initialize(client, attributes = {})
|
27
|
+
@client = client
|
28
|
+
set_attributes(attributes)
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"#<#{self.class.to_s} #{attributes.inspect}>"
|
33
|
+
end
|
34
|
+
|
35
|
+
def method_missing(name)
|
36
|
+
if attributes.keys.include?(name.to_s)
|
37
|
+
attributes[name.to_s]
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def set_attributes(attributes)
|
46
|
+
@attributes = attributes.inject({}) do |hash, (k,v)|
|
47
|
+
case k
|
48
|
+
when /\_(at|on)\Z/
|
49
|
+
hash[k] = v ? Time.parse(v) : nil
|
50
|
+
when /minutes\_since/
|
51
|
+
hash[k] = v.to_f
|
52
|
+
else
|
53
|
+
hash[k] = v
|
54
|
+
if self.class.maps.is_a?(Hash) && klass_name = self.class.maps[k]
|
55
|
+
if v.is_a?(Array)
|
56
|
+
hash[k] = v.map { |p| Sirportly.const_get(klass_name).new(@client, p) }
|
57
|
+
elsif v.is_a?(Hash)
|
58
|
+
hash[k] = Sirportly.const_get(klass_name).new(@client, v)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
hash
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Sirportly
|
2
|
+
class DataSet < Array
|
3
|
+
|
4
|
+
def initialize(client, records, klass)
|
5
|
+
@pagination = {}
|
6
|
+
if records.is_a?(Hash)
|
7
|
+
@pagination = records['pagination']
|
8
|
+
records = records['records']
|
9
|
+
end
|
10
|
+
|
11
|
+
records.map! { |r| klass.new(client, r) }
|
12
|
+
self.push(*records)
|
13
|
+
end
|
14
|
+
|
15
|
+
def page
|
16
|
+
@pagination['page']
|
17
|
+
end
|
18
|
+
|
19
|
+
def total_records
|
20
|
+
@pagination['total_records']
|
21
|
+
end
|
22
|
+
|
23
|
+
def per_page
|
24
|
+
@pagination['per_page']
|
25
|
+
end
|
26
|
+
|
27
|
+
def pages
|
28
|
+
@pagination['pages']
|
29
|
+
end
|
30
|
+
|
31
|
+
def offset
|
32
|
+
@pagination['offset']
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/sirportly/request.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
module Sirportly
|
2
2
|
class Request
|
3
3
|
|
4
|
-
def self.request(path, data = {})
|
5
|
-
req = self.new(path, :post)
|
4
|
+
def self.request(client, path, data = {})
|
5
|
+
req = self.new(client, path, :post)
|
6
6
|
req.data = data
|
7
7
|
req.make && req.success? ? req.output : false
|
8
8
|
end
|
9
9
|
|
10
|
-
attr_reader :path, :method
|
10
|
+
attr_reader :path, :method, :client
|
11
11
|
attr_accessor :data
|
12
12
|
|
13
|
-
def initialize(path, method = :get)
|
13
|
+
def initialize(client, path, method = :get)
|
14
14
|
@path = path
|
15
15
|
@method = method
|
16
|
+
@client = client
|
16
17
|
end
|
17
18
|
|
18
19
|
def success?
|
@@ -27,8 +28,13 @@ module Sirportly
|
|
27
28
|
uri = URI.parse([Sirportly.domain, "api/v1", @path].join('/'))
|
28
29
|
http_request = http_class.new(uri.request_uri)
|
29
30
|
http_request.initialize_http_header({"User-Agent" => "SirportlyRubyClient/#{Sirportly.version}"})
|
30
|
-
http_request.add_field("X-Auth-Token",
|
31
|
-
http_request.add_field("X-Auth-Secret",
|
31
|
+
http_request.add_field("X-Auth-Token", @client.token)
|
32
|
+
http_request.add_field("X-Auth-Secret", @client.secret)
|
33
|
+
|
34
|
+
if Sirportly.application
|
35
|
+
http_request.add_field("X-Auth-Application", Sirportly.application)
|
36
|
+
end
|
37
|
+
|
32
38
|
http_request.set_form_data(@data)
|
33
39
|
|
34
40
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -48,9 +54,11 @@ module Sirportly
|
|
48
54
|
when Net::HTTPForbidden, Net::HTTPUnauthorized
|
49
55
|
raise Sirportly::Errors::AccessDenied, "Access Denied for '#{Sirportly.token}'"
|
50
56
|
when Net::HTTPNotFound
|
51
|
-
|
57
|
+
|
58
|
+
raise Sirportly::Errors::NotFound, json['error']
|
52
59
|
when Net::HTTPClientError
|
53
|
-
|
60
|
+
json = JSON.parse(http_result.body)
|
61
|
+
raise Sirportly::Errors::ValidationError, json['errors'].to_s
|
54
62
|
else
|
55
63
|
raise Sirportly::Errors::CommunicationError, http_result.body
|
56
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sirportly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-16 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: adam@atechmedia.com
|
@@ -18,11 +18,10 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/sirportly.rb
|
21
|
-
- lib/sirportly/
|
22
|
-
- lib/sirportly/
|
23
|
-
- lib/sirportly/
|
21
|
+
- lib/sirportly/client.rb
|
22
|
+
- lib/sirportly/data_object.rb
|
23
|
+
- lib/sirportly/data_set.rb
|
24
24
|
- lib/sirportly/request.rb
|
25
|
-
- lib/sirportly/ticket.rb
|
26
25
|
homepage: http://www.sirportly.com
|
27
26
|
licenses: []
|
28
27
|
post_install_message:
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Sirportly
|
2
|
-
class KnowledgeBase
|
3
|
-
|
4
|
-
attr_accessor :id
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def list
|
8
|
-
Request.request('knowledge/list')
|
9
|
-
end
|
10
|
-
|
11
|
-
def find_by_id(id)
|
12
|
-
tree = Request.request('knowledge/tree', :kb => id)
|
13
|
-
self.new(id, tree = tree)
|
14
|
-
rescue Errors::NotFound
|
15
|
-
false
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(id, tree = nil)
|
20
|
-
@id = id
|
21
|
-
@tree = tree
|
22
|
-
end
|
23
|
-
|
24
|
-
def page(path)
|
25
|
-
request('page', :path => path)
|
26
|
-
end
|
27
|
-
|
28
|
-
def tree
|
29
|
-
@tree ||= request('tree')
|
30
|
-
end
|
31
|
-
|
32
|
-
def add_page(options = {})
|
33
|
-
request('add_page', options)
|
34
|
-
end
|
35
|
-
|
36
|
-
def edit_page(path, options = {})
|
37
|
-
options[:path] = path
|
38
|
-
request('edit_page', options)
|
39
|
-
end
|
40
|
-
|
41
|
-
def delete_page(path)
|
42
|
-
request('delete_page', :path => path)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def request(path, options = {})
|
48
|
-
options[:kb] = self.id
|
49
|
-
Request.request('knowledge/'+path, options)
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
data/lib/sirportly/objects.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
module Sirportly
|
2
|
-
class Objects
|
3
|
-
class << self
|
4
|
-
|
5
|
-
def statuses
|
6
|
-
Request.request('objects/statuses')
|
7
|
-
end
|
8
|
-
|
9
|
-
def priorities
|
10
|
-
Request.request('objects/priorities')
|
11
|
-
end
|
12
|
-
|
13
|
-
def users
|
14
|
-
Request.request('objects/users')
|
15
|
-
end
|
16
|
-
|
17
|
-
def teams
|
18
|
-
Request.request('objects/teams')
|
19
|
-
end
|
20
|
-
|
21
|
-
def brands
|
22
|
-
Request.request('objects/brands')
|
23
|
-
end
|
24
|
-
|
25
|
-
def departments(brand_id = nil)
|
26
|
-
if brand_id
|
27
|
-
begin
|
28
|
-
Request.request('objects/departments', :brand_id => brand_id.to_i)
|
29
|
-
rescue Errors::NotFound
|
30
|
-
false
|
31
|
-
end
|
32
|
-
else
|
33
|
-
Request.request('objects/departments')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def escalation_paths
|
38
|
-
Request.request('objects/escalation_paths')
|
39
|
-
end
|
40
|
-
|
41
|
-
def slas
|
42
|
-
Request.request('objects/slas')
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Sirportly
|
2
|
-
class PublicToken
|
3
|
-
|
4
|
-
class << self
|
5
|
-
|
6
|
-
def token_login_url(public_interface, customer_details = {})
|
7
|
-
token = generate_public_token(public_interface, customer_details)
|
8
|
-
"#{token['public_interface']['access_domain_with_protocol']}/login/#{token['token']}"
|
9
|
-
end
|
10
|
-
|
11
|
-
def generate_public_token(public_interface, customer_details={})
|
12
|
-
options = {:public_interface => public_interface}.merge(customer_details)
|
13
|
-
Request.request('authentication/public_token', options)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
data/lib/sirportly/ticket.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Sirportly
|
2
|
-
class Ticket
|
3
|
-
|
4
|
-
class << self
|
5
|
-
|
6
|
-
def find_by_reference(reference)
|
7
|
-
Request.request('tickets/ticket', :reference => reference)
|
8
|
-
rescue Errors::NotFound
|
9
|
-
false
|
10
|
-
end
|
11
|
-
|
12
|
-
def execute_spql(query)
|
13
|
-
Request.request('tickets/spql', :spql => query)
|
14
|
-
end
|
15
|
-
|
16
|
-
def submit(options)
|
17
|
-
Request.request('tickets/submit', options)
|
18
|
-
end
|
19
|
-
|
20
|
-
def update(reference, options)
|
21
|
-
options.merge!(:ticket => reference)
|
22
|
-
Request.request('tickets/post_update', options)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|