sirportly 1.3.8 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sirportly.rb CHANGED
@@ -31,29 +31,29 @@ require 'sirportly/data_objects/ticket_update'
31
31
  require 'sirportly/data_objects/user'
32
32
 
33
33
  module Sirportly
34
- VERSION = '1.3.8'
35
-
34
+ VERSION = '1.3.9'
35
+
36
36
  class << self
37
-
37
+
38
38
  ## Stores the application token if one has been provided. This can be nil if no
39
39
  ## application token exists, however if nil, you cannot authenticate using user
40
40
  ## tokens.
41
41
  attr_accessor :application
42
-
43
- ## Specifies whether or not to execute rules when running API calls. By default,
42
+
43
+ ## Specifies whether or not to execute rules when running API calls. By default,
44
44
  ## all rules will be run. Set to false to stop execution.
45
45
  attr_accessor :execute_rules
46
-
46
+
47
47
  ## Allow the domain to be changed
48
48
  attr_writer :domain
49
-
49
+
50
50
  ## Returns the domain which should be used to query the API
51
51
  def domain
52
52
  @domain ||= 'https://api.sirportly.com'
53
53
  end
54
-
54
+
55
55
  end
56
-
56
+
57
57
  ## Various error classes to raise
58
58
  class Error < StandardError; end
59
59
  module Errors
@@ -63,5 +63,5 @@ module Sirportly
63
63
  class CommunicationError < Error; end
64
64
  class ValidationError < Error; end
65
65
  end
66
-
66
+
67
67
  end
@@ -1,127 +1,127 @@
1
1
  module Sirportly
2
2
  class Client
3
-
4
- attr_reader :token, :secret
5
-
6
- def initialize(token, secret)
7
- @token, @secret = token, secret
3
+
4
+ attr_reader :token, :secret, :opts
5
+
6
+ def initialize(token, secret, opts={})
7
+ @token, @secret, @opts = token, secret, opts
8
8
  end
9
-
9
+
10
10
  ## Make a request using this client's authentication token and return the request.
11
11
  def request(*args)
12
12
  Request.request(self, *args)
13
13
  end
14
-
14
+
15
15
  ## Return all brands
16
16
  def brands
17
17
  Brand.all(self)
18
18
  end
19
-
19
+
20
20
  ## Creates a new ticket
21
21
  def create_ticket(params = {})
22
22
  Ticket.create(self, params)
23
23
  end
24
-
24
+
25
25
  ## Return all customers
26
26
  def customers(opts = {})
27
27
  Customer.all(self, opts)
28
28
  end
29
-
29
+
30
30
  ## Return a specific customer
31
31
  def customer(q)
32
32
  Customer.find(self, q)
33
33
  end
34
-
34
+
35
35
  ## Return all departments
36
36
  def departments
37
37
  Department.all(self)
38
38
  end
39
-
39
+
40
40
  ## Return all escalation paths
41
41
  def escalation_paths
42
42
  EscalationPath.all(self)
43
43
  end
44
-
44
+
45
45
  ## Return all filters
46
46
  def filters
47
47
  Filter.all(self)
48
48
  end
49
-
49
+
50
50
  ## Return all knowledge bases
51
51
  def knowledge_bases
52
52
  KnowledgeBase.all(self)
53
53
  end
54
-
54
+
55
55
  ## Return a specific knowledge base
56
56
  def knowledge_base(q)
57
57
  KnowledgeBase.find(self, q)
58
58
  end
59
-
59
+
60
60
  ## Return all priorities
61
61
  def priorities
62
62
  Priority.all(self)
63
63
  end
64
-
64
+
65
65
  ## Return all SLAs
66
66
  def slas
67
67
  SLA.all(self)
68
68
  end
69
-
69
+
70
70
  ## Return all custom fields
71
71
  def custom_fields
72
72
  CustomField.all(self)
73
73
  end
74
-
74
+
75
75
  ## Execute an SPQL query and return the SPQLQuery instance
76
76
  def spql(query)
77
77
  SPQLQuery.new(self, query)
78
78
  end
79
-
79
+
80
80
  ## Return all statuses
81
81
  def statuses
82
82
  Status.all(self)
83
83
  end
84
-
84
+
85
85
  ## Return all teams
86
86
  def teams
87
87
  Team.all(self)
88
88
  end
89
-
89
+
90
90
  ## Return all tickets
91
91
  def tickets(opts = {})
92
92
  Ticket.all(self, opts)
93
93
  end
94
-
94
+
95
95
  ## Return a specific ticket
96
96
  def ticket(q)
97
97
  Ticket.find(self, q)
98
98
  end
99
-
99
+
100
100
  ## Return a set of tickets for given search term
101
101
  def ticket_search(query, page = 1)
