Class: Redcap::Uploader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first_name, last_name, password, filename, grid = "main") ⇒ Uploader

Returns a new instance of Uploader.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/redcap/uploader.rb', line 41

def initialize(first_name, last_name, password, filename, grid="main")
  @debug = false
  @log = Logger.new('redcap.log')
  @log.level = Logger::DEBUG    # DEBUG, WARN, 
  @trace = Array.new            # global trace stored here for now
    # ? seperate from log, so it can be glommed to log in one piece
  @trace << [first_name, last_name, filename, grid, Time.now].join("/")
  
  #1: invoke [begin block has rescue at end]
  begin
    #2: login
     = (first_name, last_name, password, GRIDS[grid])
    ["seed_capability"] or raise "seed_capability not found"
    ["inventory-root"] or raise "inventory-root not found"

    #3: request the upload capability
    cap_request = send_request(["seed_capability"],
      %{<llsd><array><string>NewFileAgentInventory</string></array></llsd>})
    cap_request["NewFileAgentInventory"] or raise "no image upload capability found"

    #4: request an upload ticket
    ticket_request = send_request(cap_request["NewFileAgentInventory"],
      encode_ticket(["inventory-root"], filename))
    ticket_request["state"] == "upload" or raise "state not upload"
    ticket_request["uploader"] or raise "no uploader found"

    #5: upload image
    upload_status = send_request(ticket_request["uploader"], make_slimage(filename))
    upload_status["state"] = "complete" or raise "upload failed: #{upload_status["state"]}"

    #7: retrieve the UUID of the newly uploaded image
    @success = true
    @new_asset_id = upload_status["new_asset"]
    # upon success, log the original request and the final result.
    @log.info(@trace[0].to_yaml + @trace[-1].to_yaml)

  rescue
    @success = false
    @msg = "#{$!}"
    @log.fatal @trace.to_yaml     # on failure, log everything
    if @debug
      @msg += "\ntrace: #{@trace[0]}"
    end
  end

end

Instance Attribute Details

#aspect_ratioObject (readonly)

Returns the value of attribute aspect_ratio.



39
40
41
# File 'lib/redcap/uploader.rb', line 39

def aspect_ratio
  @aspect_ratio
end

#msgObject (readonly)

Returns the value of attribute msg.



39
40
41
# File 'lib/redcap/uploader.rb', line 39

def msg
  @msg
end

#new_asset_idObject (readonly)

Returns the value of attribute new_asset_id.



39
40
41
# File 'lib/redcap/uploader.rb', line 39

def new_asset_id
  @new_asset_id
end

#successObject (readonly)

Returns the value of attribute success.



39
40
41
# File 'lib/redcap/uploader.rb', line 39

def success
  @success
end