hcbv4 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/hcbv4/client.rb +6 -4
- data/lib/hcbv4/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c035e49436c87eccf3233afebd5fd68344d444481514a5731d5fd25f6f7cb2cb
|
|
4
|
+
data.tar.gz: 0bd27f22f97e4e328ebe309bc769a3a5cdde0349435eebf51628ee436b7be4d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee07d48d5e0487331b6a4ad4959c4348dc82aff5f4925302a56c57f3c010c5a45d32294ebeb593d56b51f8b1925e320fe4f9b7c36fe8cdfa4d2764ecefb7e4cb
|
|
7
|
+
data.tar.gz: bef11f010e84b3b6b75ad12b39fbadc2966de34713e71295f1852e1c613f894bced5da4e62ee913ffeb60f16755760541eea24f5317a90fcd7fa1dcc1746ffd0
|
data/README.md
CHANGED
|
@@ -41,6 +41,22 @@ save_to_database(
|
|
|
41
41
|
)
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
### disabling automatic token refresh
|
|
45
|
+
|
|
46
|
+
if you're managing token refresh yourself, you can disable automatic refresh:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
client = HCBV4::Client.from_credentials(
|
|
50
|
+
client_id: ENV["HCB_CLIENT_ID"],
|
|
51
|
+
client_secret: ENV["HCB_CLIENT_SECRET"],
|
|
52
|
+
access_token: "...",
|
|
53
|
+
refresh_token: "...",
|
|
54
|
+
auto_token_refresh: false
|
|
55
|
+
)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
the `auto_token_refresh` option defaults to `true`.
|
|
59
|
+
|
|
44
60
|
### using a pre-built token
|
|
45
61
|
|
|
46
62
|
if you're managing the `OAuth2::AccessToken` lifecycle yourself:
|
data/lib/hcbv4/client.rb
CHANGED
|
@@ -9,15 +9,16 @@ module HCBV4
|
|
|
9
9
|
DEFAULT_BASE_URL = "https://hcb.hackclub.com"
|
|
10
10
|
API_PATH = "/api/v4"
|
|
11
11
|
|
|
12
|
-
attr_reader :oauth_token, :base_url
|
|
12
|
+
attr_reader :oauth_token, :base_url, :auto_token_refresh
|
|
13
13
|
|
|
14
|
-
def initialize(oauth_token:, base_url: DEFAULT_BASE_URL)
|
|
14
|
+
def initialize(oauth_token:, base_url: DEFAULT_BASE_URL, auto_token_refresh: true)
|
|
15
15
|
@oauth_token = oauth_token
|
|
16
16
|
@base_url = base_url
|
|
17
|
+
@auto_token_refresh = auto_token_refresh
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def self.from_credentials(client_id:, client_secret:, access_token:, refresh_token:, expires_at: nil,
|
|
20
|
-
base_url: DEFAULT_BASE_URL)
|
|
21
|
+
base_url: DEFAULT_BASE_URL, auto_token_refresh: true)
|
|
21
22
|
oauth_client = OAuth2::Client.new(
|
|
22
23
|
client_id,
|
|
23
24
|
client_secret,
|
|
@@ -32,7 +33,7 @@ module HCBV4
|
|
|
32
33
|
expires_at:
|
|
33
34
|
)
|
|
34
35
|
|
|
35
|
-
new(oauth_token: token, base_url:)
|
|
36
|
+
new(oauth_token: token, base_url:, auto_token_refresh:)
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
# ─────────────────────────────────────────────────────────────────────────
|
|
@@ -558,6 +559,7 @@ module HCBV4
|
|
|
558
559
|
end
|
|
559
560
|
|
|
560
561
|
def refresh_token_if_needed!
|
|
562
|
+
return unless auto_token_refresh
|
|
561
563
|
return unless oauth_token.respond_to?(:expired?)
|
|
562
564
|
return unless oauth_token.expired?
|
|
563
565
|
|
data/lib/hcbv4/version.rb
CHANGED