spreadshop_client 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61d1e29aeef3a14d5174d64c269f579db384d55a904ed06f9f2db2eb29313dc0
4
- data.tar.gz: 03cf50bba404559089f63d3ab2fe12462921f2d80d366b8399d6412433b07cd4
3
+ metadata.gz: e36079277ca7c86a4202b90b10e3155fa570b47c8922b1b6e97af6f84d6623bc
4
+ data.tar.gz: 7a21faffddce4b89f0cb2a8b6426a9e6f20c32ab1ef3c39d93640b5464231230
5
5
  SHA512:
6
- metadata.gz: 2eb595decdecb9bc0651f0db35fc15c8d27c45699ecb2cadac39839047b52931ed68dc5fffaf8d40fc192e60055ffc0906a7ec1fb3c9f3c2e008caf45f7004c0
7
- data.tar.gz: 07b908a8785890ec264189b8e68c224ea13e3e46799f08804f13311b424db8c8c67b4df74d48268238118d1134c7e287dbafbf883b29f4c4f6dc76896bb90d5c
6
+ metadata.gz: b0fb8b2e877eb2fc4bc34cf75b8f55569b14daa6f46c21d275a99da9dcb0173dd13cec2cd1a556b7e0052bd934d401eba39ea9423646f81d757cd43c329f6fc0
7
+ data.tar.gz: 4fd129760e341d9bd8bb1569bff1801fb521093a5d7207c710785beb13db5a6ddca9002ce3ceb8988d61332cacb5055fb038802cc213cf38080dde13ccbaa93d
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
- ## [Unreleased]
1
+ ## [Released]
2
2
 
3
3
  ## [0.0.1] - 2025-01-25
4
4
 
5
5
  - Initial release
6
6
  - It is possible to get the Shop id and name
7
+
8
+ ## [0.0.2] - 2025-01-27
9
+
10
+ - Add Products query
11
+ - It is possible to get the products and products by id
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SpreadshopClient
2
2
 
