Class: IAuthU::Site

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

Overview

IAuthU::Site represents your remote ITunesU site.

site = IAuthU::Site.build {
  url "https://deimos.apple.com/WebObjects/Core.woa/Browse/montana.edu"
  debug_suffix "/aqc392"
  shared_secret "WQBMFYFFH7SBPVFXMCEBG43WC2ANW7LQ"
  cred :admin, "Administrator\@urn:mace:itunesu.com:sites:montana.edu"
  cred :user, "Authenticated\@urn:mace:itunesu.com:sites:montana.edu"
}

Defined Under Namespace

Classes: Builder, SettingsError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Site

Returns a new instance of Site.



23
24
25
26
27
# File 'lib/iauthu/site.rb', line 23

def initialize(opts={})
  @debug = false
  opts = {:url => "", :debug_suffix => "", :shared_secret => "", :credentials => {}}.merge(opts)
  opts.keys.each{|var| instance_variable_set "@#{var.to_s}", opts[var]}
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



28
29
30
# File 'lib/iauthu/site.rb', line 28

def credentials
  @credentials
end

#debugObject

Returns the value of attribute debug.



28
29
30
# File 'lib/iauthu/site.rb', line 28

def debug
  @debug
end

#debug_suffixObject

Returns the value of attribute debug_suffix.



28
29
30
# File 'lib/iauthu/site.rb', line 28

def debug_suffix
  @debug_suffix
end

#shared_secretObject

Returns the value of attribute shared_secret.



28
29
30
# File 'lib/iauthu/site.rb', line 28

def shared_secret
  @shared_secret
end

#urlObject

Returns the value of attribute url.



28
29
30
# File 'lib/iauthu/site.rb', line 28

def url
  @url
end

Class Method Details

.build(&block) ⇒ Object



17
18
19
20
21
# File 'lib/iauthu/site.rb', line 17

def self.build(&block)
  builder = Builder.new
  builder.instance_eval(&block)
  builder.site
end

Instance Method Details

#authentication_request(user) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/iauthu/site.rb', line 34

def authentication_request(user)
  raise SettingsError, "Site url must be set before sending request." unless url && !url.empty?
  user = user.clone
  creds = user.delete("credentials") || []
  tmp = []
  creds.each{|c| tmp << credentials[c]}
  
  begin
    req = Request.new(user, tmp, self)
  rescue Request::MissingCredentialsError
    raise MissingCredentialsError, "Credentials entry is missing in: #{user.inspect}"
  end
  req.debug = debug
  req
end

#loggerObject



30
31
32
# File 'lib/iauthu/site.rb', line 30

def logger
  CONFIG[:logger]
end