Module: DomoscioViz

Defined in:
lib/domoscio_viz.rb,
lib/domoscio_viz/json.rb,
lib/domoscio_viz/errors.rb,
lib/domoscio_viz/version.rb,
lib/domoscio_viz/resource.rb,
lib/domoscio_viz/http_calls.rb,
lib/domoscio_viz/chart/chart.rb,
lib/domoscio_viz/authorization_token.rb,
lib/domoscio_viz/generators/install_generator.rb

Defined Under Namespace

Modules: AuthorizationToken, HTTPCalls, JSON Classes: Chart, Configuration, Error, InstallGenerator, ProcessingError, Resource, ResponseError

Constant Summary collapse

VERSION =
"0.2.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



28
29
30
# File 'lib/domoscio_viz.rb', line 28

def configuration
  @configuration
end

Class Method Details

.api_uri(url = '') ⇒ Object



36
37
38
# File 'lib/domoscio_viz.rb', line 36

def self.api_uri(url='')
  URI(configuration.root_url + url)
end

.configure {|configuration| ... } ⇒ Object

Yields:



31
32
33
34
# File 'lib/domoscio_viz.rb', line 31

def self.configure
  self.configuration ||= Configuration.new
  yield configuration
end

.request(method, url, params = {}) ⇒ Object

  • method: HTTP method; lowercase symbol, e.g. :get, :post etc.

  • url: the part after Configuration#root_url

  • params: hash; entity data for creation, update etc.; will dump it by JSON and assign to Net::HTTPRequest#body

Performs HTTP requests to Adaptive Engine On token issues, will try once to get a new token then will output a DomoscioViz::ReponseError with details

Raises DomoscioViz::ResponseError on Adaptive Error Status Raises DomoscioViz::ProcessingError on Internal Error



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/domoscio_viz.rb', line 51

def self.request(method, url, params={})

  store_tokens, headers = request_headers
  params.merge!({'per_page': 2000}) unless params[:per_page]
  uri = api_uri(url)

  response = DomoscioViz.send_request(uri, method, params, headers)
  return response if response.kind_of? DomoscioViz::ProcessingError

  begin
    raise_http_failure(uri, response, params)
    data = DomoscioViz::JSON.load(response.body.nil? ? '' : response.body)
    DomoscioViz::AuthorizationToken::Manager.storage.store({access_token: response['Accesstoken'], refresh_token: response['Refreshtoken']}) if store_tokens
  rescue MultiJson::LoadError => exception
    data = ProcessingError.new(uri, 500, exception, response.body, params)
  rescue ResponseError => exception
    data = exception
  end

  data
end