lib/fir.rb in fir-cli-1.0.8 vs lib/fir.rb in fir-cli-1.1.0
- old
+ new
@@ -52,35 +52,53 @@
@token ||= config[:token] if config
end
def get url, params = {}
begin
- res = RestClient.get(url, params: params)
- rescue RestClient::Exception => e
- logger.error e.response
+ res = RestClient.get(url, default_headers.merge(params: params))
+ rescue => e
+ logger.error "#{e.class}\n#{e.message}"
exit 1
end
+
JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
end
- def post url, query, content_type = :json
+ def post url, query
begin
- res = RestClient.post(url, query, { content_type: content_type })
- rescue RestClient::Exception => e
- logger.error e.response
+ res = RestClient.post(url, query, default_headers)
+ rescue => e
+ logger.error "#{e.class}\n#{e.message}"
exit 1
end
+
JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
end
- def put url, query, content_type = :json
+ def patch url, query
begin
- res = RestClient.put(url, query, { content_type: content_type })
- rescue RestClient::Exception => e
- logger.error e.response
+ res = RestClient.patch(url, query, default_headers)
+ rescue => e
+ logger.error "#{e.class}\n#{e.message}"
exit 1
end
+
JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
+ end
+
+ def put url, query
+ begin
+ res = RestClient.put(url, query, default_headers)
+ rescue => e
+ logger.error "#{e.class}\n#{e.message}"
+ exit 1
+ end
+
+ JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
+ end
+
+ def default_headers
+ { content_type: :json, source: 'fir-cli', cli_version: FIR::VERSION }
end
alias_method :☠, :exit
end
end