3
-
3
+ [![Gem Version](https://badge.fury.io/rb/spreadshop_client.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/spreadshop_client)
4
4
  [![Build Status](https://github.com/paderich/spreadshop_client/actions/workflows/main.yml/badge.svg)](https://github.com/paderich/spreadshop_client/actions)
5
5
 
6
6
  `SpreadshopClient` is a Ruby gem that provides a convenient interface for interacting with the Spreadshop GraphQL API. It simplifies fetching shop data by encapsulating the necessary queries and handling the API communication, making it easy to integrate into your Ruby projects or Rails applications.
@@ -22,6 +22,8 @@ Or install it yourself as:
22
22
  gem install spreadshop_client
23
23
  ```
24
24
  ## Usage
25
+
26
+ ### Fetch Shop
25
27
  Here's an example of how to use the SpreadshopClient gem to fetch shop details:
26
28
  ```ruby
27
29
  require 'spreadshop_client'
@@ -42,6 +44,43 @@ else
42
44
  end
43
45
  ```
44
46
 
47
+ ### Fetching Products
48
+ To fetch all products from a shop, you can use the SpreadshopClient as follows:
49
+ ```ruby
50
+ require 'spreadshop_client'
51
+
52
+ shop_id = "1394271" # Replace with the actual shop ID
53
+ platform = "EU" # Replace with the platform
54
+ locale = "de_DE" # Replace with the locale
55
+
56
+ products = SpreadshopClient::Product.get_all(shop_id: shop_id, platform: platform, locale: locale)
57
+
58
+ if products.is_a?(Array)
59
+ puts "Number of Products: #{products.size}"
60
+
61
+ first_product = products.first
62
+ puts "First Product ID: #{first_product.id}"
63
+ puts "First Product Name: #{first_product.name}"
64
+ else
65
+ puts "Error fetching products: #{products[:error]}"
66
+ end
67
+ ```
68
+
69
+ To fetch a specific product by ID:
70
+ ```ruby
71
+ product_id = "12345" # Replace with the actual product ID
72
+
73
+ product = SpreadshopClient::Product.get_by_id(product_id: product_id, shop_id: shop_id, platform: platform, locale: locale)
74
+
75
+ if product.is_a?(SpreadshopClient::Product)
76
+ puts "Product ID: #{product.id}"
77
+ puts "Product Name: #{product.name}"
78
+ else
79
+ puts "Error fetching product by ID: #{product[:error]}"
80
+ end
81
+ ```
82
+
83
+
45
84
  ## Development and Testing
46
85
  ### Run Tests:
47
86
  ```ruby
@@ -0,0 +1,39 @@
1
+ require_relative "../client"
2
+
3
+ module SpreadshopClient
4
+ module Models
5
+ class ProductModel
6
+ include ProductsQueries
7
+
8
+ attr_reader :id, :name, :image, :price
9
+
10
+ def initialize(attributes)
11
+ @id = attributes["id"]
12
+ @name = attributes["name"]
13
+ @image = attributes["image"] || {}
14
+ @price = attributes["price"] || {}
15
+ end
16
+
17
+ def self.get_all(shop_id:, platform:, locale:)
18
+ response = SpreadshopClient::Client.query(GET_PRODUCTS, {shopId: shop_id, platform: platform, locale: locale})
19
+
20
+ if response["data"] && response["data"]["products"]
21
+ response["data"]["products"]["items"].map { |item| new(item) }
22
+ else
23
+ {error: response["errors"] || "Unknown error"}
24
+ end
25
+ end
26
+
27
+ def self.get_by_id(product_id:, shop_id:, platform:, locale:)
28
+ response = SpreadshopClient::Client.query(GET_PRODUCTS, {shopId: shop_id, platform: platform, locale: locale})
29
+
30
+ # Safely navigate through the response using dig
31
+ items = response.dig("data", "products", "items") || []
32
+ item = items.find { |item| item["id"] == product_id }
33
+
34
+ # Return a new instance if found, otherwise return nil
35
+ item ? new(item) : nil
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ module SpreadshopClient
2
+ module Models
3
+ module ProductsQueries
4
+ GET_PRODUCTS = <<~GQL.strip
5
+ query($shopId: ID!, $platform: Platform!, $locale: Locale!) {
6
+ products(shopId: $shopId, platform: $platform, locale: $locale) {
7
+ items {
8
+ id
9
+ name
10
+ image {
11
+ src
12
+ srcset
13
+ altText
14
+ format
15
+ }
16
+ price {
17
+ vatExcluded
18
+ vatIncluded
19
+ vatAmount
20
+ }
21
+ }
22
+ }
23
+ }
24
+ GQL
25
+ end
26
+ end
27
+ end
@@ -1,23 +1,24 @@
1
- require_relative "../queries/shop_queries"
2
1
  require_relative "../client"
3
2
 
4
3
  module SpreadshopClient
5
- class Shop
6
- include SpreadshopClient::Queries::ShopQueries
4
+ module Models
5
+ class ShopModel
6
+ include SpreadshopClient::Models::ShopQueries
7
7
 
8
- attr_reader :id, :name
8
+ attr_reader :id, :name
9
9
 
10
- def initialize(attributes)
11
- @id = attributes["id"]
12
- @name = attributes["name"]
13
- end
10
+ def initialize(attributes)
11
+ @id = attributes["id"]
12
+ @name = attributes["name"]
13
+ end
14
14
 
15
- def self.get_shop(name:, platform:, locale:)
16
- response = SpreadshopClient::Client.query(GET_SHOP, {name: name, platform: platform, locale: locale})
17
- if response["data"] && response["data"]["shop"]
18
- new(response["data"]["shop"])
19
- else
20
- {error: response["errors"] || "Unknown error"}
15
+ def self.get_shop(name:, platform:, locale:)
16
+ response = SpreadshopClient::Client.query(GET_SHOP, {name: name, platform: platform, locale: locale})
17
+ if response["data"] && response["data"]["shop"]
18
+ new(response["data"]["shop"])
19
+ else
20
+ {error: response["errors"] || "Unknown error"}
21
+ end
21
22
  end
22
23
  end
23
24
  end
@@ -1,5 +1,5 @@
1
1
  module SpreadshopClient
2
- module Queries
2
+ module Models
3
3
  module ShopQueries
4
4
  GET_SHOP = <<~GQL.strip
5
5
  query($name: String!, $platform: Platform!, $locale: Locale!) {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SpreadshopClient
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
@@ -3,12 +3,27 @@
3
3
  $LOAD_PATH.unshift(File.expand_path("..", __dir__))
4
4
 
5
5
  require "spreadshop_client/version"
6
+ require "spreadshop_client/models/shop_queries"
7
+ require "spreadshop_client/models/product_queries"
6
8
  require "spreadshop_client/models/shop"
9
+ require "spreadshop_client/models/product"
7
10
 
8
11
  module SpreadshopClient
9
12
  class Error < StandardError; end
10
13
 
11
- def self.get_shop(name:, platform:, locale:)
12
- Shop.get_shop(name: name, platform: platform, locale: locale)
14
+ module Shop
15
+ def self.get_shop(name:, platform:, locale:)
16
+ SpreadshopClient::Models::ShopModel.get_shop(name: name, platform: platform, locale: locale)
17
+ end
18
+ end
19
+
20
+ module Product
21
+ def self.get_all(shop_id:, platform:, locale:)
22
+ SpreadshopClient::Models::ProductModel.get_all(shop_id: shop_id, platform: platform, locale: locale)
23
+ end
24
+
25
+ def self.get_by_id(product_id:, shop_id:, platform:, locale:)
26
+ SpreadshopClient::Models::ProductModel.get_by_id(product_id: product_id, shop_id: shop_id, platform: platform, locale: locale)
27
+ end
13
28
  end
14
29
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadshop_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paderich
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-01-25 00:00:00.000000000 Z
10
+ date: 2025-01-27 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: This gems provides a client for the Spreadshop GraphQL API.
13
13
  email:
@@ -24,8 +24,10 @@ files:
24
24
  - Rakefile
25
25
  - lib/spreadshop_client.rb
26
26
  - lib/spreadshop_client/client.rb
27
+ - lib/spreadshop_client/models/product.rb
28
+ - lib/spreadshop_client/models/product_queries.rb
27
29
  - lib/spreadshop_client/models/shop.rb
28
- - lib/spreadshop_client/queries/shop_queries.rb
30
+ - lib/spreadshop_client/models/shop_queries.rb
29
31
  - lib/spreadshop_client/version.rb
30
32
  - sig/spreadshop_client.rbs
31
33
  homepage: https://github.com/paderich/spreadshop_client