sirportly 1.2.6 → 1.2.7

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.
@@ -3,12 +3,16 @@ require 'uri'
3
3
  require 'net/https'
4
4
  require 'json'
5
5
 
6
+ require 'net/http/post/multipart'
7
+
6
8
  require 'sirportly/client'
7
9
  require 'sirportly/request'
8
10
  require 'sirportly/data_set'
9
11
  require 'sirportly/data_object'
10
12
  require 'sirportly/spql_query'
13
+ require 'sirportly/extensions'
11
14
 
15
+ require 'sirportly/data_objects/api_token'
12
16
  require 'sirportly/data_objects/brand'
13
17
  require 'sirportly/data_objects/customer'
14
18
  require 'sirportly/data_objects/customer_contact_method'
@@ -27,7 +31,7 @@ require 'sirportly/data_objects/ticket_update'
27
31
  require 'sirportly/data_objects/user'
28
32
 
29
33
  module Sirportly
30
- VERSION = '1.2.6'
34
+ VERSION = '1.2.7'
31
35
 
32
36
  class << self
33
37
 
@@ -117,6 +117,16 @@ module Sirportly
117
117
  User.create(self, params)
118
118
  end
119
119
 
120
+ ## Return all api token
121
+ def api_tokens
122
+ ApiToken.all(self)
123
+ end
124
+
125
+ ## Creates a new api token
126
+ def create_api_token(params = {})
127
+ ApiToken.create(self, params)
128
+ end
129
+
120
130
  ## Enable or disable ticket mode for the token's account
121
131
  def import_mode(status = nil)
122
132
  hash = {}
@@ -0,0 +1,14 @@
1
+ module Sirportly
2
+ class ApiToken < DataObject
3
+ self.collection_path = 'api_tokens/all'
4
+
5
+ # Creates a new api token and returns an object
6
+ def self.create(client, params = {})
7
+ if req = client.request('api_tokens/create', params)
8
+ self.new(client, req)
9
+ else
10
+ false
11
+ end
12
+ end
13
+ end
14
+ end
@@ -37,6 +37,15 @@ module Sirportly
37
37
  end
38
38
  end
39
39
 
40
+ # Allows you to upload attachments to existing ticket updates. Accepts a hash of parameters needed to create the attachment.
41
+ def add_attachment(params = {})
42
+ if req = client.request('tickets/add_attachment', format_params(params))
43
+ true
44
+ else
45
+ false
46
+ end
47
+ end
48
+
40
49
  # Adds a follow up to the ticket
41
50
  def add_follow_up(params = {})
42
51
  if req = client.request('tickets/followup', format_params(params))
@@ -0,0 +1,8 @@
1
+ class Hash
2
+ def stringify_keys
3
+ inject({}) do |options, (key, value)|
4
+ options[key.to_s] = value
5
+ options
6
+ end
7
+ end
8
+ end
@@ -26,8 +26,8 @@ module Sirportly
26
26
 
27
27
  def make
28
28
  uri = URI.parse([Sirportly.domain, "api/v1", @path].join('/'))
29
- http_request = http_class.new(uri.request_uri)
30
- http_request.initialize_http_header({"User-Agent" => "SirportlyRubyClient/#{Sirportly::VERSION}"})
29
+ http_request = http_req(uri, @data.stringify_keys)
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
@@ -36,15 +36,13 @@ module Sirportly
36
36
  http_request.add_field("X-Auth-Application", Sirportly.application)
37
37
  end
38
38
 
39
- http_request.set_form_data(@data)
40
-
41
39
  http = Net::HTTP.new(uri.host, uri.port)
42
40
 
43
41
  if uri.scheme == 'https'
44
42
  http.use_ssl = true
45
43
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
46
44
  end
47
-
45
+
48
46
  http_result = http.request(http_request)
49
47
 
50
48
  if http_result.body == 'true'
@@ -77,13 +75,29 @@ module Sirportly
77
75
 
78
76
  private
79
77
 
80
- def http_class
78
+ def http_req(uri, data)
81
79
  case @method
82
- when :post then Net::HTTP::Post
83
- when :put then Net::HTTP::Put
84
- when :delete then Net::HTTP::Delete
80
+ when :post
81
+ if data["file"]
82
+ r = Net::HTTP::Post::Multipart.new(uri.request_uri, data)
83
+ else
84
+ r = Net::HTTP::Put.new(uri.request_uri)
85
+ r.set_form_data(data)
86
+ end
87
+
88
+ return r
89
+ when :put
90
+ r = Net::HTTP::Put.new(uri.request_uri)
91
+ r.set_form_data(data)
92
+ return r
93
+ when :delete
94
+ r = Net::HTTP::Delete.new(uri.request_uri)
95
+ r.set_form_data(data)
96
+ return r
85
97
  else
86
- Net::HTTP::Get
98
+ r = Net::HTTP::Get.new(uri.request_uri)
99
+ r.set_form_data(data)
100
+ return r
87
101
  end
88
102
  end
89
103
 
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.2.6
4
+ version: 1.2.7
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-11-27 00:00:00.000000000Z
12
+ date: 2012-11-29 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: A Ruby library for interacting with the Sirportly API.
15
15
  email: adam@atechmedia.com
@@ -20,6 +20,7 @@ files:
20
20
  - lib/sirportly.rb
21
21
  - lib/sirportly/client.rb
22
22
  - lib/sirportly/data_object.rb
23
+ - lib/sirportly/data_objects/api_token.rb
23
24
  - lib/sirportly/data_objects/brand.rb
24
25
  - lib/sirportly/data_objects/custom_field.rb
25
26
  - lib/sirportly/data_objects/customer.rb
@@ -37,6 +38,7 @@ files:
37
38
  - lib/sirportly/data_objects/ticket_update.rb
38
39
  - lib/sirportly/data_objects/user.rb
39
40
  - lib/sirportly/data_set.rb
41
+ - lib/sirportly/extensions.rb
40
42
  - lib/sirportly/request.rb
41
43
  - lib/sirportly/spql_query.rb
42
44
  homepage: http://www.sirportly.com