Marketcircle / jiraSOAP

Ruby interface to the JIRA SOAP API
http://rdoc.info/github/Marketcircle/jiraSOAP/master/frames
MIT License
31 stars 13 forks source link

Attachment adding doesn't work #7

Closed rjharmon closed 13 years ago

rjharmon commented 13 years ago

Any suggestions on how to soapify these string-arrays?

addAttachmentsToIssue

NoMethodError (undefined method `soapify_for' for "attachment.pdf":String):
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/core_extensions.rb:8:in `block in soapify_for'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/core_extensions.rb:8:in `each'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/core_extensions.rb:8:in `soapify_for'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/api.rb:59:in `block (3 levels) in build'
  handsoap (1.1.8) lib/handsoap/xml_mason.rb:22:in `add'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/api.rb:59:in `block (2 levels) in build'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/api.rb:56:in `each'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/api.rb:56:in `block in build'
  handsoap (1.1.8) lib/handsoap/service.rb:240:in `invoke'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/api.rb:55:in `build'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/api.rb:69:in `soap_call'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/api.rb:80:in `jira_call'
  /Users/rharmon/dev/jiraSOAP/lib/jiraSOAP/api/attachments.rb:30:in `add_base64_encoded_attachments_to_issue_with_key'
ferrous26 commented 13 years ago

Oops, looks like a regression that I let in when I refactored to handle arrays. The other two cases use arrays of objects that do respond to #soapify_for.

I can see 3 solutions to the problem.

1) Add String#soapify_for

class String
  def soapify_for msg
    msg.add 'entry', self
  end
end

However, I'm not sure if 'entry' will be acceptable to the JIRA XML parser. If not, then the method will have to take a second optional parameter somehow.

2) Make Array#soapify_for check if an object responds to #soapify_for before sending it, and if not then it just calls add on the msg object.

3) Revert #add_attachments to the jiraSOAP 0.8.6 behaviour of handling the soapifying process itself. :(

I prefer the first solution for run time performance reasons, but other APIs in the future would have to be careful if they contain an array with an object that does not respond to #soapify_for.

In either case, I can't test that this works right now, so could you try it out for me?

rjharmon commented 13 years ago

I copied the code from 0.8.6 and it works fine.

I'd dug into the problem on my own in the meantime, and I was hoping to simply pass an array of Attachment objects (renamed from AttachmentMetadata), and have add_attachments take care of converting that list of attachments to the shape of message needed by JIRA, including base64'ing it - much more rubyish.

The code from 0.8.6 demonstrates pretty clearly how to do that, if it works for you.

WDYT?

rjharmon commented 13 years ago

I got it working and I've made a pull request. We can resume discussion there, I guess.