api_duonghds 0.4.0 → 1.1.0
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/api_duonghds.gemspec +1 -1
- data/lib/api_duonghds/version.rb +1 -1
- data/lib/api_duonghds.rb +43 -2
- metadata +2 -3
- data/api_duonghds-0.2.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f9667a0babdf6560fad87cf3252fe45001583548ec4845b73b2ddc2b2e6fc0a
|
4
|
+
data.tar.gz: 4ff37c92ef962d163d622444893de2b17e7cd4cfb698c07b8242de0a5509a6cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
15
|
+
spec.required_ruby_version = ">= 2.7.8"
|
16
16
|
|
17
17
|
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
18
18
|
|
data/lib/api_duonghds/version.rb
CHANGED
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.
|
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:
|
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.
|
58
|
+
version: 2.7.8
|
60
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
60
|
requirements:
|
62
61
|
- - ">="
|
data/api_duonghds-0.2.0.gem
DELETED
Binary file
|