ticket_sharing 1.2.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b51ca8f39acac4810a623cff359b0932a6c78d0
4
- data.tar.gz: 965583e24ce9ce3dab466e15eeafcd91cec047f7
3
+ metadata.gz: 1bc8f56c0ccfb6e635bb4ac3be1715209b5c9a61
4
+ data.tar.gz: b3f6d3d8536df537b82ef3d559eba9d67f9f8cc5
5
5
  SHA512:
6
- metadata.gz: 077b31ace706771d4539827c0dc1c8ba57192cfd8e7dc6b96f88c84b92f54f7ac3c1f52d11a1482595b07852318df012c9c663485f0e6b5bc8719599014d83b6
7
- data.tar.gz: 23e7d9ea5d840f1747f52eb746b35449d99a12067dfd3376647b579e671a842fb36f06a6e4d30e116edc53e2e071f9de443e87aee39989a8861cfdf192e1f727
6
+ metadata.gz: 723ab06045867a1447abf8497580db737ee56c93975ce154bfb27e4560a6157f643358f23c3c28420cd3e10689469bb5d4070b473be3ae3187b76eba730c700b
7
+ data.tar.gz: f94a63b118dcb4867a14064bfc63942a009e743ac0dd2c1298556eb97a8db769d693960c0a3feeb8d0f260c6d43a34a55b8a0f7d84b80c946925f1195bf5cc60
data/Readme.md CHANGED
@@ -10,7 +10,7 @@ A ruby implementation of the [Networked Help Desk] [1] API
10
10
 
11
11
  ### Creating an agreement
12
12
 
13
- agreement = TicketSharing::Agreement.new({'uuid' => '5ad614f4'})
13
+ agreement = TicketSharing::Agreement.new('uuid' => '5ad614f4')
14
14
  agreement.send_to('http://example.com/sharing')
15
15
 
16
16
  ### Sending a ticket
@@ -25,7 +25,7 @@ A ruby implementation of the [Networked Help Desk] [1] API
25
25
 
26
26
  ### Updating a ticket
27
27
 
28
- ticket = TicketSharing::Ticket.new({'status' => 'new'})
28
+ ticket = TicketSharing::Ticket.new('status' => 'new')
29
29
  ticket.update_partner('http://example.com/sharing')
30
30
 
31
31
  ## Contributing
@@ -0,0 +1,9 @@
1
+ module TicketSharing
2
+ def self.connection
3
+ @connection ||= Faraday.new
4
+ end
5
+
6
+ def self.connection=(new_connection)
7
+ @connection = new_connection
8
+ end
9
+ end
@@ -23,14 +23,14 @@ module TicketSharing
23
23
  client = Client.new(url)
24
24
  @response = client.post(relative_url, self.to_json)
25
25
 
26
- @response.code.to_i
26
+ @response.status
27
27
  end
28
28
 
29
29
  def update_partner(url)
30
30
  client = Client.new(url, authentication_token)
31
31
  @response = client.put(relative_url, self.to_json)
32
32
 
33
- @response.code.to_i
33
+ @response.status
34
34
  end
35
35
 
36
36
  def relative_url
@@ -1,3 +1,4 @@
1
+ require 'ticket_sharing'
1
2
  require 'ticket_sharing/error'
2
3
  require 'ticket_sharing/request'
3
4
 
@@ -6,6 +7,8 @@ module TicketSharing
6
7
  def initialize(base_url, credentials=nil)
7
8
  @base_url = base_url
8
9
  @credentials = credentials
10
+
11
+ @requester = TicketSharing::Request.new(TicketSharing.connection)
9
12
  end
10
13
 
11
14
  def post(path, body, options={})
@@ -29,19 +32,19 @@ module TicketSharing
29
32
  def send_request(method, path, body, options)
30
33
  headers = {'X-Ticket-Sharing-Token' => @credentials} if @credentials
31
34
  options = options.merge(:body => body, :headers => headers)
32
- response = TicketSharing::Request.new.request(method, @base_url + path, options)
35
+ response = @requester.request(method, @base_url + path, options)
33
36
 
34
37
  handle_response(response)
35
38
  end
36
39
 
37
40
  def handle_response(response)
38
- @success = case response.code.to_i
41
+ @success = case response.status
39
42
  when (200..299)
40
43
  true
41
44
  when 401, 403, 404, 405, 408, 410, 422, 500..599
42
45
  false
43
46
  else
