Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ end

group :test do
gem "factory_bot"
gem "jwt"
gem "vcr"
gem "webmock"
end
24 changes: 9 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (7.2.0)
activesupport (7.1.3.4)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
coderay (1.1.3)
concurrent-ruby (1.3.4)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
Expand All @@ -50,16 +49,15 @@ GEM
i18n (1.14.5)
concurrent-ruby (~> 1.0)
json (2.7.2)
jwt (2.8.2)
base64
language_server-protocol (3.17.0.3)
logger (1.6.0)
method_source (1.1.0)
minitest (5.24.1)
mutex_m (0.2.0)
net-http (0.4.1)
uri
parallel (1.26.2)
parser (3.3.4.2)
parallel (1.25.1)
parser (3.3.4.0)
ast (~> 2.4.1)
racc
pry (0.14.2)
Expand All @@ -70,7 +68,7 @@ GEM
rainbow (3.1.1)
rake (10.5.0)
regexp_parser (2.9.2)
rexml (3.3.5)
rexml (3.3.4)
strscan
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand Down Expand Up @@ -110,13 +108,11 @@ GEM
rubocop-rspec_rails (2.29.1)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
securerandom (0.3.1)
strscan (3.1.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
uri (0.13.0)
vcr (6.2.0)
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
Expand All @@ -134,13 +130,11 @@ DEPENDENCIES
dotenv (~> 2.7)
factory_bot
faker (~> 2.2)
jwt
pry
rake (~> 10.0)
rspec (~> 3.0)
rubocop
rubocop-rspec (~> 2.4)
vcr
webmock
yard (~> 0.9)

Expand Down
3 changes: 3 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ unless ENV["CLIENT_ID"].nil? && ENV["CLIENT_SECRET"].nil?
BeyondApi.setup do |config|
config.client_id = ENV["CLIENT_ID"]
config.client_secret = ENV["CLIENT_SECRET"]
config.remove_response_links = true
config.remove_response_key_underscores = true
config.object_struct_responses = false
end
end

Expand Down
9 changes: 0 additions & 9 deletions lib/beyond_api/concerns/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ def get(path, params = {})
handle_request { agent.get(path, parse_request(params)) }
end

def put(path, body = {}, params = {})
handle_request do
agent.put(path, body) do |request|
request.params = parse_request(params)
request.body = parse_request(body)
end
end
end

def post(path, body = {}, params = {})
handle_request do
agent.post(path, body) do |request|
Expand Down
4 changes: 2 additions & 2 deletions lib/beyond_api/services/authentication/signer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def create
post("signers")
end

def delete(id)
super("signers/#{id}") # Concerns::Connection delete method
def destroy(id)
delete("signers/#{id}")
end
end
end
Expand Down
16 changes: 0 additions & 16 deletions lib/beyond_api/services/product_management/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@ class Category < BaseService
def find(id)
get("categories/#{id}")
end

def all(params = {})
fetch_all_pages("categories", params)
end

def create(body)
post("categories", body)
end

def update(id, body)
put("categories/#{id}", body)
end

def delete(id)
super("categories/#{id}") # Concerns::Connection delete method
end
end
end
end
2 changes: 1 addition & 1 deletion lib/beyond_api/services/product_management/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module BeyondApi
module ProductManagement
class Image < BaseService
def all(id, params = {})
get("products/#{id}/images", params)
get("products/#{id}/images")
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions lib/beyond_api/services/product_management/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ module BeyondApi
module ProductManagement
class Product < BaseService
def all(params = {})
fetch_all_pages("products", params)
end

def create(body)
post("products", body)
fetch_all_pages("/products", params)
end

def find(id)
Expand Down
2 changes: 1 addition & 1 deletion lib/beyond_api/services/product_management/variation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module BeyondApi
module ProductManagement
class Variation < BaseService
def all(id, params = {})
get("products/#{id}/variations", params)
get("products/#{id}/variations")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/beyond_api/services/storefront/script_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def create(script_url)
post("script-tags", script_url:)
end

def delete(id)
super("script-tags/#{id}") # Concerns::Connection delete method
def destroy(id)
delete("script-tags/#{id}")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/beyond_api/services/webhook/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def create(body)

def delete_all
all.dig(:embedded, :subscriptions).each do |subscription|
delete(subscription[:id])
destroy(subscription[:id])
end
end

def delete(id)
super("webhook-subscriptions/#{id}") # Concerns::Connection delete method
def destroy(id)
delete("webhook-subscriptions/#{id}")
end

def find(id)
Expand Down
78 changes: 78 additions & 0 deletions spec/beyond_api/resources/products_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# frozen_string_literal: true

RSpec.describe 'BeyondApi::Products' do
let!(:session) do
session = BeyondApi::Session.new(api_url: ENV["SHOP_URL"])
session.token.client_credentials
end

let(:product) { @product = session.products.create(FactoryBot.build(:product)) }

let!(:file_path) do
app_root = File.expand_path(File.dirname("ext.rb"))
"#{app_root}/spec/files/"
end

describe "non existing product" do
it "create a new regular product and " do
product = session.products.create(FactoryBot.build(:product))

expect(product).not_to be nil
expect(product.id).not_to be nil
end
end


describe "product exist" do
it "find a product sending an ID" do
response = session.products.find(product.id)
expect(response).not_to be nil
expect(response.id).to eq(product.id)
end


it "upload multiple images" do
files = [
"#{file_path}image1.png",
"#{file_path}image2.png"
]

images = session.products.upload_multiple_images(product.id,
files,
["image1.png", "image2.png"])
expect(images).not_to be nil
expect(images.embedded.images.is_a?(Array)).to eq true
end

it "upload a single image" do
file = "#{file_path}image1.png"

image = session.products.upload_image(product.id, file, "image3.png")
expect(image).not_to be nil
expect(image).to eq true
end

it "sort product images" do
files = [
"#{file_path}image1.png",
"#{file_path}image2.png"
]

session.products.upload_multiple_images(product.id,
files,
["image1.png", "image2.png"])

images = session.products.images(product.id)

images_sorted = images.embedded.images.sort_by(&:position).reverse.map(&:id)

sorted = session.products.sort_images(product.id, images_sorted)

images = session.products.images(product.id)

expect(sorted).not_to be nil
expect(sorted).to eq true
expect(images.embedded.images.map(&:id)).to eq images_sorted
end
end
end
15 changes: 15 additions & 0 deletions spec/beyond_api/resources/products_view_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
RSpec.describe 'BeyondApi::ProductsView' do
let!(:session) do
session = BeyondApi::Session.new(api_url: ENV["SHOP_URL"])
session.token.client_credentials
end

let(:product) { @product = session.products.create(FactoryBot.build(:product)) }

it "list products with specific tag" do
response = session.products_view.search_by_tag("beyond_api-ruby_client")
expect(response).not_to be nil
expect(response.embedded.products.class).to be(Array)
expect(response.embedded.products.size).to be >= 1
end
end
Loading