Skip to content

Instantly share code, notes, and snippets.

@intinig
Created January 16, 2013 08:54
Show Gist options
  • Select an option

  • Save intinig/4545664 to your computer and use it in GitHub Desktop.

Select an option

Save intinig/4545664 to your computer and use it in GitHub Desktop.
module Prestashop
include HTTParty
base_uri 'www.vinodalproduttore.it'
basic_auth 'SEGRETO!', ''
debug_output STDOUT
format :xml
def self.get_collection(klass)
get("/api/#{klass.pluralize}")["prestashop"]["#{klass.pluralize}"][klass].sort_by {|item| item["id"].to_i}
end
def self.get_item(klass, iid)
get("/api/#{klass.pluralize}/#{iid}")["prestashop"][klass]
end
def self.update_order(order)
ap put("/api/orders/#{order.oid}", :body => {"prestashop" => {"order" => order.raw}})
end
instance_eval do
%w(order order_state product customer address country state language zone).each do |item|
define_singleton_method("#{item.pluralize}") do
get_collection(item)
end
define_singleton_method("#{item}") do |iid|
get_item(item, iid)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment