Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2.1'

jobs:
build-ruby-27:
docker:
docker:
- image: circleci/ruby:2.7.0
steps:
- checkout
Expand All @@ -17,9 +17,9 @@ jobs:
paths:
- vendor/bundle
- run: bundle exec rspec

build-ruby-25:
docker:
docker:
- image: circleci/ruby:2.5.3
steps:
- checkout
Expand All @@ -28,7 +28,7 @@ jobs:
- rubygems-25-cache-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "flex-commerce-api.gemspec" }}
- rubygems-25-cache-{{ .Branch }}
- rubygems-25-cache
- run: gem install bundler -v "~> 1.17"
- run: gem install bundler -v "~> 2.1"
- run: bundle install --path vendor/bundle
- save_cache:
key: rubygems-25-cache-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "flex-commerce-api.gemspec" }}
Expand Down
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Style/TrivialAccessors:
- to_str
- to_s
- to_sym
Style/VariableName:
Naming/VariableName:
Description: Use the configured style when naming variables.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars
Enabled: true
Expand Down Expand Up @@ -1062,4 +1062,4 @@ Lint/Void:
Enabled: false
Rails/Delegate:
Description: Prefer delegate method for delegations.
Enabled: false
Enabled: false
4 changes: 1 addition & 3 deletions app/models/cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ def available_shipping_methods
private

def stock_levels
StockLevel.where(skus: line_items.map { |li| li.item.sku }.join(",")).all
StockLevel.with_params(fields: {stock_levels: "stock_available"}).where(skus: line_items.map { |li| li.item.sku }.join(",")).all
end


end
end
12 changes: 6 additions & 6 deletions app/models/customer_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ def self.authenticate(attributes = {})
nil
end

def self.find_by_email(email)
requestor.custom("email:#{URI.encode_www_form_component(email)}", {request_method: :get}, {}).first
def self.find_by_email(email, options = {})
requestor.custom("email:#{URI.encode_www_form_component(email)}", {request_method: :get}, options).first
rescue ::FlexCommerceApi::Error::NotFound
nil
end

def self.find_by_reference(reference)
requestor.custom("reference:#{reference}", {request_method: :get}, {}).first
def self.find_by_reference(reference, options = {})
requestor.custom("reference:#{reference}", {request_method: :get}, options).first
rescue ::FlexCommerceApi::Error::NotFound
nil
end

# Find customer account by password reset token provided in email's link
# Used in reset password scenario
def self.find_by_token(token)
requestor.custom("token:#{token}", {request_method: :get}, {}).first
def self.find_by_token(token, options = {})
requestor.custom("token:#{token}", {request_method: :get}, options).first
rescue ::FlexCommerceApi::Error::NotFound
nil
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/oms/billing_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class BillingAddress < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class Customer < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
15 changes: 15 additions & 0 deletions app/models/oms/customer_order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "flex_commerce_api/oms/api_base"
require "flex_commerce_api/api_base"
module FlexCommerce
module OMS
class CustomerOrder < FlexCommerceApi::OMS::ApiBase
has_many :payments, class_name: "::FlexCommerce::OMS::Payments"
has_many :line_items, class_name: "::FlexCommerce::OMS::LineItem"
has_many :discounts, class_name: "::FlexCommerce::OMS::Discount"
has_many :shipping_address, class_name: "::FlexCommerce::OMS::Address"
has_one :billing_address, class_name: "::FlexCommerce::OMS::Address"
has_one :customer, class_name: "::FlexCommerce::OMS::Customer"
has_one :shipping_method, class_name: "::FlexCommerce::OMS::ShippingMethod"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/discount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class Discount < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/line_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class LineItem < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class Payment < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/shipping_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class ShippingAddress < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
9 changes: 9 additions & 0 deletions app/models/oms/shipping_method.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "flex_commerce_api/oms/api_base"

module FlexCommerce
module OMS
class ShippingMethod < FlexCommerceApi::OMS::ApiBase
belongs_to :customer_order, class_name: "::FlexCommerce::OMS::CustomerOrder"
end
end
end
15 changes: 15 additions & 0 deletions app/models/price_entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "flex_commerce_api/api_base"

module FlexCommerce
class PriceEntry < FlexCommerceApi::ApiBase
belongs_to :variant

property :variant_reference
property :starts_at
property :ends_at
property :was_price
property :current_price
property :created_at
property :updated_at
end
end
2 changes: 2 additions & 0 deletions app/models/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Variant < FlexCommerceApi::ApiBase
has_one :product
has_many :asset_files
has_many :markdown_prices
has_many :price_entries

def add_markdown_prices(markdown_prices)
self.class.requestor.custom("relationships/markdown_prices", {request_method: :post}, {id: id, data: markdown_prices.map(&:as_relation)})
end
Expand Down
4 changes: 2 additions & 2 deletions flex-commerce-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", ">= 1.17"
spec.add_development_dependency "bundler", "~> 2.1"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.3"
spec.add_development_dependency "webmock", "~> 1.21"
Expand All @@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "json_matchers", ["~> 0.5", ">= 0.5.1"]

spec.add_dependency "oj", "~> 2.12"
spec.add_runtime_dependency "json_api_client", "1.5.3"
spec.add_runtime_dependency "json_api_client", "1.6.0"
spec.add_runtime_dependency "activesupport", ">= 4.0"
spec.add_runtime_dependency "rack", ">= 1.6"
spec.add_runtime_dependency "faraday-http-cache", "1.3.0"
Expand Down
13 changes: 13 additions & 0 deletions lib/flex_commerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ module V2
autoload :UnallocateOrder, File.join(FlexCommerce.gem_root, "app", "models", "v2", "unallocate_order")
end

