semaphore_client 2.0.10 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dee5545a316c91050470b1ae2a36e066bf84a73
4
- data.tar.gz: 01ac342eaa1b563bf483fad1783205afc5d24253
3
+ metadata.gz: 4574baf1d84eef466d70c8e8534ad85994499b91
4
+ data.tar.gz: 5c53fe2792285a994f0e6d9daeae5ae477969590
5
5
  SHA512:
6
- metadata.gz: a25e12cf79b8a1e64cd29192abe3fd28f504309eeb719a4cfda86c980fd04cb613849bf1b414958db8e4581714a3fb0f04bdb779331ee95cf97f0857fbd412d5
7
- data.tar.gz: 0c4d3d9fe3659610bc07e8edb08b51fe916b7912cbbc4d9d416d7524d585aae333c028841e0ed64638d75d136df741079649505f043603d72b3ae0070f6c82c9
6
+ metadata.gz: d0a4ac2aaefacbef936ed0533cc5ce8cad1194912685431a45ca01ab9704cb0237bddd204b55fa9c982fe8e196bb446b5d326894a1f41150fbfd71706803d157
7
+ data.tar.gz: 6786b396fe6a6fd8f106c32e603949c91f9e6039360b604e66a1bfe818b5a430ca954ae45720c4d455417bb4b713ad9cde742b96c0a8423f00726fded5d62d85
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- semaphore_client (2.0.10)
4
+ semaphore_client (2.1.0)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -1,4 +1,6 @@
1
1
  require "json"
2
+ require "securerandom"
3
+ require "faraday"
2
4
 
3
5
  require "semaphore_client/version"
4
6
  require "semaphore_client/exceptions"
@@ -22,10 +24,13 @@ class SemaphoreClient
22
24
  API_URL = "https://api.semaphoreci.com"
23
25
  API_VERSION = "v2"
24
26
 
25
- def initialize(auth_token, api_url = API_URL, api_version = API_VERSION)
27
+ def initialize(auth_token, options = {})
26
28
  @auth_token = auth_token
27
- @api_url = api_url
28
- @api_version = api_version
29
+
30
+ @api_url = options.fetch(:api_url, API_URL)
31
+ @api_version = options.fetch(:api_version, API_VERSION)
32
+ @verbose = options.fetch(:verbose, false)
33
+ @logger = options.fetch(:logger, Logger.new(STDOUT))
29
34
  end
30
35
 
31
36
  def users
@@ -59,6 +64,6 @@ class SemaphoreClient
59
64
  private
60
65
 
61
66
  def http_client
62
- @http_client ||= SemaphoreClient::HttpClient.new(@auth_token, @api_url, @api_version)
67
+ @http_client ||= SemaphoreClient::HttpClient.new(@auth_token, @api_url, @api_version, @verbose, @logger)
63
68
  end
64
69
  end
@@ -1,28 +1,34 @@
1
- require "faraday"
2
-
3
1
  class SemaphoreClient
4
2
  class HttpClient
5
3
  class RouteNotSupported < StandardError; end
6
4
 
7
- def initialize(auth_token, api_url, api_version)
5
+ def initialize(auth_token, api_url, api_version, verbose, logger)
8
6
  @auth_token = auth_token
9
7
  @api_url = api_url
10
8
  @api_version = api_version
9
+ @verbose = verbose
10
+ @logger = logger
11
11
  end
12
12
 
13
13
  def get(route_elements)
14
14
  route = route(route_elements)
15
15
 
16
- connection.get(route)
16
+ trace("GET", route) do
17
+ connection.get(route)
18
+ end
17
19
  end
18
20
 
19
21
  def post(route_elements, content = nil)
20
22
  route = route(route_elements)
21
23
 
22
24
  if content
23
- connection.post(route, content)
25
+ trace("POST", route, content) do
26
+ connection.post(route, content)
27
+ end
24
28
  else
25
- connection.post(route)
29
+ trace("POST", route) do
30
+ connection.post(route)
31
+ end
26
32
  end
27
33
  end
28
34
 
@@ -30,20 +36,43 @@ class SemaphoreClient
30
36
  route = route(route_elements)
31
37
 
32
38
  if content
33
- connection.patch(route, content)
39
+ trace("PATCH", route, content) do
40
+ connection.patch(route, content)
41
+ end
34
42
  else
35
- connection.patch(route)
43
+ trace("PATCH", route) do
44
+ connection.patch(route)
45
+ end
36
46
  end
37
47
  end
38
48
 
39
49
  def delete(route_elements)
40
50
  route = route(route_elements)
41
51
 
42
- connection.delete(route)
52
+ trace("DELETE", route) do
53
+ connection.delete(route)
54
+ end
43
55
  end
44
56
 
45
57
  private
46
58
 
59
+ def trace(method, path, content = nil)
60
+ if @verbose == true
61
+ id = SecureRandom.hex
62
+ started_at = Time.now.to_f
63
+
64
+ @logger.info "#{id} #{method} #{path} body: #{content.inspect}"
65
+ response = yield
66
+
67
+ finished_at = Time.now.to_f
68
+ @logger.info "#{id} #{response.status} duration: #{finished_at - started_at}s body: #{response.body}"
69
+
70
+ response
71
+ else
72
+ yield
73
+ end
74
+ end
75
+
47
76
  def route(route_elements)
48
77
  ["", @api_version, *route_elements].compact.join("/")
49
78
  end
@@ -1,3 +1,3 @@
1
1
  class SemaphoreClient
2
- VERSION = "2.0.10"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semaphore_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jovan Ivanović
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-21 00:00:00.000000000 Z
11
+ date: 2017-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday