Class: Genomelink::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/genomelink/base.rb

Overview

The Base class for all of the other class. Let other classes inherit from here and put common methods here.

Author:

  • ashwin

Direct Known Subclasses

Genome, Oauth, Report

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Subclass os Base

A constructor to take a hash and assign it to the instance variables

Parameters:

  • options (defaults to: {})

    {} [Hash] Could by any class’s hash, but the first level keys should be defined in the class



41
42
43
44
45
# File 'lib/genomelink/base.rb', line 41

def initialize(options = {})
  options.each do |attribute, value|
    instance_variable_set("@#{attribute}", value)
  end
end

Class Method Details

.get(path, token) ⇒ Hash

Makes a get request to genomelink for the URL given and with the given token.

TODO : use meta programming and define all Restful methods.

Parameters:

  • path (String)

    the path to hit for the request.

  • token (String)

    the access token to be used.

Returns:

  • (Hash)

    The response Json parsed as a hash.



18
19
20
21
22
23
24
# File 'lib/genomelink/base.rb', line 18

def get(path, token)
  result = service(token).get do |req|
    req.url path
    req.headers['Authorization'] = "BEARER #{token}"
  end
  JSON.parse(result.body)
end