fulfil_api 0.1.1 → 0.1.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a281b6b98a2a9e17e00dfcfc9a69c25d981742fc6be3ed3107843381ed0ee72
|
4
|
+
data.tar.gz: 709b239f59384ab61adf1f258aea4f6f429846a7d1bebce1373694c6a3b8bd1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e992ff3b009ae88f5bf03fd50694b241eb8dfdb316c8c71d036d8e55d582018a32d9c7c306d1c2dc85cf9d12413785b44dc796a11ea9f0bec8b879416014375
|
7
|
+
data.tar.gz: b3ba21ef6d73d9d077f172535451b6ba62a7410f610271601c485e356e4df22ef5fb5c741d113b7ed43773a798a036cacc29564fcfd231807f02a9520bcf5cc2
|
@@ -12,18 +12,49 @@ module FulfilApi
|
|
12
12
|
extend ActiveSupport::Concern
|
13
13
|
|
14
14
|
class_methods do
|
15
|
+
# Creates a new resource on the model name.
|
16
|
+
#
|
17
|
+
# @param model_name [String] The name of the model to which the resource belongs.
|
18
|
+
# @params attributes [Hash] The attributes to create the resource with.
|
19
|
+
# @return [FulfilApi::Resource, false] The created resource.
|
20
|
+
#
|
21
|
+
# @example Creating a resource
|
22
|
+
# FulfilApi::Resource.create(model_name: "sale.sale", reference: "MK123")
|
23
|
+
def create(model_name:, **attributes)
|
24
|
+
resource = new(model_name: model_name)
|
25
|
+
resource.create(attributes)
|
26
|
+
rescue FulfilApi::Error
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
# Creates a new resource on the model name, raising an error if the create fails.
|
31
|
+
#
|
32
|
+
# @param model_name [String] The name of the model to which the resource belongs.
|
33
|
+
# @params attributes [Hash] The attributes to create the resource with.
|
34
|
+
# @return [FulfilApi::Resource] The created resource.
|
35
|
+
# @raise [FulfilApi::Error] If the create fails.
|
36
|
+
#
|
37
|
+
# @example Creating a resource
|
38
|
+
# FulfilApi::Resource.create!(model_name: "sale.sale", reference: "MK123")
|
39
|
+
def create!(model_name:, **attributes)
|
40
|
+
resource = new(model_name: model_name)
|
41
|
+
resource.create!(attributes)
|
42
|
+
end
|
43
|
+
|
15
44
|
# Updates a resource by its ID and model name.
|
16
45
|
#
|
17
46
|
# @param id [String, Integer] The ID of the resource to update.
|
18
47
|
# @param model_name [String] The name of the model to which the resource belongs.
|
19
48
|
# @param attributes [Hash] The attributes to update on the resource.
|
20
|
-
# @return [FulfilApi::Resource] The updated resource.
|
49
|
+
# @return [FulfilApi::Resource, false] The updated resource.
|
21
50
|
#
|
22
51
|
# @example Updating a resource
|
23
52
|
# FulfilApi::Resource.update(id: 123, model_name: "sale.sale", reference: "MK123")
|
24
53
|
def update(id:, model_name:, **attributes)
|
25
54
|
resource = new(id: id, model_name: model_name)
|
26
55
|
resource.update(attributes)
|
56
|
+
rescue FulfilApi::Error
|
57
|
+
false
|
27
58
|
end
|
28
59
|
|
29
60
|
# Updates a resource by its ID and model name, raising an error if the update fails.
|
@@ -42,6 +73,31 @@ module FulfilApi
|
|
42
73
|
end
|
43
74
|
end
|
44
75
|
|
76
|
+
# Creates a resource with the given attributes and saves it.
|
77
|
+
#
|
78
|
+
# @param attributes [Hash] The attributes to assign to the resource.
|
79
|
+
# @return [FulfilApi::Resource] The created resource.
|
80
|
+
#
|
81
|
+
# @example Creating a resource
|
82
|
+
# resource.create(reference: "MK123")
|
83
|
+
def create(attributes)
|
84
|
+
assign_attributes(attributes)
|
85
|
+
save
|
86
|
+
end
|
87
|
+
|
88
|
+
# Creates a resource with the given attributes and saves it, raising an error if saving fails.
|
89
|
+
#
|
90
|
+
# @param attributes [Hash] The attributes to assign to the resource.
|
91
|
+
# @return [FulfilApi::Resource] The created resource.
|
92
|
+
# @raise [FulfilApi::Error] If an error occurs during the create.
|
93
|
+
#
|
94
|
+
# @example Creating a resource with error raising
|
95
|
+
# resource.create(reference: "MK123")
|
96
|
+
def create!(attributes)
|
97
|
+
assign_attributes(attributes)
|
98
|
+
save!
|
99
|
+
end
|
100
|
+
|
45
101
|
# Saves the current resource, rescuing any errors that occur and handling them based on error type.
|
46
102
|
#
|
47
103
|
# @return [FulfilApi::Resource, nil] Returns the resource if saved successfully, otherwise nil.
|
@@ -67,8 +123,8 @@ module FulfilApi
|
|
67
123
|
|
68
124
|
if id.present?
|
69
125
|
FulfilApi.client.put("/model/#{model_name}/#{id}", body: to_h)
|
70
|
-
else
|
71
|
-
|
126
|
+
else
|
127
|
+
FulfilApi.client.post("/model/#{model_name}", body: to_h)
|
72
128
|
end
|
73
129
|
|
74
130
|
self
|
@@ -67,7 +67,7 @@ module FulfilApi
|
|
67
67
|
# @return [FulfilApi::Resource::Relation] A new {Relation} instance with the conditions applied.
|
68
68
|
def where(conditions)
|
69
69
|
clone.tap do |relation|
|
70
|
-
relation.conditions << conditions
|
70
|
+
relation.conditions << conditions
|
71
71
|
relation.conditions.uniq!
|
72
72
|
end
|
73
73
|
end
|
data/lib/fulfil_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fulfil_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vermaas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
|
-
rubygems_version: 3.5.
|
124
|
+
rubygems_version: 3.5.11
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: A HTTP client to interact the Fulfil.io API
|