flex_commerce_api 0.6.57
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +6 -0
- data/.gitignore +14 -0
- data/.rspec +4 -0
- data/.rubocop.yml +1065 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/app/models/address.rb +41 -0
- data/app/models/asset_file.rb +26 -0
- data/app/models/asset_folder.rb +14 -0
- data/app/models/bundle.rb +20 -0
- data/app/models/bundle_group.rb +15 -0
- data/app/models/cart.rb +136 -0
- data/app/models/category.rb +70 -0
- data/app/models/category_tree.rb +11 -0
- data/app/models/component.rb +8 -0
- data/app/models/container_coupon.rb +12 -0
- data/app/models/country.rb +11 -0
- data/app/models/coupon.rb +18 -0
- data/app/models/customer_account.rb +96 -0
- data/app/models/customer_account_authentication.rb +5 -0
- data/app/models/customer_segment.rb +6 -0
- data/app/models/customer_segment_member.rb +6 -0
- data/app/models/data_attribute.rb +6 -0
- data/app/models/data_store_record.rb +9 -0
- data/app/models/data_store_type.rb +9 -0
- data/app/models/discount_summary.rb +12 -0
- data/app/models/email.rb +5 -0
- data/app/models/ewis_opt_in.rb +8 -0
- data/app/models/external_url.rb +6 -0
- data/app/models/free_shipping_promotion.rb +12 -0
- data/app/models/import.rb +6 -0
- data/app/models/import_entry.rb +6 -0
- data/app/models/line_item.rb +34 -0
- data/app/models/line_item_discount.rb +7 -0
- data/app/models/markdown_price.rb +11 -0
- data/app/models/menu.rb +36 -0
- data/app/models/menu_item.rb +7 -0
- data/app/models/menu_item_item.rb +5 -0
- data/app/models/note.rb +18 -0
- data/app/models/order.rb +38 -0
- data/app/models/password_recovery.rb +20 -0
- data/app/models/payment_address_verification.rb +13 -0
- data/app/models/payment_process.rb +13 -0
- data/app/models/payment_provider.rb +15 -0
- data/app/models/payment_transaction.rb +13 -0
- data/app/models/product.rb +99 -0
- data/app/models/product_asset_file.rb +12 -0
- data/app/models/promotion.rb +19 -0
- data/app/models/promotion_qualifying_product_exclusion.rb +8 -0
- data/app/models/redirect.rb +14 -0
- data/app/models/refund.rb +14 -0
- data/app/models/remote_address.rb +22 -0
- data/app/models/remote_line_item.rb +11 -0
- data/app/models/remote_order.rb +15 -0
- data/app/models/remote_shipping_method.rb +12 -0
- data/app/models/report.rb +18 -0
- data/app/models/report_invocation.rb +18 -0
- data/app/models/retail_store.rb +18 -0
- data/app/models/role.rb +6 -0
- data/app/models/search_suggestion.rb +17 -0
- data/app/models/section.rb +9 -0
- data/app/models/session.rb +8 -0
- data/app/models/shipping_method.rb +26 -0
- data/app/models/slug.rb +19 -0
- data/app/models/static_page.rb +60 -0
- data/app/models/static_page_folder.rb +8 -0
- data/app/models/stock_level.rb +21 -0
- data/app/models/tax_code.rb +6 -0
- data/app/models/taxonomy.rb +5 -0
- data/app/models/template.rb +9 -0
- data/app/models/template_component.rb +11 -0
- data/app/models/template_definition.rb +12 -0
- data/app/models/template_section.rb +12 -0
- data/app/models/user.rb +8 -0
- data/app/models/user_profile.rb +6 -0
- data/app/models/v2/create_order.rb +10 -0
- data/app/models/v2/deallocate_order.rb +10 -0
- data/app/models/v2/line_item.rb +9 -0
- data/app/models/v2/order.rb +9 -0
- data/app/models/v2/unallocate_order.rb +10 -0
- data/app/models/variant.rb +18 -0
- data/app/models/webhook.rb +17 -0
- data/app/services/param_to_shql.rb +72 -0
- data/app/services/surrogate_keys.rb +44 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/locales/payments.en.yml +3 -0
- data/flex-commerce-api.gemspec +41 -0
- data/lib/flex_commerce.rb +95 -0
- data/lib/flex_commerce_api.rb +21 -0
- data/lib/flex_commerce_api/api_base.rb +11 -0
- data/lib/flex_commerce_api/base_resource.rb +250 -0
- data/lib/flex_commerce_api/config.rb +55 -0
- data/lib/flex_commerce_api/error/access_denied.rb +6 -0
- data/lib/flex_commerce_api/error/bad_request.rb +10 -0
- data/lib/flex_commerce_api/error/base.rb +12 -0
- data/lib/flex_commerce_api/error/client_error.rb +7 -0
- data/lib/flex_commerce_api/error/connection_error.rb +6 -0
- data/lib/flex_commerce_api/error/internal_server.rb +37 -0
- data/lib/flex_commerce_api/error/not_found.rb +13 -0
- data/lib/flex_commerce_api/error/record_invalid.rb +16 -0
- data/lib/flex_commerce_api/error/unexpected_status.rb +7 -0
- data/lib/flex_commerce_api/errors.rb +13 -0
- data/lib/flex_commerce_api/json_api_client_extension/builder.rb +28 -0
- data/lib/flex_commerce_api/json_api_client_extension/capture_surrogate_keys_middleware.rb +16 -0
- data/lib/flex_commerce_api/json_api_client_extension/flexible_connection.rb +59 -0
- data/lib/flex_commerce_api/json_api_client_extension/has_many_association_proxy.rb +60 -0
- data/lib/flex_commerce_api/json_api_client_extension/included_data.rb +27 -0
- data/lib/flex_commerce_api/json_api_client_extension/json_format_middleware.rb +20 -0
- data/lib/flex_commerce_api/json_api_client_extension/logging_middleware.rb +24 -0
- data/lib/flex_commerce_api/json_api_client_extension/paginator.rb +26 -0
- data/lib/flex_commerce_api/json_api_client_extension/parse_json.rb +23 -0
- data/lib/flex_commerce_api/json_api_client_extension/parsers/parser.rb +16 -0
- data/lib/flex_commerce_api/json_api_client_extension/previewed_request_middleware.rb +17 -0
- data/lib/flex_commerce_api/json_api_client_extension/remote_builder.rb +29 -0
- data/lib/flex_commerce_api/json_api_client_extension/requestor.rb +42 -0
- data/lib/flex_commerce_api/json_api_client_extension/save_request_body_middleware.rb +20 -0
- data/lib/flex_commerce_api/json_api_client_extension/status_middleware.rb +40 -0
- data/lib/flex_commerce_api/v2/api_base.rb +13 -0
- data/lib/flex_commerce_api/version.rb +3 -0
- data/lib/json_erb.rb +9 -0
- data/lib/json_struct.rb +73 -0
- data/lib/patches.rb +4 -0
- data/lib/patches/json_api_client/resource.rb +50 -0
- data/lib/paypal_express.rb +3 -0
- data/lib/paypal_express/additional_info.rb +45 -0
- data/lib/paypal_express/api.rb +86 -0
- data/lib/paypal_express/auth.rb +83 -0
- data/lib/paypal_express/cart_shipping_method.rb +38 -0
- data/lib/paypal_express/exception/access_denied.rb +10 -0
- data/lib/paypal_express/exception/connection_error.rb +10 -0
- data/lib/paypal_express/exception/not_authorized.rb +10 -0
- data/lib/paypal_express/exception/transaction.rb +15 -0
- data/lib/paypal_express/generate_summary.rb +118 -0
- data/lib/paypal_express/process/paypal_params.rb +123 -0
- data/lib/paypal_express/process/response_parser.rb +146 -0
- data/lib/paypal_express/setup.rb +94 -0
- data/lib/paypal_express/shipping_methods_for_cart.rb +46 -0
- data/lib/retry.rb +20 -0
- data/schemas/jsonapi/schema.json +370 -0
- data/schemas/shift/v1/documents/collection/address.json +45 -0
- data/schemas/shift/v1/documents/collection/asset_file.json +43 -0
- data/schemas/shift/v1/documents/collection/asset_folder.json +43 -0
- data/schemas/shift/v1/documents/collection/customer_account.json +50 -0
- data/schemas/shift/v1/documents/collection/markdown_price.json +43 -0
- data/schemas/shift/v1/documents/collection/product.json +43 -0
- data/schemas/shift/v1/documents/collection/variant.json +43 -0
- data/schemas/shift/v1/documents/member/address.json +39 -0
- data/schemas/shift/v1/documents/member/asset_file.json +37 -0
- data/schemas/shift/v1/documents/member/asset_folder.json +39 -0
- data/schemas/shift/v1/documents/member/customer_account.json +44 -0
- data/schemas/shift/v1/documents/member/markdown_price.json +37 -0
- data/schemas/shift/v1/documents/member/product.json +39 -0
- data/schemas/shift/v1/documents/member/variant.json +46 -0
- data/schemas/shift/v1/resources/address.json +130 -0
- data/schemas/shift/v1/resources/asset_file.json +146 -0
- data/schemas/shift/v1/resources/asset_folder.json +188 -0
- data/schemas/shift/v1/resources/customer_account.json +339 -0
- data/schemas/shift/v1/resources/markdown_price.json +52 -0
- data/schemas/shift/v1/resources/product.json +230 -0
- data/schemas/shift/v1/resources/variant.json +298 -0
- data/tasks/json_schema.thor +275 -0
- data/todo.md +8 -0
- metadata +470 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
module FlexCommerceApi
|
2
|
+
module Error
|
3
|
+
class InternalServer < Base
|
4
|
+
def message
|
5
|
+
body = response_env.fetch(:body, {"errors" => []})
|
6
|
+
error = extract_error(body)
|
7
|
+
return "Internal server error" unless error.present?
|
8
|
+
if error.is_a?(::Enumerable)
|
9
|
+
title = error.fetch("title", "")
|
10
|
+
detail = error.fetch("detail", "")
|
11
|
+
meta = error.fetch("meta", {})
|
12
|
+
exception = meta.fetch("exception", "")
|
13
|
+
backtrace = meta.fetch("backtrace", [])
|
14
|
+
event_id = meta.fetch("event_id", "")
|
15
|
+
"Internal server error - #{title} #{detail} #{event_id} #{exception} #{backtrace}"
|
16
|
+
else
|
17
|
+
"Internal server error - #{error}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def raven_context
|
22
|
+
{
|
23
|
+
extra: {
|
24
|
+
body: response_env[:body]
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def extract_error(body)
|
32
|
+
return body if body.is_a?(::String)
|
33
|
+
body["message"] || body["errors"]&.first
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module FlexCommerceApi
|
2
|
+
module Error
|
3
|
+
class RecordInvalid < Base
|
4
|
+
attr_reader :record
|
5
|
+
|
6
|
+
def initialize(record)
|
7
|
+
@record = record
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"Record Invalid - #{record.errors.full_messages.join(", ")}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module FlexCommerceApi
|
2
|
+
module Error
|
3
|
+
autoload :Base, File.expand_path(File.join("error", "base"), __dir__)
|
4
|
+
autoload :ClientError, File.expand_path(File.join("error", "client_error"), __dir__)
|
5
|
+
autoload :ConnectionError, File.expand_path(File.join("error", "connection_error"), __dir__)
|
6
|
+
autoload :InternalServer, File.expand_path(File.join("error", "internal_server"), __dir__)
|
7
|
+
autoload :UnexpectedStatus, File.expand_path(File.join("error", "unexpected_status"), __dir__)
|
8
|
+
autoload :NotFound, File.expand_path(File.join("error", "not_found"), __dir__)
|
9
|
+
autoload :AccessDenied, File.expand_path(File.join("error", "access_denied"), __dir__)
|
10
|
+
autoload :RecordInvalid, File.expand_path(File.join("error", "record_invalid"), __dir__)
|
11
|
+
autoload :BadRequest, File.expand_path(File.join("error", "bad_request"), __dir__)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module FlexCommerceApi
|
2
|
+
module JsonApiClientExtension
|
3
|
+
class Builder < ::JsonApiClient::Query::Builder
|
4
|
+
def initialize(*)
|
5
|
+
super
|
6
|
+
@temp_search_criteria = nil
|
7
|
+
end
|
8
|
+
def temp_search(options = {})
|
9
|
+
@temp_search_criteria = options
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(args = {})
|
14
|
+
case args
|
15
|
+
when Hash
|
16
|
+
where(args)
|
17
|
+
else
|
18
|
+
@primary_key = args
|
19
|
+
end
|
20
|
+
if @temp_search_criteria.nil?
|
21
|
+
klass.requestor.get(params)
|
22
|
+
else
|
23
|
+
klass.requestor.custom(:search, { request_method: :get }, params.merge(filter: @temp_search_criteria))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Captures surrogate keys headers and collects them for passing to the client.
|
2
|
+
module FlexCommerceApi
|
3
|
+
module JsonApiClientExtension
|
4
|
+
class CaptureSurrogateKeysMiddleware < ::Faraday::Middleware
|
5
|
+
def call(environment)
|
6
|
+
@app.call(environment).on_complete do |env|
|
7
|
+
surrogate_keys = env.response_headers['external-surrogate-key'].split(' ') if env.response_headers['external-surrogate-key']
|
8
|
+
|
9
|
+
if surrogate_keys && Thread.current[:shift_surrogate_keys]
|
10
|
+
Thread.current[:shift_surrogate_keys].concat(surrogate_keys)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'faraday-http-cache'
|
2
|
+
|
3
|
+
module FlexCommerceApi
|
4
|
+
module JsonApiClientExtension
|
5
|
+
class FlexibleConnection < JsonApiClient::Connection
|
6
|
+
attr_accessor :last_response
|
7
|
+
def initialize(options = {})
|
8
|
+
site = options.fetch(:site)
|
9
|
+
adapter_options = Array(options.fetch(:adapter, Faraday.default_adapter))
|
10
|
+
add_json_api_extension = options.fetch(:add_json_api_extension, true)
|
11
|
+
authenticate = options.fetch(:authenticate, true)
|
12
|
+
include_previewed = options.fetch :include_previewed, false
|
13
|
+
@faraday = Faraday.new(site) do |builder|
|
14
|
+
builder.request :json
|
15
|
+
builder.use JsonApiClientExtension::SaveRequestBodyMiddleware
|
16
|
+
builder.use JsonApiClientExtension::JsonFormatMiddleware if add_json_api_extension
|
17
|
+
builder.use JsonApiClientExtension::PreviewedRequestMiddleware if include_previewed
|
18
|
+
builder.use JsonApiClient::Middleware::JsonRequest
|
19
|
+
# Surrogate Key middleware should always be above HTTP caching to ensure we're reading headers
|
20
|
+
# from the original response not the 304 responses
|
21
|
+
builder.use JsonApiClientExtension::CaptureSurrogateKeysMiddleware
|
22
|
+
# disable the cache when HTTP cache is set to false
|
23
|
+
unless false == options[:http_cache]
|
24
|
+
builder.use :http_cache, cache_options(options)
|
25
|
+
end
|
26
|
+
builder.use JsonApiClientExtension::StatusMiddleware
|
27
|
+
builder.use JsonApiClient::Middleware::ParseJson
|
28
|
+
builder.use JsonApiClientExtension::LoggingMiddleware unless FlexCommerceApi.logger.nil?
|
29
|
+
builder.adapter *adapter_options
|
30
|
+
builder.options[:open_timeout] = options.fetch(:open_timeout)
|
31
|
+
builder.options[:timeout] = options.fetch(:timeout)
|
32
|
+
end
|
33
|
+
faraday.basic_auth(ApiBase.username, ApiBase.password) if authenticate
|
34
|
+
|
35
|
+
yield(self) if block_given?
|
36
|
+
end
|
37
|
+
|
38
|
+
def run(*args)
|
39
|
+
super.tap do |response|
|
40
|
+
self.last_response = response
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def cache_options(options)
|
46
|
+
{
|
47
|
+
# treats the cache like a client, not a proxy
|
48
|
+
shared_cache: false,
|
49
|
+
# use the Rails cache, if set, otherwise default to MemoryStore
|
50
|
+
store: defined?(::Rails) ? ::Rails.cache : nil,
|
51
|
+
# serialize the data using Marshal
|
52
|
+
serializer: Marshal,
|
53
|
+
# use our configured logger
|
54
|
+
logger: FlexCommerceApi.logger
|
55
|
+
}.merge(options.fetch(:http_cache, {}))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "active_support/core_ext/module/delegation"
|
2
|
+
|
3
|
+
module FlexCommerceApi
|
4
|
+
module JsonApiClientExtension
|
5
|
+
class HasManyAssociationProxy
|
6
|
+
def initialize(real_instance, container_instance, association_name, options)
|
7
|
+
self.real_instance = real_instance
|
8
|
+
self.container_instance = container_instance
|
9
|
+
self.association_name = association_name
|
10
|
+
self.options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
delegate :empty?, :each, :each_with_index, :length, :count, :map, :select, :detect, :first, :last, :[], :any?, to: :real_instance
|
14
|
+
#
|
15
|
+
# Finds an instance by primary key
|
16
|
+
#
|
17
|
+
# @param [Integer|Number|Float] pk The primary key value to be found
|
18
|
+
# @return The resource found or nil if not found
|
19
|
+
def find(pk)
|
20
|
+
method = primary_key
|
21
|
+
real_instance.detect {|i| i.send(method) == pk}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Creates a new associated item - if the option "inverse_of" is specified, then
|
25
|
+
# automatically create a relationship back to the container with the name
|
26
|
+
# specified in "inverse_of"
|
27
|
+
def new(attrs)
|
28
|
+
my_attrs = attrs.dup
|
29
|
+
if options.key?(:inverse_of)
|
30
|
+
my_attrs[:relationships] ||= {}
|
31
|
+
# Dont modify the original relationship if it was present below
|
32
|
+
my_attrs[:relationships] = my_attrs[:relationships].merge(options[:inverse_of] => container_instance)
|
33
|
+
end
|
34
|
+
association.association_class.new(my_attrs)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create(attrs)
|
38
|
+
new(attrs).tap do |instance|
|
39
|
+
instance.save
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_a
|
44
|
+
real_instance
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def association
|
50
|
+
container_instance.class.associations.detect {|a| a.attr_name == association_name.to_sym}
|
51
|
+
end
|
52
|
+
|
53
|
+
def primary_key
|
54
|
+
association.association_class.primary_key
|
55
|
+
end
|
56
|
+
|
57
|
+
attr_accessor :real_instance, :container_instance, :association_name, :options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'json_api_client/included_data'
|
2
|
+
|
3
|
+
module FlexCommerceApi
|
4
|
+
module JsonApiClientExtension
|
5
|
+
class IncludedData < ::JsonApiClient::IncludedData
|
6
|
+
def initialize(result_set, *args)
|
7
|
+
super(result_set, *args)
|
8
|
+
@result_set = result_set
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# attempt to load the record from included data first, failing that, look
|
14
|
+
# in the root resource(s) for the record
|
15
|
+
def record_for(link_def)
|
16
|
+
data.dig(link_def["type"], link_def["id"]) || root_record_for(link_def)
|
17
|
+
end
|
18
|
+
|
19
|
+
def root_record_for(link_def)
|
20
|
+
@result_set.find do |resource|
|
21
|
+
resource.attributes["type"] == link_def["type"] &&
|
22
|
+
resource.attributes["id"] == link_def["id"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module FlexCommerceApi
|
2
|
+
module JsonApiClientExtension
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# @!visibility private
|
6
|
+
# This class is used internally to modify the URL to have .json at the end to
|
7
|
+
# suit the flex platform.
|
8
|
+
class JsonFormatMiddleware < ::Faraday::Middleware
|
9
|
+
#
|
10
|
+
# Adds .json to the URL before it gets sent
|
11
|
+
#
|
12
|
+
def call(env)
|
13
|
+
env.url.tap do |url|
|
14
|
+
url.path << ".json_api" unless url.path=~/\.json_api$/
|
15
|
+
end
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module FlexCommerceApi
|
2
|
+
module JsonApiClientExtension
|
3
|
+
#
|
4
|
+
#
|
5
|
+
class LoggingMiddleware < ::Faraday::Middleware
|
6
|
+
attr_accessor :request_id, :logger
|
7
|
+
def initialize(*args)
|
8
|
+
super
|
9
|
+
self.request_id = 0
|
10
|
+
self.logger = FlexCommerceApi.logger
|
11
|
+
end
|
12
|
+
#
|
13
|
+
#
|
14
|
+
def call(env)
|
15
|
+
self.request_id += 1
|
16
|
+
@app.call(env).on_complete do |response_env|
|
17
|
+
logger.debug("FlexApi::Request id #{request_id} #{env.method.to_s.upcase} #{env.url} started at #{Time.now}")
|
18
|
+
logger.debug("\t >>> #{env[:request_body]}") unless env[:request_body].nil? || env[:request_body].empty?
|
19
|
+
logger.debug("\t <<< (#{env[:status]}) #{env.body}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module FlexCommerceApi
|
2
|
+
module JsonApiClientExtension
|
3
|
+
# @!visibility private
|
4
|
+
# This class overrides the default paginator to allow for
|
5
|
+
# the custom things that are required by the flex platform.
|
6
|
+
# This class is private and should not be used by end users
|
7
|
+
class Paginator < ::JsonApiClient::Paginating::Paginator
|
8
|
+
|
9
|
+
def current_page
|
10
|
+
params.fetch("page[number]", 1).to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
def total_pages
|
14
|
+
result_set.meta.page_count
|
15
|
+
end
|
16
|
+
|
17
|
+
def total_entries
|
18
|
+
result_set.meta.total_entries
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# This module extends json_api_client's ParseJson service
|
2
|
+
# to make sure malformed repsonse bodies is always included as context in
|
3
|
+
# the thrown error message when json parsing fails.
|
4
|
+
module FlexCommerceApi
|
5
|
+
module JsonApiClientExtension
|
6
|
+
module ParseJson
|
7
|
+
def call(environment)
|
8
|
+
super
|
9
|
+
rescue JSON::ParserError => error
|
10
|
+
error.define_singleton_method(:raven_context) do
|
11
|
+
{
|
12
|
+
extra: {
|
13
|
+
body: environment.body
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
raise
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
JsonApiClient::Middleware::ParseJson.send :prepend, FlexCommerceApi::JsonApiClientExtension::ParseJson
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "../included_data"
|
2
|
+
|
3
|
+
module FlexCommerceApi
|
4
|
+
module JsonApiClientExtension
|
5
|
+
module Parsers
|
6
|
+
class Parser < ::JsonApiClient::Parsers::Parser
|
7
|
+
class << self
|
8
|
+
def handle_included(result_set, data)
|
9
|
+
result_set.included = ::FlexCommerceApi::JsonApiClientExtension::IncludedData.new(result_set, data.fetch("included", []))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rack/utils"
|
2
|
+
|
3
|
+
# Adds preview param to all requests to Flex API.
|
4
|
+
module FlexCommerceApi
|
5
|
+
module JsonApiClientExtension
|
6
|
+
class PreviewedRequestMiddleware < ::Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
env.url.tap do |url|
|
9
|
+
parsed_query = Rack::Utils.parse_nested_query url.query
|
10
|
+
parsed_query[:preview] = true
|
11
|
+
url.query = parsed_query.to_param
|
12
|
+
end
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|