mad_cart 0.0.1

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.
@@ -0,0 +1,56 @@
1
+ require 'etsy'
2
+ require 'money'
3
+
4
+ module MadCart
5
+ module Store
6
+ class Etsy
7
+ include MadCart::Store::Base
8
+
9
+ create_connection_with :create_connection, :requires => [:store_name, :api_key]
10
+ fetch :products, :with => :get_products
11
+ format :products, :with => :format_products
12
+
13
+ def valid?
14
+ self.connection ? true : false
15
+ end
16
+
17
+ private
18
+ def get_products(options={})
19
+ connection.listings(:active, product_options(options))
20
+ end
21
+
22
+ def format_products(listing)
23
+ {
24
+ :external_id => listing.id,
25
+ :name => listing.title,
26
+ :description => listing.description,
27
+ :price => "#{listing.price} #{listing.currency}".to_money.format,
28
+ :url => listing.url,
29
+ :currency_code => listing.currency,
30
+ :image_url => listing.result["MainImage"].try(:[], "url_570xN"),
31
+ :square_image_url => listing.result["MainImage"].try(:[], "url_75x75")
32
+ }
33
+ end
34
+
35
+ def create_connection(args)
36
+ ::Etsy.api_key = args[:api_key] if !::Etsy.api_key || (::Etsy.api_key != args[:api_key])
37
+ ::Etsy.environment = :production
38
+ store = ::Etsy::Shop.find(args[:store_name])
39
+ if store.is_a? Array
40
+ return store.first
41
+ else
42
+ raise InvalidStore if store.nil?
43
+ return store
44
+ end
45
+ end
46
+
47
+ def product_options(options)
48
+ prod_options = options.clone
49
+ prod_options[:page] ||= 1
50
+
51
+ return prod_options
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,3 @@
1
+ module MadCart
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mad_cart.rb ADDED
@@ -0,0 +1,23 @@
1
+ # lib
2
+ require 'json'
3
+ require 'singleton'
4
+
5
+ # gems
6
+ require 'active_support/core_ext'
7
+ require 'faraday'
8
+ require 'faraday_middleware'
9
+
10
+ # core
11
+ require 'mad_cart/configuration'
12
+ require 'mad_cart/attribute_mapper'
13
+ require 'mad_cart/inheritable_attributes'
14
+
15
+ # models
16
+ require 'mad_cart/model/base'
17
+ require 'mad_cart/model/customer'
18
+ require 'mad_cart/model/product'
19
+
20
+ # stores
21
+ require 'mad_cart/store/base'
22
+ require 'mad_cart/store/big_commerce'
23
+ require 'mad_cart/store/etsy'
data/mad_cart.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mad_cart/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mad_cart"
8
+ spec.version = MadCart::VERSION
9
+ spec.authors = ["Marc Heiligers", "Stuart Corbishley", "Nic Young"]
10
+ spec.email = [""]
11
+ spec.description = %q{Provides a unified api for various e-commerce merchants.}
12
+ spec.summary = %q{Allows communication with various e-commerce merchants such as BigCommerce and Etsy through a single gem. Extensible to allow the easy addition of merchants and functionality.}
13
+ spec.homepage = "https://github.com/madmimi/mad_cart"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "faraday"
22
+ spec.add_dependency "faraday_middleware"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency 'json', '~> 1.7.7'
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "vcr", '2.5.0'
28
+ spec.add_development_dependency "webmock", '~> 1.11.0'
29
+ spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency "etsy", "0.2.1"
31
+ spec.add_development_dependency 'money'
32
+ spec.add_development_dependency 'activesupport', "~> 3.2"
33
+ end