Module: AssayDepot::Model::ClassMethods

Defined in:
lib/assaydepot/model.rb

Instance Method Summary collapse

Instance Method Details

#delete(id: nil, body: nil, params: {}, format: "json") ⇒ Object



127
128
129
130
131
132
# File 'lib/assaydepot/model.rb', line 127

def delete(id: nil, body: nil, params: {}, format: "json")
  puts "DELETE id #{id}, params #{params}" if ENV["DEBUG"] == "true"
  result = Client.new(endpoint: endpoint(id, format)).delete(params: params)
  return JSON.parse(result) if format == "json"
  result
end

#get(id: nil, params: {}, format: "json") ⇒ Object

HTTP request verbs optional “id” followed by optional hash



99
100
101
102
103
104
# File 'lib/assaydepot/model.rb', line 99

def get(id: nil, params: {}, format: "json")
  puts "GET id #{id}, params #{params}" if ENV["DEBUG"] == "true"
  result = Client.new(endpoint: endpoint(id, format)).get(params: params)
  return JSON.parse(result) if format == "json"
  result
end

#get_endpoint(id, endpoint, format = "json") ⇒ Object



92
93
94
95
# File 'lib/assaydepot/model.rb', line 92

def get_endpoint(id, endpoint, format = "json")
  id = id[0] if id && id.kind_of?(Array)
  id ? "#{endpoint}/#{id}.#{format}" : "#{endpoint}.#{format}"
end

#get_token(client_id, client_secret, site) ⇒ Object



87
88
89
90
# File 'lib/assaydepot/model.rb', line 87

def get_token(client_id, client_secret, site)
  response = Client.new.request(AssayDepot::TokenAuth.endpoint(site), {}, {}, {:username => client_id, :password => client_secret})
  response[AssayDepot::TokenAuth.ref_name]
end

#patch(id: nil, body: nil, params: {}, format: "json") ⇒ Object



113
114
115
116
117
118
# File 'lib/assaydepot/model.rb', line 113

def patch(id: nil, body: nil, params: {}, format: "json")
  puts "PATCH id #{id}, body #{body.to_s}, params #{params}" if ENV["DEBUG"] == "true"
  result = Client.new(endpoint: endpoint(id, format)).put( body: body, params: params )
  return JSON.parse(result) if format == "json"
  result
end

#post(id: nil, body: nil, params: {}, format: "json") ⇒ Object



120
121
122
123
124
125
# File 'lib/assaydepot/model.rb', line 120

def post(id: nil, body: nil, params: {}, format: "json")
  puts "POST id #{id}, body #{body.to_s}, params #{params}" if ENV["DEBUG"] == "true"
  result = Client.new(endpoint: endpoint(id, format)).post( body: body, params: params )
  return JSON.parse(result) if format == "json"
  result
end

#put(id: nil, body: nil, params: {}, format: "json") ⇒ Object



106
107
108
109
110
111
# File 'lib/assaydepot/model.rb', line 106

def put(id: nil, body: nil, params: {}, format: "json")
  puts "PUT id #{id}, body #{body.to_s}, params #{params}" if ENV["DEBUG"] == "true"
  result = Client.new(endpoint: endpoint(id, format)).put( body: body, params: params )
  return JSON.parse(result) if format == "json"
  result
end