tribune_recurly_api 1.0.2 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58af8cbf779fe4fd7123c8721b9047742bfe3c5cf65e198d684cb1db47e69948
4
- data.tar.gz: 5fc8b5e12bf3875fb0804c2832a13ed540680ac0c8c8a8be1c2414889155ff9b
3
+ metadata.gz: 428cd1714997ee102df9b99bc56183a720cd4666f1d552cf9105781dd1b460f3
4
+ data.tar.gz: 8067703da783c5903489b116b748522fedd2b685c77d66d1411658306b805855
5
5
  SHA512:
6
- metadata.gz: b446b40811f68202554293ad18450eb81da9e36ce9e3a5a5f0282cb39bb8303f79c62766edb3a7e491c77567bc9c7e2665a8f07ad127b1a8a34effb8cf137ece
7
- data.tar.gz: 461e45b651ffe4b3d8b31ba6d8d25b21f12b13ea2686316ad2925b5b16e60829604dc30ffc12c60c575c56e5ace61d5f07db2310001957700523a0a8b7e82a9c
6
+ metadata.gz: 57d171be31c09ebaf536e9d14934e2260c38cf22d6ceb034e3616dbeadf87f2036d040f85cd72622103a7d99ce70af78802deac349d766cda15cc2b9484e7561
7
+ data.tar.gz: b72b9e239cd6248761e52e59fbb4af4e14252e46f980c1a543f1cff6c1eab1b5a23ce3f650d8436814dd11b96f7f3dc6254d339e73b1da68216136fad6e5a15c
@@ -53,12 +53,12 @@ module RecurlyApi
53
53
 
54
54
  # TODO: remove below method once integration testing is done
55
55
  def check_logs_for_caching_info
56
- logger.info("#{logger_heading}: ----> caching_enabled?: #{caching_enabled?}")
57
- # logger.info("#{logger_heading}: ----> ignore_caching?: #{ignore_caching?}")
58
- logger.info("#{logger_heading}: ----> bypass_caching?: #{bypass_caching?}")
59
- logger.info("#{logger_heading}: ----> http_method: #{http_method} -- #{http_method.class}")
60
- logger.info("#{logger_heading}: ----> cache_expires_in: #{cache_expires_in}")
61
- logger.info("#{logger_heading}: ----> cache_key: #{cache_key} -- #{cache_key.class}")
56
+ # logger.info("#{logger_heading}: ----> caching_enabled?: #{caching_enabled?}")
57
+ # # logger.info("#{logger_heading}: ----> ignore_caching?: #{ignore_caching?}")
58
+ # logger.info("#{logger_heading}: ----> bypass_caching?: #{bypass_caching?}")
59
+ # logger.info("#{logger_heading}: ----> http_method: #{http_method} -- #{http_method.class}")
60
+ # logger.info("#{logger_heading}: ----> cache_expires_in: #{cache_expires_in}")
61
+ # logger.info("#{logger_heading}: ----> cache_key: #{cache_key} -- #{cache_key.class}")
62
62
  # logger.info("#{logger_heading}: ----> final response: #{final_response || fetch_response_from_cache}")
63
63
  logger.info("#{logger_heading}: ----> ratelimit_retries: #{ratelimit_retries}")
64
64
  end
@@ -8,7 +8,11 @@ module RecurlyApi
8
8
  # @param ssor_id [String], Recurly Account Code(i.e SsorID)
9
9
  # - The unique identifier of the Recurly account
10
10
  def account_info(ssor_id:, **optional_params)
11
- request_api(path_name: "accounts/code-#{ssor_id}", **optional_params) # cache_key_name: cache_key_name
11
+ # cache_key should be uniq for each account(here ssor_id is uniq)
12
+ # final cache key with prefix: tribune_recurly_api.account_info.<abcdef>
13
+ cache_key_name = "account_info.#{ssor_id}"
14
+ request_api(path_name: "accounts/code-#{ssor_id}",
15
+ cache_key_name: cache_key_name, **optional_params)
12
16
  end
13
17
 
14
18
  # Deactivate account ---
@@ -8,7 +8,11 @@ module RecurlyApi
8
8
  # @param ssor_id [String] Recurly Account ID(SsorID) or code.
9
9
  # For ID no prefix is used e.g. +e28zov4fw0v2+. For code use prefix +code-+, e.g. +code-bob+.
10
10
  def coupon_redemptions(ssor_id:, **optional_params)
