magenthor 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/magenthor/base.rb +85 -65
 - data/lib/magenthor/customer.rb +163 -140
 - data/lib/magenthor/version.rb +2 -1
 - data/lib/magenthor.rb +2 -1
 - data/magenthor.gemspec +1 -1
 - metadata +13 -12
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 589ee0fefcf3a0e84a42551a7f393caa738b58c9
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7b70817c5a5eb059cd3067aaf2343df5c9654f25
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 76c4abc74187ed91ca5ad96e077bfbe18dafbe603f05f4f08de557d2d42680fb3ebdcb344e0014a0f3a97bbc0ba743f0db2aff68415cb5a474238fad9526b908
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2dabff7cbd1b452341a270e07763ede344819543ab7633531eb81fd27cf0bca0850c5988fc308c93ae13078e4aa9ea54e2c4e6d830169d6a41f152c6c449c382
         
     | 
    
        data/lib/magenthor/base.rb
    CHANGED
    
    | 
         @@ -1,65 +1,85 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
                    @@ 
     | 
| 
       6 
     | 
    
         
            -
                    @@ 
     | 
| 
       7 
     | 
    
         
            -
                    
         
     | 
| 
       8 
     | 
    
         
            -
                     
     | 
| 
       9 
     | 
    
         
            -
                     
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                        
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                     
     | 
| 
       38 
     | 
    
         
            -
                    
         
     | 
| 
       39 
     | 
    
         
            -
                    # 
     | 
| 
       40 
     | 
    
         
            -
                     
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                        
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                     
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # @author Daniele Lenares
         
     | 
| 
      
 2 
     | 
    
         
            +
            module Magenthor
         
     | 
| 
      
 3 
     | 
    
         
            +
                class Base
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                    @@client = nil
         
     | 
| 
      
 6 
     | 
    
         
            +
                    @@session_id = nil
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @@api_user = nil
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @@api_key = nil
         
     | 
| 
      
 9 
     | 
    
         
            +
                    
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                    # Initialize the constants that will be used to make the connection to Magento
         
     | 
| 
      
 12 
     | 
    
         
            +
                    #
         
     | 
| 
      
 13 
     | 
    
         
            +
                    # @param params [Hash] contains the paramters needed for connection
         
     | 
| 
      
 14 
     | 
    
         
            +
                    # @return [Magenthor::Base]
         
     | 
| 
      
 15 
     | 
    
         
            +
                    def self.setup params
         
     | 
| 
      
 16 
     | 
    
         
            +
                        if params.class != Hash
         
     | 
| 
      
 17 
     | 
    
         
            +
                            puts "Parameters must be in an Hash."
         
     | 
| 
      
 18 
     | 
    
         
            +
                            return false
         
     | 
| 
      
 19 
     | 
    
         
            +
                        end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                        if !params.key? :host or !params.key? :api_user or !params.key? :api_key
         
     | 
| 
      
 22 
     | 
    
         
            +
                            puts "Mandatory parameter missing. Check if :host, :api_user and :api_key are there."
         
     | 
| 
      
 23 
     | 
    
         
            +
                            return false
         
     | 
| 
      
 24 
     | 
    
         
            +
                        end
         
     | 
| 
      
 25 
     | 
    
         
            +
                
         
     | 
| 
      
 26 
     | 
    
         
            +
                        @@api_user = params[:api_user]
         
     | 
| 
      
 27 
     | 
    
         
            +
                        @@api_key = params[:api_key]
         
     | 
| 
      
 28 
     | 
    
         
            +
                        url = "http://#{params[:host]}:#{params[:port]}/api/xmlrpc"
         
     | 
| 
      
 29 
     | 
    
         
            +
                        
         
     | 
| 
      
 30 
     | 
    
         
            +
                        @@client = XMLRPC::Client.new2(url)
         
     | 
| 
      
 31 
     | 
    
         
            +
                        @@client.http_header_extra = { "accept-encoding" => "identity" }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                        return true
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
                    
         
     | 
| 
      
 36 
     | 
    
         
            +
                    private
         
     | 
| 
      
 37 
     | 
    
         
            +
                    
         
     | 
| 
      
 38 
     | 
    
         
            +
                    # Login to Magento using the parameters setted on #initialize
         
     | 
