api_duonghds 0.4.0 → 1.1.0

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: 5be8266c2a53ab0a1ecdf9cedd1165d80e4f2e04de37a1da42b01582070df4cf
4
- data.tar.gz: d055c57e2f47a53c2a58bed7aa2934f46f10a321c5de728e2b92c12570638f91
3
+ metadata.gz: 1f9667a0babdf6560fad87cf3252fe45001583548ec4845b73b2ddc2b2e6fc0a
4
+ data.tar.gz: 4ff37c92ef962d163d622444893de2b17e7cd4cfb698c07b8242de0a5509a6cc
5
5
  SHA512:
6
- metadata.gz: 2dd493585df5416fae3f50c0098b2d46e08c4a959890bae49be1c76ae9f9021926a92bcfe78890aeaa180b28ef9176609a13730b86d11aa0de6b61c5f8553dcb
7
- data.tar.gz: 495f008c268515382107ebb90de3e662195da5031ea89fb2b70eb02731034bdc37bd6fc8f877e069d2d62e65ffd2316ee5865c32d6a45b4385b406d500b22076
6
+ metadata.gz: d04f104d0dbd4774fa95136b84636c5a3075001a8ac88479cc26486b038d71d7ec125e64f206d6a490279ebdfaa5ef16f431fe96d9caff0c931791dcd2dde70c
7
+ data.tar.gz: ff74a5a02633cbeb50e085dcdcb6cb7b2b819400ab9e1183ed28c0ebfcd87cda1c2b818a340a51f47743966c56aff24c683eb0ad4a94dbc2a0c237f41375f7bc
data/api_duonghds.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Write a longer description or delete this line."
13
13
  spec.homepage = "https://duonghds.com"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.6.0"
15
+ spec.required_ruby_version = ">= 2.7.8"
16
16
 
17
17
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
18
18
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiDuonghds
4
- VERSION = "0.4.0"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/api_duonghds.rb CHANGED
@@ -3,8 +3,45 @@ require 'uri'
3
3
  require 'json'
4
4
 
5
5
  module ApiDuonghds
6
+ # A simple struct representing a product.
7
+ class Product
8
+ # @return [Integer] The unique identifier of the product.
9
+ attr_accessor :id
10
+ # @return [String] The title.
11
+ attr_accessor :title
12
+ # @return [Float] The price.
13
+ attr_accessor :price
14
+ # @return [String] The description.
15
+ attr_accessor :description
16
+ # @return [Float] The discount percent.
17
+ attr_accessor :discountPercentage
18
+
19
+ # Initializes a new instance of Product.
20
+ #
21
+ # @param [Integer] id The unique identifier of the product.
22
+ # @param [String] title The title or name of the product.
23
+ # @param [Float] price The price of the product.
24
+ # @param [String] description A description or details about the product.
25
+ # @param [Float] discountPercentage The discount percentage applied to the product.
26
+ def initialize(id, title, price, description, discountPercentage)
27
+ @id = id
28
+ @title = title
29
+ @price = price
30
+ @description = description
31
+ @discountPercentage = discountPercentage
32
+ end
33
+
34
+ def to_json
35
+ {
36
+ id: @id,
37
+ title: @title,
38
+ price: @price,
39
+ description: @description,
40
+ discountPercentage: @discountPercentage
41
+ }.to_json
42
+ end
43
+ end
6
44
  class Api
7
- Product = Struct.new(:id, :title, :price, :description, :discountPercentage)
8
45
  # call api get product
9
46
  #
10
47
  # @param [String] id The id of the product.
@@ -19,12 +56,16 @@ module ApiDuonghds
19
56
  end
20
57
  end
21
58
 
59
+ # call api add/post product
60
+ #
61
+ # @param [Product] product The product you want to add.
62
+ # @return [Product] The product.
22
63
  def self.post_product(product)
23
64
  uri = URI("https://dummyjson.com/products/add")
24
65
  http = Net::HTTP.new(uri.host, uri.port)
25
66
  http.use_ssl = true
26
67
  request = Net::HTTP::Post.new(uri.path, {'Content-Type' => 'application/json'})
27
- request.body = product.to_h.to_json
68
+ request.body = product.to_json
28
69
  puts request.body
29
70
  response = http.request(request)
30
71
  if response.is_a?(Net::HTTPSuccess)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_duonghds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - duonghdse
@@ -38,7 +38,6 @@ files:
38
38
  - LICENSE.txt
39
39
  - README.md
40
40
  - Rakefile
41
- - api_duonghds-0.2.0.gem
42
41
  - api_duonghds.gemspec
43
42
  - lib/api_duonghds.rb
44
43
  - lib/api_duonghds/version.rb
@@ -56,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
55
  requirements:
57
56
  - - ">="
58
57
  - !ruby/object:Gem::Version
59
- version: 2.6.0
58
+ version: 2.7.8
60
59
  required_rubygems_version: !ruby/object:Gem::Requirement
61
60
  requirements:
62
61
  - - ">="
Binary file