lib/hungry.rb in hungry-0.1.0 vs lib/hungry.rb in hungry-0.1.1
- old
+ new
@@ -2,21 +2,22 @@
require 'support/presence'
require 'support/symbolize_keys'
module Hungry
- VERSION = '0.1.0'
+ VERSION = '0.1.1'
class << self
- attr_accessor :api_url, :json_parser, :logger
+ attr_accessor :api_url, :credentials, :json_parser, :logger
end
- self.api_url = 'https://api.eet.nu/'
- self.json_parser = lambda do |json|
- require 'json'
- JSON.parse(json)
- end
+ def self.credentials=(new_credentials = {})
+ @credentials = new_credentials.symbolize_keys
+
+ Resource.basic_auth credentials[:username], credentials[:password]
+ Collection.basic_auth credentials[:username], credentials[:password]
+ end
### LIBRARY:
# Utility:
autoload :Collection, 'hungry/collection'
@@ -44,6 +45,15 @@
# Exception raised when a geolocation is required, but it is not given:
class GeolocationNotGiven < StandardError; end
# Exception raised when an endpoint is not specified for a resource:
class EndpointNotSpecified < StandardError; end
+
+ ### CONFIGURATION:
+
+ self.credentials = { username: nil, password: nil }
+ self.api_url = 'https://api.eet.nu/'
+ self.json_parser = lambda do |json|
+ require 'json'
+ JSON.parse(json)
+ end
end