Class: EDANQuery

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id, username = ENV['EDANUSER'], password = ENV['EDANPASS'], options = {}) ⇒ EDANQuery

Returns a new instance of EDANQuery.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/edan.rb', line 14

def initialize(app_id,
                  username = ENV['EDANUSER'],
                  password = ENV['EDANPASS'],
                  options = {})
  warn_if_empty(app_id, "app_id")

  @server = options[:server] || 'http://edan-api.si.edu'
  @app_id = app_id

  @username = username
  warn_if_empty(@username, "username or set ENV['EDANUSER']")

  @password = password
  warn_if_empty(@password, "password or set ENV['EDANPASS']")
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



8
9
10
# File 'lib/edan.rb', line 8

def app_id
  @app_id
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/edan.rb', line 8

def password
  @password
end

#serverObject

Returns the value of attribute server.



8
9
10
# File 'lib/edan.rb', line 8

def server
  @server
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/edan.rb', line 8

def username
  @username
end

Instance Method Details

#request(params = "start=0", service = "/metadataService") ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/edan.rb', line 30

def request(params="start=0", service="/metadataService")
  #puts "==> #{username} #{password}"
  uri = URI.parse(server + service + '?' + params)

  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Get.new(uri.request_uri)
  request.basic_auth(username, password)
  request['X-AppId'] = app_id
  response = http.request(request)
  return response;
end

#warn_if_empty(var, var_name) ⇒ Object



10
11
12
# File 'lib/edan.rb', line 10

def warn_if_empty(var, var_name)
  puts "please provide a value for #{var_name}" if var.nil? || var.empty?
end