rom-http 0.8.0 → 0.10.0

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: d88086baa2e0dccb6c7917f2e0a5ccf3ec268fa722f1648283b66ea9feb839e2
4
- data.tar.gz: 3c4385179232ad49adc12214a00ecd690663828eaf1defb05d7af042a3e85d8e
3
+ metadata.gz: 61c453477460f53014006e52726ef7a85f2d310c0062ff41f1d692500c351478
4
+ data.tar.gz: 13c4315a83c75575a6d22cc5585b9c65e9e1d6d2327ec700b59f1cf991fd2852
5
5
  SHA512:
6
- metadata.gz: 2a9ff4446983f2b2a996e8ea488b2f8212a16aaaeac1165244169c6d914df3bb8decdc8eb7ecef4c5afec98c0f29162d923dd288146770de8f10b4ff5335ba32
7
- data.tar.gz: e0078237b342b0578adad5a8741fa80ad2798d9d5038d30eb4eef329e440486e028f98084ffac936948e1bb94d27552c81ecca56a83b98ec67980598e8a2761f
6
+ metadata.gz: 8d29e2a152a63a6169d001863cda61a731996cd2f5e7e514bc0ebe27bc1fb101392f6b5243c86d36ed3062eb33b15f47158c1db52a4d8bebc207cf5bc62eb14f
7
+ data.tar.gz: c07a8f9d87389eb0620ee57f98fc004eae5fc22a5ece7c49d28b52179758f68f473e881640cf38d3e4e38e862c77c5a40ccd85c6f6d38a524ec4e9ee97ea93ff
data/CHANGELOG.md CHANGED
@@ -1,6 +1,29 @@
1
- # v0.8.0 2019-04-29
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
+ ## 0.10.0 2022-11-26
2
3
 
