rom-http 0.7.0 → 0.9.0

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.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +81 -28
  3. data/README.md +15 -181
  4. data/lib/rom/http/associations/many_to_many.rb +12 -0
  5. data/lib/rom/http/associations/many_to_one.rb +20 -0
  6. data/lib/rom/http/associations/one_to_many.rb +20 -0
  7. data/lib/rom/http/associations/one_to_one.rb +12 -0
  8. data/lib/rom/http/associations.rb +14 -0
  9. data/lib/rom/http/attribute.rb +10 -0
  10. data/lib/rom/http/commands/create.rb +2 -0
  11. data/lib/rom/http/commands/delete.rb +2 -0
  12. data/lib/rom/http/commands/update.rb +2 -0
  13. data/lib/rom/http/commands.rb +6 -4
  14. data/lib/rom/http/dataset.rb +212 -115
  15. data/lib/rom/http/error.rb +2 -0
  16. data/lib/rom/http/gateway.rb +47 -6
  17. data/lib/rom/http/handlers/json.rb +64 -0
  18. data/lib/rom/http/handlers.rb +16 -0
  19. data/lib/rom/http/mapper_compiler.rb +11 -0
  20. data/lib/rom/http/relation.rb +22 -66
  21. data/lib/rom/http/schema/dsl.rb +12 -0
  22. data/lib/rom/http/schema.rb +40 -0
  23. data/lib/rom/http/transformer.rb +2 -0
  24. data/lib/rom/http/types.rb +13 -0
  25. data/lib/rom/http/version.rb +3 -1
  26. data/lib/rom/http.rb +9 -6
  27. data/lib/rom-http.rb +3 -1
  28. metadata +41 -120
  29. data/.gitignore +0 -16
  30. data/.rspec +0 -3
  31. data/.rubocop.yml +0 -22
  32. data/.rubocop_todo.yml +0 -12
  33. data/.travis.yml +0 -20
  34. data/Gemfile +0 -24
  35. data/LICENSE.txt +0 -22
  36. data/Rakefile +0 -24
  37. data/examples/repository_with_combine.rb +0 -154
  38. data/lib/rom/http/dataset/class_interface.rb +0 -33
  39. data/rakelib/rubocop.rake +0 -18
  40. data/rom-http.gemspec +0 -32
  41. data/spec/integration/abstract/commands/create_spec.rb +0 -119
  42. data/spec/integration/abstract/commands/delete_spec.rb +0 -52
  43. data/spec/integration/abstract/commands/update_spec.rb +0 -119
  44. data/spec/integration/abstract/relation_spec.rb +0 -78
  45. data/spec/shared/setup.rb +0 -18
  46. data/spec/shared/users_and_tasks.rb +0 -30
  47. data/spec/spec_helper.rb +0 -19
  48. data/spec/support/mutant.rb +0 -10
  49. data/spec/unit/rom/http/dataset_spec.rb +0 -824
  50. data/spec/unit/rom/http/gateway_spec.rb +0 -69
  51. data/spec/unit/rom/http/relation_spec.rb +0 -268
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5fd07f83166373c0e0f2bfe8c83f8f68578818dc
4
- data.tar.gz: e643299868045661adadfd6ea6881cf59feda4fe
2
+ SHA256:
3
+ metadata.gz: f7be96043fffc0399b99aba04e426d0600b8f88e3a90725b6566fab079476b1f
4
+ data.tar.gz: a94c64dd5d3091a875e2691c6d2d5380ec056b9667d206b43376022ad37be85f
5
5
  SHA512:
6
- metadata.gz: 2a2de5a39a3cf600c2464250809a2e292c7abef3a8e1b2e79232ac035b14992a160a56035c5c7a65414ab60b643093ac375e234ffab952c6a262f3517cd146fd
7
- data.tar.gz: 44315f4744aa86c60fb92c801bd1521e2834dbada29fd53a6cfc4a6f35f27fb09cb335719d9bb4b52be5f1bda9c549539f4e98c96fca2344640c2e7b0a096062
6
+ metadata.gz: e89e4e48537fbe0a14b770e4069f931f24d8418357adfc179fb1ee72b933b88a82132b7d9abd8baef42b7dd8d1868b8ada2a74f93dae67c06f6b53f3f4265d4f
7
+ data.tar.gz: 7fbd7ff1d889affbcc4530af2fd8b08f440af929ba3e1efa99f234c454f04c2fd14fdacdd21be6fb8688c21481f6cff35cdc4c61f3527f899cb23ebd1a131656
data/CHANGELOG.md CHANGED
@@ -1,20 +1,45 @@
1
- # v0.7.0 2018-01-11
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
- - Add Dataset#add_params(AMHOL)
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
- [Compare v0.4.0...v0.5.0](https://github.com/rom-rb/rom-http/compare/v0.4.0...v0.5.0)
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
- - updated to depend on the forthcoming rom 2.0 (cflipse)
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
- # v0.3.0 2016-03-17
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
- # v0.2.0 2016-01-30
52
- ### Added
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
- # v0.1.2 2015-09-16
59
- ### Added
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
- # v0.1.1 2015-09-03
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
- # v0.1.0 2015-08-19
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
- [travis]: https://travis-ci.org/rom-rb/rom-http
3
- [gemnasium]: https://gemnasium.com/rom-rb/rom-http
4
- [codeclimate]: https://codeclimate.com/github/rom-rb/rom-http
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
- [![Build Status](https://travis-ci.org/rom-rb/rom-http.svg?branch=master)][travis]
14
- [![Dependency Status](https://gemnasium.com/rom-rb/rom-http.svg)][gemnasium]
15
- [![Code Climate](https://codeclimate.com/github/rom-rb/rom-http/badges/gpa.svg)][codeclimate]
16
- [![Documentation Status](http://inch-ci.org/github/rom-rb/rom-http.svg?branch=master&style=flat)][inchpages]
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
- And then execute:
15
+ ## Links
29
16
 
30
- $ bundle
17
+ * [User documentation](http://rom-rb.org/learn/http)
18
+ * [API documentation](http://rubydoc.info/gems/rom-http)
31
19
 
32
- Or install it yourself as:
20
+ ## Supported Ruby versions
33
21
 
34
- $ gem install rom-http
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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rom/associations/many_to_many"
4
+
5
+ module ROM
6
+ module HTTP
7
+ module Associations
8
+ class ManyToMany < ROM::Associations::ManyToMany
9
+ end
10
+ end
11
+ end
12
+ end
@@ -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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rom/http/associations/one_to_many"
4
+
5
+ module ROM
6
+ module HTTP
7
+ module Associations
8
+ class OneToOne < OneToMany
9
+ end
10
+ end
11
+ end
12
+ 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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rom/attribute"
4
+
5
+ module ROM
6
+ module HTTP
7
+ class Attribute < ROM::Attribute
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module HTTP
3
5
  module Commands
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module HTTP
3
5
  module Commands
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module HTTP
3
5
  module Commands
@@ -1,4 +1,6 @@
1
- require 'rom/commands'
2
- require 'rom/http/commands/create'
3
- require 'rom/http/commands/update'
4
- require 'rom/http/commands/delete'
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"