gmc 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 464eb8b61fb26f7aa3406420982b8d0de03a255b33dc09a9dd45064d9c63975c
4
- data.tar.gz: 591f5c94d155770d8e3bdabc3c04657136affd6de8d9d18ffbffd29f521e068e
3
+ metadata.gz: 23deb5b73592b26e9ba1a1c03c08a3db63c8406a750f3567f35d461ab0917fb2
4
+ data.tar.gz: a606c12fec600d40c50a826389de62df317ca8e452a17e21c311ee337f6b63bf
5
5
  SHA512:
6
- metadata.gz: 4790b9416355260d75ee1d4428a46d3be156b34f02a906973ecb2101b19d3a062d3c34f87d4f7e5e01b111aba4acb6fba14103066c14ec96885f79e9b02b3b40
7
- data.tar.gz: c17250aa389968bf9f14a75ccf953a4a1f96ba60cbc42bfdb40fbff4897b46708f56b225e4111dc4c4a28af78d5ffe30bdbd96e5780f50247644e1ebe92445aa
6
+ metadata.gz: 86158b367116a1f58e796cf446b2b45e0d5ac3e8de7f1b4ff2b8535339c14eae733350f8ec699d38ee59d0c44ebfbbda16a2b20b0517a4a7ad4084d0620905d1
7
+ data.tar.gz: 88b7483d0af10209ce3713e768cff06a05c7e8350fc62237736b240f856ab983b39ec2fbacf985865125962521ae543e4f9079e02ac68676c62a2196b26f4cd6
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.2"
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
@@ -29,5 +30,9 @@ module Gmc
29
30
  def_delegators :@config, :access_token, :access_token=
30
31
  def_delegators :@config, :api_key, :api_key=
31
32
  def_delegators :@config, :base_url, :base_url=
33
+
34
+ def setup
35
+ yield self
36
+ end
32
37
  end
33
38
  end
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.2
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-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: APIs to upload product details on the merchant center.
14
14
  email:
@@ -36,14 +36,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '2.5'
39
+ version: '2.4'
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  version: '0'
45
45
  requirements: []
46
- rubygems_version: 3.2.3
46
+ rubygems_version: 3.2.33
47
47
  signing_key:
48
48
  specification_version: 4
49
49
  summary: GMC is Google merchant API for Product