3
- This is a major overhaul of the gem which brings it closer to 1.0.0. Custom data mapping was replaced by core APIs that leverage schemas and their attributes. Custom `MapperCompiler` was added that rejects keys that are not specified in the schemas, and can be extended further to meet any future requirements.
4
+ ### Changed
5
+ - Bump dry-core to ~> 1.0 (via #52) (@tiev)
6
+
7
+ [Compare v0.9.0...v0.10.0](https://github.com/rom-rb/rom-http/compare/v0.9.0...v0.10.0)
8
+
9
+ ## 0.9.0 2022-09-27
10
+
11
+ ### Added
12
+
13
+ - Support for associations :tada: (@ianks)
14
+ - Support for ruby 3 (@AMHOL)
15
+
16
+ ### Changed
17
+ - Request params separated into query_params and body_params (@AMHOL in [#44](https://github.com/rom-rb/rom-http/pull/44))
18
+ - Minimal ruby version is set to 2.7 (@flash-gordon)
19
+
20
+ ### Fixed
21
+
22
+ - Warning message from dry-configurable (@gkostin1966)
23
+
24
+ [Compare v0.8.0...v0.9.0](https://github.com/rom-rb/rom-http/compare/v0.8.0...v0.9.0)
25
+
26
+ ## 0.8.0 2019-04-29
4
27
 
5
28
  As a consequence of these changes, with this release you can easily use `rom-http` along with repositories and changesets.
6
29
 
@@ -12,33 +35,17 @@ As a consequence of these changes, with this release you can easily use `rom-htt
12
35
  - Built-in `JSON` handlers that you can set via `handlers: :json` gateway option (solnic)
13
36
  - Convenient request method predicates `Dataset#{get?,post?,delete?,put?}` (solnic)
14
37
 
15
- ### Changed
16
-
17
- - Updated to work with `rom ~> 5.0` (parndt)
18
- - Input/output data are now handled by core functionality using schema's `input_schema` and `output_schema` (solnic)
19
- - `Dataset#name` was removed in favor of `Dataset#base_path`
20
-
21
38
  ### Fixed
22
39
 
23
40
  - `Relation#append_path` no longer duplicates `base_path` (solnic)
24
41
 
25
- [Compare v0.7.0...v0.8.0](https://github.com/rom-rb/rom-http/compare/v0.7.0...v0.8.0)
26
-
27
- # v0.7.0 2018-01-11
28
-
29
- ### Added
30
42
  - Add Dataset#add_params(AMHOL)
31
43
 
32
- ### Changed
33
44
  - Updated error messages (AMHOL)
34
45
  - updated to depend on ROM 4.0 (maximderbin)
35
46
  - Removed ruby 2.1 support (maximderbin)
36
47
  - Removed rbx-3 support (maximderbin)
37
48
 
38
- [Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom-http/compare/v0.6.0...v0.7.0)
39
-
40
- # v0.6.0 2017-02-06
41
- ### Changed
42
49
  - Make schemas mandatory and use schema API from ROM core (AMHOL)
43
50
  - Generate transformer using schema (AMHOL)
44
51
  - Removed rbx-2 support (solnic)
@@ -49,47 +56,75 @@ As a consequence of these changes, with this release you can easily use `rom-htt
49
56
  - Transform keys on insert and update (maximderbin)
50
57
  - Remove `rom-support` dependency (maximderbin)
51
58
 
52
- [Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom-http/compare/v0.5.0...v0.6.0)
53
-
54
- # v0.5.0 2016-08-08
55
- ### Changed
56
59
  - Removed ruby 2.0 support
57
60
  - Use `schema` API from ROM::Core. Replaces old schema (solnic)
58
61
  - Now works out of the box with `rom-repository` (solnic)
59
62
 
60
- [Compare v0.4.0...v0.5.0](https://github.com/rom-rb/rom-http/compare/v0.4.0...v0.5.0)
63
+ - updated to depend on the forthcoming rom 2.0 (cflipse)
64
+
65
+ - replaced dry-data with dry-types (Nikita Shilnikov <ns@latera.ru>)
66
+
67
+
68
+ - schema support using `dry-data` (AMHOL)
69
+
70
+
71
+ - Projections (`container.relation(:users).project(:id, :name)`) (AMHOL)
72
+
73
+
74
+ - `ROM::HTTP::Dataset` macros for setting `default_request_handler` and `default_response_handler` (AMHOL)
61
75
 
62
- # v0.4.0 2016-04-30
63
76
  ### Changed
64
- - updated to depend on the forthcoming rom 2.0 (cflipse)
77
+
78
+ - Updated to work with `rom ~> 5.0` (parndt)
79
+ - Input/output data are now handled by core functionality using schema's `input_schema` and `output_schema` (solnic)
80
+ - `Dataset#name` was removed in favor of `Dataset#base_path`
81
+
82
+ [Compare v0.7.0...v0.8.0](https://github.com/rom-rb/rom-http/compare/v0.7.0...v0.8.0)
83
+
84
+ ## 0.7.0 2018-01-11
85
+
86
+
87
+
88
+ [Compare v0.6.0...v0.7.0](https://github.com/rom-rb/rom-http/compare/v0.6.0...v0.7.0)
89
+
90
+ ## 0.6.0 2017-02-06
91
+
92
+
93
+
94
+ [Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom-http/compare/v0.5.0...v0.6.0)
95
+
96
+ ## 0.5.0 2016-08-08
97
+
98
+
99
+
100
+ [Compare v0.4.0...v0.5.0](https://github.com/rom-rb/rom-http/compare/v0.4.0...v0.5.0)
101
+
102
+ ## 0.4.0 2016-04-30
103
+
104
+
65
105
 
66
106
  [Compare v0.3.0...v0.4.0](https://github.com/rom-rb/rom-http/compare/v0.3.0...v0.4.0)
67
107
 
68
- # v0.3.0 2016-03-17
108
+ ## 0.3.0 2016-03-17
109
+
69
110
 
70
- ### Changed
71
- - replaced dry-data with dry-types (Nikita Shilnikov <ns@latera.ru>)
72
111
 
73
112
  [Compare v0.2.0...v0.3.0](https://github.com/rom-rb/rom-http/compare/v0.2.0...v0.3.0)
74
113
 
75
- # v0.2.0 2016-01-30
76
- ### Added
114
+ ## 0.2.0 2016-01-30
115
+
77
116
 
78
- - schema support using `dry-data` (AMHOL)
79
117
 
80
118
  [Compare v0.1.2...v0.2.0](https://github.com/rom-rb/rom-http/compare/v0.1.2...v0.2.0)
81
119
 
82
- # v0.1.2 2015-09-16
83
- ### Added
120
+ ## 0.1.2 2015-09-16
121
+
84
122
 
85
- - Projections (`container.relation(:users).project(:id, :name)`) (AMHOL)
86
123
 
87
124
  [Compare v0.1.1...v0.1.2](https://github.com/rom-rb/rom-http/compare/v0.1.1...v0.1.2)
88
125
 
89
- # v0.1.1 2015-09-03
90
- ### Added
126
+ ## 0.1.1 2015-09-03
91
127
 
92
- - `ROM::HTTP::Dataset` macros for setting `default_request_handler` and `default_response_handler` (AMHOL)
93
128
 
94
129
  ### Changed
95
130
 
@@ -99,6 +134,6 @@ As a consequence of these changes, with this release you can easily use `rom-htt
99
134
 
100
135
  [Compare v0.1.0...v0.1.1](https://github.com/rom-rb/rom-http/compare/v0.1.0...v0.1.1)
101
136
 
102
- # v0.1.0 2015-08-19
137
+ ## 0.1.0 2015-08-19
103
138
 
104
139
  First public release \o/
data/README.md CHANGED
@@ -1,192 +1,29 @@
1
1
  [gem]: https://rubygems.org/gems/rom-http
2
- [travis]: https://travis-ci.org/rom-rb/rom-http
3
- [codeclimate]: https://codeclimate.com/github/rom-rb/rom-http
4
- [inchpages]: http://inch-ci.org/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
5
4
  [chat]: https://rom-rb.zulipchat.com
5
+ [inchpages]: http://inch-ci.org/github/rom-rb/rom-http
6
6
 
7
- # rom-http [![Join the chat at https://rom-rb.zulipchat.com](https://img.shields.io/badge/rom--rb-join%20chat-942283.svg)][chat]
7
+ # rom-http [![Join the chat at https://rom-rb.zulipchat.com](https://img.shields.io/badge/rom--rb-join%20chat-%23346b7a.svg)][chat]
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/rom-http.svg)][gem]
10
- [![Build Status](https://travis-ci.org/rom-rb/rom-http.svg?branch=master)][travis]
11
- [![Code Climate](https://codeclimate.com/github/rom-rb/rom-http/badges/gpa.svg)][codeclimate]
12
- [![Test Coverage](https://codeclimate.com/github/rom-rb/rom-http/badges/coverage.svg)][codeclimate]
13
- [![Inline docs](http://inch-ci.org/github/rom-rb/rom-http.svg?branch=master)][inchpages]
14
-
15
- HTTP adapter for [rom-rb](https://github.com/rom-rb/rom).
16
-
17
- Resources:
18
-
19
- - [User Documentation](http://rom-rb.org/learn/http/)
20
- - [API Documentation](http://rubydoc.info/gems/rom-http)
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]
21
14
 
22
- ## Installation
15
+ ## Links
23
16
 
24
- Add this line to your application's Gemfile:
17
+ * [User documentation](http://rom-rb.org/learn/http)
18
+ * [API documentation](http://rubydoc.info/gems/rom-http)
25
19
 
26
- ```ruby
27
- gem 'rom-http'
28
- ```
20
+ ## Supported Ruby versions
29
21
 
30
- And then execute:
22
+ This library officially supports the following Ruby versions:
31
23
 
32
- $ bundle
33
-
34
- Or install it yourself as:
35
-
36
- $ gem install rom-http
24
+ * MRI >= `2.7`
25
+ * ~jruby >= `9.3`~ (awaits Ruby 2.7 compatibility)
37
26
 
38
27
  ## License
39
28
 
40
29
  See `LICENSE` file.
41
-
42
- ## Synopsis
43
-
44
- ```ruby
45
- require 'inflecto'
46
- require 'json'
47
- require 'uri'
48
- require 'net/http'
49
-
50
- class RequestHandler
51
- def call(dataset)
52
- uri = dataset.uri
53
- http = Net::HTTP.new(uri.host, uri.port)
54
- request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))
55
-
56
- request = request_klass.new(uri.request_uri)
57
- dataset.headers.each_with_object(request) do |(header, value), request|
58
- request[header.to_s] = value
59
- end
60
-
61
- response = http.request(request)
62
- end
63
- end
64
-
65
- class ResponseHandler
66
- def call(response, dataset)
67
- if %i(post put patch).include?(dataset.request_method)
68
- JSON.parse(response.body, symbolize_names: true)
69
- else
70
- Array([JSON.parse(response.body, symbolize_names: true)]).flatten
71
- end
72
- end
73
- end
74
-
75
- class Users < ROM::Relation[:http]
76
- schema(:users) do
77
- attribute :id, ROM::Types::Integer
78
- attribute :name, ROM::Types::String
79
- attribute :username, ROM::Types::String
80
- attribute :email, ROM::Types::String
81
- attribute :phone, ROM::Types::String
82
- attribute :website, ROM::Types::String
83
- end
84
-
85
- def by_id(id)
86
- with_path(id.to_s)
87
- end
88
- end
89
-
90
- configuration = ROM::Configuration.new(:http, {
91
- uri: 'http://jsonplaceholder.typicode.com',
92
- headers: {
93
- Accept: 'application/json'
94
- },
95
- request_handler: RequestHandler.new,
96
- response_handler: ResponseHandler.new
97
- })
98
- configuration.register_relation(Users)
99
- container = ROM.container(configuration)
100
-
101
- container.relation(:users).by_id(1).to_a
102
- # => GET http://jsonplaceholder.typicode.com/users/1 [ Accept: application/json ]
103
- ```
104
-
105
- ### Extending
106
-
107
- ```ruby
108
- require 'inflecto'
109
- require 'json'
110
- require 'uri'
111
- require 'net/http'
112
-
113
- module ROM
114
- module MyAdapter
115
- class Dataset < ROM::HTTP::Dataset
116
- configure do |config|
117
- config.default_request_handler = ->(dataset) do
118
- uri = dataset.uri
119
-
120
- http = Net::HTTP.new(uri.host, uri.port)
121
- request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))
122
-
123
- request = request_klass.new(uri.request_uri)
124
- dataset.headers.each_with_object(request) do |(header, value), request|
125
- request[header.to_s] = value
126
- end
127
-
128
- response = http.request(request)
129
- end
130
-
131
- config.default_response_handler = ->(response, dataset) do
132
- if %i(post put patch).include?(dataset.request_method)
133
- JSON.parse(response.body, symbolize_names: true)
134
- else
135
- Array([JSON.parse(response.body, symbolize_names: true)]).flatten
136
- end
137
- end
138
- end
139
- end
140
-
141
- class Gateway < ROM::HTTP::Gateway; end
142
-
143
- class Relation < ROM::HTTP::Relation
144
- adapter :my_adapter
145
- end
146
-
147
- module Commands
148
- class Create < ROM::HTTP::Commands::Create
149
- adapter :my_adapter
150
- end
151
-
152
- class Update < ROM::HTTP::Commands::Update
153
- adapter :my_adapter
154
- end
155
-
156
- class Delete < ROM::HTTP::Commands::Delete
157
- adapter :my_adapter
158
- end
159
- end
160
- end
161
- end
162
-
163
- ROM.register_adapter(:my_adapter, ROM::MyAdapter)
164
-
165
- configuration = ROM::Configuration.new(:my_adapter, {
166
- uri: 'http://jsonplaceholder.typicode.com',
167
- headers: {
168
- Accept: 'application/json'
169
- }
170
- })
171
-
172
- class Users < ROM::Relation[:my_adapter]
173
- schema(:users) do
174
- attribute :id, ROM::Types::Integer
175
- attribute :name, ROM::Types::String
176
- attribute :username, ROM::Types::String
177
- attribute :email, ROM::Types::String
178
- attribute :phone, ROM::Types::String
179
- attribute :website, ROM::Types::String
180
- end
181
-
182
- def by_id(id)
183
- with_path(id.to_s)
184
- end
185
- end
186
-
187
- configuration.register_relation(Users)
188
- container = ROM.container(configuration)
189
-
190
- container.relation(:users).by_id(1).to_a
191
- # => GET http://jsonplaceholder.typicode.com/users/1 [ Accept: application/json ]
192
- ```
@@ -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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/attribute'
3
+ require "rom/attribute"
4
4
 
5
5
  module ROM
6
6
  module HTTP
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/commands'
4
- require 'rom/http/commands/create'
5
- require 'rom/http/commands/update'
6
- require 'rom/http/commands/delete'
3
+ require "rom/commands"
4
+ require "rom/http/commands/create"
5
+ require "rom/http/commands/update"
6
+ require "rom/http/commands/delete"
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'uri'
3
+ require "uri"
4
4
 
5
- require 'dry/configurable'
6
- require 'dry/core/deprecations'
5
+ require "dry/configurable"
6
+ require "dry/core/deprecations"
7
7
 
8
- require 'rom/support/memoizable'
9
- require 'rom/constants'
10
- require 'rom/initializer'
11
- require 'rom/http/types'
12
- require 'rom/http/transformer'
8
+ require "rom/support/memoizable"
9
+ require "rom/constants"
10
+ require "rom/initializer"
11
+ require "rom/http/types"
12
+ require "rom/http/transformer"
13
13
 
14
14
  module ROM
15
15
  module HTTP
@@ -22,7 +22,7 @@ module ROM
22
22
  #
23
23
  # @api public
24
24
  class Dataset
25
- PATH_SEPARATOR = '/'.freeze
25
+ PATH_SEPARATOR = "/"
26
26
 
27
27
  extend Dry::Configurable
28
28
  extend ROM::Initializer
@@ -59,19 +59,19 @@ module ROM
59
59
  # MyDataset.new(uri: "http://localhost").response_handler # MyResponseHandler
60
60
  setting :default_response_handler, reader: true
61
61
 
62
- # @!method self.param_encoder
63
- # Return configured param encoder
62
+ # @!method self.query_param_encoder
63
+ # Return configured query param encoder
64
64
  #
65
65
  # @example
66
66
  # class MyDataset < ROM::HTTP::Dataset
67
67
  # configure do |config|
68
- # config.param_encoder = MyParamEncoder
68
+ # config.query_param_encoder = MyParamEncoder
69
69
  # end
70
70
  # end
71
71
  #
72
- # MyDataset.param_encoder # MyParamEncoder
73
- # MyDataset.new(uri: "http://localhost").param_encoder # MyParamEncoder
74
- setting :param_encoder, URI.method(:encode_www_form), reader: true
72
+ # MyDataset.query_param_encoder # MyParamEncoder
73
+ # MyDataset.new(uri: "http://localhost").query_param_encoder # MyParamEncoder
74
+ setting :query_param_encoder, default: URI.method(:encode_www_form), reader: true
75
75
 
76
76
  # @!attribute [r] request_handler
77
77
  # @return [Object]
@@ -98,10 +98,15 @@ module ROM
98
98
  # @api public
99
99
  option :path, type: Types::Path, default: proc { EMPTY_STRING }
100
100
 
101
- # @!attribute [r] params
101
+ # @!attribute [r] query_params
102
102
  # @return [Hash]
103
103
  # @api public
104
- option :params, type: Types::Hash, default: proc { EMPTY_HASH }
104
+ option :query_params, type: Types::Hash, default: proc { EMPTY_HASH }
105
+
106
+ # @!attribute [r] body_params
107
+ # @return [Hash]
108
+ # @api public
109
+ option :body_params, type: Types::Hash, default: proc { EMPTY_HASH }
105
110
 
106
111
  # @!attribute [r] headers
107
112
  # @return [Hash]
@@ -111,7 +116,7 @@ module ROM
111
116
  # @!attribute [r] headers
112
117
  # @return [Hash]
113
118
  # @api public
114
- option :param_encoder, default: proc { self.class.param_encoder }
119
+ option :query_param_encoder, default: proc { self.class.query_param_encoder }
115
120
 
116
121
  # @!attribute [r] uri
117
122
  # @return [String]
@@ -126,8 +131,8 @@ module ROM
126
131
  def uri
127
132
  uri = URI(join_path(super, path))
128
133
 
129
- if get? && params.any?
130
- uri.query = param_encoder.call(params)
134
+ if query_params.any?
135
+ uri.query = query_param_encoder.call(query_params)
131
136
  end
132
137
 
133
138
  uri
@@ -239,7 +244,7 @@ module ROM
239
244
  #
240
245
  # @api public
241
246
  def with_options(opts)
242
- __new__(options.merge(opts))
247
+ __new__(**options.merge(opts))
243
248
  end
244
249
 
245
250
  # Return a new dataset with a different base path
@@ -301,36 +306,70 @@ module ROM
301
306
  with_options(request_method: request_method)
302
307
  end
303
308
 
304
- # Return a new dataset with replaced request parameters
309
+ # Return a new dataset with replaced request query parameters
310
+ #
311
+ # @param [Hash] query_params the new request query parameters
312
+ #
313
+ # @example
314
+ # users = Dataset.new(query_params: { uid: 33 })
315
+ # users.with_query_params(login: 'jdoe').query_params
316
+ # # => { :login => 'jdoe' }
317
+ #
318
+ # @return [Dataset]
319
+ #
320
+ # @api public
321
+ def with_query_params(query_params)
322
+ with_options(query_params: query_params)
323
+ end
324
+
325
+ # Return a new dataset with merged request query parameters
326
+ #
327
+ # @param [Hash] query_params the new request query parameters to add
328
+ #
329
+ # @example
330
+ # users = Dataset.new(query_params: { uid: 33 })
331
+ # users.add_query_params(login: 'jdoe').query_params
332
+ # # => { uid: 33, :login => 'jdoe' }
333
+ #
334
+ # @return [Dataset]
335
+ #
336
+ # @api public
337
+ def add_query_params(new_query_params)
338
+ with_options(query_params: ::ROM::HTTP::Transformer[:deep_merge][query_params,
339
+ new_query_params])
340
+ end
341
+
342
+ # Return a new dataset with replaced request body parameters
305
343
  #
306
- # @param [Hash] params the new request parameters
344
+ # @param [Hash] body_params the new request body parameters
307
345
  #
308
346
  # @example
309
- # users = Dataset.new(params: { uid: 33 })
310
- # users.with_params(login: 'jdoe').params
347
+ # users = Dataset.new(body_params: { uid: 33 })
348
+ # users.with_body_params(login: 'jdoe').body_params
311
349
  # # => { :login => 'jdoe' }
312
350
  #
313
351
  # @return [Dataset]
314
352
  #
315
353
  # @api public
316
- def with_params(params)
317
- with_options(params: params)
354
+ def with_body_params(body_params)
355
+ with_options(body_params: body_params)
318
356
  end
319
357
 
320
- # Return a new dataset with merged request parameters
358
+ # Return a new dataset with merged request body parameters
321
359
  #
322
- # @param [Hash] params the new request parameters to add
360
+ # @param [Hash] body_params the new request body parameters to add
323
361
  #
324
362
  # @example
325
- # users = Dataset.new(params: { uid: 33 })
326
- # users.add_params(login: 'jdoe').params
363
+ # users = Dataset.new(body_params: { uid: 33 })
364
+ # users.add_body_params(login: 'jdoe').body_params
327
365
  # # => { uid: 33, :login => 'jdoe' }
328
366
  #
329
367
  # @return [Dataset]
330
368
  #
331
369
  # @api public
332
- def add_params(new_params)
333
- with_options(params: ::ROM::HTTP::Transformer[:deep_merge][params, new_params])
370
+ def add_body_params(new_body_params)
371
+ with_options(body_params: ::ROM::HTTP::Transformer[:deep_merge][body_params,
372
+ new_body_params])
334
373
  end
335
374
 
336
375
  # Iterate over each response value
@@ -343,29 +382,36 @@ module ROM
343
382
  # @api public
344
383
  def each(&block)
345
384
  return to_enum unless block_given?
385
+
346
386
  response.each(&block)
347
387
  end
348
388
 
349
389
  # Perform an insert over HTTP Post
350
390
  #
351
- # @params [Hash] params The request parameters to send
391
+ # @param [Hash] attributes the attributes to insert
352
392
  #
353
393
  # @return [Array<Hash>]
354
394
  #
355
395
  # @api public
356
- def insert(params)
357
- with_options(request_method: :post, params: params).response
396
+ def insert(attributes)
397
+ with_options(
398
+ request_method: :post,
399
+ body_params: attributes
400
+ ).response
358
401
  end
359
402
 
360
403
  # Perform an update over HTTP Put
361
404
  #
362
- # @params [Hash] params The request parameters to send
405
+ # @param [Hash] attributes the attributes to update
363
406
  #
364
407
  # @return [Array<Hash>]
365
408
  #
366
409
  # @api public
367
- def update(params)
368
- with_options(request_method: :put, params: params).response
410
+ def update(attributes)
411
+ with_options(
412
+ request_method: :put,
413
+ body_params: attributes
414
+ ).response
369
415
  end
370
416
 
371
417
  # Perform an delete over HTTP Delete
@@ -392,8 +438,8 @@ module ROM
392
438
  private
393
439
 
394
440
  # @api private
395
- def __new__(*args, &block)
396
- self.class.new(*args, &block)
441
+ def __new__(*args, **kwargs, &block)
442
+ self.class.new(*args, **kwargs, &block)
397
443
  end
398
444
 
399
445
  # @api private
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'concurrent'
3
+ require "concurrent"
4
4
 
5
- require 'rom/http/dataset'
6
- require 'rom/http/handlers'
7
- require 'rom/http/mapper_compiler'
5
+ require "rom/http/dataset"
6
+ require "rom/http/handlers"
7
+ require "rom/http/mapper_compiler"
8
8
 
9
9
  module ROM
10
10
  module HTTP
@@ -58,7 +58,7 @@ module ROM
58
58
  #
59
59
  # @api public
60
60
  def dataset(name)
61
- datasets[name] = dataset_class.new(dataset_options(name))
61
+ datasets[name] = dataset_class.new(**dataset_options(name))
62
62
  end
63
63
 
64
64
  # Check if dataset exists
@@ -96,7 +96,7 @@ module ROM
96
96
  #
97
97
  # @api private
98
98
  def default_handlers
99
- if handlers_key = config[:handlers]
99
+ if (handlers_key = config[:handlers])
100
100
  Handlers[handlers_key]
101
101
  .map { |key, value| [:"#{key}_handler", value] }.to_h
102
102
  else
@@ -106,12 +106,12 @@ module ROM
106
106
 
107
107
  # @api private
108
108
  def uri
109
- config.fetch(:uri) { fail Error, '+uri+ configuration missing' }
109
+ config.fetch(:uri) { raise Error, "+uri+ configuration missing" }
110
110
  end
111
111
 
112
112
  # @api private
113
113
  def namespace
114
- self.class.to_s[/(.*)(?=::)/].split('::').inject(::Object) do |constant, const_name|
114
+ self.class.to_s[/(.*)(?=::)/].split("::").inject(::Object) do |constant, const_name|
115
115
  constant.const_get(const_name)
116
116
  end
117
117
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'uri'
4
- require 'net/http'
5
- require 'json'
3
+ require "uri"
4
+ require "net/http"
5
+ require "json"
6
6
 
7
- require 'rom/support/inflector'
7
+ require "rom/support/inflector"
8
8
 
9
9
  module ROM
10
10
  module HTTP
@@ -24,22 +24,21 @@ module ROM
24
24
  #
25
25
  # @api public
26
26
  def self.call(dataset)
27
- uri = URI(dataset.uri)
28
-
29
- uri.path = dataset.absolute_path
30
- uri.query = URI.encode_www_form(dataset.params)
27
+ uri = dataset.uri
31
28
 
32
29
  http = Net::HTTP.new(uri.host, uri.port)
33
- http.use_ssl = true if uri.scheme.eql?('https')
30
+ http.use_ssl = true if uri.scheme.eql?("https")
34
31
 
35
32
  request_class = Net::HTTP.const_get(ROM::Inflector.classify(dataset.request_method))
36
33
 
37
34
  request = request_class.new(uri.request_uri)
38
35
 
39
- dataset.headers.each_with_object(request) do |(header, value), request|
40
- request[header.to_s] = value
36
+ dataset.headers.each_with_object(request) do |(header, value), req|
37
+ req[header.to_s] = value
41
38
  end
42
39
 
40
+ request.body = JSON.dump(dataset.body_params) if dataset.body_params.any?
41
+
43
42
  http.request(request)
44
43
  end
45
44
  end
@@ -56,7 +55,7 @@ module ROM
56
55
  # @return [Array<Hash>]
57
56
  #
58
57
  # @api public
59
- def self.call(response, dataset)
58
+ def self.call(response, _dataset)
60
59
  Array([JSON.parse(response.body)]).flatten(1)
61
60
  end
62
61
  end
@@ -1,4 +1,6 @@
1
- require 'rom/http/handlers/json'
1
+ # frozen_string_literal: true
2
+
3
+ require "rom/http/handlers/json"
2
4
 
3
5
  module ROM
4
6
  module HTTP
@@ -6,7 +8,7 @@ module ROM
6
8
  #
7
9
  # @api public
8
10
  class Handlers
9
- extend Dry::Container::Mixin
11
+ extend Dry::Core::Container::Mixin
10
12
 
11
13
  register(:json, request: JSONRequest, response: JSONResponse)
12
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/mapper_compiler'
3
+ require "rom/mapper_compiler"
4
4
 
5
5
  module ROM
6
6
  module HTTP
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/initializer'
3
+ require "rom/initializer"
4
4
 
5
- require 'rom/http/types'
6
- require 'rom/http/attribute'
7
- require 'rom/http/schema'
8
- require 'rom/http/schema/dsl'
5
+ require "rom/http/types"
6
+ require "rom/http/attribute"
7
+ require "rom/http/schema"
8
+ require "rom/http/schema/dsl"
9
9
 
10
10
  module ROM
11
11
  module HTTP
@@ -24,7 +24,8 @@ module ROM
24
24
 
25
25
  forward :with_headers, :add_header, :with_options,
26
26
  :with_base_path, :with_path, :append_path,
27
- :with_request_method, :with_params, :add_params
27
+ :with_request_method, :with_query_params, :add_query_params,
28
+ :with_body_params, :add_body_params
28
29
 
29
30
  def primary_key
30
31
  schema.primary_key_name
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/schema/dsl'
3
+ require "rom/schema/dsl"
4
4
 
5
5
  module ROM
6
6
  module HTTP
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/schema'
4
- require 'rom/http/types'
3
+ require "rom/schema"
4
+ require "rom/http/types"
5
5
 
6
6
  module ROM
7
7
  module HTTP
@@ -15,6 +15,26 @@ module ROM
15
15
  .schema(map { |attr| [attr.key, attr.to_read_type] }.to_h)
16
16
  .with_key_transform(&:to_sym)
17
17
  end
18
+
19
+ # To maintain compatibility with other adapters
20
+ #
21
+ # @api private
22
+ def qualified
23
+ self
24
+ end
25
+
26
+ # Internal hook used during setup process
27
+ #
28
+ # @see Schema#finalize_associations!
29
+ #
30
+ # @api private
31
+ def finalize_associations!(relations:)
32
+ super do
33
+ associations.map do |definition|
34
+ HTTP::Associations.const_get(definition.type).new(definition, relations)
35
+ end
36
+ end
37
+ end
18
38
  end
19
39
  end
20
40
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/types'
3
+ require "rom/types"
4
4
 
5
5
  module ROM
6
6
  module HTTP
7
7
  module Types
8
8
  include ROM::Types
9
9
 
10
- Path = Coercible::String.constructor { |s| s.sub(%r{\A/}, '') }
10
+ Path = Coercible::String.constructor { |s| s.sub(%r{\A/}, "") }
11
11
  end
12
12
  end
13
13
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ROM
4
4
  module HTTP
5
- VERSION = '0.8.0'.freeze
5
+ VERSION = "0.10.0"
6
6
  end
7
7
  end
data/lib/rom/http.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom'
4
- require 'rom/http/error'
5
- require 'rom/http/commands'
6
- require 'rom/http/gateway'
7
- require 'rom/http/relation'
8
- require 'rom/http/version'
3
+ require "rom"
4
+ require "rom/http/error"
5
+ require "rom/http/commands"
6
+ require "rom/http/associations"
7
+ require "rom/http/gateway"
8
+ require "rom/http/relation"
9
+ require "rom/http/version"
9
10
 
10
11
  ROM.register_adapter(:http, ROM::HTTP)
data/lib/rom-http.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/http'
3
+ require "rom/http"
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  - Andy Holland
9
9
  - Chris Flipse
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-04-29 00:00:00.000000000 Z
13
+ date: 2022-11-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby
@@ -41,7 +41,7 @@ dependencies:
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2.6'
43
43
  - !ruby/object:Gem::Dependency
44
- name: rom-core
44
+ name: rom
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
@@ -66,14 +66,14 @@ dependencies:
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0.4'
69
+ version: '1.0'
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '0.4'
76
+ version: '1.0'
77
77
  - !ruby/object:Gem::Dependency
78
78
  name: dry-equalizer
79
79
  requirement: !ruby/object:Gem::Requirement
@@ -94,70 +94,14 @@ dependencies:
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '0.6'
97
+ version: '1.0'
98
98
  type: :runtime
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0.6'
105
- - !ruby/object:Gem::Dependency
106
- name: bundler
107
- requirement: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- type: :development
113
- prerelease: false
114
- version_requirements: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- - !ruby/object:Gem::Dependency
120
- name: rspec
121
- requirement: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - "~>"
124
- - !ruby/object:Gem::Version
125
- version: '3.1'
126
- type: :development
127
- prerelease: false
128
- version_requirements: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - "~>"
131
- - !ruby/object:Gem::Version
132
- version: '3.1'
133
- - !ruby/object:Gem::Dependency
134
- name: rspec-its
135
- requirement: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: '0'
140
- type: :development
141
- prerelease: false
142
- version_requirements: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- version: '0'
147
- - !ruby/object:Gem::Dependency
148
- name: rake
149
- requirement: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - "~>"
152
- - !ruby/object:Gem::Version
153
- version: '10.0'
154
- type: :development
155
- prerelease: false
156
- version_requirements: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - "~>"
159
- - !ruby/object:Gem::Version
160
- version: '10.0'
104
+ version: '1.0'
161
105
  description: HTTP support for ROM
162
106
  email:
163
107
  - piotr.solnica@gmail.com
@@ -168,10 +112,14 @@ extensions: []
168
112
  extra_rdoc_files: []
169
113
  files:
170
114
  - CHANGELOG.md
171
- - LICENSE.txt
172
115
  - README.md
173
116
  - lib/rom-http.rb
174
117
  - lib/rom/http.rb
118
+ - lib/rom/http/associations.rb
119
+ - lib/rom/http/associations/many_to_many.rb
120
+ - lib/rom/http/associations/many_to_one.rb
121
+ - lib/rom/http/associations/one_to_many.rb
122
+ - lib/rom/http/associations/one_to_one.rb
175
123
  - lib/rom/http/attribute.rb
176
124
  - lib/rom/http/commands.rb
177
125
  - lib/rom/http/commands/create.rb
@@ -193,7 +141,7 @@ homepage: https://rom-rb.org
193
141
  licenses:
194
142
  - MIT
195
143
  metadata: {}
196
- post_install_message:
144
+ post_install_message:
197
145
  rdoc_options: []
198
146
  require_paths:
199
147
  - lib
@@ -201,15 +149,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
149
  requirements:
202
150
  - - ">="
203
151
  - !ruby/object:Gem::Version
204
- version: 2.4.0
152
+ version: 2.7.0
205
153
  required_rubygems_version: !ruby/object:Gem::Requirement
206
154
  requirements:
207
155
  - - ">="
208
156
  - !ruby/object:Gem::Version
209
157
  version: '0'
210
158
  requirements: []
211
- rubygems_version: 3.0.3
212
- signing_key:
159
+ rubygems_version: 3.3.7
160
+ signing_key:
213
161
  specification_version: 4
214
162
  summary: HTTP support for ROM
215
163
  test_files: []
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2015-2019 rom-rb team
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.