vscale-api 0.2.46 → 0.2.47

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: 55a759f760acb59de98213ddd7055077549dba0e
4
- data.tar.gz: bc740e8e471c5388b910deb7653cc65824f53c59
3
+ metadata.gz: 9ac876acdea7222da72661d422f9305e3b8226a3
4
+ data.tar.gz: 555e9cf0095d7a126c7d2dd63938a22f8c0fb511
5
5
  SHA512:
6
- metadata.gz: b38bfbd7ff70d9547f44b6f249013c3798ce6ed7c381bea5a4d40612bf6ad35f438fd2cb90c67bd1e27759146d463fb4b40879eb9d3c2d0c28a820557644eca3
7
- data.tar.gz: 75b8771f65ed1f374902ebf3d7cc325cf9b01137dac5df7c1130bb38692de6bc16e2dc1a7cfd535a15abe7855b72213b24213efa4c5e2fed72671f639070e3e6
6
+ metadata.gz: b80fcefe8bcdc4b3d150cfeb412d11f48515de0273f5b3311eec19f265e2cd3cc9724622f4636ca8b38ccab42defc595eba6eea437fc4f828e5e46739b8e6bf5
7
+ data.tar.gz: a091c6e04ca8a0971fbfec310618ab86ab80bcd8248f519edacd457d904b82e28b35880ac371605fb459beecfcd38fa6a7444441f4bf7df37eadc1ea80b6cad1
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ### VScale API v1 (WIP)
2
2
 
3
- [![Coverage Status](https://coveralls.io/repos/Smolget/vscale-api/badge.svg?branch=master&service=github)](https://coveralls.io/github/Smolget/vscale-api?branch=master)
3
+ [![Coverage Status](https://coveralls.io/repos/github/Smolget/vscale-api/badge.svg?branch=feature%2Fcoveralls)](https://coveralls.io/github/Smolget/vscale-api?branch=feature%2Fcoveralls)
4
4
  [![Build Status](https://travis-ci.org/Smolget/vscale-api.svg?branch=master)](https://travis-ci.org/Smolget/vscale-api)
5
5
  [![Gem Version](https://badge.fury.io/rb/vscale-api.svg)](https://badge.fury.io/rb/vscale-api)
6
6
  ![](http://ruby-gem-downloads-badge.herokuapp.com/vscale-api?type=total)
@@ -1,6 +1,5 @@
1
1
  require 'net/http'
2
2
  require 'openssl'
3
- require 'ostruct'
4
3
  require 'json'
5
4
  require 'uri'
6
5
 
@@ -34,11 +33,10 @@ module Vscale
34
33
  include Servers
35
34
  include SSHKeys
36
35
 
37
- def initialize(token, api_endpoint = API_ENDPOINT)
36
+ def initialize(token)
38
37
  @token = token
39
- @api_endpoint = api_endpoint
40
38
 
41
- uri = URI.parse(@api_endpoint)
39
+ uri = URI.parse(API_ENDPOINT)
42
40
 
43
41
  # TODO: rescue StandardError
44
42
  @http = Net::HTTP.start(uri.host, uri.port, use_ssl: true)
@@ -50,27 +48,35 @@ module Vscale
50
48
 
51
49
  def request_json(meth, path, params = {})
52
50
  response = request(meth, path, params)
53
- body = JSON.parse(response.body)
54
- OpenStruct.new(code: response.code, body: body)
55
- rescue JSON::ParserError
56
- response # TODO: convert to Hash
51
+
52
+ result = Struct.new(:code, :body)
53
+
54
+ if response.body.nil? || response.body.empty?
55
+ result.new(nil, nil)
56
+ else
57
+ json_body = JSON.parse(response.body, quirks_mode: true) # TODO: TypeError if nil
58
+ result.new(response.code, json_body)
59
+ end
57
60
  end
58
61
 
59
62
  def request(meth, path, params = {})
60
- full_path = encode_path_params(@api_endpoint + path, params)
63
+ full_path = encode_path_params([API_ENDPOINT, path].join, params)
64
+
61
65
  request = VERB_MAP[meth.to_sym].new(full_path)
66
+
62
67
  request['Accept'] = 'application/json, text/plain'
63
68
  request['Content-Type'] = 'application/json'
64
69
  request['X-Token'] = @token
65
70
 
66
- request.set_form_data(params) if ['post', 'put', 'patch'].include?(meth)
67
-
71
+ if ['post', 'put', 'patch'].include?(meth.to_s)
72
+ request.body = params.to_json
73
+ return @http.request(request)
74
+ end
68
75
  @http.request(request)
69
76
  end
70
77
 
71
78
  def encode_path_params(path, params)
72
- encoded = URI.encode_www_form(params)
73
- [path, encoded].join('?')
79
+ [path, URI.encode_www_form(params)].join('?')
74
80
  end
75
81
  end
76
82
  end
@@ -1,5 +1,13 @@
1
1
  module Vscale
2
2
  module Backups
3
+ def create_backup(scalet_id, params)
4
+ post("#{scalet_id}/backup", params)
5
+ end
6
+
7
+ def create_from_backup(scalet_id, params)
8
+ patch("scalets/#{scalet_id}/rebuild", params)
9
+ end
10
+
3
11
  def backups
4
12
  get('backups')
5
13
  end
@@ -1,5 +1,5 @@
1
1
  module Vscale
2
2
  module Api
3
- VERSION = '0.2.46' # TODO: {APIversion}.10
3
+ VERSION = '0.2.47' # TODO: {APIversion}.10
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vscale-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.46
4
+ version: 0.2.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya V
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-24 00:00:00.000000000 Z
11
+ date: 2016-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".coveralls.yml"
76
77
  - ".gitignore"
77
78
  - ".rubocop.yml"
78
79
  - ".travis.yml"