| 
      
 39 
     | 
    
         
            +
                    #
         
     | 
| 
      
 40 
     | 
    
         
            +
                    # @return [TrueClass, FalseClass] true if login successful or false
         
     | 
| 
      
 41 
     | 
    
         
            +
                    def self.login
         
     | 
| 
      
 42 
     | 
    
         
            +
                        begin
         
     | 
| 
      
 43 
     | 
    
         
            +
                            @@session_id = @@client.call('login', @@api_user, @@api_key)
         
     | 
| 
      
 44 
     | 
    
         
            +
                            return true
         
     | 
| 
      
 45 
     | 
    
         
            +
                        rescue => e
         
     | 
| 
      
 46 
     | 
    
         
            +
                            if e.class == NoMethodError
         
     | 
| 
      
 47 
     | 
    
         
            +
                                puts 'You must first set the connection parameters using Magenthor::Base.setup'
         
     | 
| 
      
 48 
     | 
    
         
            +
                                return false
         
     | 
| 
      
 49 
     | 
    
         
            +
                            end
         
     | 
| 
      
 50 
     | 
    
         
            +
                        end
         
     | 
| 
      
 51 
     | 
    
         
            +
                    end
         
     | 
| 
      
 52 
     | 
    
         
            +
                    
         
     | 
| 
      
 53 
     | 
    
         
            +
                    # End the current Magento api session
         
     | 
| 
      
 54 
     | 
    
         
            +
                    def self.logout
         
     | 
| 
      
 55 
     | 
    
         
            +
                        response = @@client.call('endSession', @@session_id)
         
     | 
| 
      
 56 
     | 
    
         
            +
                        @@session_id = nil
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
                    
         
     | 
| 
      
 59 
     | 
    
         
            +
                    # Call the Magento Api resource passing parameters
         
     | 
| 
      
 60 
     | 
    
         
            +
                    #
         
     | 
| 
      
 61 
     | 
    
         
            +
                    # @param resource_path [String] the Magento Api resource path to call
         
     | 
| 
      
 62 
     | 
    
         
            +
                    # @param params [Hash, Array] the paramters needed for the call
         
     | 
| 
      
 63 
     | 
    
         
            +
                    # @return [Array, FalseClass] the result set if the call is successful or false
         
     | 
| 
      
 64 
     | 
    
         
            +
                    def self.commit resource_path, params
         
     | 
| 
      
 65 
     | 
    
         
            +
                        if params.class == Hash
         
     | 
| 
      
 66 
     | 
    
         
            +
                            params = [params]   # Magento wants an Array, always!
         
     | 
| 
      
 67 
     | 
    
         
            +
                        end
         
     | 
| 
      
 68 
     | 
    
         
            +
                        
         
     | 
| 
      
 69 
     | 
    
         
            +
                        if login
         
     | 
| 
      
 70 
     | 
    
         
            +
                            begin
         
     | 
| 
      
 71 
     | 
    
         
            +
                                @@client.call('call', @@session_id, resource_path, params)
         
     | 
| 
      
 72 
     | 
    
         
            +
                            rescue => e
         
     | 
| 
      
 73 
     | 
    
         
            +
                                if e.class == XMLRPC::FaultException
         
     | 
| 
      
 74 
     | 
    
         
            +
                                    puts "Magento says: #{e.message}"
         
     | 
| 
      
 75 
     | 
    
         
            +
                                end
         
     | 
| 
      
 76 
     | 
    
         
            +
                                return false
         
     | 
| 
      
 77 
     | 
    
         
            +
                            ensure
         
     | 
| 
      
 78 
     | 
    
         
            +
                                logout
         
     | 
| 
      
 79 
     | 
    
         
            +
                            end
         
     | 
| 
      
 80 
     | 
    
         
            +
                        else
         
     | 
| 
      
 81 
     | 
    
         
            +
                            return false
         
     | 
| 
      
 82 
     | 
    
         
            +
                        end
         
     | 
| 
      
 83 
     | 
    
         
            +
                    end
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/magenthor/customer.rb
    CHANGED
    
    | 
         @@ -1,143 +1,166 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
                     
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                                : 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                    
         
     | 
| 
       9 
     | 
    
         
            -
                     
     | 
| 
       10 
     | 
    
         
            -
                     
     | 
