storesapp-rb 0.1.5 → 0.1.6

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.
@@ -12,39 +12,39 @@ module StoresApp
12
12
  end
13
13
 
14
14
  def collections
15
- StoresApp::Resources::Collection
15
+ StoresApp::Resources::Collection.find(:all)
16
16
  end
17
17
 
18
18
  def collection_products
19
- StoresApp::Resources::CollectionProduct
19
+ StoresApp::Resources::CollectionProduct.find(:all)
20
20
  end
21
21
 
22
22
  def pages
23
- StoresApp::Resources::Page
23
+ StoresApp::Resources::Page.find(:all)
24
24
  end
25
25
 
26
26
  def products
27
- StoresApp::Resources::Product
27
+ StoresApp::Resources::Product.find(:all)
28
28
  end
29
29
 
30
30
  def product_images
31
- StoresApp::Resources::ProductImage
31
+ StoresApp::Resources::ProductImage.find(:all)
32
32
  end
33
33
 
34
34
  def product_properties
35
- StoresApp::Resources::ProductProperty
35
+ StoresApp::Resources::ProductProperty.find(:all)
36
36
  end
37
37
 
38
38
  def users
39
- StoresApp::Resources::User
39
+ StoresApp::Resources::User.find(:all)
40
40
  end
41
41
 
42
42
  def variants
43
- StoresApp::Resources::Variant
43
+ StoresApp::Resources::Variant.find(:all)
44
44
  end
45
45
 
46
46
  def variant_properties
47
- StoresApp::Resources::VariantProperty
47
+ StoresApp::Resources::VariantProperty.find(:all)
48
48
  end
49
49
 
50
50
  private
@@ -1,22 +1,23 @@
1
1
  module StoresApp
2
2
  module Resources
3
3
  class Collection < StoresApp::StoresAppResource
4
- # def products
5
- # CollectionProduct.find(:all, :from => "/api/v1/collection_products.xml?search[product_id]=#{self.id}")
6
- # Product.find(:all, :from => "/api/v1/products.xml?search[collection_id_equals]=#{self.id}")
7
- # end
4
+ def products
5
+ collection_products = CollectionProduct.find(:all, :from => "/api/v1/collection_products.xml?search[collection_id_equals]=#{self.id}")
6
+ product_ids = collection_products.collect {|cp| cp.product_id}
7
+ return Product.find(:all).select {|p| product_ids.include?(p.id)}
8
+ end
8
9
 
9
- # def add_product(options={})
10
- # # options.assert_valid_keys(:product_id)
11
- # # options.assert_required_keys(:product_id)
12
- # put(:add_product, :params => options)
13
- # end
10
+ def add_product(options={})
11
+ options.assert_valid_keys(:product_id)
12
+ options.assert_required_keys(:product_id)
13
+ CollectionProduct.create(:product_id => options[:product_id], :collection_id => self.id)
14
+ end
14
15
 
15
- # def remove_product(options={})
16
- # # options.assert_valid_keys(:product_id)
17
- # # options.assert_required_keys(:product_id)
18
- # put(:remove_product, :prarams => options)
19
- # end
16
+ def remove_product(options={})
17
+ options.assert_valid_keys(:product_id)
18
+ options.assert_required_keys(:product_id)
19
+ CollectionProduct.find(:first, :from => "/api/v1/collection_products.xml?search[collection_id_equals]=#{self.id}&search[product_id_equals]=#{options[:collection_id]}").destroy
20
+ end
20
21
 
21
22
  # def enable
22
23
  # put(:enable)
@@ -1,6 +1,13 @@
1
1
  module StoresApp
2
2
  module Resources
3
3
  class CollectionProduct < StoresApp::StoresAppResource
4
+ def collection
5
+ return Collection.find(:first, :from => "/api/v1/collections.xml?search[collection_id_equals]=#{self.collection_id}")
6
+ end
7
+
8
+ def products
9
+ return Product.find(:first, :from => "/api/v1/products.xml?search[product_id_equals]=#{self.product_id}")
10
+ end
4
11
  end
5
12
  end
6
13
  end
@@ -1,33 +1,35 @@
1
1
  module StoresApp
2
2
  module Resources
3
3
  class Product < StoresApp::StoresAppResource
4
- # def collections
5
- # Collection.find(:all, :from => "/api/v1/collections.xml?search[product_id_equals]=#{self.id}")
6
- # end
4
+ def collections
5
+ collection_products = CollectionProduct.find(:all, :from => "/api/v1/collection_products.xml?search[product_id_equals]=#{self.id}")
6
+ collection_ids = collection_products.collect {|cp| cp.collection_id}
7
+ return Collection.find(:all).select {|c| collection_ids.include?(c.id)}
8
+ end
7
9
 
8
- # def images
9
- # ProductImage.find(:all, :from => "/api/v1/products/#{self.id}/images.xml")
10
- # end
10
+ def images
11
+ ProductImage.find(:all, :from => "/api/v1/product_images.xml?search[product_id_equals]=#{self.id}")
12
+ end
11
13
 
