remote_entity 2.0.0 → 2.1.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: 0d8b35779a4cd6204b0f6358cee10e4eb64d168f73fecb5295d50bd8659993b4
4
- data.tar.gz: b0e7d3508d849c0de2c3025059be4658890dc73f5d396ecc3f14b1f55536a2c2
3
+ metadata.gz: 8b067d90ced8890a77499154dea7970e77d5805d48a16b5d67eef7890a3d21b9
4
+ data.tar.gz: 99284e3c3f68804086a88b6d0bad1b55b5cc3b52b2c38f1b5a7c314a0334467f
5
5
  SHA512:
6
- metadata.gz: 274f9feec9c4c1a44513b0e0caf1875d0e5463b836c10d086a61e6140b7b09335c921039b2dd3c086c11f981bed0e39fd2048eae60f760bba645d83ecb1eef80
7
- data.tar.gz: 85d6388a3d9d9414f7db1a0b0eadc094f30cdce523360d0593ee3e16bb11ed18103e0d415ef692f76fbe9612c63e74cc8f435da2aa3176c1c26313732806d5ef
6
+ metadata.gz: 1e557430c6043180f1ca654c62f143798764a7297154823528cd7e327f68a764a6684224672ca744dca94682562a96d7b9d96123df79651568c7773e4bed1c53
7
+ data.tar.gz: d527cfc59ec21bf1c969dc7c29beb515097f5b62f18597bdb7ee41bfeb3ec867092e21a4f602fee7acec52e5c269d9ac1459f1b1b416d0c925c3ef4c49e8d051
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.5
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
data/CHANGELOG.md CHANGED
@@ -5,3 +5,9 @@
5
5
  ## [2.0.0] - 2024-02-09
6
6
 
7
7
  - Add `RemoteEntity` namespace to class generated. For example, `RemoteEntity::User`.
8
+
9
+
10
+ ## [2.1.0] - 2024-04-26
11
+
12
+ - Allow instant authorized token in the method params and bypass request to get oauth2 token
13
+ - Allow this gem to use with Ruby >= 2.5.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remote_entity (2.0.0)
4
+ remote_entity (2.1.0)
5
5
  cgi (~> 0.2)
6
6
  oauth2 (~> 2.0)
7
7
 
@@ -9,6 +9,7 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  ast (2.4.2)
12
+ base64 (0.2.0)
12
13
  cgi (0.4.1)
13
14
  diff-lcs (1.5.0)
14
15
  docile (1.4.0)
@@ -18,7 +19,8 @@ GEM
18
19
  net-http
19
20
  hashie (5.0.0)
20
21
  json (2.7.1)
21
- jwt (2.7.1)
22
+ jwt (2.8.1)
23
+ base64
22
24
  language_server-protocol (3.17.0.3)
23
25
  multi_xml (0.6.0)
24
26
  net-http (0.4.1)
@@ -35,7 +37,7 @@ GEM
35
37
  ast (~> 2.4.1)
36
38
  racc
37
39
  racc (1.7.3)
38
- rack (3.0.9)
40
+ rack (3.0.10)
39
41
  rainbow (3.1.1)
40
42
  rake (13.1.0)
41
43
  regexp_parser (2.9.0)
@@ -78,7 +80,7 @@ GEM
78
80
  version_gem (~> 1.1, >= 1.1.1)
79
81
  unicode-display_width (2.5.0)
80
82
  uri (0.13.0)
81
- version_gem (1.1.3)
83
+ version_gem (1.1.4)
82
84
 
83
85
  PLATFORMS
84
86
  ruby
data/README.md CHANGED
@@ -6,6 +6,9 @@ It is something less restricts than [her](https://github.com/remi/her) which map
6
6
 
7
7
  Currently it supports oauth2 `client_credentials` grant type for API authentication.
8
8
 
9
+ ## Supporting Ruby versions
10
+ This gem can be used in Ruby >= 2.5.0. However, it might have incompatibilities as this gem was tested with Ruby 3.2.2. Please test thoroughly.
11
+
9
12
  ## Installation
10
13
 
11
14
  Install the gem and add to the application's Gemfile by executing:
@@ -31,7 +34,8 @@ RemoteEntity.configure(
31
34
  query_params: [:public]
32
35
  },
33
36
  authentication: {
34
- method: "oauth2.client_credentials"
37
+ method: "oauth2.client_credentials",
38
+ accepting_instant_token: :authorized_token
35
39
  },
36
40
  r_turn: true
37
41
  },
@@ -83,7 +87,11 @@ curl --location 'https://example.com/users/1?public=true' \
83
87
 
84
88
  `Content-Type` header as `application/json` is by default.
85
89
 
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)
90
+ `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). However, if the method has `authentication` key which includes `accepting_instant_token: :authorized_token`, the authentication token request will be bypassed. The `authorized_token` param value will pass instantly in the request `Authorization` header. For example:
91
+
92
+ ```
93
+ RemoteEntity::User.find(id: 1, public: true, authorized_token: "authorized-token")
94
+ ```
87
95
 
88
96
  Since the `find` method is configured to return value (`r_turn` is set to `true`), it will return whatever the http response has. For example:
89
97
  ```
