tribune_recurly_api 1.0.1 → 1.0.5
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/client.rb +7 -0
- data/lib/recurly_api/client/accounts.rb +10 -6
- data/lib/recurly_api/client/other_requests.rb +5 -1
- data/lib/recurly_api/client/plans.rb +7 -3
- data/lib/recurly_api/client/subscriptions.rb +15 -10
- data/lib/recurly_api/exception_handler.rb +5 -5
- data/lib/recurly_api/logging.rb +33 -33
- data/lib/recurly_api/version.rb +5 -1
- data/lib/tribune_recurly_api.rb +3 -3
- 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: 330e1d6e2d4a12cf9d767a5e3223e80bde8b4f7c31ddee9c6395eb062f36e7b4
|
4
|
+
data.tar.gz: 8e3c9f7293df1eb36de9dcf29f4a24f15c7d6833f5f24a74359f0f42d36c9375
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c082798d31feedaeb831c04f51f7c7dcec8035b5549cdee6d0de909ba1171516e65445a27c34ab89d9421f8642adc2669aea284e8adeddd0c08abdb4e3d1cb9
|
7
|
+
data.tar.gz: 032d4515cac6bb3b2c8e98573b9d4e4164472185f3691a67051fb2cc11e9a047a23eafb6a61c52aafeaef5f400ad40bd2dd7ac218e06843ee26446e98bf63e79
|
data/lib/recurly_api/client.rb
CHANGED
@@ -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
|
@@ -5,18 +5,22 @@ module RecurlyApi
|
|
5
5
|
class Client
|
6
6
|
# Fetch Account Info--
|
7
7
|
# { https://developers.recurly.com/api/v2021-02-25/index.html#operation/get_account }
|
8
|
-
# @param ssor_id [String]
|
9
|
-
#
|
8
|
+
# @param ssor_id [String], Recurly Account Code(i.e SsorID)
|
9
|
+
# - The unique identifier of the Recurly account
|
10
10
|
def account_info(ssor_id:, **optional_params)
|
11
|
-
|
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 ---
|
15
19
|
# { https://developers.recurly.com/api/v2021-02-25/index.html#operation/deactivate_account }
|
16
|
-
# @param ssor_id [String]
|
17
|
-
#
|
20
|
+
# @param ssor_id [String], Recurly Account Code(i.e SsorID)
|
21
|
+
# - The unique identifier of the Recurly account
|
18
22
|
def deactivate_account(ssor_id:)
|
19
|
-
path = "accounts
|
23
|
+
path = "accounts/code-#{ssor_id}"
|
20
24
|
request_api(path_name: path, http_method: :delete)
|
21
25
|
end
|
22
26
|
end
|
@@ -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
|
-
|
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
|
-
|
32
|
-
|
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,11 @@ 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
|
-
|
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)
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
@@ -5,31 +5,36 @@ module RecurlyApi
|
|
5
5
|
class Client
|
6
6
|
# Fetch Account Subscriptions ---
|
7
7
|
# { https://developers.recurly.com/api/v2021-02-25/index.html#operation/list_account_subscriptions }
|
8
|
-
# @param ssor_id [String] Account
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# for other params ref documentation
|
8
|
+
# @param ssor_id [String], Recurly Account Code(i.e SsorID)
|
9
|
+
# - The unique identifier of the Recurly account
|
10
|
+
# for other params refer documentation
|
12
11
|
def account_subscriptions(ssor_id:, recurly_query_params: {}, **optional_params)
|
13
|
-
path = "accounts
|
12
|
+
path = "accounts/code-#{ssor_id}/subscriptions"
|
14
13
|
self.cache_expires_in = optional_params[:cache_expires_in] || cache_settings[:subscription_expiry] unless bypass_caching?
|
15
|
-
|
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)
|
16
19
|
end
|
17
20
|
|
18
21
|
# Checking if user already has subscription OR
|
19
22
|
# Checking if user has a subscription for particular plan by its code
|
20
23
|
# ---------------
|
21
24
|
# @param ssor_id [String] required, Recurly Account Code(i.e SsorID)
|
25
|
+
# - The unique identifier of the Recurly account
|
22
26
|
# @param plan_code [String] optional,
|
23
27
|
# - if present then checks if user has subscription for that particular plan by its code
|
24
28
|
# Usage ex:
|
25
29
|
# client.check_user_subscription(ssor_id: '4900-0272-6875', plan_code: '000150d03d')
|
26
|
-
# response => { :success=>true, :
|
30
|
+
# response => { :success=>true, :status_code=>200, :has_subscription=>true }
|
27
31
|
def check_user_subscription(ssor_id:, plan_code: nil)
|
28
|
-
|
32
|
+
query_params = { limit: 2 }
|
33
|
+
resp = account_subscriptions(ssor_id: ssor_id, recurly_query_params: query_params)
|
29
34
|
if resp[:success]
|
30
35
|
has_subscription = false
|
31
|
-
subs = resp[:data]
|
32
|
-
has_subscription = true if subs
|
36
|
+
subs = resp[:payload]['data']
|
37
|
+
has_subscription = true if subs&.any?
|
33
38
|
if plan_code
|
34
39
|
sub = subs.detect { |s| s['plan']['code'].eql?(plan_code) }
|
35
40
|
has_subscription = sub ? true : false
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
21
|
+
handle_recurly_error_response(e.response)
|
22
22
|
rescue RestClient::ExceptionWithResponse => e
|
23
23
|
logger.error("#{logger_heading} ERROR: RestClient::ExceptionWithResponse")
|
24
|
-
|
24
|
+
handle_recurly_error_response(e.response)
|
25
25
|
rescue RestClient::Exception => e
|
26
26
|
logger.error("#{logger_heading} ERROR: RestClient::Exception")
|
27
|
-
|
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 ")
|
data/lib/recurly_api/logging.rb
CHANGED
@@ -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
|
data/lib/recurly_api/version.rb
CHANGED
@@ -14,5 +14,9 @@ module RecurlyApi
|
|
14
14
|
# def self.to_s
|
15
15
|
# STRING
|
16
16
|
# end
|
17
|
-
VERSION = '1.0.1' # cache settings from configuration file
|
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
|
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
|
18
22
|
end
|
data/lib/tribune_recurly_api.rb
CHANGED
@@ -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.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- udevulapally
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|