Class: EDANQuery
- Inherits:
-
Object
- Object
- EDANQuery
- Defined in:
- lib/edan.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#password ⇒ Object
Returns the value of attribute password.
-
#server ⇒ Object
Returns the value of attribute server.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(app_id, username = ENV['EDANUSER'], password = ENV['EDANPASS'], options = {}) ⇒ EDANQuery
constructor
A new instance of EDANQuery.
- #request(params = "start=0", service = "/metadataService") ⇒ Object
- #warn_if_empty(var, var_name) ⇒ Object
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'], = {}) warn_if_empty(app_id, "app_id") @server = [: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_id ⇒ Object
Returns the value of attribute app_id.
8 9 10 |
# File 'lib/edan.rb', line 8 def app_id @app_id end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/edan.rb', line 8 def password @password end |
#server ⇒ Object
Returns the value of attribute server.
8 9 10 |
# File 'lib/edan.rb', line 8 def server @server end |
#username ⇒ Object
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 |