44
- raise TicketSharing::Error.new(%Q{#{response.code} "#{response.message}"\n\n#{response.body}})
47
+ raise TicketSharing::Error.new(%Q{#{response.status}\n\n#{response.body}})
45
48
  end
46
49
  response
47
50
  end
@@ -1,3 +1,4 @@
1
+ require 'ticket_sharing'
1
2
  require 'ticket_sharing/error'
2
3
 
3
4
  module TicketSharing
@@ -6,67 +7,66 @@ module TicketSharing
6
7
 
7
8
  CA_PATH = "/etc/ssl/certs"
8
9
 
9
- def request(method, url, options = {})
10
- request_class = case method
11
- when :get then Net::HTTP::Get
12
- when :post then Net::HTTP::Post
13
- when :put then Net::HTTP::Put
14
- when :delete then Net::HTTP::Delete
15
- else
16
- raise ArgumentError, "Unsupported method: #{method.inspect}"
17
- end
10
+ def initialize(connection = TicketSharing.connection)
11
+ @connection = connection
12
+ end
18
13
 
19
- response = send_request(request_class, url, options)
14
+ def request(method, url, options = {})
15
+ raise ArgumentError, "Unsupported method: #{method.inspect}" unless %i(get post put delete).include?(method)
20
16
 
21
- follow_redirects!(request_class, response, options)
17
+ response = send_request(method, url, options)
18
+ follow_redirects!(method, response, options)
22
19
  end
23
20
 
24
21
  private
25
22
 
26
- def send_request(request_class, url, options)
27
- uri = URI.parse(url)
28
- request = build_request(request_class, uri, options)
29
- send!(request, uri, options)
30
- end
23
+ def send_request(method, url, options)
24
+ response = nil
31
25
 
32
- def build_request(request_class, uri, options)
33
- request = request_class.new(uri.path)
34
- request['Accept'] = 'application/json'
35
- request['Content-Type'] = 'application/json'
36
-
37
- (options[:headers] || {}).each do |k, v|
38
- request[k] = v
26
+ with_ssl_connection(options) do
27
+ response = @connection.send(method) do |request|
28
+ configure_request(request, url, options)
29
+ end
39
30
  end
40
31
 
41
- request.body = options[:body]
42
-
43
- request
32
+ response
44
33
  end
45
34
 
46
- def send!(request, uri, options)
47
- http = Net::HTTP.new(uri.host, uri.port)
35
+ def with_ssl_connection(options)
36
+ ssl_config = {}
37
+ ssl_config[:ca_path] = CA_PATH if File.exist?(CA_PATH)
38
+ ssl_config[:verify] = false if options[:ssl] && options[:ssl][:verify] == false
39
+
40
+ old_configuration = @connection.instance_variable_get(:@ssl)
41
+ @connection.instance_variable_set(:@ssl, ssl_config) unless ssl_config.empty?
42
+ yield
43
+ ensure
44
+ @connection.instance_variable_set(:@ssl, old_configuration)
45
+ end
48
46
 
49
- if uri.scheme == 'https'
50
- http.use_ssl = true
51
- http.ca_path = CA_PATH if File.exist?(CA_PATH)
47
+ def configure_request(request, url, options)
48
+ uri = URI.parse(url)
52
49
 
53
- if options[:ssl] && options[:ssl][:verify] == false
54
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
55
- end
50
+ request.url url
51
+ {
52
+ 'Accept' => 'application/json',
53
+ 'Content-Type' => 'application/json'
54
+ }.merge(options[:headers] || {}).each do |h, v|
55
+ request.headers[h] = v
56
56
  end
57
57
 
58
- http.start { |http| http.request(request) }
58
+ request.body = options[:body]
59
59
  end
60
60
 
61
- def follow_redirects!(request_class, response, options)
61
+ def follow_redirects!(method, response, options)
62
62
  redirects = 0
63
- while (300..399).include?(response.code.to_i)
63
+ while (300..399).include?(response.status)
64
64
  if redirects >= MAX_REDIRECTS
65
65
  raise TicketSharing::TooManyRedirects
66
66
  else
67
67
  redirects += 1
68
68
  end
69
- response = send_request(request_class, response['Location'], options)
69
+ response = send_request(method, response['Location'], options)
70
70
  end
71
71
  response
72
72
  end
@@ -48,21 +48,21 @@ module TicketSharing
48
48
  client = Client.new(url, agreement.authentication_token)
49
49
  @response = client.post(relative_url, self.to_json)
50
50
 
51
- @response.code.to_i
51
+ @response.status
52
52
  end
53
53
 
54
54
  def update_partner(url)
55
55
  client = Client.new(url, agreement.authentication_token)
56
56
  @response = client.put(relative_url, self.to_json)
57
57
 
58
- @response.code.to_i
58
+ @response.status
59
59
  end
60
60
 
61
61
  def unshare(base_url)
62
62
  client = Client.new(base_url, agreement.authentication_token)
63
63
  @response = client.delete(relative_url)
64
64
 
65
- @response.code.to_i
65
+ @response.status
66
66
  end
67
67
 
68
68
  def relative_url
metadata CHANGED
@@ -1,15 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ticket_sharing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Lubaway
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-03 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bump
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
13
83
  description: A ruby implementation of the Networked Help Desk API
14
84
  email: josh@zendesk.com
15
85
  executables: []
@@ -18,6 +88,7 @@ extra_rdoc_files:
18
88
  - Readme.md
19
89
  files:
20
90
  - Readme.md
91
+ - lib/ticket_sharing.rb
21
92
  - lib/ticket_sharing/actor.rb
22
93
  - lib/ticket_sharing/agreement.rb
23
94
  - lib/ticket_sharing/attachment.rb
@@ -43,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
114
  requirements:
44
115
  - - ">="
45
116
  - !ruby/object:Gem::Version
46
- version: '0'
117
+ version: 2.1.0
47
118
  required_rubygems_version: !ruby/object:Gem::Requirement
48
119
  requirements:
49
120
  - - ">="