Created
January 16, 2013 08:54
-
-
Save intinig/4545664 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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