Class: Redcap::Uploader
- Inherits:
-
Object
- Object
- Redcap::Uploader
- Defined in:
- lib/redcap/uploader.rb
Instance Attribute Summary collapse
-
#aspect_ratio ⇒ Object
readonly
Returns the value of attribute aspect_ratio.
-
#msg ⇒ Object
readonly
Returns the value of attribute msg.
-
#new_asset_id ⇒ Object
readonly
Returns the value of attribute new_asset_id.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
-
#initialize(first_name, last_name, password, filename, grid = "main") ⇒ Uploader
constructor
A new instance of Uploader.
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 login_data = login(first_name, last_name, password, GRIDS[grid]) login_data["seed_capability"] or raise "seed_capability not found" login_data["inventory-root"] or raise "inventory-root not found" #3: request the upload capability cap_request = send_request(login_data["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(login_data["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_ratio ⇒ Object (readonly)
Returns the value of attribute aspect_ratio.
39 40 41 |
# File 'lib/redcap/uploader.rb', line 39 def aspect_ratio @aspect_ratio end |
#msg ⇒ Object (readonly)
Returns the value of attribute msg.
39 40 41 |
# File 'lib/redcap/uploader.rb', line 39 def msg @msg end |
#new_asset_id ⇒ Object (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 |
#success ⇒ Object (readonly)
Returns the value of attribute success.
39 40 41 |
# File 'lib/redcap/uploader.rb', line 39 def success @success end |