Class: CDD::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cdd/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/cdd/client.rb', line 9

def initialize(token, options={})
  self.token = token
  self.url = options[:url] || "https://app.collaborativedrug.com"
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/cdd/client.rb', line 6

def token
  @token
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/cdd/client.rb', line 7

def url
  @url
end

Instance Method Details

#execute(uri, params = {}) ⇒ Object



24
25
26
27
# File 'lib/cdd/client.rb', line 24

def execute(uri, params={})
  response = RestClient.get "#{self.url}#{uri}", { :params => params, "X-CDD-Token" => token }
  JSON.parse(response.to_s)
end

#vaultsObject



14
15
16
17
18
# File 'lib/cdd/client.rb', line 14

def vaults
  @vaults ||= execute(vaults_url).collect do |hash|
    CDD::Vault.new(self,hash)
  end
end

#vaults_urlObject



20
21
22
# File 'lib/cdd/client.rb', line 20

def vaults_url
  "/api/v1/vaults"
end