leaseweb-rest-api 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -0
- data/leaseweb-rest-api.gemspec +1 -1
- data/lib/leaseweb-rest-api.rb +24 -14
- data/readme.md +18 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d2aac5e36fa1ddbeab7ca822846a079aaea17d9
|
4
|
+
data.tar.gz: c2112b2e361ab38d9748b32492a40b2394f3a559
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8890b2ab77228b22a50143188f8734a373dab38f52f2292ac81496abd7574474feea457d73560b107d05401af4b2c415eae837ac67d8c7e9244c6d9d056df23c
|
7
|
+
data.tar.gz: 1ae5426e7ff41dce43d73d4a5bcde4d1c12ed65f4b9876e29413fe719d3ac39ddb881a0a5fc159744ea0dfe32ed2b2024e401015bc1fe7dd48d1f2348e813ebd
|
data/.rubocop.yml
ADDED
data/leaseweb-rest-api.gemspec
CHANGED
data/lib/leaseweb-rest-api.rb
CHANGED
@@ -13,29 +13,39 @@ class LeasewebAPI
|
|
13
13
|
|
14
14
|
base_uri 'https://api.leaseweb.com/v1'
|
15
15
|
|
16
|
-
def
|
17
|
-
@
|
18
|
-
if !apikey.nil?
|
19
|
-
@options = { headers: { 'X-Lsw-Auth' => apikey } }
|
20
|
-
elsif !clientId.nil? && !clientSecret.nil?
|
21
|
-
access_token = getOauthToken(clientId, clientSecret)['access_token']
|
22
|
-
@options = { headers: { 'Authorization' => "Bearer #{access_token}" } }
|
23
|
-
else
|
24
|
-
puts 'Your API credentials are required.'
|
25
|
-
exit
|
26
|
-
end
|
27
|
-
@private_key = OpenSSL::PKey::RSA.new(File.read(privateKey), password) unless privateKey.nil? || password.nil?
|
16
|
+
def apiKeyAuth(apikey)
|
17
|
+
@options = { headers: { 'X-Lsw-Auth' => apikey } }
|
28
18
|
end
|
29
19
|
|
30
20
|
def getOauthToken(clientId, clientSecret)
|
31
|
-
auth
|
32
|
-
|
21
|
+
self.class.post('https://auth.leaseweb.com/token', basic_auth: { username: clientId, password: clientSecret }, body: { grant_type: 'client_credentials' })
|
22
|
+
@options = { headers: { 'Authorization' => "Bearer #{access_token}" } }
|
23
|
+
end
|
24
|
+
|
25
|
+
def readPrivateKey(privateKey, password)
|
26
|
+
@private_key = OpenSSL::PKey::RSA.new(File.read(privateKey), password)
|
33
27
|
end
|
34
28
|
|
35
29
|
def get(url)
|
36
30
|
self.class.get(url, @options)
|
37
31
|
end
|
38
32
|
|
33
|
+
def get_paginated(url, key, offset = 0, limit = 50)
|
34
|
+
data = []
|
35
|
+
|
36
|
+
loop do
|
37
|
+
response = self.class.get(url + "&offset=#{offset}&limit=#{limit}", @options)
|
38
|
+
total = response.parsed_response['_metadata']['totalCount']
|
39
|
+
|
40
|
+
data += response.parsed_response[key]
|
41
|
+
|
42
|
+
offset += limit
|
43
|
+
break unless offset < total
|
44
|
+
end
|
45
|
+
|
46
|
+
data
|
47
|
+
end
|
48
|
+
|
39
49
|
def post(url, body)
|
40
50
|
opt = @options.merge!(body: body)
|
41
51
|
self.class.post(url, opt)
|
data/readme.md
CHANGED
@@ -43,12 +43,28 @@ Start by creating a new instance of the `LeasewebAPI` class, and passing your ap
|
|
43
43
|
api_key = 'e12b534e-3bf6-4208-89e6-e43798b3c30f'
|
44
44
|
privateKeyFile = './id_rsa'
|
45
45
|
password = 'my_super_strong_s3cr3t_passw0rd'
|
46
|
-
|
46
|
+
|
47
|
+
api = LeasewebAPI.new
|
48
|
+
api.apiKeyAuth(api_key)
|
49
|
+
api.readPrivateKey(privateKeyFile, password)
|
50
|
+
```
|
51
|
+
|
52
|
+
or via oAuth:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
client_id = 'sadasdasd.asdasdasd.com'
|
56
|
+
client_secret = 'a844f7c131a7b63e4129cbcf88352034ef11c86481e0cb2ed3653c07345a113b'
|
57
|
+
privateKeyFile = './id_rsa'
|
58
|
+
password = 'my_super_strong_s3cr3t_passw0rd'
|
59
|
+
|
60
|
+
api = LeasewebAPI.new
|
61
|
+
getOauthToken(client_id, client_secret)
|
62
|
+
api.readPrivateKey(privateKeyFile, password)
|
47
63
|
```
|
48
64
|
|
49
65
|
All return values are the direct JSON responses from Leaseweb converted into a Hash.
|
50
66
|
|
51
|
-
See: [documentation](http://developer.leaseweb.com/
|
67
|
+
See: [documentation](http://developer.leaseweb.com/docs/)
|
52
68
|
|
53
69
|
### Managing servers
|
54
70
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaseweb-rest-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnoud Vermeer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -60,6 +60,7 @@ extra_rdoc_files: []
|
|
60
60
|
files:
|
61
61
|
- ".gitignore"
|
62
62
|
- ".rspec"
|
63
|
+
- ".rubocop.yml"
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- leaseweb-rest-api.gemspec
|