rom-http 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +81 -28
- data/README.md +15 -181
- data/lib/rom/http/associations/many_to_many.rb +12 -0
- data/lib/rom/http/associations/many_to_one.rb +20 -0
- data/lib/rom/http/associations/one_to_many.rb +20 -0
- data/lib/rom/http/associations/one_to_one.rb +12 -0
- data/lib/rom/http/associations.rb +14 -0
- data/lib/rom/http/attribute.rb +10 -0
- data/lib/rom/http/commands/create.rb +2 -0
- data/lib/rom/http/commands/delete.rb +2 -0
- data/lib/rom/http/commands/update.rb +2 -0
- data/lib/rom/http/commands.rb +6 -4
- data/lib/rom/http/dataset.rb +212 -115
- data/lib/rom/http/error.rb +2 -0
- data/lib/rom/http/gateway.rb +47 -6
- data/lib/rom/http/handlers/json.rb +64 -0
- data/lib/rom/http/handlers.rb +16 -0
- data/lib/rom/http/mapper_compiler.rb +11 -0
- data/lib/rom/http/relation.rb +22 -66
- data/lib/rom/http/schema/dsl.rb +12 -0
- data/lib/rom/http/schema.rb +40 -0
- data/lib/rom/http/transformer.rb +2 -0
- data/lib/rom/http/types.rb +13 -0
- data/lib/rom/http/version.rb +3 -1
- data/lib/rom/http.rb +9 -6
- data/lib/rom-http.rb +3 -1
- metadata +41 -120
- data/.gitignore +0 -16
- data/.rspec +0 -3
- data/.rubocop.yml +0 -22
- data/.rubocop_todo.yml +0 -12
- data/.travis.yml +0 -20
- data/Gemfile +0 -24
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -24
- data/examples/repository_with_combine.rb +0 -154
- data/lib/rom/http/dataset/class_interface.rb +0 -33
- data/rakelib/rubocop.rake +0 -18
- data/rom-http.gemspec +0 -32
- data/spec/integration/abstract/commands/create_spec.rb +0 -119
- data/spec/integration/abstract/commands/delete_spec.rb +0 -52
- data/spec/integration/abstract/commands/update_spec.rb +0 -119
- data/spec/integration/abstract/relation_spec.rb +0 -78
- data/spec/shared/setup.rb +0 -18
- data/spec/shared/users_and_tasks.rb +0 -30
- data/spec/spec_helper.rb +0 -19
- data/spec/support/mutant.rb +0 -10
- data/spec/unit/rom/http/dataset_spec.rb +0 -824
- data/spec/unit/rom/http/gateway_spec.rb +0 -69
- data/spec/unit/rom/http/relation_spec.rb +0 -268
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f7be96043fffc0399b99aba04e426d0600b8f88e3a90725b6566fab079476b1f
|
4
|
+
data.tar.gz: a94c64dd5d3091a875e2691c6d2d5380ec056b9667d206b43376022ad37be85f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e89e4e48537fbe0a14b770e4069f931f24d8418357adfc179fb1ee72b933b88a82132b7d9abd8baef42b7dd8d1868b8ada2a74f93dae67c06f6b53f3f4265d4f
|
7
|
+
data.tar.gz: 7fbd7ff1d889affbcc4530af2fd8b08f440af929ba3e1efa99f234c454f04c2fd14fdacdd21be6fb8688c21481f6cff35cdc4c61f3527f899cb23ebd1a131656
|
data/CHANGELOG.md
CHANGED
@@ -1,20 +1,45 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
|
+
|
3
|
+
## 0.9.0 2022-09-27
|
2
4
|
|
3
5
|
### Added
|
4
|
-
|
6
|
+
|
7
|
+
- Support for associations :tada: (@ianks)
|
8
|
+
- Support for ruby 3 (@AMHOL)
|
5
9
|
|
6
10
|
### Changed
|
11
|
+
- Request params separated into query_params and body_params (@AMHOL in [#44](https://github.com/rom-rb/rom-http/pull/44))
|
12
|
+
- Minimal ruby version is set to 2.7 (@flash-gordon)
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
|
16
|
+
- Warning message from dry-configurable (@gkostin1966)
|
17
|
+
|
18
|
+
[Compare v0.8.0...v0.9.0](https://github.com/rom-rb/rom-http/compare/v0.8.0...v0.9.0)
|
19
|
+
|
20
|
+
## 0.8.0 2019-04-29
|
21
|
+
|
22
|
+
As a consequence of these changes, with this release you can easily use `rom-http` along with repositories and changesets.
|
23
|
+
|
24
|
+
### Added
|
25
|
+
|
26
|
+
- Support for relation schemas (solnic)
|
27
|
+
- Support for auto-struct mapping (solnic)
|
28
|
+
- Support for registering your own request/response handlers for all datasets from a specific gateway (solnic)
|
29
|
+
- Built-in `JSON` handlers that you can set via `handlers: :json` gateway option (solnic)
|
30
|
+
- Convenient request method predicates `Dataset#{get?,post?,delete?,put?}` (solnic)
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
|
34
|
+
- `Relation#append_path` no longer duplicates `base_path` (solnic)
|
35
|
+
|
36
|
+
- Add Dataset#add_params(AMHOL)
|
37
|
+
|
7
38
|
- Updated error messages (AMHOL)
|
8
39
|
- updated to depend on ROM 4.0 (maximderbin)
|
9
40
|
- Removed ruby 2.1 support (maximderbin)
|
10
41
|
- Removed rbx-3 support (maximderbin)
|
11
42
|
|
12
|
-
|
13
|
-
|
14
|
-
[Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom-http/compare/v0.6.0...v0.7.0)
|
15
|
-
|
16
|
-
# v0.6.0 2017-02-06
|
17
|
-
### Changed
|
18
43
|
- Make schemas mandatory and use schema API from ROM core (AMHOL)
|
19
44
|
- Generate transformer using schema (AMHOL)
|
20
45
|
- Removed rbx-2 support (solnic)
|
@@ -25,47 +50,75 @@
|
|
25
50
|
- Transform keys on insert and update (maximderbin)
|
26
51
|
- Remove `rom-support` dependency (maximderbin)
|
27
52
|
|
28
|
-
[Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom-http/compare/v0.5.0...v0.6.0)
|
29
|
-
|
30
|
-
# v0.5.0 2016-08-08
|
31
|
-
### Changed
|
32
53
|
- Removed ruby 2.0 support
|
33
54
|
- Use `schema` API from ROM::Core. Replaces old schema (solnic)
|
34
55
|
- Now works out of the box with `rom-repository` (solnic)
|
35
56
|
|
36
|
-
|
57
|
+
- updated to depend on the forthcoming rom 2.0 (cflipse)
|
58
|
+
|
59
|
+
- replaced dry-data with dry-types (Nikita Shilnikov <ns@latera.ru>)
|
60
|
+
|
61
|
+
|
62
|
+
- schema support using `dry-data` (AMHOL)
|
63
|
+
|
64
|
+
|
65
|
+
- Projections (`container.relation(:users).project(:id, :name)`) (AMHOL)
|
66
|
+
|
67
|
+
|
68
|
+
- `ROM::HTTP::Dataset` macros for setting `default_request_handler` and `default_response_handler` (AMHOL)
|
37
69
|
|
38
|
-
# v0.4.0 2016-04-30
|
39
70
|
### Changed
|
40
|
-
|
71
|
+
|
72
|
+
- Updated to work with `rom ~> 5.0` (parndt)
|
73
|
+
- Input/output data are now handled by core functionality using schema's `input_schema` and `output_schema` (solnic)
|
74
|
+
- `Dataset#name` was removed in favor of `Dataset#base_path`
|
75
|
+
|
76
|
+
[Compare v0.7.0...v0.8.0](https://github.com/rom-rb/rom-http/compare/v0.7.0...v0.8.0)
|
77
|
+
|
78
|
+
## 0.7.0 2018-01-11
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
[Compare v0.6.0...v0.7.0](https://github.com/rom-rb/rom-http/compare/v0.6.0...v0.7.0)
|
83
|
+
|
84
|
+
## 0.6.0 2017-02-06
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
[Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom-http/compare/v0.5.0...v0.6.0)
|
89
|
+
|
90
|
+
## 0.5.0 2016-08-08
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
[Compare v0.4.0...v0.5.0](https://github.com/rom-rb/rom-http/compare/v0.4.0...v0.5.0)
|
95
|
+
|
96
|
+
## 0.4.0 2016-04-30
|
97
|
+
|
98
|
+
|
41
99
|
|
42
100
|
[Compare v0.3.0...v0.4.0](https://github.com/rom-rb/rom-http/compare/v0.3.0...v0.4.0)
|
43
101
|
|
44
|
-
|
102
|
+
## 0.3.0 2016-03-17
|
103
|
+
|
45
104
|
|
46
|
-
### Changed
|
47
|
-
- replaced dry-data with dry-types (Nikita Shilnikov <ns@latera.ru>)
|
48
105
|
|
49
106
|
[Compare v0.2.0...v0.3.0](https://github.com/rom-rb/rom-http/compare/v0.2.0...v0.3.0)
|
50
107
|
|
51
|
-
|
52
|
-
|
108
|
+
## 0.2.0 2016-01-30
|
109
|
+
|
53
110
|
|
54
|
-
- schema support using `dry-data` (AMHOL)
|
55
111
|
|
56
112
|
[Compare v0.1.2...v0.2.0](https://github.com/rom-rb/rom-http/compare/v0.1.2...v0.2.0)
|
57
113
|
|
58
|
-
|
59
|
-
|
114
|
+
## 0.1.2 2015-09-16
|
115
|
+
|
60
116
|
|
61
|
-
- Projections (`container.relation(:users).project(:id, :name)`) (AMHOL)
|
62
117
|
|
63
118
|
[Compare v0.1.1...v0.1.2](https://github.com/rom-rb/rom-http/compare/v0.1.1...v0.1.2)
|
64
119
|
|
65
|
-
|
66
|
-
### Added
|
120
|
+
## 0.1.1 2015-09-03
|
67
121
|
|
68
|
-
- `ROM::HTTP::Dataset` macros for setting `default_request_handler` and `default_response_handler` (AMHOL)
|
69
122
|
|
70
123
|
### Changed
|
71
124
|
|
@@ -75,6 +128,6 @@
|
|
75
128
|
|
76
129
|
[Compare v0.1.0...v0.1.1](https://github.com/rom-rb/rom-http/compare/v0.1.0...v0.1.1)
|
77
130
|
|
78
|
-
|
131
|
+
## 0.1.0 2015-08-19
|
79
132
|
|
80
133
|
First public release \o/
|
data/README.md
CHANGED
@@ -1,195 +1,29 @@
|
|
1
1
|
[gem]: https://rubygems.org/gems/rom-http
|
2
|
-
[
|
3
|
-
[
|
4
|
-
[
|
2
|
+
[actions]: https://github.com/rom-rb/rom-http/actions
|
3
|
+
[codacy]: https://www.codacy.com/gh/rom-rb/rom-http
|
4
|
+
[chat]: https://rom-rb.zulipchat.com
|
5
5
|
[inchpages]: http://inch-ci.org/github/rom-rb/rom-http
|
6
|
-
[gitter]: https://gitter.im/rom-rb/chat
|
7
|
-
[rom]: https://github.com/rom-rb/rom
|
8
6
|
|
9
|
-
|
10
|
-
# rom-http [![Gitter chat](https://badges.gitter.im/rom-rb/chat.svg)][gitter]
|
7
|
+
# rom-http [![Join the chat at https://rom-rb.zulipchat.com](https://img.shields.io/badge/rom--rb-join%20chat-%23346b7a.svg)][chat]
|
11
8
|
|
12
9
|
[![Gem Version](https://badge.fury.io/rb/rom-http.svg)][gem]
|
13
|
-
[![
|
14
|
-
[![
|
15
|
-
[![
|
16
|
-
[![
|
17
|
-
|
18
|
-
HTTP adapter for [Ruby Object Mapper][rom]
|
19
|
-
|
20
|
-
## Installation
|
21
|
-
|
22
|
-
Add this line to your application's Gemfile:
|
23
|
-
|
24
|
-
```ruby
|
25
|
-
gem 'rom-http'
|
26
|
-
```
|
10
|
+
[![CI Status](https://github.com/rom-rb/rom-http/workflows/ci/badge.svg)][actions]
|
11
|
+
[![RuboCop](https://github.com/rom-rb/rom-http/actions/workflows/rubocop.yml/badge.svg)](https://github.com/rom-rb/rom-http/actions/workflows/rubocop.yml)
|
12
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/d37d66bb711d4aeebf5e1c1650aee261)][codacy]
|
13
|
+
[![Inline docs](http://inch-ci.org/github/rom-rb/rom-http.svg?branch=main)][inchpages]
|
27
14
|
|
28
|
-
|
15
|
+
## Links
|
29
16
|
|
30
|
-
|
17
|
+
* [User documentation](http://rom-rb.org/learn/http)
|
18
|
+
* [API documentation](http://rubydoc.info/gems/rom-http)
|
31
19
|
|
32
|
-
|
20
|
+
## Supported Ruby versions
|
33
21
|
|
34
|
-
|
35
|
-
|
36
|
-
## ROADMAP
|
37
|
-
|
38
|
-
For details please refer to [issues](https://github.com/rom-rb/rom-http/issues).
|
22
|
+
This library officially supports the following Ruby versions:
|
39
23
|
|
24
|
+
* MRI >= `2.7`
|
25
|
+
* ~jruby >= `9.3`~ (awaits Ruby 2.7 compatibility)
|
40
26
|
|
41
27
|
## License
|
42
28
|
|
43
29
|
See `LICENSE` file.
|
44
|
-
|
45
|
-
## Synopsis
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
require 'inflecto'
|
49
|
-
require 'json'
|
50
|
-
require 'uri'
|
51
|
-
require 'net/http'
|
52
|
-
|
53
|
-
class RequestHandler
|
54
|
-
def call(dataset)
|
55
|
-
uri = dataset.uri
|
56
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
57
|
-
request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))
|
58
|
-
|
59
|
-
request = request_klass.new(uri.request_uri)
|
60
|
-
dataset.headers.each_with_object(request) do |(header, value), request|
|
61
|
-
request[header.to_s] = value
|
62
|
-
end
|
63
|
-
|
64
|
-
response = http.request(request)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class ResponseHandler
|
69
|
-
def call(response, dataset)
|
70
|
-
if %i(post put patch).include?(dataset.request_method)
|
71
|
-
JSON.parse(response.body, symbolize_names: true)
|
72
|
-
else
|
73
|
-
Array([JSON.parse(response.body, symbolize_names: true)]).flatten
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class Users < ROM::Relation[:http]
|
79
|
-
schema(:users) do
|
80
|
-
attribute :id, ROM::Types::Int
|
81
|
-
attribute :name, ROM::Types::String
|
82
|
-
attribute :username, ROM::Types::String
|
83
|
-
attribute :email, ROM::Types::String
|
84
|
-
attribute :phone, ROM::Types::String
|
85
|
-
attribute :website, ROM::Types::String
|
86
|
-
end
|
87
|
-
|
88
|
-
def by_id(id)
|
89
|
-
with_path(id.to_s)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
configuration = ROM::Configuration.new(:http, {
|
94
|
-
uri: 'http://jsonplaceholder.typicode.com',
|
95
|
-
headers: {
|
96
|
-
Accept: 'application/json'
|
97
|
-
},
|
98
|
-
request_handler: RequestHandler.new,
|
99
|
-
response_handler: ResponseHandler.new
|
100
|
-
})
|
101
|
-
configuration.register_relation(Users)
|
102
|
-
container = ROM.container(configuration)
|
103
|
-
|
104
|
-
container.relation(:users).by_id(1).to_a
|
105
|
-
# => GET http://jsonplaceholder.typicode.com/users/1 [ Accept: application/json ]
|
106
|
-
```
|
107
|
-
|
108
|
-
### Extending
|
109
|
-
|
110
|
-
```ruby
|
111
|
-
require 'inflecto'
|
112
|
-
require 'json'
|
113
|
-
require 'uri'
|
114
|
-
require 'net/http'
|
115
|
-
|
116
|
-
module ROM
|
117
|
-
module MyAdapter
|
118
|
-
class Dataset < ROM::HTTP::Dataset
|
119
|
-
configure do |config|
|
120
|
-
config.default_request_handler = ->(dataset) do
|
121
|
-
uri = dataset.uri
|
122
|
-
|
123
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
124
|
-
request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))
|
125
|
-
|
126
|
-
request = request_klass.new(uri.request_uri)
|
127
|
-
dataset.headers.each_with_object(request) do |(header, value), request|
|
128
|
-
request[header.to_s] = value
|
129
|
-
end
|
130
|
-
|
131
|
-
response = http.request(request)
|
132
|
-
end
|
133
|
-
|
134
|
-
config.default_response_handler = ->(response, dataset) do
|
135
|
-
if %i(post put patch).include?(dataset.request_method)
|
136
|
-
JSON.parse(response.body, symbolize_names: true)
|
137
|
-
else
|
138
|
-
Array([JSON.parse(response.body, symbolize_names: true)]).flatten
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
class Gateway < ROM::HTTP::Gateway; end
|
145
|
-
|
146
|
-
class Relation < ROM::HTTP::Relation
|
147
|
-
adapter :my_adapter
|
148
|
-
end
|
149
|
-
|
150
|
-
module Commands
|
151
|
-
class Create < ROM::HTTP::Commands::Create
|
152
|
-
adapter :my_adapter
|
153
|
-
end
|
154
|
-
|
155
|
-
class Update < ROM::HTTP::Commands::Update
|
156
|
-
adapter :my_adapter
|
157
|
-
end
|
158
|
-
|
159
|
-
class Delete < ROM::HTTP::Commands::Delete
|
160
|
-
adapter :my_adapter
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
ROM.register_adapter(:my_adapter, ROM::MyAdapter)
|
167
|
-
|
168
|
-
configuration = ROM::Configuration.new(:my_adapter, {
|
169
|
-
uri: 'http://jsonplaceholder.typicode.com',
|
170
|
-
headers: {
|
171
|
-
Accept: 'application/json'
|
172
|
-
}
|
173
|
-
})
|
174
|
-
|
175
|
-
class Users < ROM::Relation[:my_adapter]
|
176
|
-
schema(:users) do
|
177
|
-
attribute :id, ROM::Types::Int
|
178
|
-
attribute :name, ROM::Types::String
|
179
|
-
attribute :username, ROM::Types::String
|
180
|
-
attribute :email, ROM::Types::String
|
181
|
-
attribute :phone, ROM::Types::String
|
182
|
-
attribute :website, ROM::Types::String
|
183
|
-
end
|
184
|
-
|
185
|
-
def by_id(id)
|
186
|
-
with_path(id.to_s)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
configuration.register_relation(Users)
|
191
|
-
container = ROM.container(configuration)
|
192
|
-
|
193
|
-
container.relation(:users).by_id(1).to_a
|
194
|
-
# => GET http://jsonplaceholder.typicode.com/users/1 [ Accept: application/json ]
|
195
|
-
```
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rom/associations/many_to_one"
|
4
|
+
|
5
|
+
module ROM
|
6
|
+
module HTTP
|
7
|
+
module Associations
|
8
|
+
# ManyToOne implementation
|
9
|
+
class ManyToOne < ROM::Associations::ManyToOne
|
10
|
+
def call(target: self.target)
|
11
|
+
raise MissingAssociationViewError, "must override view" unless view
|
12
|
+
|
13
|
+
schema = target.schema.qualified
|
14
|
+
relation = target
|
15
|
+
apply_view(schema, relation)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rom/associations/one_to_many"
|
4
|
+
|
5
|
+
module ROM
|
6
|
+
module HTTP
|
7
|
+
module Associations
|
8
|
+
# OneToMany implementation
|
9
|
+
class OneToMany < ROM::Associations::OneToMany
|
10
|
+
def call(target: self.target)
|
11
|
+
raise MissingAssociationViewError, "must override view" unless view
|
12
|
+
|
13
|
+
schema = target.schema.qualified
|
14
|
+
relation = target
|
15
|
+
apply_view(schema, relation)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rom/http/associations/many_to_many"
|
4
|
+
require "rom/http/associations/one_to_many"
|
5
|
+
require "rom/http/associations/many_to_one"
|
6
|
+
require "rom/http/associations/one_to_one"
|
7
|
+
|
8
|
+
module ROM
|
9
|
+
module HTTP
|
10
|
+
module Associations
|
11
|
+
class MissingAssociationViewError < Error; end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rom/http/commands.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rom/commands"
|
4
|
+
require "rom/http/commands/create"
|
5
|
+
require "rom/http/commands/update"
|
6
|
+
require "rom/http/commands/delete"
|