class Rainforest::Client
Constants
- API_END_POINT
- VERSION
Public Class Methods
api_key()
click to toggle source
# File lib/rainforest/client.rb, line 17 def self.api_key @@api_key end
api_key=(api_key)
click to toggle source
# File lib/rainforest/client.rb, line 14 def self.api_key=(api_key) @@api_key = api_key end
new()
click to toggle source
# File lib/rainforest/client.rb, line 21 def initialize end
Public Instance Methods
build_request_uri(resource)
click to toggle source
More information about resource at: app.rainforestqa.com/docs
# File lib/rainforest/client.rb, line 25 def build_request_uri(resource) _resource = resource.split('/')[0] raise ArgumentError, 'resource is invalid' unless ['auth', 'clients', 'runs', 'tests', 'environments', 'pricing_plan'].include? _resource return "#{API_END_POINT}#{resource}" end
request(cmd, payload, method = :post)
click to toggle source
# File lib/rainforest/client.rb, line 31 def request(cmd, payload, method = :post) raise Rainforest::ConfigurationError, "Client token is missing" if @@api_key == nil url = build_request_uri(cmd) payload = payload.to_json if payload.class == Hash if [:get, :post, :put, :delete].include? method case method when :get response = HTTParty.get url, { body: payload, headers: {"CLIENT_TOKEN" => @@api_key, "Content-type" => "application/json"} } when :post response = HTTParty.post url, { body: payload, headers: {"CLIENT_TOKEN" => @@api_key, "Content-type" => "application/json"} } when :put response = HTTParty.put url, { body: payload, headers: {"CLIENT_TOKEN" => @@api_key, "Content-type" => "application/json"} } when :delete response = HTTParty.delete url, { body: payload, headers: {"CLIENT_TOKEN" => @@api_key, "Content-type" => "application/json"} } end body = JSON.parse(response.body) if body.include? 'error' raise body['error'] end return JSON.parse(response.body) end raise ArgumentError, "Invalid Method. We support only: :get, :post, :put, :delete" end