remote_entity 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +20 -7
- data/lib/remote_entity/version.rb +1 -1
- data/lib/remote_entity.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d8b35779a4cd6204b0f6358cee10e4eb64d168f73fecb5295d50bd8659993b4
|
4
|
+
data.tar.gz: b0e7d3508d849c0de2c3025059be4658890dc73f5d396ecc3f14b1f55536a2c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 274f9feec9c4c1a44513b0e0caf1875d0e5463b836c10d086a61e6140b7b09335c921039b2dd3c086c11f981bed0e39fd2048eae60f760bba645d83ecb1eef80
|
7
|
+
data.tar.gz: 85d6388a3d9d9414f7db1a0b0eadc094f30cdce523360d0593ee3e16bb11ed18103e0d415ef692f76fbe9612c63e74cc8f435da2aa3176c1c26313732806d5ef
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
remote_entity (
|
4
|
+
remote_entity (2.0.0)
|
5
5
|
cgi (~> 0.2)
|
6
6
|
oauth2 (~> 2.0)
|
7
7
|
|
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
ast (~> 2.4.1)
|
36
36
|
racc
|
37
37
|
racc (1.7.3)
|
38
|
-
rack (3.0.
|
38
|
+
rack (3.0.9)
|
39
39
|
rainbow (3.1.1)
|
40
40
|
rake (13.1.0)
|
41
41
|
regexp_parser (2.9.0)
|
data/README.md
CHANGED
@@ -58,15 +58,29 @@ RemoteEntity.configure(
|
|
58
58
|
}
|
59
59
|
)
|
60
60
|
```
|
61
|
+
The configuration generated `RemoteEntity::User` class with `find` method which can be used by the following example:
|
62
|
+
|
63
|
+
```
|
64
|
+
RemoteEntity::User.find(id: 1, public: true)
|
61
65
|
```
|
62
|
-
|
66
|
+
**NOTE**:
|
67
|
+
- All entity classes created are under `RemoteEntity` namespace.
|
68
|
+
- The classes generated are a typical Ruby class which can be extended, inherited. For example:
|
63
69
|
```
|
64
|
-
|
70
|
+
class UserService < RemoteEntity::User
|
71
|
+
|
72
|
+
end
|
73
|
+
```
|
74
|
+
- The methods generated are `class method`.
|
75
|
+
- The method parameter generated from configuration is always key/value pairs (hash)
|
76
|
+
|
77
|
+
The method parameters will be transformed into `path parameter`, `query parameter` or `body parameter` of the request by `param_mapping` configuration. It makes the following `GET` http request:
|
65
78
|
```
|
66
79
|
curl --location 'https://example.com/users/1?public=true' \
|
67
80
|
--header 'Content-Type: application/json' \
|
68
81
|
--header 'Authorization: Bearer <token>'
|
69
82
|
```
|
83
|
+
|
70
84
|
`Content-Type` header as `application/json` is by default.
|
71
85
|
|
72
86
|
`Authorization` header is generated by oauth2 request using grant type defined in the configuration. The example above uses ouath2 client_credentials grant type. (The gem uses [oauth2](https://gitlab.com/oauth-xx/oauth2/) gem underdying, so the param structure is pretty the same as oauth2)
|
@@ -79,10 +93,11 @@ Since the `find` method is configured to return value (`r_turn` is set to `true`
|
|
79
93
|
age: 22
|
80
94
|
}
|
81
95
|
```
|
96
|
+
The configuration also creates `create` method. For example:
|
82
97
|
```
|
83
|
-
User.create(name: "John", age: 23)
|
98
|
+
RemoteEntity::User.create(name: "John", age: 23)
|
84
99
|
```
|
85
|
-
|
100
|
+
It will make the following `POST` http request:
|
86
101
|
```
|
87
102
|
curl --location 'https://example.com/users' \
|
88
103
|
--header 'Content-Type: application/json' \
|
@@ -94,9 +109,7 @@ curl --location 'https://example.com/users' \
|
|
94
109
|
```
|
95
110
|
It has no authorization configured, so no `Authorization` header.
|
96
111
|
|
97
|
-
It does not return anything as `r_turn` is set to `false
|
98
|
-
|
99
|
-
**NOTE**: All http request params whether it is query parameter, path parameter or body parameter, it will always transform into key/value pairs parameter of the entity method.
|
112
|
+
It does not return anything as `r_turn` is set to `false`.
|
100
113
|
|
101
114
|
## Contributing
|
102
115
|
|
data/lib/remote_entity.rb
CHANGED
@@ -16,7 +16,7 @@ module RemoteEntity
|
|
16
16
|
raise "missing required parameter - name" if options[:name].nil?
|
17
17
|
raise "missing required parameter - methods" if options[:methods].nil?
|
18
18
|
|
19
|
-
|
19
|
+
RemoteEntity.const_set(options[:name], build_dynamic_class(options))
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.build_dynamic_class(options)
|
@@ -104,4 +104,6 @@ module RemoteEntity
|
|
104
104
|
token = client.send(grant_type).get_token(scope: credentials_info[:scope]).token
|
105
105
|
"Bearer #{token}"
|
106
106
|
end
|
107
|
+
|
108
|
+
private_class_method :build_dynamic_class
|
107
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_entity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuroun Seung
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cgi
|