         } else {
             return message
         }
+    }
+    
+    private func uploadToImgur(imageData: Data) {
+        ImgurManager.shared.delegate = self
+        ImgurManager.shared.clientID = self.imgurAPIClientID! // shouldn't be nil as it validated in presentationAnimationDidFinish.
+        ImgurManager.shared.uploadImage(image: imageData)
+        // NOTE: lator task is processed in ImgurManagerDelegate methods
     }
     
     // MARK: - ReposSelectionTableViewControllerDelegate

        
        let task = session.dataTask(with: request)
        task.resume()
    }
    
    private func getParams(title: String, body: String) -> [String: Any?] {

        
        if let extensionContext = self.extensionContext,
            let item = extensionContext.inputItems.first as? NSExtensionItem,
            let attachments = item.attachments as? [NSItemProvider] {
            let contentType = kUTTypeImage as String
            
            for attachment in attachments {
                if attachment.hasItemConformingToTypeIdentifier(contentType) {
                    attachment.loadItem(forTypeIdentifier: contentType, options: nil) { data, error in
                        guard let data = data else { return }
                        if type(of: data) == UIImage.self {
                            if let image = data as? UIImage, let imageData = UIImageJPEGRepresentation(image, 0.8) {
                                self.uploadToImgur(imageData: imageData)
                            } else {
                                self.showAlert(message: "Failed to fetch Image. Try Later.", completionHandler: nil)
                            }
                        } else if type(of: data) == URL.self {
                            guard let url = data as? URL else { return }
                            do {
                                let imageData = try Data(contentsOf: url)
                                self.uploadToImgur(imageData: imageData)
                            } catch {
                                self.showAlert(message: "Error occured loading image: \(error.localizedDescription)", completionHandler: nil)
                            }
                        } else {
                            self.showAlert(message:"Image not found.", completionHandler: nil)
                        }
                    }
                } else {
                    self.showAlert(message:"Image item not found.", completionHandler: nil)
                }
            }
        } else {
            self.showAlert(message:"Image item extension not found.", completionHandler: nil)
        }
        
    }

    override func configurationItems() -> [Any]! {