102
102
  Ticket.search(self, query, page)
103
103
  end
104
-
104
+
105
105
  ## Return all users
106
106
  def users(opts = {})
107
107
  User.all(self, opts)
108
108
  end
109
-
109
+
110
110
  ## Return a specific user
111
111
  def user(q)
112
112
  User.find(self, q)
113
113
  end
114
-
114
+
115
115
  ## Create a user
116
116
  def create_user(params = {})
117
117
  User.create(self, params)
118
118
  end
119
-
119
+
120
120
  ## Return all api token
121
121
  def api_tokens
122
122
  ApiToken.all(self)
123
123
  end
124
-
124
+
125
125
  ## Creates a new api token
126
126
  def create_api_token(params = {})
127
127
  ApiToken.create(self, params)
@@ -130,7 +130,7 @@ module Sirportly
130
130
  def contact_tickets(params = {})
131
131
  Ticket.contact(self, params)
132
132
  end
133
-
133
+
134
134
  ## Enable or disable ticket mode for the token's account
135
135
  def import_mode(status = nil)
136
136
  hash = {}
@@ -138,6 +138,6 @@ module Sirportly
138
138
  response = Request.request(self, 'accounts/import_mode', hash)
139
139
  response.is_a?(Hash) ? response['status'] : nil
140
140
  end
141
-
141
+
142
142
  end
143
143
  end
@@ -1,50 +1,50 @@
1
1
  module Sirportly
2
2
  class Request
3
-
3
+
4
4
  def self.request(client, path, data = {})
5
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
10
  attr_reader :path, :method, :client
11
11
  attr_accessor :data
12
-
12
+
13
13
  def initialize(client, path, method = :get)
14
14
  @path = path
15
15
  @method = method
16
16
  @client = client
17
17
  end
18
-
18
+
19
19
  def success?
20
20
  @success || false
21
21
  end
22
-
22
+
23
23
  def output
24
24
  @output || nil
25
25
  end
26
-
26
+
27
27
  def make
28
- uri = URI.parse([Sirportly.domain, "api/v1", @path].join('/'))
28
+ uri = URI.parse([domain, "api/v1", @path].join('/'))
29
29
  http_request = http_req(uri, @data.stringify_keys)
30
30
  http_request.add_field("User-Agent", "SirportlyRubyClient/#{Sirportly::VERSION}")
31
31
  http_request.add_field("X-Auth-Token", @client.token)
32
32
  http_request.add_field("X-Auth-Secret", @client.secret)
33
33
  http_request.add_field("X-Sirportly-Rules", "disabled") if Sirportly.execute_rules == false
34
34
 
35
- if Sirportly.application
36
- http_request.add_field("X-Auth-Application", Sirportly.application)
35
+ if application
36
+ http_request.add_field("X-Auth-Application", application)
37
37
  end
38
38
 
39
39
  http = Net::HTTP.new(uri.host, uri.port)
40
-
40
+
41
41
  if uri.scheme == 'https'
42
42
  http.use_ssl = true
43
43
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
44
  end
45
45
 
46
46
  http_result = http.request(http_request)
47
-
47
+
48
48
  if http_result.body == 'true'
49
49
  @output = true
50
50
  elsif http_result.body == 'false'
@@ -52,7 +52,7 @@ module Sirportly
52
52
  else
53
53
  @output = JSON.parse(http_result.body)
54
54
  end
55
-
55
+
56
56
  @success = case http_result
57
57
  when Net::HTTPSuccess
58
58
  true
@@ -72,9 +72,9 @@ module Sirportly
72
72
  end
73
73
  self
74
74
  end
75
-
75
+
76
76
  private
77
-
77
+
78
78
  def http_req(uri, data)
79
79
  case @method
80
80
  when :post
@@ -84,7 +84,7 @@ module Sirportly
84
84
  r = Net::HTTP::Put.new(uri.request_uri)
85
85
  r.set_form_data(data)
86
86
  end
87
-
87
+
88
88
  return r
89
89
  when :put
90
90
  r = Net::HTTP::Put.new(uri.request_uri)
@@ -100,6 +100,14 @@ module Sirportly
100
100
  return r
101
101
  end
102
102
  end
103
-
103
+
104
+ def domain
105
+ @client.opts[:domain] || Sirportly.domain
106
+ end
107
+
108
+ def application
109
+ @client.opts[:application] || Sirportly.application
110
+ end
111
+
104
112
  end
105
113
  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.3.8
4
+ version: 1.3.9
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: 2014-01-29 00:00:00.000000000 Z
12
+ date: 2015-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multipart-post
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 1.8.23
80
+ rubygems_version: 1.8.23.2
81
81
  signing_key:
82
82
  specification_version: 3
83
83
  summary: Easy to use client library for Sirportly.