lib/shoppr.rb in shoppr-0.1.1 vs lib/shoppr.rb in shoppr-0.2.3

- old
+ new

@@ -1,50 +1,11 @@ require 'forwardable' require 'rubygems' require 'active_support' - -gem 'roxml' -require 'roxml' - -gem 'mash', '0.0.3' -require 'mash' - -gem 'httparty', '~> 0.4.3' +require 'hashie' require 'httparty' -module HTTParty - module ClassMethods - def parser(customer_parser) - default_options[:parser] = customer_parser - end - end - - class Request - def parse_response(body) - return nil if body.nil? or body.empty? - if options[:parser].blank? - case format - when :xml - Crack::XML.parse(body) - when :json - Crack::JSON.parse(body) - when :yaml - YAML::load(body) - else - body - end - else - if options[:parser].is_a?(Proc) - options[:parser].call(body) - else - body - end - end - end - end -end - module Shoppr def self.api_key @api_key ||= 'authorized-key' end @@ -57,9 +18,21 @@ @tracking_id ||= '7000610' end def self.tracking_id=(value) @tracking_id = value + end + + def self.map_mash_attrs(obj, mash) + attrs = mash.map {|k,v| k.underscore} + + obj.class_eval do + attr_accessor *attrs + end + + mash.each do |k,v| + obj.send("#{k.underscore}=", v) + end end end directory = File.expand_path(File.dirname(__FILE__))