storesapp-rb 0.0.7 → 0.0.8
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.
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/Manifest.txt +15 -9
- data/README.markdown +58 -0
- data/lib/storesapp.rb +34 -13
- data/lib/storesapp/base.rb +62 -1
- data/lib/storesapp/plugins/active_resource_inheritable_headers.rb +32 -0
- data/lib/storesapp/plugins/hash_ext.rb +11 -0
- data/lib/storesapp/resources/cart.rb +9 -0
- data/lib/storesapp/resources/cart_item.rb +9 -0
- data/lib/storesapp/resources/cart_item_property.rb +6 -0
- data/lib/storesapp/resources/collection.rb +29 -0
- data/lib/storesapp/resources/collection_product.rb +6 -0
- data/lib/storesapp/resources/page.rb +6 -0
- data/lib/storesapp/resources/product.rb +41 -0
- data/lib/storesapp/resources/product_image.rb +6 -0
- data/lib/storesapp/resources/product_property.rb +9 -0
- data/lib/storesapp/resources/product_property_value.rb +6 -0
- data/lib/storesapp/resources/product_variant.rb +9 -0
- data/lib/storesapp/resources/user.rb +6 -0
- data/lib/storesapp/stores_app_resource.rb +5 -0
- data/storesapp.gemspec +13 -16
- metadata +32 -26
- data/README +0 -1
- data/lib/storesapp/cart.rb +0 -7
- data/lib/storesapp/cart_line_item.rb +0 -7
- data/lib/storesapp/collection.rb +0 -11
- data/lib/storesapp/collection_product.rb +0 -4
- data/lib/storesapp/page.rb +0 -4
- data/lib/storesapp/product.rb +0 -11
- data/lib/storesapp/store.rb +0 -15
data/{MIT-LICENSE → LICENSE}
RENAMED
data/Manifest.txt
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
lib/storesapp/base.rb
|
2
|
-
lib/storesapp/
|
3
|
-
lib/storesapp/
|
4
|
-
lib/storesapp/
|
5
|
-
lib/storesapp/
|
6
|
-
lib/storesapp/
|
7
|
-
lib/storesapp/
|
8
|
-
lib/storesapp/
|
2
|
+
lib/storesapp/stores_app_resource.rb
|
3
|
+
lib/storesapp/resources/cart.rb
|
4
|
+
lib/storesapp/resources/cart_item.rb
|
5
|
+
lib/storesapp/resources/cart_item_property.rb
|
6
|
+
lib/storesapp/resources/collection.rb
|
7
|
+
lib/storesapp/resources/collection_product.rb
|
8
|
+
lib/storesapp/resources/page.rb
|
9
|
+
lib/storesapp/resources/product.rb
|
10
|
+
lib/storesapp/resources/product_image.rb
|
11
|
+
lib/storesapp/resources/product_property.rb
|
12
|
+
lib/storesapp/resources/product_property_value.rb
|
13
|
+
lib/storesapp/resources/product_variant.rb
|
14
|
+
lib/storesapp/resources/user.rb
|
9
15
|
lib/storesapp.rb
|
10
|
-
|
11
|
-
README
|
16
|
+
LICENSE
|
17
|
+
README.markdown
|
data/README.markdown
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# storesapp-rb #
|
2
|
+
|
3
|
+
A ruby library wrapping the StoresApp API.
|
4
|
+
|
5
|
+
## Description ##
|
6
|
+
|
7
|
+
This library uses ActiveResource to provide simple, reliable access to the StoresApp API. Good for building eCommerce websites.
|
8
|
+
|
9
|
+
## Usage ##
|
10
|
+
|
11
|
+
### Creating a new StoresApp object: ###
|
12
|
+
|
13
|
+
All calls to the StoresApp API will originate from a StoresApp object. Initialize it like so:
|
14
|
+
|
15
|
+
`@store = StoresApp(:api_key => "12340987asdf12340987qwer", :sub_domain => "joeandcompany")`
|
16
|
+
|
17
|
+
### Collections ###
|
18
|
+
|
19
|
+
Index
|
20
|
+
|
21
|
+
`@store.collections.find(:all)`
|
22
|
+
|
23
|
+
Show
|
24
|
+
|
25
|
+
`@store.collections.find(43235) # ID`
|
26
|
+
|
27
|
+
`@store.collections.find('clothing') # Handle`
|
28
|
+
|
29
|
+
Create
|
30
|
+
|
31
|
+
`@collection = @store.collection.new`
|
32
|
+
|
33
|
+
`@collection.attributes = {:name => "Toys", :description => "lorem ipsum..."}`
|
34
|
+
|
35
|
+
`@collection.save`
|
36
|
+
|
37
|
+
Update
|
38
|
+
|
39
|
+
`@collection.name = "Adult Toys"`
|
40
|
+
|
41
|
+
`@collection.save`
|
42
|
+
|
43
|
+
Destroy
|
44
|
+
|
45
|
+
`@client.destroy`
|
46
|
+
|
47
|
+
## Features / Problems ##
|
48
|
+
|
49
|
+
Supports most of the StoresApp API (http://api.storesapp.com).
|
50
|
+
|
51
|
+
## Requirements ##
|
52
|
+
|
53
|
+
Requires active_support >= 2.3.5
|
54
|
+
Requires active_resource >= 2.3.5
|
55
|
+
|
56
|
+
## Install ##
|
57
|
+
|
58
|
+
`gem install storesapp-rb`
|
data/lib/storesapp.rb
CHANGED
@@ -1,13 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
module StoresApp
|
2
|
+
VERSION = "0.0.8"
|
3
|
+
ApiDomain = "storesapp.com"
|
4
|
+
|
5
|
+
# Class method to load all ruby files from a given path.
|
6
|
+
def self.load_all_ruby_files_from_path(path)
|
7
|
+
Dir.foreach(path) do |file|
|
8
|
+
require File.join(path, file) if file =~ /\.rb$/
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gems
|
14
|
+
require "rubygems"
|
15
|
+
require "activesupport"
|
16
|
+
require "activeresource"
|
17
|
+
|
18
|
+
# Plugins
|
19
|
+
PluginPath = File.join(File.dirname(__FILE__), "storesapp", "plugins")
|
20
|
+
StoresApp.load_all_ruby_files_from_path(PluginPath)
|
21
|
+
|
22
|
+
# Base
|
23
|
+
require File.join(File.dirname(__FILE__), "storesapp", "base")
|
24
|
+
require File.join(File.dirname(__FILE__), "storesapp", "stores_app_resource")
|
25
|
+
|
26
|
+
# Shortcut for Harvest::Base.new
|
27
|
+
#
|
28
|
+
# Example:
|
29
|
+
# StoresApp(:api_key => "asdf1234",
|
30
|
+
# :sub_domain => "myhostname",
|
31
|
+
# :headers => {"User-Agent => "Harvest Rubygem"})
|
32
|
+
def StoresApp(options={})
|
33
|
+
StoresApp::Base.new(options)
|
34
|
+
end
|
data/lib/storesapp/base.rb
CHANGED
@@ -1,4 +1,65 @@
|
|
1
1
|
module StoresApp
|
2
|
-
class Base
|
2
|
+
class Base
|
3
|
+
# Requires a sub_domain, and api_key.
|
4
|
+
# Specifying headers is optional, but useful for setting a user agent.
|
5
|
+
def initialize(options={})
|
6
|
+
options.assert_valid_keys(:api_key, :sub_domain, :headers)
|
7
|
+
options.assert_required_keys(:api_key, :sub_domain)
|
8
|
+
@api_key = options[:api_key]
|
9
|
+
@sub_domain = options[:sub_domain]
|
10
|
+
@headers = options[:headers]
|
11
|
+
configure_base_resource
|
12
|
+
end
|
13
|
+
|
14
|
+
def collections
|
15
|
+
StoresApp::Resources::Collection
|
16
|
+
end
|
17
|
+
|
18
|
+
def pages
|
19
|
+
StoresApp::Resources::Page
|
20
|
+
end
|
21
|
+
|
22
|
+
def products
|
23
|
+
StoresApp::Resources::Product
|
24
|
+
end
|
25
|
+
|
26
|
+
def product_images
|
27
|
+
StoresApp::Resources::ProductImage
|
28
|
+
end
|
29
|
+
|
30
|
+
def product_properties
|
31
|
+
StoresApp::Resources::ProductProperty
|
32
|
+
end
|
33
|
+
|
34
|
+
def product_property_values
|
35
|
+
StoresApp::Resources::ProductPropertyValue
|
36
|
+
end
|
37
|
+
|
38
|
+
def product_variants
|
39
|
+
StoresApp::Resources::ProductVariant
|
40
|
+
end
|
41
|
+
|
42
|
+
def users
|
43
|
+
StoresApp::Resources::User
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
# Configure resource base class so that
|
48
|
+
# inherited classes can access the api.
|
49
|
+
def configure_base_resource
|
50
|
+
StoresAppResource.site = "http://#{@sub_domain}.#{StoresApp::ApiDomain}/api/v1"
|
51
|
+
if @api_key
|
52
|
+
StoresAppResource.user = @api_key
|
53
|
+
StoresAppResource.password = 'x'
|
54
|
+
end
|
55
|
+
StoresAppResource.headers.update(@headers) if @headers.is_a?(Hash)
|
56
|
+
load_resources
|
57
|
+
end
|
58
|
+
|
59
|
+
# Load the classes representing the various resources.
|
60
|
+
def load_resources
|
61
|
+
resource_path = File.join(File.dirname(__FILE__), "resources")
|
62
|
+
StoresApp.load_all_ruby_files_from_path(resource_path)
|
63
|
+
end
|
3
64
|
end
|
4
65
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Allows headers in an ActiveResource::Base class
|
2
|
+
# to be inherited by subclasses. Useful for setting
|
3
|
+
# a User-Agent used by all resources.
|
4
|
+
module Harvest
|
5
|
+
module Plugins
|
6
|
+
module ActiveResourceInheritableHeaders
|
7
|
+
module ClassMethods
|
8
|
+
# If headers are not defined in a
|
9
|
+
# given subclass, then obtain headers
|
10
|
+
# from the superclass.
|
11
|
+
def inheritable_headers
|
12
|
+
if defined?(@headers)
|
13
|
+
@headers
|
14
|
+
elsif superclass != Object && superclass.headers
|
15
|
+
superclass.headers
|
16
|
+
else
|
17
|
+
@headers ||= {}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included(klass)
|
23
|
+
klass.instance_eval do
|
24
|
+
klass.extend ClassMethods
|
25
|
+
class << self
|
26
|
+
alias_method :headers, :inheritable_headers
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Hash
|
2
|
+
def assert_valid_keys(*valid_keys)
|
3
|
+
invalid_keys = keys - valid_keys
|
4
|
+
raise ArgumentError, "Invalid key(s): #{invalid_keys.join(", ")}" unless invalid_keys.empty?
|
5
|
+
end
|
6
|
+
|
7
|
+
def assert_required_keys(*required_keys)
|
8
|
+
missing_keys = required_keys.select {|key| !keys.include?(key)}
|
9
|
+
raise ArgumentError, "Missing required option(s): #{missing_keys.join(", ")}" unless missing_keys.empty?
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module StoresApp
|
2
|
+
module Resources
|
3
|
+
class Collection < StoresApp::StoresAppResource
|
4
|
+
def products
|
5
|
+
Product.find(:all, :from => "/api/collections/#{self.id}/products.xml")
|
6
|
+
end
|
7
|
+
|
8
|
+
# def add_product(options={})
|
9
|
+
# # options.assert_valid_keys(:product_id)
|
10
|
+
# # options.assert_required_keys(:product_id)
|
11
|
+
# put(:add_product, :params => options)
|
12
|
+
# end
|
13
|
+
|
14
|
+
# def remove_product(options={})
|
15
|
+
# # options.assert_valid_keys(:product_id)
|
16
|
+
# # options.assert_required_keys(:product_id)
|
17
|
+
# put(:remove_product, :prarams => options)
|
18
|
+
# end
|
19
|
+
|
20
|
+
# def enable
|
21
|
+
# put(:enable)
|
22
|
+
# end
|
23
|
+
|
24
|
+
# def disable
|
25
|
+
# put(:disable)
|
26
|
+
# end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module StoresApp
|
2
|
+
module Resources
|
3
|
+
class Product < StoresApp::StoresAppResource
|
4
|
+
def collections
|
5
|
+
Collection.find(:all, :from => "/api/products/#{self.id}/collections.xml")
|
6
|
+
end
|
7
|
+
|
8
|
+
def images
|
9
|
+
ProductImage.find(:all, :from => "/api/products/#{self.id}/images.xml")
|
10
|
+
end
|
11
|
+
|
12
|
+
def properties
|
13
|
+
ProductProperty.find(:all, :from => "/api/products/#{self.id}/properties.xml")
|
14
|
+
end
|
15
|
+
|
16
|
+
def variants
|
17
|
+
ProductVariant.find(:all, :from => "/api/products/#{self.id}/variants.xml")
|
18
|
+
end
|
19
|
+
|
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
|
25
|
+
|
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
|
31
|
+
|
32
|
+
# def enable
|
33
|
+
# put(:enable)
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# def disable
|
37
|
+
# put(:disable)
|
38
|
+
# end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module StoresApp
|
2
|
+
module Resources
|
3
|
+
class ProductProperty < StoresApp::StoresAppResource
|
4
|
+
def values
|
5
|
+
ProductPropertyValue.find(:all, :from => "/api/product_properties/#{self.id}/values.xml", :params => {:product_id => self.product_id})
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/storesapp.gemspec
CHANGED
@@ -2,21 +2,18 @@
|
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.authors
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.description = s.summary
|
11
|
-
s.
|
12
|
-
s.email
|
13
|
-
s.
|
14
|
-
|
15
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.1") if s.respond_to?(:required_rubygems_version=)
|
16
|
-
s.rubygems_version = %q{1.3.1}
|
17
|
-
s.required_ruby_version = Gem::Requirement.new("~> 1.8")
|
18
|
-
s.files = `git ls-files`.split("\n")
|
5
|
+
s.name = "storesapp-rb"
|
6
|
+
s.version = "0.0.8"
|
7
|
+
s.authors = ["Next Feature"]
|
8
|
+
s.summary = "A wrapper for the StoresApp Api. See http://api.storesapp.com for details."
|
9
|
+
s.date = Date.today.to_s
|
10
|
+
# s.description = s.summary
|
11
|
+
s.homepage = "http://github.com/nextfeature/storesapp-rb"
|
12
|
+
s.email = ["info@nextfeature.com"]
|
13
|
+
s.files = `git ls-files`.split("\n")
|
19
14
|
s.require_paths = ["lib"]
|
20
|
-
s.
|
21
|
-
s.
|
15
|
+
# s.test_files = [""]
|
16
|
+
s.has_rdoc = false
|
17
|
+
s.add_dependency("activesupport", [">= 2.3.5"])
|
18
|
+
s.add_dependency("activeresource", [">= 2.3.5"])
|
22
19
|
end
|
metadata
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storesapp-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Next Feature
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
|
-
cert_chain:
|
17
|
-
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-05 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,7 +50,7 @@ dependencies:
|
|
49
50
|
version: 2.3.5
|
50
51
|
type: :runtime
|
51
52
|
version_requirements: *id002
|
52
|
-
description:
|
53
|
+
description:
|
53
54
|
email:
|
54
55
|
- info@nextfeature.com
|
55
56
|
executables: []
|
@@ -60,18 +61,26 @@ extra_rdoc_files: []
|
|
60
61
|
|
61
62
|
files:
|
62
63
|
- .gitignore
|
63
|
-
-
|
64
|
+
- LICENSE
|
64
65
|
- Manifest.txt
|
65
|
-
- README
|
66
|
+
- README.markdown
|
66
67
|
- lib/storesapp.rb
|
67
68
|
- lib/storesapp/base.rb
|
68
|
-
- lib/storesapp/
|
69
|
-
- lib/storesapp/
|
70
|
-
- lib/storesapp/
|
71
|
-
- lib/storesapp/
|
72
|
-
- lib/storesapp/
|
73
|
-
- lib/storesapp/
|
74
|
-
- lib/storesapp/
|
69
|
+
- lib/storesapp/plugins/active_resource_inheritable_headers.rb
|
70
|
+
- lib/storesapp/plugins/hash_ext.rb
|
71
|
+
- lib/storesapp/resources/cart.rb
|
72
|
+
- lib/storesapp/resources/cart_item.rb
|
73
|
+
- lib/storesapp/resources/cart_item_property.rb
|
74
|
+
- lib/storesapp/resources/collection.rb
|
75
|
+
- lib/storesapp/resources/collection_product.rb
|
76
|
+
- lib/storesapp/resources/page.rb
|
77
|
+
- lib/storesapp/resources/product.rb
|
78
|
+
- lib/storesapp/resources/product_image.rb
|
79
|
+
- lib/storesapp/resources/product_property.rb
|
80
|
+
- lib/storesapp/resources/product_property_value.rb
|
81
|
+
- lib/storesapp/resources/product_variant.rb
|
82
|
+
- lib/storesapp/resources/user.rb
|
83
|
+
- lib/storesapp/stores_app_resource.rb
|
75
84
|
- storesapp.gemspec
|
76
85
|
has_rdoc: true
|
77
86
|
homepage: http://github.com/nextfeature/storesapp-rb
|
@@ -85,30 +94,27 @@ require_paths:
|
|
85
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
95
|
none: false
|
87
96
|
requirements:
|
88
|
-
- -
|
97
|
+
- - ">="
|
89
98
|
- !ruby/object:Gem::Version
|
90
|
-
hash:
|
99
|
+
hash: 3
|
91
100
|
segments:
|
92
|
-
-
|
93
|
-
|
94
|
-
version: "1.8"
|
101
|
+
- 0
|
102
|
+
version: "0"
|
95
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
104
|
none: false
|
97
105
|
requirements:
|
98
106
|
- - ">="
|
99
107
|
- !ruby/object:Gem::Version
|
100
|
-
hash:
|
108
|
+
hash: 3
|
101
109
|
segments:
|
102
|
-
-
|
103
|
-
|
104
|
-
- 1
|
105
|
-
version: 1.3.1
|
110
|
+
- 0
|
111
|
+
version: "0"
|
106
112
|
requirements: []
|
107
113
|
|
108
114
|
rubyforge_project:
|
109
115
|
rubygems_version: 1.3.7
|
110
116
|
signing_key:
|
111
117
|
specification_version: 3
|
112
|
-
summary:
|
118
|
+
summary: A wrapper for the StoresApp Api. See http://api.storesapp.com for details.
|
113
119
|
test_files: []
|
114
120
|
|
data/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
StoresApp-rb
|
data/lib/storesapp/cart.rb
DELETED
data/lib/storesapp/collection.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module StoresApp
|
2
|
-
class Collection < Base
|
3
|
-
def collection_products
|
4
|
-
CollectionProduct.find(:all).select {|cp| cp.collection_id == id}
|
5
|
-
end
|
6
|
-
|
7
|
-
def products
|
8
|
-
Product.find(:all).select {|p| collection_products.collect {|cp| cp.product_id}.include?(p.id)}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/lib/storesapp/page.rb
DELETED
data/lib/storesapp/product.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module StoresApp
|
2
|
-
class Product < Base
|
3
|
-
def collection_products
|
4
|
-
CollectionProduct.find(:all).select {|cp| cp.product_id == id}
|
5
|
-
end
|
6
|
-
|
7
|
-
def collections
|
8
|
-
Collection.find(:all).select {|c| collection_products.collect {|cp| cp.collection_id}.include?(c.id)}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/lib/storesapp/store.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module StoresApp
|
2
|
-
class Store < Base
|
3
|
-
# def collections
|
4
|
-
# Collection.find(:all, :from => "/collections.xml")
|
5
|
-
# end
|
6
|
-
#
|
7
|
-
# def pages
|
8
|
-
# Page.find(:all, :from => "/pages.xml")
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# def products
|
12
|
-
# Product.find(:all, :from => "/products.xml")
|
13
|
-
# end
|
14
|
-
end
|
15
|
-
end
|