Module: Scalarium::Api

Included in:
Scalarium, Resource
Defined in:
lib/scalarium/api.rb

Defined Under Namespace

Classes: TokenNotFound

Instance Method Summary (collapse)

Instance Method Details

- (Object) get(resource)

Raises:



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/scalarium/api.rb', line 6

def get(resource)
  raise TokenNotFound unless @token
  $stderr.puts "Getting #{resource}" if $DEBUG
  url = "https://manage.scalarium.com/api/#{resource}"
  headers = {
    'X-Scalarium-Token' => @token,
    'Accept' => 'application/vnd.scalarium-v1+json'
  }
  response = RestClient.get(url, headers)
  JSON.parse(response)
end

- (Object) post(resource, data)

Raises:



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/scalarium/api.rb', line 18

def post(resource, data)
  raise TokenNotFound unless @token
  $stderr.puts "Posting #{data.inspect} to #{resource}" if $DEBUG
  url = "https://manage.scalarium.com/api/#{resource}"
  headers = {
    'X-Scalarium-Token' => @token,
    'Accept' => 'application/vnd.scalarium-v1+json'
  }
  response = RestClient.post(url, JSON.dump(data), headers)
  JSON.parse(response)
end