# OMS
module OMS
autoload :BillingAddress, File.join(FlexCommerce.gem_root, "app", "models", "oms", "billing_address")
autoload :CustomerOrder, File.join(FlexCommerce.gem_root, "app", "models", "oms", "customer_order")
autoload :Customer, File.join(FlexCommerce.gem_root, "app", "models", "oms", "customer")
autoload :Discount, File.join(FlexCommerce.gem_root, "app", "models", "oms", "discount")
autoload :LineItem, File.join(FlexCommerce.gem_root, "app", "models", "oms", "line_item")
autoload :Payment, File.join(FlexCommerce.gem_root, "app", "models", "oms", "payment")
autoload :ShippingAddress, File.join(FlexCommerce.gem_root, "app", "models", "oms", "shipping_address")
autoload :ShippingMethod, File.join(FlexCommerce.gem_root, "app", "models", "oms", "shipping_method")
end

# V1 Models
autoload :Address, File.join(gem_root, "app", "models", "address")
autoload :AssetFile, File.join(gem_root, "app", "models", "asset_file")
Expand Down Expand Up @@ -54,6 +66,7 @@ module V2
autoload :PaymentProvider, File.join(gem_root, "app", "models", "payment_provider")
autoload :PaymentProviderSetup, File.join(gem_root, "app", "models", "payment_provider_setup")
autoload :PaymentTransaction, File.join(gem_root, "app", "models", "payment_transaction")
autoload :PriceEntry, File.join(gem_root, "app", "models", "price_entry")
autoload :Product, File.join(gem_root, "app", "models", "product")
autoload :ProductAssetFile, File.join(gem_root, "app", "models", "product_asset_file")
autoload :Promotion, File.join(gem_root, "app", "models", "promotion")
Expand Down
4 changes: 1 addition & 3 deletions lib/flex_commerce_api/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BaseResource < JsonApiClient::Resource
self.requestor_class = JsonApiClientExtension::Requestor
self.connection_class = ::FlexCommerceApi::JsonApiClientExtension::FlexibleConnection
self.parser = ::FlexCommerceApi::JsonApiClientExtension::Parsers::Parser
self.keep_request_params = true

class << self
def create!(*args)
Expand Down Expand Up @@ -246,9 +247,6 @@ def get_related(relationship)
end
FlexCommerceApi::JsonApiClientExtension::RemoteBuilder.new(association.association_class, path: path, connection: connection)
end

end


end
end
37 changes: 27 additions & 10 deletions lib/flex_commerce_api/json_api_client_extension/builder.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
module FlexCommerceApi
module JsonApiClientExtension
class Builder < ::JsonApiClient::Query::Builder
def initialize(*)
super
@temp_search_criteria = nil
def initialize(klass, opts = {})
super(klass, opts)
@temp_search_criteria = opts.fetch(:temp_search_criteria, nil)
end

def temp_search(options = {})
@temp_search_criteria = options
self
_new_scope
end

def find(args = {})
case args
when Hash
where(args)
else
@primary_key = args
when Hash
scope = where(args)
else
scope = _new_scope( primary_key: args )
end
if @temp_search_criteria.nil?
klass.requestor.get(params)
klass.requestor.get(scope.params)
else
klass.requestor.custom(:search, { request_method: :get }, params.merge(filter: @temp_search_criteria))
klass.requestor.custom(:search, { request_method: :get }, scope.params.merge(filter: @temp_search_criteria))
end
end

private

def _new_scope( opts = {} )
self.class.new( @klass,
primary_key: opts.fetch( :primary_key, @primary_key ),
pagination_params: @pagination_params.merge( opts.fetch( :pagination_params, {} ) ),
path_params: @path_params.merge( opts.fetch( :path_params, {} ) ),
additional_params: @additional_params.merge( opts.fetch( :additional_params, {} ) ),
filters: @filters.merge( opts.fetch( :filters, {} ) ),
includes: @includes + opts.fetch( :includes, [] ),
orders: @orders + opts.fetch( :orders, [] ),
fields: @fields + opts.fetch( :fields, [] ),
temp_search_criteria: @temp_search_criteria,
)
end
end
end
end
35 changes: 25 additions & 10 deletions lib/flex_commerce_api/json_api_client_extension/remote_builder.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
module FlexCommerceApi
module JsonApiClientExtension
class RemoteBuilder < ::JsonApiClient::Query::Builder
def initialize(klass, path: klass.path, connection: klass.connection)
super(klass)
self.connection = connection
self.path = path
def initialize(klass, **options)
super(klass, **options)
@connection = options[:connection]
@path = options[:path]
end

def find(args = {})
case args
when Hash
where(args)
else
@primary_key = args
when Hash
scope = where(args)
else
scope = _new_scope( primary_key: args )
end

get_request(params)
get_request(scope.params)
end

private

def get_request(params)
klass.parser.parse(klass, connection.run(:get, path, params, klass.custom_headers))
klass.parser.parse(klass, connection.run(:get, path, params: params, headers: klass.custom_headers))
end

def _new_scope( opts = {} )
self.class.new( @klass,
primary_key: opts.fetch( :primary_key, @primary_key ),
pagination_params: @pagination_params.merge( opts.fetch( :pagination_params, {} ) ),
path_params: @path_params.merge( opts.fetch( :path_params, {} ) ),
additional_params: @additional_params.merge( opts.fetch( :additional_params, {} ) ),
filters: @filters.merge( opts.fetch( :filters, {} ) ),
includes: @includes + opts.fetch( :includes, [] ),
orders: @orders + opts.fetch( :orders, [] ),
fields: @fields + opts.fetch( :fields, [] ),
connection: opts.fetch( :connection, connection),
path: opts.fetch( :path, path))
end

attr_accessor :path, :connection
end
end
Expand Down
Loading