| 
       11 
     | 
    
         
            -
                    
         
     | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
       13 
     | 
    
         
            -
                    
         
     | 
| 
       14 
     | 
    
         
            -
                     
     | 
| 
       15 
     | 
    
         
            -
                    #Initialize a new  
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
      
 1 
     | 
    
         
            +
            # @author Daniele Lenares
         
     | 
| 
      
 2 
     | 
    
         
            +
            module Magenthor
         
     | 
| 
      
 3 
     | 
    
         
            +
                class Customer < Base
         
     | 
| 
      
 4 
     | 
    
         
            +
                    
         
     | 
| 
      
 5 
     | 
    
         
            +
                    attr_accessor :firstname, :lastname, :middlename, :increment_id, :store_id, 
         
     | 
| 
      
 6 
     | 
    
         
            +
                                :website_id, :created_in, :email, :group_id, :prefix, :suffix, :dob,
         
     | 
| 
      
 7 
     | 
    
         
            +
                                :taxvat, :confirmation, :gender, :password
         
     | 
| 
      
 8 
     | 
    
         
            +
                    attr_reader :customer_id, :increment_id, :created_at, :updated_at, :password_hash
         
     | 
| 
      
 9 
     | 
    
         
            +
                    
         
     | 
| 
      
 10 
     | 
    
         
            +
                    private
         
     | 
| 
      
 11 
     | 
    
         
            +
                    attr_writer :customer_id, :increment_id, :created_at, :updated_at, :password_hash
         
     | 
| 
      
 12 
     | 
    
         
            +
                    
         
     | 
| 
      
 13 
     | 
    
         
            +
                    public
         
     | 
| 
      
 14 
     | 
    
         
            +
                    
         
     | 
| 
      
 15 
     | 
    
         
            +
                    # Initialize a new Customer entity
         
     | 
| 
      
 16 
     | 
    
         
            +
                    #
         
     | 
| 
      
 17 
     | 
    
         
            +
                    # @param params [Hash] the to save in the instance on initialization
         
     | 
| 
      
 18 
     | 
    
         
            +
                    # @return [Magenthor::Customer] a new instance of Customer
         
     | 
| 
      
 19 
     | 
    
         
            +
                    def initialize params = {}
         
     | 
| 
       17 
20 
     | 
    
         
             
                        methods.grep(/\w=$/).each do |m|
         
     | 
| 
       18 
21 
     | 
    
         
             
                            send(m, nil)
         
     | 
| 
       19 
22 
     | 
    
         
             
                        end
         
     | 
| 
       20 
     | 
    
         
            -
                        params.each do |k, v|
         
     | 
| 
       21 
     | 
    
         
            -
                            send("#{k}=", v) if respond_to? "#{k}="
         
     | 
| 
       22 
     | 
    
         
            -
                        end
         
     | 
| 
       23 
     | 
    
         
            -
                        self.customer_id = params["customer_id"]
         
     | 
| 
       24 
     | 
    
         
            -
                        self.increment_id = params["increment_id"]
         
     | 
| 
       25 
     | 
    
         
            -
                        self.created_at = params["created_at"]
         
     | 
| 
       26 
     | 
    
         
            -
                        self.updated_at = params["updated_at"]
         
     | 
| 
       27 
     | 
    
         
            -
                        self.password_hash = params["password_hash"]
         
     | 
| 
       28 
     | 
    
         
            -
                        
         
     | 
| 
       29 
     | 
    
         
            -
                    end
         
     | 
| 
       30 
     | 
    
         
            -
                    
         
     | 
| 
       31 
     | 
    
         
            -
                    # 
     | 
| 
       32 
     | 
    
         
            -
                    # 
     | 
| 
       33 
     | 
    
         
            -
                     
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                    #Create  
     | 
| 
       43 
     | 
    
         
            -
                     
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                         
     | 
| 
       57 
     | 
    
         
            -
                        self. 
     | 
| 
       58 
     | 
    
         
            -
                        self. 
     | 
| 
       59 
     | 
    
         
            -
                        self. 
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                     
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                     
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                         
     | 
| 
       76 
     | 
    
         
            -
                        self. 
     | 
| 
       77 
     | 
    
         
            -
                        self. 
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                             
     | 
| 
       98 
     | 
    
         
            -
                             
     | 
