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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 464eb8b61fb26f7aa3406420982b8d0de03a255b33dc09a9dd45064d9c63975c
4
- data.tar.gz: 591f5c94d155770d8e3bdabc3c04657136affd6de8d9d18ffbffd29f521e068e
3
+ metadata.gz: 379cff3820d0016b1288a7fe8d65f212942d96bf9bc8b8193f8eb9b778f31ed4
4
+ data.tar.gz: a0aecbfdc233eb525defff7775f9e71f12bdb8646e21a334f5aa2e2e27bce6c0
5
5
  SHA512:
6
- metadata.gz: 4790b9416355260d75ee1d4428a46d3be156b34f02a906973ecb2101b19d3a062d3c34f87d4f7e5e01b111aba4acb6fba14103066c14ec96885f79e9b02b3b40
7
- data.tar.gz: c17250aa389968bf9f14a75ccf953a4a1f96ba60cbc42bfdb40fbff4897b46708f56b225e4111dc4c4a28af78d5ffe30bdbd96e5780f50247644e1ebe92445aa
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] || 'online'
19
- body[:availability] = args[:availability] || 'in stock'
20
- body[:condition] = args[:condition] || 'new'
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('/products', body, 'POST')
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] || 'in stock'
35
- body[:condition] = args[:condition] || 'new'
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, 'PATCH')
43
+ call("/products/#{args[:id]}", body, "PATCH")
41
44
  end
42
45
 
43
46
  def destroy(id)
44
- call("/products/#{id}", 'DELETE')
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 = 'GET')
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 'POST'
66
+ when "POST"
64
67
  request = Net::HTTP::Post.new(url)
65
68
  request.body = JSON.dump(body)
66
- when 'PATCH'
69
+ when "PATCH"
67
70
  request = Net::HTTP::Patch.new(url)
68
71
  request.body = JSON.dump(body)
69
- when 'DELETE'
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['Authorization'] = "Bearer #{@config.access_token}"
76
- request['Accept'] = 'application/json'
77
- request['Content-Type'] = 'application/json'
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
 
@@ -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 = 'AU'
28
- @currency = 'AUD'
29
- @language = 'en'
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gmc
2
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
3
5
  end
data/lib/gmc.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "gmc/version"
12
12
  require "gmc/client"
13
13
  require "gmc/configuration"
14
14
 
15
+ # Google Merchant Center
15
16
  module Gmc
16
17
  class Error < StandardError; end
17
18
  @config = Gmc::Configuration.setup
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.0
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-08 00:00:00.000000000 Z
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.2.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