Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added XML Parsing and Loosened MultiJson dependency #20

Closed
wants to merge 2 commits into from
Closed

Added XML Parsing and Loosened MultiJson dependency #20

wants to merge 2 commits into from

Conversation

aaronchi
Copy link

@aaronchi aaronchi commented Jul 9, 2012

No description provided.

@mwunsch
Copy link
Owner

mwunsch commented Aug 1, 2012

Hmm, don't feel like this is as worthwhile as json parsing built-in (since we also do json serialization on the Request), but if you think this is a big deal, can you provide a spec?

Why loosen the multi_json requirement? Are you seeing conflicts?

@aaronchi
Copy link
Author

aaronchi commented Aug 1, 2012

I can put together a spec. I just ran into a case where the api only output XML. For multi_json, yes it was conflicting with other gems since it is not the most recent version. Most other gems I've seen don't add a version requirement which just takes the latest.

@mwunsch
Copy link
Owner

mwunsch commented Sep 14, 2012

I'm going to reject this request, but I think I've provided some additional functionality that will help you with this use case.

I think Weary ought to be very opinionated about the types of Services it is optimized for, and it's starting to be much more rare to see XML in responses. I think that allowing Response#parse to become a switch statement for different formats is a bad idea, since what you're expecting from the response should be really explicit, and anything unexpected should raise a flag. I also don't want to increase Weary's dependencies.

However, I still see value in handing off response parsing to Weary. So in commit 129377e, I added the ability to add a block to Response#parse that accepts the body and content_type, so in your calling code you can do:

my_response.parse do |body, content_type|
  if content_type.match(/(xml)($|;.*)/)[1]
    MultiXml.parse body  
  end
end

This allows the client to do whatever content negotiation it needs to get something meaningful from the response.

I also think it's dangerous to loosen the requirements Weary's dependencies. Stuff will break and it will be unclear to the implementor why it broke.

Thanks for the pull request, and I hope this solution is satisfactory.

@mwunsch mwunsch closed this Sep 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants