etrieve_content_api 0.1.0 → 0.2.1
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/README.md +1 -1
- data/lib/etrieve_content_api/connection.rb +4 -2
- data/lib/etrieve_content_api/handler.rb +52 -0
- data/lib/etrieve_content_api/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 798114b4c8cb961ec2b48e5089c471c741e5975b06b309983793321f081e94f0
|
|
4
|
+
data.tar.gz: d98804a6b1534e9421f21a5092fc565e92ad31c55396ddef2add8395bdaecae7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5667356c266ec6b35a9419399b81230eb619f1d474b33d1a5aae01b9bb7d558e6bcbde10a5e83bb124c6627f29023c83cb4bfd54f77603b3e06bf1f278abac5
|
|
7
|
+
data.tar.gz: 852523ed18fee312dd5442ba5a4531f967de24c95843de829c4a29674d4c80e4c8d313d422cf2ee526078c332726f648dc8349dffe3682200a28270cac8f9e42
|
data/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Configuration can be passed as a hash.
|
|
|
28
28
|
auth_url: 'https://example.com/auth', # default: ''
|
|
29
29
|
base_url: 'https://example.com/api', # default: ''
|
|
30
30
|
password: password, # default: ''
|
|
31
|
-
username: username, # default: ''
|
|
31
|
+
username: username, # default: '' - might be a client_id as opposed to a user login
|
|
32
32
|
timeout: 1, # default: 30 seconds
|
|
33
33
|
verify_ssl: false # default: true
|
|
34
34
|
}
|
|
@@ -51,7 +51,7 @@ module EtrieveContentApi
|
|
|
51
51
|
)
|
|
52
52
|
results = JSON.parse(resp)
|
|
53
53
|
rescue RestClient::ExceptionWithResponse => err
|
|
54
|
-
results = JSON.parse(err.response)
|
|
54
|
+
results = err.respond_to?(:response) ? JSON.parse(err.response) : err
|
|
55
55
|
rescue
|
|
56
56
|
results = { error: $!.message }
|
|
57
57
|
end
|
|
@@ -197,7 +197,9 @@ module EtrieveContentApi
|
|
|
197
197
|
when 200
|
|
198
198
|
return response
|
|
199
199
|
when 401
|
|
200
|
-
raise AuthenticationError
|
|
200
|
+
raise AuthenticationError
|
|
201
|
+
when 400
|
|
202
|
+
raise ArgumentError, response
|
|
201
203
|
else
|
|
202
204
|
# Some other error. Let it bubble up.
|
|
203
205
|
response.return!(&block)
|
|
@@ -86,6 +86,39 @@ module EtrieveContentApi
|
|
|
86
86
|
get path, query: query_s, headers: headers, &block
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
+
# Creates a new document, returns JSON results of operation, including
|
|
90
|
+
# new document ID
|
|
91
|
+
# key fields should be passed as an array of hashes:
|
|
92
|
+
# {fieldCode: '', value: '', parentFieldCode: ''}
|
|
93
|
+
def create_document(area_code: '', document_name: '', field_values: [], headers: {}, &block)
|
|
94
|
+
headers = headers.empty? ? { "Content-Type" => "application/json" } : headers
|
|
95
|
+
params = {
|
|
96
|
+
areaCode: area_code,
|
|
97
|
+
documentTypeCode: document_name,
|
|
98
|
+
fieldValues: field_values
|
|
99
|
+
}.to_json
|
|
100
|
+
post_json DOCUMENTS_PATH, params: params, headers: headers, &block
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Sets the contents of an existing document
|
|
104
|
+
def set_document_content(document_id, file_path, headers: {}, &block)
|
|
105
|
+
file = begin
|
|
106
|
+
File.open(file_path)
|
|
107
|
+
rescue Errno::ENOENT
|
|
108
|
+
end
|
|
109
|
+
raise AttributeMissingError, 'Valid file or local filepath is required to submit a document.' unless file.is_a?(File)
|
|
110
|
+
|
|
111
|
+
path = [DOCUMENTS_PATH, document_id, 'contents'].join('/')
|
|
112
|
+
headers = headers.merge({
|
|
113
|
+
'X-File-Attributes' => {
|
|
114
|
+
'filename' => File.basename(file.path),
|
|
115
|
+
'contenttype' => MIME::Types.type_for(file.path).first.content_type
|
|
116
|
+
}.to_json,
|
|
117
|
+
'Content-Length' => File.size(file.path)
|
|
118
|
+
})
|
|
119
|
+
post_json path, params: file, headers: headers
|
|
120
|
+
end
|
|
121
|
+
|
|
89
122
|
# Format a request and pass it on to the connection's get method
|
|
90
123
|
def get(path = '', query: '', headers: {}, &block)
|
|
91
124
|
query = query.empty? ? nil : query
|
|
@@ -107,6 +140,25 @@ module EtrieveContentApi
|
|
|
107
140
|
[json, r.headers]
|
|
108
141
|
end
|
|
109
142
|
|
|
143
|
+
# Format a request and pass it on to the connection's post method
|
|
144
|
+
def post(path = '', params: {}, headers: {}, &block)
|
|
145
|
+
connection.post path, payload: params, headers: headers, &block
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Process content from #post and parse JSON from body.
|
|
149
|
+
def post_json(path = '', params: {}, headers: {}, &block)
|
|
150
|
+
r = post path, params: params, headers: headers, &block
|
|
151
|
+
return { message: r } unless r.respond_to?(:body)
|
|
152
|
+
|
|
153
|
+
json = begin
|
|
154
|
+
JSON.parse(r.body)
|
|
155
|
+
rescue JSON::ParserError
|
|
156
|
+
{}
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
[json, r.headers]
|
|
160
|
+
end
|
|
161
|
+
|
|
110
162
|
private
|
|
111
163
|
|
|
112
164
|
def encoded_query(query: {}, keys_allowed: :all)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: etrieve_content_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shannon Henderson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-10-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|
|
@@ -134,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
134
134
|
- !ruby/object:Gem::Version
|
|
135
135
|
version: '0'
|
|
136
136
|
requirements: []
|
|
137
|
-
|
|
138
|
-
rubygems_version: 2.7.6
|
|
137
|
+
rubygems_version: 3.0.3
|
|
139
138
|
signing_key:
|
|
140
139
|
specification_version: 4
|
|
141
140
|
summary: A Ruby wrapper for the Etrieve Content API
|