magenthor 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 589ee0fefcf3a0e84a42551a7f393caa738b58c9
4
- data.tar.gz: 7b70817c5a5eb059cd3067aaf2343df5c9654f25
3
+ metadata.gz: 3f215d41c0f32f299d9b0dc9fd35efc81857b9a8
4
+ data.tar.gz: 85ecdf6a136dcd8351489d083172d2423483d591
5
5
  SHA512:
6
- metadata.gz: 76c4abc74187ed91ca5ad96e077bfbe18dafbe603f05f4f08de557d2d42680fb3ebdcb344e0014a0f3a97bbc0ba743f0db2aff68415cb5a474238fad9526b908
7
- data.tar.gz: 2dabff7cbd1b452341a270e07763ede344819543ab7633531eb81fd27cf0bca0850c5988fc308c93ae13078e4aa9ea54e2c4e6d830169d6a41f152c6c449c382
6
+ metadata.gz: f29992ab85cdbef685cb5f9c4406b0601873292b3f005ca3bde86b7362022bc8ea8965f745567738bdbe11679dfbcfe53b1b39e280b68f4f9bf29e5f590295a0
7
+ data.tar.gz: a456bc1c67fcb46992d08cf56a8dbb18b34676321576a17998091f744b156c35d2be3827a84cce9d1ba230ef0642031570354fd945fe7f26de7d0182969ceeda
data/README.md CHANGED
@@ -12,7 +12,7 @@ Since this is still in an early stage of development, I discourage the installat
12
12
 
13
13
  Initialize the connection
14
14
  ```ruby
15
- Magenthor::Base.new({
15
+ Magenthor::Base.setup({
16
16
  :port => 80,
17
17
  :host => 'magentohost.tld',
18
18
  :api_user => 'apiuser',
@@ -0,0 +1,23 @@
1
+ # @author Daniele Lenares
2
+ module Magenthor
3
+ class Catalog < Base
4
+
5
+ class << self
6
+ # Get the list of all products sets
7
+ #
8
+ # @return [Array] a list of all attribute sets
9
+ def attribute_set_list
10
+ commit('catalog_product_attribute_set.list', [])
11
+ end
12
+
13
+ # Get the list of a attribute set
14
+ #
15
+ # @param set_id [String, Integer] the set id to get the attributes from
16
+ # @return [Array] a list of all attributes of the set
17
+ def attribute_list set_id
18
+ commit('catalog_product_attribute.list', ["setId" => set_id])
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -33,7 +33,7 @@ module Magenthor
33
33
 
34
34
  # Save on Magento the updates on the local Customer
35
35
  #
36
- # @return [TrueCalss, FalseClass] true if successful or false
36
+ # @return [TrueClass, FalseClass] true if successful or false
37
37
  def update
38
38
  attributes = {}
39
39
  methods.grep(/\w=$/).each do |m|
@@ -0,0 +1,97 @@
1
+ # @author Daniele Lenares
2
+ module Magenthor
3
+ class Product < Base
4
+
5
+ attr_reader :product_id
6
+ private
7
+ attr_writer :product_id
8
+
9
+ public
10
+
11
+ # Initialize a new product entity based on an attribute set id
12
+ #
13
+ # @param set_id [Integer, String] the attribute set of the new product
14
+ # @return [Magenthor::Product] the empty product
15
+ def initialize set_id
16
+ attributes = Magenthor::Catalog.attribute_list set_id
17
+ attributes.each do |attr|
18
+ if attr["code"] != 'product_id' and attr["code"] != 'created_at'
19
+ singleton_class.class_eval do; attr_accessor attr["code"]; end
20
+ send(attr["code"]+"=", nil)
21
+ end
22
+ end
23
+ singleton_class.class_eval do; attr_accessor "type"; end
24
+ singleton_class.class_eval do; attr_accessor "set"; end
25
+ self.set = set_id
26
+ self.type = nil
27
+ self.product_id = nil
28
+ end
29
+
30
+ # Save on Magento the updates made on the local product
31
+ #
32
+ # @return [TrueClass, FalseClass] true if successful or false
33
+ def update
34
+ attributes = {}
35
+ methods.grep(/\w=$/).each do |m|
36
+ attributes[m.to_s.gsub('=','')] = send(m.to_s.gsub('=',''))
37
+ end
38
+ self.class.commit('catalog_product.update', [self.product_id, attributes])
39
+ end
40
+
41
+ # Create on Magento a new product base on the local one
42
+ #
43
+ # @return [TrueClass, FalseClass] true if successful or false
44
+ def create
45
+ if self.type.nil? or self.set.nil? or self.sku.nil?
46
+ puts "Type, set and sku are mandatory"
47
+ return false
48
+ end
49
+ attributes = {}
50
+ methods.grep(/\w=$/).each do |m|
51
+ value = send(m.to_s.gsub('=',''))
52
+ attributes[m.to_s.gsub('=','')] = value unless value.nil?
53
+ end
54
+ response = self.class.commit('catalog_product.create', [self.type, self.set, self.sku, attributes])
55
+ return false if response == false
56
+ obj = self.class.info response
57
+ methods.grep(/\w=$/).each do |m|
58
+ send(m, obj.send(m.to_s.gsub('=','')))
59
+ end
60
+ self.product_id = obj.product_id
61
+ return true
62
+ end
63
+
64
+ class << self
65
+ # Retrieve the list of Magento product based on filters and store view
66
+ #
67
+ # @param filters [Array] array of filters by attributes
68
+ # @param store_view [String, Integer] Magento store view ID or code
69
+ # @return [Array<Magenthor::Product>] the list of products entities matching the search
70
+ def list filters = [], store_view = ''
71
+ response = commit('catalog_product.list', [filters, store_view])
72
+ return false if response == false
73
+ products = []
74
+ response.each do |p|
75
+ products << Magenthor::Product.info(p["product_id"], store_view)
76
+ end
77
+ return products
78
+ end
79
+
80
+ # Retrieve the information about a specific product
81
+ #
82
+ # @param product_id [String, Integer] the id of the product to get
83
+ # @param store_view [String, Integer] Magento store view ID or code
84
+ # @return [Magenthor::Product] the product entity searched
85
+ def info product_id, store_view = ''
86
+ response = commit('catalog_product.info', [product_id, store_view])
87
+ return false if response == false
88
+ obj = new response["set"]
89
+ response.each do |key, value|
90
+ obj.class.class_eval do; attr_accessor key; end unless obj.respond_to?(key)
91
+ obj.send(key+"=", value)
92
+ end
93
+ return obj
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,4 +1,4 @@
1
1
  # @author Daniele Lenares
2
2
  module Magenthor
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
data/lib/magenthor.rb CHANGED
@@ -10,4 +10,6 @@ XMLRPC::Config.send(:const_set, :ENABLE_NIL_CREATE, true)
10
10
 
11
11
  module Magenthor
12
12
  autoload :Customer, 'magenthor/customer'
13
+ autoload :Catalog, 'magenthor/catalog'
14
+ autoload :Product, 'magenthor/product'
13
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magenthor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-16 00:00:00.000000000 Z
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,9 @@ files:
66
66
  - Rakefile
67
67
  - lib/magenthor.rb
68
68
  - lib/magenthor/base.rb
69
+ - lib/magenthor/catalog.rb
69
70
  - lib/magenthor/customer.rb
71
+ - lib/magenthor/product.rb
70
72
  - lib/magenthor/version.rb
71
73
  - magenthor.gemspec
72
74
  homepage: https://github.com/Ryuk87/magenthor