11
- request_api(path_name: "accounts/code-#{ssor_id}/coupon_redemptions", **optional_params)
11
+ # cache_key should be uniq for each account(here ssor_id is uniq)
12
+ # final cache key with prefix: tribune_recurly_api.coupon_redemptions.<abcdef>
13
+ cache_key_name = "coupon_redemptions.#{ssor_id}"
14
+ request_api(path_name: "accounts/code-#{ssor_id}/coupon_redemptions",
15
+ cache_key_name: cache_key_name, **optional_params)
12
16
  end
13
17
 
14
18
  # Other request any.....
@@ -28,8 +28,8 @@ module RecurlyApi
28
28
  # payload_name = optional_params[:payload_name] # if not present default value is :payload
29
29
  # cache_key_name = 'list_all_plans' # optional by default cache_key is caller method_name in receiver i.e. list_plans here
30
30
  self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:plan_expiry] unless bypass_caching?
31
- request_api(path_name: 'plans', query_params: recurly_query_params,
32
- cache_key_name: cache_key_name, **optional_params)
31
+ # cache_key_name = 'all_plans' # for custom cache key pass as extra argument
32
+ request_api(path_name: 'plans', query_params: recurly_query_params, **optional_params)
33
33
  end
34
34
 
35
35
  # Fetch Plan Info--
@@ -39,7 +39,25 @@ module RecurlyApi
39
39
  # @param optional_params [Hash] Optional, same as above
40
40
  def plan_info(plan_id:, **optional_params)
41
41
  self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:plan_expiry] unless bypass_caching?
42
- request_api(path_name: "plans/#{plan_id}", **optional_params) # cache_key_name: cache_key_name
42
+ # cache_key should be uniq for each plan(here plan_id is uniq)
43
+ # final cache key with prefix: tribune_recurly_api.plan_info.<abcdef>
44
+ cache_key_name = "plan_info.#{plan_id}"
45
+ request_api(path_name: "plans/#{plan_id}",
46
+ cache_key_name: cache_key_name, **optional_params)
47
+ end
48
+
49
+ # Fetch Plan Info--
50
+ # { https://developers.recurly.com/api/v2021-02-25/index.html#operation/list_plan_add_ons }
51
+ # @param plan_id [String] Required, Plan ID or code.
52
+ # - For ID no prefix is used e.g. <e28zov4fw0v2>. For code use prefix <code->, ex. <code-gold>.
53
+ # @param optional_params [Hash] Optional, same as above
54
+ def plan_add_ons(plan_id:, **optional_params)
55
+ self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:plan_expiry] unless bypass_caching?
56
+ # cache_key should be uniq for each plan(here plan_id is uniq)
57
+ # final cache key with prefix: tribune_recurly_api.plan_info.<abcdef>
58
+ cache_key_name = "plan_info.#{plan_id}.add_ons"
59
+ request_api(path_name: "plans/#{plan_id}/add_ons",
60
+ cache_key_name: cache_key_name, **optional_params)
43
61
  end
44
62
  end
45
63
  end
@@ -11,7 +11,11 @@ module RecurlyApi
11
11
  def account_subscriptions(ssor_id:, recurly_query_params: {}, **optional_params)
12
12
  path = "accounts/code-#{ssor_id}/subscriptions"
13
13
  self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:subscription_expiry] unless bypass_caching?
14
- request_api(path_name: path, query_params: recurly_query_params, **optional_params) # cache_key_name: cache_key_name
14
+ # cache_key should be uniq for each account(here ssor_id is uniq)
15
+ # final cache key with prefix: tribune_recurly_api.account_subscriptions.<abcdef>
16
+ cache_key_name = "account_subscriptions.#{ssor_id}"
17
+ request_api(path_name: path, query_params: recurly_query_params,
18
+ cache_key_name: cache_key_name, **optional_params)
15
19
  end
16
20
 
17
21
  # Checking if user already has subscription OR
@@ -184,5 +184,12 @@ module RecurlyApi
184
184
  error: json_body['error']['type'],
185
185
  message: json_body['error']['message'] }
186
186
  end
187
+
188
+ def handle_recurly_error_response(resp)
189
+ json_body = JSON.parse(resp.body)
190
+ return unless json_body['error']
191
+
192
+ handle_error_response(resp.code, json_body)
193
+ end
187
194
  end
188
195
  end
@@ -10,21 +10,21 @@ module RecurlyApi
10
10
  rescue RestClient::Unauthorized, RestClient::Forbidden => e
