zammad_api 1.0.3 → 1.0.4

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: 2e95c1c0bc5851fdcca09a21cc6a838f3c2e56e0
4
- data.tar.gz: 345dfba7420253395b72a5873632cf266ddd7bc9
3
+ metadata.gz: e1bb0038ac1d1bc1bbdd053a402cea8ddab59ef1
4
+ data.tar.gz: dbdccff12deaf8eabced103d0ce1e26ef20b450f
5
5
  SHA512:
6
- metadata.gz: 8126945b6c9242ed6dac2c9903eb374cf6c336a8e3bab5a1478fa0728146612a04f6f03635381ec58d7965adbb7e3b6299893c0d45f569c5038afe48a2807043
7
- data.tar.gz: b48b1f4b7a6c135fd972503b03dc153b35af573317d221b2810794819ff0889e9e1d63f57d7b4ff0350d2892f4e8afe58e765083536d0d442700e6819364c790
6
+ metadata.gz: d5d298bb3bfaa5a84e2220bf6c7f061597367089ee63b21ab9db0fc0f37f5112c0d6d1264ecf909fc4b6a4d5ed74f1ede051dab1d67f78ebbb1f022b0a81b15c
7
+ data.tar.gz: c8648dcd6818ef1ded4dcd295174032d75bd8221b517ebda9e5cc58f2064fcd19f4280f7bc34dbd549d39da7911a1d757d9873b74b21104a8d3999ed82ee9011
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  require 'zammad_api/log'
2
4
  require 'zammad_api/transport'
3
5
  require 'zammad_api/dispatcher'
@@ -6,6 +8,9 @@ require 'zammad_api/resources'
6
8
  module ZammadAPI
7
9
 
8
10
  class Client
11
+ extend Forwardable
12
+
13
+ def_delegators :@transport, :on_behalf_of, :on_behalf_of=
9
14
 
10
15
  def initialize(config)
11
16
  @config = config
@@ -14,6 +19,13 @@ module ZammadAPI
14
19
  check_config
15
20
  end
16
21
 
22
+ def perform_on_behalf_of(identifier)
23
+ self.on_behalf_of = identifier
24
+ yield.tap do |_|
25
+ self.on_behalf_of = nil
26
+ end
27
+ end
28
+
17
29
  def method_missing(method, *_args)
18
30
  method = modulize( method.to_s )
19
31
  class_name = "ZammadAPI::Resources::#{method}"
@@ -4,7 +4,7 @@ require 'openssl'
4
4
  module ZammadAPI
5
5
  class Transport
6
6
 
7
- attr_accessor :url, :user, :password
7
+ attr_accessor :url, :user, :password, :on_behalf_of
8
8
 
9
9
  def initialize(config, logger)
10
10
  @logger = logger
@@ -24,42 +24,42 @@ module ZammadAPI
24
24
  end
25
25
  end
26
26
 
27
- def get(param)
28
- @logger.debug "GET: #{@url}#{param[:url]}"
29
- response = @conn.get param[:url]
30
- response
27
+ %w[get post put delete].each do |method|
28
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
29
+ def #{method}(params)
30
+ run_request(:#{method}, params)
31
+ end
32
+ RUBY
31
33
  end
32
34
 
33
- def post(param)
34
- @logger.debug "POST: #{@url}#{param[:url]}"
35
- @logger.debug "Params: #{param[:params].inspect}"
36
- response = @conn.post do |req|
37
- req.url param[:url]
38
- req.headers['Content-Type'] = 'application/json'
39
- req.body = param[:params].to_json
35
+ private
36
+
37
+ def run_request(verb, param)
38
+
39
+ @logger.debug "#{verb.to_s.upcase}: #{@url}#{param[:url]}"
40
+
41
+ with_params = !param[:params].nil?
42
+ if with_params
43
+ @logger.debug "Params: #{param[:params].inspect}"
40
44
  end
41
- @logger.debug "Response: #{response.body}"
42
- response
43
- end
44
45
 
45
- def put(param)
46
- @logger.debug "PUT: #{@url}#{param[:url]}"
47
- @logger.debug "Params: #{param[:params].inspect}"
48
- response = @conn.put do |req|
46
+ response = @conn.public_send(verb) do |req|
49
47
  req.url param[:url]
50
- req.headers['Content-Type'] = 'application/json'
51
- req.body = param[:params].to_json
48
+
49
+ if with_params
50
+ req.headers['Content-Type'] = 'application/json'
51
+ req.body = param[:params].to_json
52
+ end
53
+
54
+ if !on_behalf_of.nil?
55
+ req.headers['X-On-Behalf-Of'] = on_behalf_of
56
+ end
57
+
58
+ yield(req) if block_given?
52
59
  end
53
- @logger.debug "Response: #{response.body}"
54
- response
55
- end
56
60
 
57
- def delete(param)
58
- @logger.debug "DELETE: #{@url}#{param[:url]}"
59
- response = @conn.delete param[:url]
60
61
  @logger.debug "Response: #{response.body}"
61
62
  response
62
63
  end
63
-
64
64
  end
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module ZammadAPI
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.0.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zammad_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Edenhofer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-10 00:00:00.000000000 Z
12
+ date: 2018-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '3.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: webmock
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  description: Ruby wrapper for the Zammad API v1.0.
85
99
  email:
86
100
  - support@zammad.org
@@ -126,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
140
  version: '0'
127
141
  requirements: []
128
142
  rubyforge_project:
129
- rubygems_version: 2.6.8
143
+ rubygems_version: 2.6.13
130
144
  signing_key:
131
145
  specification_version: 4
132
146
  summary: Zammad API v1.0 client.