api_duonghds 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_duonghds/version.rb +1 -1
- data/lib/api_duonghds.rb +43 -2
- metadata +1 -2
- 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/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: 1.
|
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
|
data/api_duonghds-0.2.0.gem
DELETED
Binary file
|