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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33a2e9d809f7e4a0c941f234aa3e3d3c7233934cb476b44505ea12ae8980847d
4
- data.tar.gz: 3eadac241251a0e74fa92673864799579bc20b3fb6fd8d8fd894566379b56caf
3
+ metadata.gz: 0d8b35779a4cd6204b0f6358cee10e4eb64d168f73fecb5295d50bd8659993b4
4
+ data.tar.gz: b0e7d3508d849c0de2c3025059be4658890dc73f5d396ecc3f14b1f55536a2c2
5
5
  SHA512:
6
- metadata.gz: 4a4ddfb164a2ab1c6509fbfba0892ae8e0c8a0edc3c23fb67e8235971ee58c4df6dd585d0bba8f7cdd9f1b161bef0d23c4b3143676531b0c22811f6389e15184
7
- data.tar.gz: 3512aaac40f588bae7f232b77e8953662718182d0473ce946ca7cacd8839fef15633c042330c601bb201167b6060718688a585d0f17a4d8ab551c075631f974e
6
+ metadata.gz: 274f9feec9c4c1a44513b0e0caf1875d0e5463b836c10d086a61e6140b7b09335c921039b2dd3c086c11f981bed0e39fd2048eae60f760bba645d83ecb1eef80
7
+ data.tar.gz: 85d6388a3d9d9414f7db1a0b0eadc094f30cdce523360d0593ee3e16bb11ed18103e0d415ef692f76fbe9612c63e74cc8f435da2aa3176c1c26313732806d5ef
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
1
  ## [1.0.0] - 2024-01-18
2
2
 
3
3
  - Initial release
4
+
5
+ ## [2.0.0] - 2024-02-09
6
+
7
+ - Add `RemoteEntity` namespace to class generated. For example, `RemoteEntity::User`.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remote_entity (1.0.0)
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.8)
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
- User.find(id: 1, public: true)
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
- Above will translate to following `GET` http request. `param_mapping` will transform any `path parameter`, and `query parameter` of the request into `User` entity method parameter.
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
- Above will translate to following `POST` http request. `param_mapping` will transform `body parameter` of the request into `User` entity method parameter.
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteEntity
4
- VERSION = "1.0.0"
4
+ VERSION = "2.0.0"
5
5
  end
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
- Object.const_set(options[:name], RemoteEntity.build_dynamic_class(options))
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: 1.0.0
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-01-18 00:00:00.000000000 Z
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cgi