| 
       99 
     | 
    
         
            -
                        end
         
     | 
| 
       100 
     | 
    
         
            -
                        
         
     | 
| 
       101 
     | 
    
         
            -
                        # 
     | 
| 
       102 
     | 
    
         
            -
                        # 
     | 
| 
       103 
     | 
    
         
            -
                         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                             
     | 
| 
       107 
     | 
    
         
            -
                             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
                            " 
     | 
| 
       113 
     | 
    
         
            -
                            " 
     | 
| 
       114 
     | 
    
         
            -
                            " 
     | 
| 
       115 
     | 
    
         
            -
                            " 
     | 
| 
       116 
     | 
    
         
            -
                            " 
     | 
| 
       117 
     | 
    
         
            -
                            " 
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
                             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
                             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
                        
         
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
                             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
                             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
                         
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
                        params.each do |k, v|
         
     | 
| 
      
 24 
     | 
    
         
            +
                            send("#{k}=", v) if respond_to? "#{k}="
         
     | 
| 
      
 25 
     | 
    
         
            +
                        end
         
     | 
| 
      
 26 
     | 
    
         
            +
                        self.customer_id = params["customer_id"]
         
     | 
| 
      
 27 
     | 
    
         
            +
                        self.increment_id = params["increment_id"]
         
     | 
| 
      
 28 
     | 
    
         
            +
                        self.created_at = params["created_at"]
         
     | 
| 
      
 29 
     | 
    
         
            +
                        self.updated_at = params["updated_at"]
         
     | 
| 
      
 30 
     | 
    
         
            +
                        self.password_hash = params["password_hash"]
         
     | 
| 
      
 31 
     | 
    
         
            +
                        
         
     | 
| 
      
 32 
     | 
    
         
            +
                    end
         
     | 
| 
      
 33 
     | 
    
         
            +
                    
         
     | 
| 
      
 34 
     | 
    
         
            +
                    # Save on Magento the updates on the local Customer
         
     | 
| 
      
 35 
     | 
    
         
            +
                    #
         
     | 
| 
      
 36 
     | 
    
         
            +
                    # @return [TrueCalss, FalseClass] true if successful or false
         
     | 
| 
      
 37 
     | 
    
         
            +
                    def update
         
     | 
| 
      
 38 
     | 
    
         
            +
                        attributes = {}
         
     | 
| 
      
 39 
     | 
    
         
            +
                        methods.grep(/\w=$/).each do |m|
         
     | 
| 
      
 40 
     | 
    
         
            +
                            attributes[m.to_s.gsub('=','')] = send(m.to_s.gsub('=',''))
         
     | 
| 
      
 41 
     | 
    
         
            +
                        end
         
     | 
| 
      
 42 
     | 
    
         
            +
                        self.class.commit('customer.update', [self.customer_id, attributes])
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                    # Create on Magento the local Customer
         
     | 
| 
      
 46 
     | 
    
         
            +
                    #
         
     | 
| 
      
 47 
     | 
    
         
            +
                    # @return [TrueClass, FalseClass] true if successful or false
         
     | 
| 
      
 48 
     | 
    
         
            +
                    def create
         
     | 
| 
      
 49 
     | 
    
         
            +
                        attributes = {}
         
     | 
| 
      
 50 
     | 
    
         
            +
                        methods.grep(/\w=$/).each do |m|
         
     | 
| 
      
 51 
     | 
    
         
            +
                            attributes[m.to_s.gsub('=','')] = send(m.to_s.gsub('=',''))
         
     | 
| 
      
 52 
     | 
    
         
            +
                        end
         
     | 
| 
      
 53 
     | 
    
         
            +
                        response = self.class.commit('customer.create', [attributes])
         
     | 
| 
      
 54 
     | 
    
         
            +
                        return false if response == false
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                        obj = self.class.find(response)
         
     | 
| 
      
 57 
     | 
    
         
            +
                        methods.grep(/\w=$/).each do |m|
         
     | 
| 
      
 58 
     | 
    
         
            +
                            send(m, obj.send(m.to_s.gsub('=','')))
         
     | 
| 
      
 59 
     | 
    
         
            +
                        end
         
     | 
| 
      
 60 
     | 
    
         
            +
                        self.customer_id = obj.customer_id
         
     | 
| 
      
 61 
     | 
    
         
            +
                        self.increment_id = obj.increment_id
         
     | 
| 
      
 62 
     | 
    
         
            +
                        self.created_at = obj.created_at
         
     | 
| 
      
 63 
     | 
    
         
            +
                        self.updated_at = obj.updated_at
         
     | 
| 
      
 64 
     | 
    
         
            +
                        self.password_hash = obj.password_hash
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                        return true
         
     | 
| 
      
 67 
     | 
    
         
            +
                    end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                    # Remove from Magento the local Customer
         
     | 
| 
      
 70 
     | 
    
         
            +
                    #
         
     | 
| 
      
 71 
     | 
    
         
            +
                    # @return [TrueClass, FalseClass] true if successful or false
         
     | 
| 
      
 72 
     | 
    
         
            +
                    def delete
         
     | 
| 
      
 73 
     | 
    
         
            +
                        response = self.class.commit('customer.delete', [self.customer_id])
         
     | 
| 
      
 74 
     | 
    
         
            +
                        return false if response == false
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                        methods.grep(/\w=$/).each do |m|
         
     | 
| 
      
 77 
     | 
    
         
            +
                            send(m, nil)
         
     | 
| 
      
 78 
     | 
    
         
            +
                        end
         
     | 
| 
      
 79 
     | 
    
         
            +
                        self.customer_id = nil
         
     | 
| 
      
 80 
     | 
    
         
            +
                        self.increment_id = nil
         
     | 
| 
      
 81 
     | 
    
         
            +
                        self.created_at = nil
         
     | 
| 
      
 82 
     | 
    
         
            +
                        self.updated_at = nil
         
     | 
| 
      
 83 
     | 
    
         
            +
                        self.password_hash = nil
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                        return true
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                    class << self
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                        # Retrieve the list of all Magento customers with or without filters
         
     | 
| 
      
 91 
     | 
    
         
            +
                        #
         
     | 
| 
      
 92 
     | 
    
         
            +
                        # @param filters [Array] the filters by customer attributes
         
     | 
| 
      
 93 
     | 
    
         
            +
                        # @return [Array<Magenthor::Customer>, FalseClass] the list of all customers as Customer entities or false
         
     | 
| 
      
 94 
     | 
    
         
            +
                        def list filters = []
         
     | 
| 
      
 95 
     | 
    
         
            +
                            response = commit('customer.list', filters)
         
     | 
| 
      
 96 
     | 
    
         
            +
                            return false if response == false
         
     | 
| 
      
 97 
     | 
    
         
            +
                            customers = []
         
     | 
| 
      
 98 
     | 
    
         
            +
                            response.each do |r|
         
     | 
| 
      
 99 
     | 
    
         
            +
                                customers << find(r["customer_id"])
         
     | 
| 
      
 100 
     | 
    
         
            +
                            end
         
     | 
| 
      
 101 
     | 
    
         
            +
                            return customers
         
     | 
| 
      
 102 
     | 
    
         
            +
                        end
         
     | 
| 
      
 103 
     | 
    
         
            +
                        
         
     | 
| 
      
 104 
     | 
    
         
            +
                        # Find a specific Customer by Magento ID
         
     | 
| 
      
 105 
     | 
    
         
            +
                        #
         
     | 
| 
      
 106 
     | 
    
         
            +
                        # @param customer_id [String, Integer] the id of the customer to retrieve
         
     | 
| 
      
 107 
     | 
    
         
            +
                        # @return [Magenthor::Customer, FalseClass] the customer entity or false if not found
         
     | 
| 
      
 108 
     | 
    
         
            +
                        def find customer_id
         
     | 
| 
      
 109 
     | 
    
         
            +
                            response = commit('customer.info', [customer_id])
         
     | 
| 
      
 110 
     | 
    
         
            +
                            new(response) unless response == false
         
     | 
| 
      
 111 
     | 
    
         
            +
                        end
         
     | 
| 
      
 112 
     | 
    
         
            +
                        
         
     | 
| 
      
 113 
     | 
    
         
            +
                        # Magento Customer Attributes
         
     | 
| 
      
 114 
     | 
    
         
            +
                        customer_attributes = [
         
     | 
| 
      
 115 
     | 
    
         
            +
                            "increment_id",
         
     | 
| 
      
 116 
     | 
    
         
            +
                            "created_in",
         
     | 
| 
      
 117 
     | 
    
         
            +
                            "store_id",
         
     | 
| 
      
 118 
     | 
    
         
            +
                            "website_id",
         
     | 
| 
      
 119 
     | 
    
         
            +
                            "email",
         
     | 
| 
      
 120 
     | 
    
         
            +
                            "firstname",
         
     | 
| 
      
 121 
     | 
    
         
            +
                            "middlename",
         
     | 
| 
      
 122 
     | 
    
         
            +
                            "lastname",
         
     | 
| 
      
 123 
     | 
    
         
            +
                            "group_id",
         
     | 
| 
      
 124 
     | 
    
         
            +
                            "prefix",
         
     | 
| 
      
 125 
     | 
    
         
            +
                            "suffix",
         
     | 
| 
      
 126 
     | 
    
         
            +
                            "dob",
         
     | 
| 
      
 127 
     | 
    
         
            +
                            "taxvat",
         
     | 
| 
      
 128 
     | 
    
         
            +
                            "confirmation"]
         
     | 
| 
      
 129 
     | 
    
         
            +
                        customer_attributes.each do |a|
         
     | 
| 
      
 130 
     | 
    
         
            +
                            # Dynamic methods to find customers based on Magento attributes
         
     | 
| 
      
 131 
     | 
    
         
            +
                            define_method("find_by_#{a}") do |arg|
         
     | 
| 
      
 132 
     | 
    
         
            +
                                find_by a, arg
         
     | 
| 
      
 133 
     | 
    
         
            +
                            end
         
     | 
| 
      
 134 
     | 
    
         
            +
                        end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                        # Get the list of all Magento customer groups
         
     | 
| 
      
 137 
     | 
    
         
            +
                        #
         
     | 
| 
      
 138 
     | 
    
         
            +
                        # @return [Array, FalseClass] the list of all customer groups or false
         
     | 
| 
      
 139 
     | 
    
         
            +
                        def groups
         
     | 
| 
      
 140 
     | 
    
         
            +
                            commit('customer_group.list',  [])
         
     | 
| 
      
 141 
     | 
    
         
            +
                        end
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                        
         
     | 
| 
      
 144 
     | 
    
         
            +
                        private
         
     | 
| 
      
 145 
     | 
    
         
            +
                        
         
     | 
| 
      
 146 
     | 
    
         
            +
                        # Method to find customers based on a specific Magento attribute, used to create the dynamic methods
         
     | 
| 
      
 147 
     | 
    
         
            +
                        #
         
     | 
| 
      
 148 
     | 
    
         
            +
                        # @param attribute [String] the attribute used to make the search
         
     | 
| 
      
 149 
     | 
    
         
            +
                        # @param value [String, Integer] the value of the attribute
         
     | 
| 
      
 150 
     | 
    
         
            +
                        # @return [Array<Magenthor::Customer>, Magenthor::Customer, FalseClass] the list of customer entities or a single customer entity or false
         
     | 
| 
      
 151 
     | 
    
         
            +
                        def find_by (attribute, value)
         
     | 
| 
      
 152 
     | 
    
         
            +
                            response = commit('customer.list', [attribute => value])
         
     | 
| 
      
 153 
     | 
    
         
            +
                            return false if response == false
         
     | 
| 
      
 154 
     | 
    
         
            +
                            if response.count > 1
         
     | 
| 
      
 155 
     | 
    
         
            +
                                customers = []
         
     | 
| 
      
 156 
     | 
    
         
            +
                                response.each do |r|
         
     | 
| 
      
 157 
     | 
    
         
            +
                                    customers << find(r["customer_id"])
         
     | 
| 
      
 158 
     | 
    
         
            +
                                end
         
     | 
| 
      
 159 
     | 
    
         
            +
                                return customers
         
     | 
| 
      
 160 
     | 
    
         
            +
                            else
         
     | 
| 
      
 161 
     | 
    
         
            +
                                return new(response[0])
         
     | 
| 
      
 162 
     | 
    
         
            +
                            end
         
     | 
| 
      
 163 
     | 
    
         
            +
                        end
         
     | 
| 
      
 164 
     | 
    
         
            +
                    end
         
     | 
| 
      
 165 
     | 
    
         
            +
                end
         
     | 
| 
      
 166 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/magenthor/version.rb
    CHANGED
    
    
    
        data/lib/magenthor.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # @author Daniele Lenares
         
     | 
| 
       1 
2 
     | 
    
         
             
            require "magenthor/version"
         
     | 
| 
       2 
3 
     | 
    
         
             
            require "magenthor/base"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require "xmlrpc/client"
         
     | 
| 
         @@ -9,4 +10,4 @@ XMLRPC::Config.send(:const_set, :ENABLE_NIL_CREATE, true) 
     | 
|
| 
       9 
10 
     | 
    
         | 
| 
       10 
11 
     | 
    
         
             
            module Magenthor
         
     | 
| 
       11 
12 
     | 
    
         
             
                autoload :Customer, 'magenthor/customer'
         
     | 
| 
       12 
     | 
    
         
            -
            end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
    
        data/magenthor.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,55 +1,55 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: magenthor
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Daniele Lenares
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014-10- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-10-16 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
       15 
15 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
     | 
    
         
            -
                - - ~>
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
19 
     | 
    
         
             
                    version: '1.7'
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :development
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
     | 
    
         
            -
                - - ~>
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
26 
     | 
    
         
             
                    version: '1.7'
         
     | 
| 
       27 
27 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
28 
     | 
    
         
             
              name: rake
         
     | 
| 
       29 
29 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       30 
30 
     | 
    
         
             
                requirements:
         
     | 
| 
       31 
     | 
    
         
            -
                - - ~>
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       32 
32 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       33 
33 
     | 
    
         
             
                    version: '10.0'
         
     | 
| 
       34 
34 
     | 
    
         
             
              type: :development
         
     | 
| 
       35 
35 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       36 
36 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       37 
37 
     | 
    
         
             
                requirements:
         
     | 
| 
       38 
     | 
    
         
            -
                - - ~>
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       39 
39 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       40 
40 
     | 
    
         
             
                    version: '10.0'
         
     | 
| 
       41 
41 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       42 
42 
     | 
    
         
             
              name: pry
         
     | 
| 
       43 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       44 
44 
     | 
    
         
             
                requirements:
         
     | 
| 
       45 
     | 
    
         
            -
                - -  
     | 
| 
      
 45 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       46 
46 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       47 
47 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       48 
48 
     | 
    
         
             
              type: :development
         
     | 
| 
       49 
49 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       50 
50 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       51 
51 
     | 
    
         
             
                requirements:
         
     | 
| 
       52 
     | 
    
         
            -
                - -  
     | 
| 
      
 52 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       53 
53 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       54 
54 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       55 
55 
     | 
    
         
             
            description: A Rubygem wrapper for the XMLRPC Magento API.
         
     | 
| 
         @@ -59,7 +59,7 @@ executables: [] 
     | 
|
| 
       59 
59 
     | 
    
         
             
            extensions: []
         
     | 
| 
       60 
60 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       61 
61 
     | 
    
         
             
            files:
         
     | 
| 
       62 
     | 
    
         
            -
            - .gitignore
         
     | 
| 
      
 62 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
       63 
63 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       64 
64 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       65 
65 
     | 
    
         
             
            - README.md
         
     | 
| 
         @@ -79,18 +79,19 @@ require_paths: 
     | 
|
| 
       79 
79 
     | 
    
         
             
            - lib
         
     | 
| 
       80 
80 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       81 
81 
     | 
    
         
             
              requirements:
         
     | 
| 
       82 
     | 
    
         
            -
              - -  
     | 
| 
      
 82 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       83 
83 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       84 
84 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       85 
85 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       86 
86 
     | 
    
         
             
              requirements:
         
     | 
| 
       87 
     | 
    
         
            -
              - -  
     | 
| 
      
 87 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       88 
88 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       89 
89 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       90 
90 
     | 
    
         
             
            requirements: []
         
     | 
| 
       91 
91 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       92 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 92 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
       93 
93 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       94 
94 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       95 
95 
     | 
    
         
             
            summary: A Rubygem wrapper for the XMLRPC Magento API.
         
     | 
| 
       96 
96 
     | 
    
         
             
            test_files: []
         
     | 
| 
      
 97 
     | 
    
         
            +
            has_rdoc: 
         
     |