Module: Mingle4r::Card::InstanceMethods
- Defined in:
- lib/mingle4r/card.rb
Instance Method Summary collapse
-
#add_comment(comment) ⇒ Object
adds a comment to a card.
-
#at_version(version_no) ⇒ Object
returns back the version of the card given.
- #attachments(refresh = false) ⇒ Object
-
#execute_transition(args_hash) ⇒ Object
TODO - Check if working with https Executes the given transition on the card.
- #upload_attachment(file_path) ⇒ Object
Instance Method Details
#add_comment(comment) ⇒ Object
adds a comment to a card.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mingle4r/card.rb', line 81 def add_comment(comment) comment_uri = URI.parse(File.join(self.class.site.to_s, "cards/add_comment?card_id=#{self.id}")) http = Net::HTTP.new(comment_uri.host, comment_uri.port) http.use_ssl = comment_uri.is_a?(URI::HTTPS) http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl basic_encode = 'Basic ' + ["#{self.class.user}:#{self.class.password}"].pack('m').delete("\r\n") post_headers = { 'Authorization' => basic_encode, 'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' } post_body = "comment=#{comment}&card_id=#{self.id}" http.post(comment_uri.path, post_body, post_headers) end |
#at_version(version_no) ⇒ Object
returns back the version of the card given. If an invalid version is given, the latest version is returned, takes a number or :next or :before
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mingle4r/card.rb', line 67 def at_version(version_no) version_2_find = 0 case version_no when :before version_2_find = self.version.to_i - 1 when :next version_2_find = self.version.to_i + 1 else version_2_find = version_no.to_i end self.class.find(self.number, :params => {:version => version_2_find}) end |
#attachments(refresh = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mingle4r/card.rb', line 24 def (refresh = false) return @attachments if(!refresh && @attachments_cached) = File.join(self.class.site.to_s, "cards/#{self.number()}").to_s Mingle4r::Card::Attachment.site = Mingle4r::Card::Attachment.user = self.class.user Mingle4r::Card::Attachment.password = self.class.password = Mingle4r::Card::Attachment.send(:create_resource_class) @attachments = .find(:all) @attachments_cached = true @attachments end |
#execute_transition(args_hash) ⇒ Object
TODO - Check if working with https Executes the given transition on the card. Example : defect_card.execute_transition(:transition_name => ‘Close Defect’, :Owner => nil, :Status => ‘Closed’, :transition_comment => comment) transition_comment is mandatory if the transition is set that way. after transition ‘Owner’ would have value ‘Not Set’ and ‘Status’ would be ‘Closed’ for defect card
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/mingle4r/card.rb', line 106 def execute_transition(args_hash) project_id = File.basename(self.class.site.to_s) transition_name = args_hash.delete(:transition_name) raise 'Transition name for given' unless transition_name transition_uri = URI.parse(File.join(self.class.site.to_s, 'transition_executions.xml')) # create the form data form_data = { 'transition_execution[transition]' => transition_name, 'transition_execution[card]' => self.number.to_s } comment = args_hash.delete(:transition_comment) form_data['transition_execution[comment]'] = Helpers.encode2html(comment) if comment args_hash.each do |key, value| form_data['transition_execution[properties][][name]'] = Helpers.encode2html(key.to_s) form_data['transition_execution[properties][][value]'] = Helpers.encode2html(value.to_s) end req = Net::HTTP::Post.new(transition_uri.path) req.basic_auth self.class.user, self.class.password req.set_form_data(form_data) Net::HTTP.new(transition_uri.host, transition_uri.port).start { |http| http.request(req) } end |
#upload_attachment(file_path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mingle4r/card.rb', line 36 def (file_path) = URI.parse(File.join(self.class.site.to_s, "cards/#{self.number()}/attachments.xml")) http = Net::HTTP.new(.host, .port) http.use_ssl = .is_a?(URI::HTTPS) http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl basic_encode = 'Basic ' + ["#{self.class.user}:#{self.class.password}"].pack('m').delete("\r\n") post_headers = { 'Authorization' => basic_encode, 'Content-Type' => 'multipart/form-data; boundary=----------XnJLe9ZIbbGUYtzPQJ16u1' } file_content = IO.read(file_path) post_body = <<EOS ------------XnJLe9ZIbbGUYtzPQJ16u1\r Content-Disposition: form-data; name="file"; filename="#{File.basename(file_path)}"\r Content-Type: application/octet-stream\r Content-Length: #{file_content.size}\r \r #{file_content}\r ------------XnJLe9ZIbbGUYtzPQJ16u1--\r EOS http.post(.path, post_body, post_headers) end |