12
- # def properties
13
- # ProductProperty.find(:all, :from => "/api/v1/products/#{self.id}/properties.xml")
14
- # end
14
+ def properties
15
+ ProductProperty.find(:all, :from => "/api/v1/product_properties.xml?search[product_id_equals]=#{self.id}")
16
+ end
15
17
 
16
- # def variants
17
- # ProductVariant.find(:all, :from => "/api/v1/products/#{self.id}/variants.xml")
18
- # end
18
+ def variants
19
+ Variant.find(:all, :from => "/api/v1/variants.xml?search[product_id_equals]=#{self.id}")
20
+ end
19
21
 
20
- # def add_collection(options={})
21
- # # options.assert_valid_keys(:collection_id)
22
- # # options.assert_required_keys(:collection_id)
23
- # put(:add_collection, :params => options)
24
- # end
22
+ def add_collection(options={})
23
+ options.assert_valid_keys(:collection_id)
24
+ options.assert_required_keys(:collection_id)
25
+ CollectionProduct.create(:collection_id => options[:collection_id], :product_id => self.id)
26
+ end
25
27
 
26
- # def remove_collection(options={})
27
- # # options.assert_valid_keys(:collection_id)
28
- # # options.assert_required_keys(:collection_id)
29
- # put(:remove_collection, :prarams => options)
30
- # end
28
+ def remove_collection(options={})
29
+ options.assert_valid_keys(:collection_id)
30
+ options.assert_required_keys(:collection_id)
31
+ CollectionProduct.find(:first, :from => "/api/v1/collection_products.xml?search[product_id_equals]=#{self.id}&search[collection_id_equals]=#{options[:collection_id]}").destroy
32
+ end
31
33
 
32
34
  # def enable
33
35
  # put(:enable)
@@ -1,6 +1,9 @@
1
1
  module StoresApp
2
2
  module Resources
3
3
  class ProductImage < StoresApp::StoresAppResource
4
+ def product
5
+ Product.find(:first, :from => "/api/v1/product.xml?search[product_id_equals]=#{self.product_id}")
6
+ end
4
7
  end
5
8
  end
6
9
  end
@@ -1,9 +1,9 @@
1
1
  module StoresApp
2
2
  module Resources
3
3
  class ProductProperty < StoresApp::StoresAppResource
4
- # def values
5
- # ProductPropertyValue.find(:all, :from => "/api/v1/product_properties/#{self.id}/values.xml", :params => {:product_id => self.product_id})
6
- # end
4
+ def product
5
+ Product.find(:first, :from => "/api/v1/product.xml?search[product_id_equals]=#{self.product_id}")
6
+ end
7
7
  end
8
8
  end
9
9
  end
@@ -1,9 +1,13 @@
1
1
  module StoresApp
2
2
  module Resources
3
3
  class Variant < StoresApp::StoresAppResource
4
- # def values
5
- # ProductPropertyValue.find(:all, :from => "/api/v1/product_variants/#{self.id}/values.xml", :params => {:product_id => self.product_id})
6
- # end
4
+ def product
5
+ Product.find(:first, :from => "/api/v1/product.xml?search[product_id_equals]=#{self.product_id}")
6
+ end
7
+
8
+ def properties
9
+ VariantProperty.find(:all, :from => "/api/v1/variant_properties.xml?search[product_variant_id_equals]=#{self.id}")
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -1,6 +1,9 @@
1
1
  module StoresApp
2
2
  module Resources
3
3
  class VariantProperty < StoresApp::StoresAppResource
4
+ def variant
5
+ Variant.find(:first, :from => "/api/v1/variants.xml?search[variant_id_equals]=#{self.variant_id}")
6
+ end
4
7
  end
5
8
  end
6
9
  end
data/lib/storesapp.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module StoresApp
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  ApiDomain = 'storesapp.com'
4
4
  DevelopmentApiDomain = 'storesapp-com.local'
5
5
 
data/storesapp.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "storesapp-rb"
6
- s.version = "0.1.5"
6
+ s.version = "0.1.6"
7
7
  s.authors = ["Next Feature"]
8
8
  s.summary = "A wrapper for the StoresApp Api. See http://api.storesapp.com for details."
9
9
  s.date = Date.today.to_s
@@ -14,6 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.require_paths = ["lib"]
15
15
  # s.test_files = [""]
16
16
  s.has_rdoc = false
17
- s.add_dependency("activesupport", [">= 2.3.5"])
18
- s.add_dependency("activeresource", [">= 2.3.5"])
17
+ s.add_dependency("activesupport", [">= 2.3.8"])
18
+ s.add_dependency("activeresource", [">= 2.3.8"])
19
19
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storesapp-rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Next Feature
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-25 00:00:00 -04:00
18
+ date: 2010-07-29 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 9
29
+ hash: 19
30
30
  segments:
31
31
  - 2
32
32
  - 3
33
- - 5
34
- version: 2.3.5
33
+ - 8
34
+ version: 2.3.8
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 9
45
+ hash: 19
46
46
  segments:
47
47
  - 2
48
48
  - 3
49
- - 5
50
- version: 2.3.5
49
+ - 8
50
+ version: 2.3.8
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  description: