Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Use ActiveResource with non-Rails REST API
class Accommodation < ActiveResource::Base
class << self
def element_path(id, prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
end
def collection_path(prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
end
def instantiate_collection(collection, prefix_options = {})
super collection['accommodations'], prefix_options
end
end
self.site = "http://api.accommmodations.com/"
def persisted?
false
end
end
{
totalNumberOfResults: 818,
accommodations: [
{
id: "bulgarije-burgas-sunny_beach-best_hotel_ever",
name: "Best Hotel Ever",
city: {
code: "sunny_beach",
name: "Sunny Beach"
},
region: {
code: "burgas",
name: "Burgas"
},
country: {
code: "bulgarije",
name: "Bulgarije"
}
},
{
id: "bulgarije-burgas-sunny_beach-hotel_awesome",
name: "Hotel Awesome",
city: {
code: "sunny_beach",
name: "Sunny Beach"
},
region: {
code: "burgas",
name: "Burgas"
},
country: {
code: "bulgarije",
name: "Bulgarije"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment