maestrano 1.0.0.pre.RC7 → 1.0.0.pre.RC8

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: 82ec4814d881186a1f8890716dc77deffdc71508
4
- data.tar.gz: 5ee9ca302567a4fe51d41a9da379aa203279017e
3
+ metadata.gz: 7b5c99f99b33b4e0b1710ba6b6740e867b07c9ea
4
+ data.tar.gz: 89304bfc67cd1aba77ea6166a4238dc47f552315
5
5
  SHA512:
6
- metadata.gz: 853f8b39ff3255416247d6019ab51330cb0398283c9b0c63d44af929870a57498f5fd8629c5e6bd7e15a0f36266b92d8edf503a7b24d0a5be846fbfc8f8498c1
7
- data.tar.gz: 979bc66f886591f07de3ceb00b60b0ba178b3543efe4d5bf14204c8d03a0b63f45936065cffebdf1bfd875e2fcf17aab96b551947326ed91e6e5c840a2f80bb2
6
+ metadata.gz: 8aaf21f203c3821fa5a75f9239e36c4a6276d0fb411d72c8cd4706400be90c9b5e986d02345c69a7a38746e15db65c57899add7f1feefae33485c16798e06ecf
7
+ data.tar.gz: 4cf28b46269b9dfe5b5198ce0f49b01a674b652ad75f2999c92a76263dd767b8089d4d3b75d6c02e8b03b9518a181342d11aaacf93db1fae5a5227b9c3b342ad
@@ -8,59 +8,97 @@ module Maestrano
8
8
  headers 'Accept' => 'application/vnd.api+json'
9
9
  headers 'Content-Type' => 'application/vnd.api+json'
10
10
  format :json
11
-
11
+
12
12
  attr_reader :group_id
13
-
13
+
14
14
  def initialize(group_id)
15
15
  @group_id = group_id
16
+ @debug = !!ENV['DEBUG_CONNEC']
17
+
16
18
  self.class.base_uri("#{Maestrano[self.class.preset].param('connec.host')}#{Maestrano[self.class.preset].param('connec.base_path')}")
17
19
  end
18
-
20
+
19
21
  # Return the default options which includes
20
22
  # maestrano authentication
21
23
  def default_options
22
24
  {
23
- basic_auth: {
24
- username: Maestrano[self.class.preset].param('api.id'),
25
+ basic_auth: {
26
+ username: Maestrano[self.class.preset].param('api.id'),
25
27
  password: Maestrano[self.class.preset].param('api.key')
26
28
  },
27
29
  timeout: Maestrano[self.class.preset].param('connec.timeout')
28
30
  }
29
31
  end
30
-
32
+
31
33
  # Return the right path scoped using the customer
32
34
  # group id
33
35
  def scoped_path(relative_path)
34
36
  clean_path = relative_path.gsub(/^\/+/, "").gsub(/\/+$/, "")
35
37
  "/#{@group_id}/#{clean_path}"
36
38
  end
37
-
39
+
38
40
  # E.g: client.get('/organizations')
39
41
  # E.g: client.get('/organizations/123')
40
42
  def get(relative_path, options = {})
41
- self.class.get(self.scoped_path(relative_path),default_options.merge(options))
43
+ url = self.scoped_path(relative_path)
44
+ response = self.class.get(url, default_options.merge(options))
45
+
46
+ save_request_response(:get, url, nil, response) if @debug
47
+
48
+ response
42
49
  end
43
-
50
+
44
51
  # E.g: client.post('/organizations', { organizations: { name: 'DoeCorp Inc.' } })
45
52
  def post(relative_path, body, options = {})
46
- self.class.post(self.scoped_path(relative_path),
47
- default_options.merge(body: body.to_json).merge(options)
48
- )
53
+ url = self.scoped_path(relative_path)
54
+ response = self.class.post(url, default_options.merge(body: body.to_json).merge(options))
55
+
56
+ save_request_response(:post, url, body.to_json, response) if @debug
57
+
58
+ response
49
59
  end
50
-
51
- # E.g for collection:
60
+
61
+ # E.g for collection:
52
62
  # => client.put('/organizations/123', { organizations: { name: 'DoeCorp Inc.' } })
53
- # E.g for singular resource:
63
+ # E.g for singular resource:
54
64
  # => client.put('/company', { company: { name: 'DoeCorp Inc.' } })
55
65
  def put(relative_path, body, options = {})
56
- self.class.put(self.scoped_path(relative_path),
57
- default_options.merge(body: body.to_json).merge(options)
58
- )
66
+ url = self.scoped_path(relative_path)
67
+ response = self.class.put(url, default_options.merge(body: body.to_json).merge(options))
68
+
69
+ save_request_response(:put, url, body.to_json, response) if @debug
70
+
71
+ response
59
72
  end
60
73
 
61
74
  def batch(body, options = {})
62
- self.class.post("#{Maestrano[self.class.preset].param('connec.host')}/batch", default_options.merge(body: body.to_json).merge(options))
75
+ url = "#{Maestrano[self.class.preset].param('connec.host')}/batch"
76
+ response = self.class.post(url, default_options.merge(body: body.to_json).merge(options))
77
+
78
+ save_request_response(:post, '/batch', body.to_json, response) if @debug
79
+
80
+ response
81
+ end
82
+
83
+ # Save request/response files
84
+ # * GET
85
+ # request: /tmp/connec/get/cld-123/organizations/XYZ/request
86
+ # response: /tmp/connec/get/cld-123/organizations/XYZ/response
87
+ # * POST
88
+ # request: /tmp/connec/post/cld-123/organizations/XYZ/request
89
+ # response: /tmp/connec/post/cld-123/organizations/XYZ/response
90
+ # * PUT
91
+ # request: /tmp/connec/put/cld-123/organizations/XYZ/request
92
+ # response: /tmp/connec/put/cld-123/organizations/XYZ/response
93
+ def save_request_response(action, url, request_body, response)
94
+ # Path to store files
95
+ file_path = "#{Dir.tmpdir}/connec/#{action}#{url}/#{SecureRandom.hex}"
96
+ FileUtils.mkdir_p(file_path)
97
+
98
+ # Save request and response
99
+ File.open("#{file_path}/request", 'w') { |file| file.write(request_body) }
100
+ File.open("#{file_path}/response", 'w') { |file| file.write(response.body) }
63
101
  end
64
102
  end
65
103
  end
66
- end
104
+ end
@@ -1,3 +1,3 @@
1
1
  module Maestrano
2
- VERSION = '1.0.0.pre.RC7'
2
+ VERSION = '1.0.0.pre.RC8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maestrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.RC7
4
+ version: 1.0.0.pre.RC8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Lachaume
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client