11
11
  # https://www.rubydoc.info/gems/rest-client/1.6.7/frames#label-Result+handling
12
12
  logger.error("#{logger_heading} ERROR: Access denied to Recurly API")
13
- raise e.response
13
+ handle_recurly_error_response(e.response)
14
14
  rescue RestClient::ImATeapot => e
15
15
  logger.error("#{logger_heading} ERROR: Recurly Server is a teapot! # RFC 2324")
16
- raise e.response
16
+ handle_recurly_error_response(e.response)
17
17
  rescue RestClient::MovedPermanently,
18
18
  RestClient::Found,
19
19
  RestClient::TemporaryRedirect => e
20
20
  logger.error("#{logger_heading} ERROR: Follow redirection- #{e.response.follow_redirection}")
21
- raise e.response
21
+ handle_recurly_error_response(e.response)
22
22
  rescue RestClient::ExceptionWithResponse => e
23
23
  logger.error("#{logger_heading} ERROR: RestClient::ExceptionWithResponse")
24
- raise e.response
24
+ handle_recurly_error_response(e.response)
25
25
  rescue RestClient::Exception => e
26
26
  logger.error("#{logger_heading} ERROR: RestClient::Exception")
27
- raise e.response
27
+ handle_recurly_error_response(e.response)
28
28
  # rescue StandardError => e # Note: don't rescue standard error
29
29
  # logger.error("#{logger_heading} ERROR: Internal Server Error")
30
30
  # # e.backtrace.join("\n ")
@@ -1,33 +1,33 @@
1
- # frozen_string_literal: true
2
-
3
- # Logger for Gem
4
- module RecurlyApi
5
- # fallback to STDOUT for non-rails project
6
- module Logging
7
- # accessor setter method
8
- attr_writer :logger
9
-
10
- # Fallback to STDOUT logger for non-rails applications
11
- # Usage examples to logging details in RecurlyApi:Client
12
- # a. logger.info("I'm an info log")
13
- # b. logger.warn("I'm a warn log")
14
- # c. logger.error("I'm an error log: error message")
15
- # d. logger.fatal("I'm a fatal log")
16
- def logger
17
- @logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
18
- end
19
-
20
- # Classical set method(instead used attr_writer)
21
- # def logger=(logger)
22
- # @logger = logger
23
- # end
24
-
25
- def logger_heading
26
- 'tribune_recurly_api'
27
- end
28
-
29
- def logger_cache_heading
30
- "#{logger_heading} CACHING"
31
- end
32
- end
33
- end
1
+ # frozen_string_literal: true
2
+
3
+ # Logger for Gem
4
+ module RecurlyApi
5
+ # fallback to STDOUT for non-rails project
6
+ module Logging
7
+ # accessor setter method
8
+ attr_writer :logger
9
+
10
+ # Fallback to STDOUT logger for non-rails applications
11
+ # Usage examples to logging details in RecurlyApi:Client
12
+ # a. logger.info("I'm an info log")
13
+ # b. logger.warn("I'm a warn log")
14
+ # c. logger.error("I'm an error log: error message")
15
+ # d. logger.fatal("I'm a fatal log")
16
+ def logger
17
+ @logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
18
+ end
19
+
20
+ # Classical set method(instead used attr_writer)
21
+ # def logger=(logger)
22
+ # @logger = logger
23
+ # end
24
+
25
+ def logger_heading
26
+ 'tribune_recurly_api'
27
+ end
28
+
29
+ def logger_cache_heading
30
+ "#{logger_heading} CACHING"
31
+ end
32
+ end
33
+ end
@@ -15,5 +15,9 @@ module RecurlyApi
15
15
  # STRING
16
16
  # end
17
17
  # VERSION = '1.0.1' # cache settings from configuration file
18
- VERSION = '1.0.2' # prefixing '<code->' to ssor_id is now part of GEM
18
+ # VERSION = '1.0.2' # prefixing '<code->' to ssor_id is now part of GEM
19
+ # VERSION = '1.0.3' # return recurly error response
20
+ # VERSION = '1.0.4' # is yanked in rubygems.org
21
+ # VERSION = '1.0.5' # cache key should be uniq
22
+ VERSION = '1.0.6' # new api call to fetch plan add_ons
19
23
  end
@@ -1,3 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require 'recurly_api'
1
+ # frozen_string_literal: true
2
+
3
+ require 'recurly_api'
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.2
4
+ version: 1.0.6
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-23 00:00:00.000000000 Z
11
+ date: 2021-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport