tribune_recurly_api 1.0.0 → 1.0.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/lib/recurly_api/caching.rb +4 -2
- data/lib/recurly_api/client.rb +13 -8
- data/lib/recurly_api/client/plans.rb +4 -2
- data/lib/recurly_api/client/subscriptions.rb +2 -0
- data/lib/recurly_api/version.rb +1 -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: 9da5718917f44aef31d9b80de00d8c0329c17c116144ea4e4c41d30597061c1a
|
4
|
+
data.tar.gz: 67dbddf046ce829454660f1e2d4ecbb5dc96c00ba48fd5a09f99fb745b7d435d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d41f16026b8c2d42eaa8b2e66706bfb1e4434cb69950c5b70ef873a8db246db65a84a64db67a9fd89e2439b5c0b857abf051b93ae8e817c452f854adfef05d3a
|
7
|
+
data.tar.gz: 97c1da4a7194b7f2b254e792f0792b00e6e5a12721bae672fb34a5df658a413c8aa8111af44aaef04975e9221eb76bd99289fe4f9e37377ed7fc9696aaf65a91
|
data/lib/recurly_api/caching.rb
CHANGED
@@ -9,9 +9,11 @@ module RecurlyApi
|
|
9
9
|
:cache_expires_in,
|
10
10
|
:cache_key # key name to read/write cache, # default value is caller method_name
|
11
11
|
|
12
|
-
# default settings for caching, every GET request is cached by default with default expiry_time 5
|
12
|
+
# default settings for caching, every GET request is cached by default with default expiry_time 300 seconds(5 minutes)
|
13
13
|
CACHE_SETTINGS = { bypass: false,
|
14
|
-
|
14
|
+
default_expiry: 300,
|
15
|
+
plan_expiry: 300,
|
16
|
+
subscription_expiry: 5 }.freeze
|
15
17
|
|
16
18
|
# Usage examples to perform caching in RecurlyApi:Client
|
17
19
|
# cache.write('key', 'val', expires_in: 30)
|
data/lib/recurly_api/client.rb
CHANGED
@@ -27,7 +27,7 @@ module RecurlyApi
|
|
27
27
|
|
28
28
|
# Initialize method attributes
|
29
29
|
attr_accessor :site_id, :authorization_key, :base_host,
|
30
|
-
:api_version, :api_endpoint
|
30
|
+
:api_version, :api_endpoint, :cache_settings
|
31
31
|
# request attributes for request_api method
|
32
32
|
attr_accessor :path_name, :http_method, :query_params,
|
33
33
|
:payload, :additional_headers, :payload_name,
|
@@ -45,11 +45,14 @@ module RecurlyApi
|
|
45
45
|
# @param base_host [String] Optional, default: v3.recurly.com
|
46
46
|
# @param api_version [String] Optional, Recurly api_version ex: 'v2021-02-25' | 'v2019-10-10'
|
47
47
|
# @param ratelimit_retries [Integer] Optional, retry limit for rate limit exceeds, default: 3
|
48
|
+
# @param cache_settings [Hash] Optional, default settings for caching
|
49
|
+
# rubocop:disable Metrics/ParameterLists
|
48
50
|
def initialize(authorization_key:,
|
49
51
|
site_id:,
|
50
52
|
base_host: nil,
|
51
53
|
api_version: nil,
|
52
|
-
ratelimit_retries: RATE_LIMIT_MAX_RETRIES
|
54
|
+
ratelimit_retries: RATE_LIMIT_MAX_RETRIES,
|
55
|
+
cache_settings: CACHE_SETTINGS)
|
53
56
|
@authorization_key = authorization_key
|
54
57
|
@site_id = site_id
|
55
58
|
raise ArgumentError, "'authorization_key' must be set to a non-nil value" if @authorization_key.nil?
|
@@ -59,8 +62,9 @@ module RecurlyApi
|
|
59
62
|
@api_version = api_version || API_DEFAULTS[:api_version]
|
60
63
|
@api_endpoint = "https://#{@base_host}/sites/#{@site_id}"
|
61
64
|
@ratelimit_retries = ratelimit_retries
|
62
|
-
@
|
63
|
-
@
|
65
|
+
@cache_settings = cache_settings
|
66
|
+
@cache_expires_in = cache_settings[:default_expiry]
|
67
|
+
@ignore_caching = cache_settings[:bypass]
|
64
68
|
end
|
65
69
|
|
66
70
|
# TODO: remove unnecessary logs once integration testing completed
|
@@ -78,7 +82,7 @@ module RecurlyApi
|
|
78
82
|
# @param optional_params [Hash] Optional, or any of below ( ref full usage example)
|
79
83
|
# :payload_name [Symbol] Optional, defaults to ':data'
|
80
84
|
# :bypass_caching [Boolean] Optional, default value is false
|
81
|
-
# :
|
85
|
+
# :cache_expiry_in [Integer] Optional, default value is 300 seconds
|
82
86
|
|
83
87
|
# Ful Usage Example: Below is the example for 'request_api' call that includes all options
|
84
88
|
# res = request_api(path_name: 'plans', # required
|
@@ -89,12 +93,13 @@ module RecurlyApi
|
|
89
93
|
# cache_key_name: 'key123', # optional, defaults to method_name
|
90
94
|
# bypass_caching: true, # optionals, default false
|
91
95
|
# payload_name: 'list_all_plans', # optional defaults to caller method_name
|
92
|
-
#
|
96
|
+
# cache_expiry_in: 300 # optional default 300
|
93
97
|
# )
|
94
98
|
# RestClient retry { https://blog.appsignal.com/2018/05/16/ensure-retry-and-reraise-exceptions-in-ruby.html }
|
95
|
-
# rubocop:disable Metrics/ParameterLists
|
96
99
|
# rubocop:disable Metrics/AbcSize
|
97
100
|
# rubocop:disable Metrics/PerceivedComplexity
|
101
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
102
|
+
# rubocop:disable Metrics/MethodLength
|
98
103
|
def request_api(path_name:, http_method: :get, query_params: {},
|
99
104
|
payload: {}, additional_headers: {},
|
100
105
|
cache_key_name: nil, **optional_params)
|
@@ -110,7 +115,7 @@ module RecurlyApi
|
|
110
115
|
# optional params ===>
|
111
116
|
self.payload_name = optional_params[:payload_name] || 'payload'
|
112
117
|
self.ignore_caching = optional_params[:bypass_caching] || ignore_caching
|
113
|
-
self.cache_expires_in = optional_params[:
|
118
|
+
self.cache_expires_in = optional_params[:cache_expires_in] || cache_expires_in
|
114
119
|
# caller_method_name = caller_locations.first.label # Ruby 2.0 +
|
115
120
|
caller_method_name = caller(1..1).first[/`(.*)'/, 1] # Prior Ruby 2.0
|
116
121
|
self.cache_key = cache_key_name || caller_method_name # fallbacks to caller method if cache_key_name not present
|
@@ -16,7 +16,7 @@ module RecurlyApi
|
|
16
16
|
# @param optional_params [Hash] Optional, or any of below ( ref full usage example)
|
17
17
|
# :payload_name [Symbol] Optional, defaults to caller method_name
|
18
18
|
# :bypass_caching [Boolean] Optional, default value is false
|
19
|
-
# :
|
19
|
+
# :cache_expires_in [Integer] Optional, default value is 300 seconds(5 minutes)
|
20
20
|
|
21
21
|
# Examples:
|
22
22
|
# query_params = { limit: 2, order: :asc, ids: ['abc', 'def'..etc], :sort: <value>}
|
@@ -26,7 +26,8 @@ module RecurlyApi
|
|
26
26
|
|
27
27
|
def list_plans(recurly_query_params: {}, **optional_params)
|
28
28
|
# payload_name = optional_params[:payload_name] # if not present default value is :payload
|
29
|
-
cache_key_name = 'list_all_plans' # optional by default cache_key is caller method_name in receiver i.e. list_plans here
|
29
|
+
# cache_key_name = 'list_all_plans' # optional by default cache_key is caller method_name in receiver i.e. list_plans here
|
30
|
+
self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:plan_expiry] unless bypass_caching?
|
30
31
|
request_api(path_name: 'plans', query_params: recurly_query_params,
|
31
32
|
cache_key_name: cache_key_name, **optional_params)
|
32
33
|
end
|
@@ -37,6 +38,7 @@ module RecurlyApi
|
|
37
38
|
# - For ID no prefix is used e.g. <e28zov4fw0v2>. For code use prefix <code->, ex. <code-gold>.
|
38
39
|
# @param optional_params [Hash] Optional, same as above
|
39
40
|
def plan_info(plan_id:, **optional_params)
|
41
|
+
self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:plan_expiry] unless bypass_caching?
|
40
42
|
request_api(path_name: "plans/#{plan_id}", **optional_params) # cache_key_name: cache_key_name
|
41
43
|
end
|
42
44
|
end
|
@@ -11,6 +11,7 @@ module RecurlyApi
|
|
11
11
|
# for other params ref documentation
|
12
12
|
def account_subscriptions(ssor_id:, recurly_query_params: {}, **optional_params)
|
13
13
|
path = "accounts/#{ssor_id}/subscriptions"
|
14
|
+
self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:subscription_expiry] unless bypass_caching?
|
14
15
|
request_api(path_name: path, query_params: recurly_query_params, **optional_params) # cache_key_name: cache_key_name
|
15
16
|
end
|
16
17
|
|
@@ -51,6 +52,7 @@ module RecurlyApi
|
|
51
52
|
# recurly_query_params = { limit: RECORDS_LIMIT, order: :asc, .....}
|
52
53
|
# ex: client.site_subscriptions(params)
|
53
54
|
def site_subscriptions(recurly_query_params: {}, **optional_params)
|
55
|
+
self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:subscription_expiry] unless bypass_caching?
|
54
56
|
request_api(path_name: 'subscriptions', query_params: recurly_query_params, **optional_params)
|
55
57
|
end
|
56
58
|
|
data/lib/recurly_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tribune_recurly_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- udevulapally
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|