gmc 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/gmc/client.rb +18 -15
- data/lib/gmc/configuration.rb +8 -11
- data/lib/gmc/version.rb +3 -1
- data/lib/gmc.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 379cff3820d0016b1288a7fe8d65f212942d96bf9bc8b8193f8eb9b778f31ed4
|
4
|
+
data.tar.gz: a0aecbfdc233eb525defff7775f9e71f12bdb8646e21a334f5aa2e2e27bce6c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1965454bdc78e6f1d02cef10055487f703eb7b1dbf92a29e78504d5cae93688f8d2e1d7db8fb2edd6ef2ba18fe8bcae0e1f3e9970ac7c5cb1e35a735ad626b6e
|
7
|
+
data.tar.gz: be68e871d2e2716c55f4f8be1a8f811792de44a4716e8bf539a38037f7a6caae7828aca0864142e0fb85f93262b7237ee8e314bbf448cdba677c3ac1daeb8804
|
data/lib/gmc/client.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gmc
|
4
|
+
# API endpoints of GMC
|
2
5
|
class Client
|
3
6
|
def initialize(config_arg = {})
|
4
7
|
@config = Gmc.config.reverse_duplicate_merge(config_arg)
|
@@ -15,14 +18,14 @@ module Gmc
|
|
15
18
|
body[:targetCountry] = args[:target_country] || @config.country
|
16
19
|
body[:brand] = args[:brand]
|
17
20
|
body[:feedLabel] = args[:feed_label] || @config.country
|
18
|
-
body[:channel] = args[:channel] ||
|
19
|
-
body[:availability] = args[:availability] ||
|
20
|
-
body[:condition] = args[:condition] ||
|
21
|
+
body[:channel] = args[:channel] || "online"
|
22
|
+
body[:availability] = args[:availability] || "in stock"
|
23
|
+
body[:condition] = args[:condition] || "new"
|
21
24
|
body[:price] = {}
|
22
25
|
body[:price][:currency] = args[:currency] || @config.currency
|
23
26
|
body[:price][:value] = args[:price]
|
24
27
|
|
25
|
-
call(
|
28
|
+
call("/products", body, "POST")
|
26
29
|
end
|
27
30
|
|
28
31
|
def update(**args)
|
@@ -31,17 +34,17 @@ module Gmc
|
|
31
34
|
body[:description] = args[:description]
|
32
35
|
body[:link] = args[:link]
|
33
36
|
body[:imageLink] = args[:image_link]
|
34
|
-
body[:availability] = args[:availability] ||
|
35
|
-
body[:condition] = args[:condition] ||
|
37
|
+
body[:availability] = args[:availability] || "in stock"
|
38
|
+
body[:condition] = args[:condition] || "new"
|
36
39
|
body[:price] = {}
|
37
40
|
body[:price][:currency] = args[:currency] || @config.currency
|
38
41
|
body[:price][:value] = args[:price]
|
39
42
|
|
40
|
-
call("/products/#{args[:id]}", body,
|
43
|
+
call("/products/#{args[:id]}", body, "PATCH")
|
41
44
|
end
|
42
45
|
|
43
46
|
def destroy(id)
|
44
|
-
call("/products/#{id}",
|
47
|
+
call("/products/#{id}", "DELETE")
|
45
48
|
end
|
46
49
|
|
47
50
|
def product(id)
|
@@ -54,27 +57,27 @@ module Gmc
|
|
54
57
|
|
55
58
|
private
|
56
59
|
|
57
|
-
def call(endpoint, body, method_name =
|
60
|
+
def call(endpoint, body, method_name = "GET")
|
58
61
|
url = URI("#{@config.base_url}/#{@config.merchant_id}#{endpoint}?key=#{@config.api_key}")
|
59
62
|
https = Net::HTTP.new(url.host, url.port)
|
60
63
|
https.use_ssl = true
|
61
64
|
|
62
65
|
case method_name
|
63
|
-
when
|
66
|
+
when "POST"
|
64
67
|
request = Net::HTTP::Post.new(url)
|
65
68
|
request.body = JSON.dump(body)
|
66
|
-
when
|
69
|
+
when "PATCH"
|
67
70
|
request = Net::HTTP::Patch.new(url)
|
68
71
|
request.body = JSON.dump(body)
|
69
|
-
when
|
72
|
+
when "DELETE"
|
70
73
|
request = Net::HTTP::Delete.new(url)
|
71
74
|
else
|
72
75
|
request = Net::HTTP::Get.new(url)
|
73
76
|
end
|
74
77
|
|
75
|
-
request[
|
76
|
-
request[
|
77
|
-
request[
|
78
|
+
request["Authorization"] = "Bearer #{@config.access_token}"
|
79
|
+
request["Accept"] = "application/json"
|
80
|
+
request["Content-Type"] = "application/json"
|
78
81
|
response_formate(https.request(request))
|
79
82
|
end
|
80
83
|
|
data/lib/gmc/configuration.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gmc
|
4
|
+
# Google Merchant Configuration
|
2
5
|
class Configuration
|
3
|
-
attr_accessor :merchant_id
|
4
|
-
attr_accessor :currency
|
5
|
-
attr_accessor :access_token
|
6
|
-
attr_accessor :api_key
|
7
|
-
attr_accessor :language
|
8
|
-
attr_accessor :country
|
9
|
-
attr_accessor :base_url
|
6
|
+
attr_accessor :merchant_id, :currency, :access_token, :api_key, :language, :country, :base_url
|
10
7
|
|
11
8
|
def self.setup
|
12
9
|
new.tap do |instance|
|
@@ -24,9 +21,9 @@ module Gmc
|
|
24
21
|
|
25
22
|
def initialize
|
26
23
|
@base_url = "https://shoppingcontent.googleapis.com/content/v2.1"
|
27
|
-
@country =
|
28
|
-
@currency =
|
29
|
-
@language =
|
24
|
+
@country = "AU"
|
25
|
+
@currency = "AUD"
|
26
|
+
@language = "en"
|
30
27
|
end
|
31
28
|
end
|
32
|
-
end
|
29
|
+
end
|
data/lib/gmc/version.rb
CHANGED
data/lib/gmc.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Varun Kothari
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: APIs to upload product details on the merchant center.
|
14
14
|
email:
|
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
46
|
+
rubygems_version: 3.4.10
|
47
47
|
signing_key:
|
48
48
|
specification_version: 4
|
49
49
|
summary: GMC is Google merchant API for Product
|