@@ -113,7 +121,7 @@ It does not return anything as `r_turn` is set to `false`.
113
121
 
114
122
  ## Contributing
115
123
 
116
- Bug reports and pull requests are welcome on GitHub at https://github.com/kseung-gpsw/remote_entity. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/remote_entity/blob/main/CODE_OF_CONDUCT.md).
124
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kuroun/remote_entity. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/remote_entity/blob/main/CODE_OF_CONDUCT.md).
117
125
 
118
126
  ## License
119
127
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RemoteEntity
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.0"
5
5
  end
data/lib/remote_entity.rb CHANGED
@@ -32,24 +32,32 @@ module RemoteEntity
32
32
  request = http_class.new(url)
33
33
  request["Content-Type"] = "application/json"
34
34
 
35
- if method[:authentication] && method[:authentication][:method].include?("oauth2")
36
- request["Authorization"] =
37
- RemoteEntity.build_oauth2_authorized_token_header(method[:authentication][:method],
38
- options[:authentications])
39
- end
35
+ RemoteEntity.set_authorization_header(request, method, arg, options) if method[:authentication]
40
36
 
41
37
  if method[:param_mapping] && method[:param_mapping][:body_params]
42
38
  request.body = JSON.dump(RemoteEntity.build_body_params(method[:param_mapping][:body_params], arg))
43
39
  end
44
40
 
45
41
  response = https.request(request)
46
- attributes = JSON.parse(response.read_body)
47
- return attributes if method[:r_turn]
42
+
43
+ return JSON.parse(response.read_body) if method[:r_turn] && !response.read_body.empty?
48
44
  end
49
45
  end
50
46
  end
51
47
  end
52
48
 
49
+ def self.set_authorization_header(request, method, arg, options)
50
+ accepting_instant_token_key = method[:authentication][:accepting_instant_token]
51
+
52
+ if accepting_instant_token_key && arg[accepting_instant_token_key]
53
+ request["Authorization"] = "Bearer #{arg[accepting_instant_token_key]}"
54
+ elsif method[:authentication][:method].include?("oauth2")
55
+ request["Authorization"] =
56
+ RemoteEntity.build_oauth2_authorized_token_header(method[:authentication][:method],
57
+ options[:authentications])
58
+ end
59
+ end
60
+
53
61
  def self.build_url(method, arg)
54
62
  url = method[:url]
55
63
 
@@ -102,6 +110,7 @@ module RemoteEntity
102
110
  site: credentials_info[:site],
103
111
  token_url: credentials_info[:token_url])
104
112
  token = client.send(grant_type).get_token(scope: credentials_info[:scope]).token
113
+
105
114
  "Bearer #{token}"
106
115
  end
107
116
 
@@ -9,15 +9,15 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["kuroun.seung@gmail.com"]
10
10
 
11
11
  spec.summary = "Using configuration style to generate Ruby classes and methods that wrap the API calls to a remote service."
12
- spec.homepage = "https://github.com/kseung-gpsw/remote_entity"
12
+ spec.homepage = "https://github.com/kuroun/remote_entity"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.6.0"
14
+ spec.required_ruby_version = ">= 2.5.0"
15
15
 
16
16
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
17
 
18
18
  spec.metadata["homepage_uri"] = spec.homepage
19
- spec.metadata["source_code_uri"] = "https://github.com/kseung-gpsw/remote_entity"
20
- spec.metadata["changelog_uri"] = "https://github.com/kseung-gpsw/remote_entity/blob/main/CHANGELOG.md"
19
+ spec.metadata["source_code_uri"] = "https://github.com/kuroun/remote_entity"
20
+ spec.metadata["changelog_uri"] = "https://github.com/kuroun/remote_entity/blob/main/CHANGELOG.md"
21
21
 
22
22
  # Specify which files should be added to the gem when it is released.
23
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
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: 2.0.0
4
+ version: 2.1.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-02-09 00:00:00.000000000 Z
11
+ date: 2024-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cgi
@@ -64,14 +64,14 @@ files:
64
64
  - lib/remote_entity/version.rb
65
65
  - remote_entity.gemspec
66
66
  - sig/remote_entity.rbs
67
- homepage: https://github.com/kseung-gpsw/remote_entity
67
+ homepage: https://github.com/kuroun/remote_entity
68
68
  licenses:
69
69
  - MIT
70
70
  metadata:
71
71
  allowed_push_host: https://rubygems.org
72
- homepage_uri: https://github.com/kseung-gpsw/remote_entity
73
- source_code_uri: https://github.com/kseung-gpsw/remote_entity
74
- changelog_uri: https://github.com/kseung-gpsw/remote_entity/blob/main/CHANGELOG.md
72
+ homepage_uri: https://github.com/kuroun/remote_entity
73
+ source_code_uri: https://github.com/kuroun/remote_entity
74
+ changelog_uri: https://github.com/kuroun/remote_entity/blob/main/CHANGELOG.md
75
75
  post_install_message:
76
76
  rdoc_options: []
77
77
  require_paths:
@@ -80,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: 2.6.0
83
+ version: 2.5.0
84
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="