0

I'm doing some work with Adcourier. They send me an xml feed with some job data, i.e. job_title, job_description and so on.

I'd like to provide them with a url in my application, i.e. myapp:3000/job/inbox. When they send their feed to that URL, it takes the data and stores it in my database on a Job object that I already created.

  1. What's the best way to structure this? I'm quite new to MVC and i'm not sure where something like this would fit.

  2. How can I get an action to interpret the XML feed from an external source? I use Nokogiri to handle local XMl documents, but never ones from a feed.

I was thinking about using http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-raw_post to handle the post. Doest anyone any thoughts on this?

2
  • If it is a typical feed (e.g. Atom or RSS), then you request it. Feeds don't actually get pushed. Commented Dec 18, 2012 at 23:07
  • As mentioned on the Adcourier page, the feed gets sent or submitted from their end. The data will be sent to the 3rd party interface over a HTTP POST Commented Dec 19, 2012 at 7:44

1 Answer 1

1

In your job controller add a action inbox which gets the correct parameter(s) from the post request and saves them (or whatever you need to do with it).

def inbox
  data = Xml::ParseStuff(params[:data])
  title = data[:title]
  description = data[:description]
  if Job.create(:title => title, :description => description)
    render :string => "Thanks!"
  else
    render :string => "Data was not valid :("
  end
end 

Next set your routes.rb to send posts request for that URL to the correct location

resources :jobs do
  collection do
    post 'inbox'
  end
end

Note I did just made up the xml parse stuff here, just google a bit to find out what would be the best solution/gem for parsing your request.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Vikko, that has certainly helped clarify the structure. And yeah I'm happy to research XML stuff. It seems request.raw_post() will open the data and Nokogiri will let me parse it, so all seems good on that front. Thank you for taking the time to help.
Yeah, you can use data = Nokogiri::XML(request.body.read) for instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.