maas-client 0.3.0 → 0.3.1

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
  SHA256:
3
- metadata.gz: 471f5ee6442b4722061249e081b46b9ac8e1536ffaa8211d5288b8f924b3b52f
4
- data.tar.gz: 9d8e5af1e3d0150acc0002ee5701f15ab2a49252a3cd27f93ba50e49bb3ab722
3
+ metadata.gz: 0e0af0884af520930a87251571b10143d7a7cfcccda21ef13427027bab7a3cb3
4
+ data.tar.gz: c1eca77a6dc752adbe75474cf70647140b0562f5471ca01067295f6dc44d43ae
5
5
  SHA512:
6
- metadata.gz: 77db95ae809a57ecb501b7e3b6283840c16d3a5ac2cb3e86c95b4d2bb51c9a84497937a45ba7a7405a78726bc01d3450a90bbe638ce600a62327622beeec49f3
7
- data.tar.gz: 007f067feddda6a797bf0475509ce7a01fafd0d03a8244afea9058e19c03fc3d5e6b091a17799be9f8512b8cebab363a2a65e1a23791e83c3f5aa3c5522ed870
6
+ metadata.gz: 98d56e06f44c57e59e40b20c63b559911be99e881af6d23eee500bed37bc0b7aaca32ac26defe6e3f6048fb78104dab96b689bf2a9fe4c8f7f6f93d58ec4e1d0
7
+ data.tar.gz: 98848a20e98a5934473e8a46003a8f55686cf2e39d9ba76b05bba56f669d0bb8dc603f82fe819e2c9b1336c921bf453906fb474bdcfe36925847317faa20febf
data/README.md CHANGED
@@ -6,6 +6,10 @@ This is a simple client library for MAAS, Metal as a Service, written in Ruby.
6
6
 
7
7
  ```ruby
8
8
 
9
+ # https://github.com/typhoeus/typhoeus/issues/390
10
+ # since 0.3.0
11
+ $ sudo apt install libcurl4-openssl-dev
12
+
9
13
  $ bundle
10
14
 
11
15
  # Or install it yourself as:
@@ -27,6 +31,8 @@ con = Maas::Client::MaasClient.new()
27
31
  con = Maas::Client::MaasClient.new("#{CONSUMER_KEY}:#{KEY}:#{SECRET}",
28
32
  "http://#{IP_OR_DOMAIN_NAME}/MAAS/api/2.0")
29
33
 
34
+ # use cases
35
+ con.request(:get, ['maas'], {'op' => 'get_config', 'name' => 'main_archive'})
30
36
 
31
37
  con.request(:get, ['users'])
32
38
 
@@ -50,7 +56,7 @@ con.request(:get, ['ipaddresses'])
50
56
  myarr = []
51
57
  dns_records = con.request(:get, ['dnsresources'])
52
58
  dns_records.each_with_index { |item, index| myarr << item['fqdn'] }
53
- myarr
59
+ pp myarr
54
60
 
55
61
  ```
56
62
  ```bash
@@ -180,12 +186,16 @@ Pushed maas-client x.x.xx to rubygems.org.
180
186
  ** Execute release
181
187
 
182
188
  ```
189
+
183
190
  ## Reference
184
191
  https://docs.maas.io/2.4/en/api-authentication
185
192
  https://github.com/oauth-xx/oauth-ruby
186
193
  https://github.com/typhoeus/typhoeus
187
194
  https://docs.maas.io/2.4/en/api
188
195
 
196
+ ## rubygems
197
+ https://rubygems.org/gems/maas-client
198
+
189
199
  ## License
190
200
 
191
201
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/lib/maas/client.rb CHANGED
@@ -100,15 +100,26 @@ module Maas
100
100
  hydra.queue(req); hydra.run
101
101
  response = req.response
102
102
 
103
- return JSON.parse(response.body) if response.code == 200
104
-
105
- if response.code == 204
103
+ if response.code == 200
104
+ if valid_json?(response.body)
105
+ return JSON.parse(response.body)
106
+ else
107
+ return response.body
108
+ end
109
+ elsif response.code == 204
106
110
  puts 'No Content'
107
111
  else
108
112
  raise "#{response.class} #{response.code} \
109
113
  #{response.status_message} #{response.body}"
110
114
  end
111
115
  end
116
+
117
+ def valid_json?(json)
118
+ JSON.parse(json)
119
+ return true
120
+ rescue JSON::ParserError => e
121
+ return false
122
+ end
112
123
  end
113
124
  end
114
125
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Maas
4
4
  module Client
5
- VERSION = '0.3.0'
5
+ VERSION = '0.3.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maas-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Don Draper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake