Releases: local-ch/lhc
v3.8.0
You can also access response data directly through the response object (with square bracket notation only):
LHC.json.get(url: 'http://datastore/entry/1')[:name]
This makes accessing the data object with .data
unnecessary and direct data retrieval a little more convenient.
v3.7.3
Bump resolves some version conflicts with previous 'pre' release
v3.7.2
Minor fixes in regards of requiring files and std. libraries and gracefully initializing constants.
v3.7.1
3.7.0 introduced data accessing improvements but also improved the following different behaviour:
before 3.7.0
LHC.get('something').data.not_existing_key # nil
after 3.7.0
LHC.get('something').data.not_existing_key
# throws no method error
v3.7.0
Accessing data
The response data can be access with dot-notation and square-bracket notation. You can convert response data to open structs or json (if the response format is json).
response = LHC.request(url: 'http://datastore/entry/1')
response.data.as_open_struct #<OpenStruct name='local.ch'>
response.data.as_json # { name: 'local.ch' }
response.data.name # 'local.ch'
response.data[:name] # 'local.ch'
v3.6.1
- fix active support dependency
v3.6.0
Custom error handling
You can provide custom error handlers to handle errors happening during the request.
If a error handler is provided nothing is raised.
If your error handler returns anything else but nil
it replaces the response body.
handler = ->{ do_something; return {name: 'unknown'} }
response = LHC.get('http://something', error_handler: handler)
response.data.name # 'unknown'
v3.5.5
v3.5.4
Fixes problem with URL-Templates containing .
(dots)
e.g.
http://datastore/entries/:id.json
v3.5.3
Also sets the Accept
header when format json
is set.