rtx-api 0.6.5 → 0.6.6

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: c41a008dcb1d74712eff3591c95d85e30120441d0d754903f19d2767e8c85a3b
4
- data.tar.gz: 65ed7ac4921d37eb2e7e013da78bdd65154ca78a37021d1d7e1e219a726cd04f
3
+ metadata.gz: 408b8a58e0ff9761a884d58ef645a46a4ce9a620734dcbb715ecbdba8701b4df
4
+ data.tar.gz: 6b50a573f9ceeed9def34a0d681a4fb62f2e29912194f550a17a5ce041ac76f1
5
5
  SHA512:
6
- metadata.gz: e9d0803af24864c904912f9edb3c08bbe77bdabd94db1cd6c46a0b9847d6a3dd343ff0f8c0bd16de2ca3e10206f2040556859088cf3441b3a6ea21af3a5e2b4c
7
- data.tar.gz: '08d2c315eacbce3f05bef6c031432f105adacddc3ba5634be33a8172254ce15b087dcdd2df51239da278f43575950b0200c2b95072cc20bb41716403cad2ad82'
6
+ metadata.gz: 4407961c6508c5ca6c38fd541753aaf951e7288b77206057cd89dc5beeb1d265a369b23c255329beb6d184189a3c3edc5978f8fbd86bf442174daf3fc26d1a56
7
+ data.tar.gz: 1aac284d6c4c4b7b66ad473aef3918e21e20024d68268b859b4ba65efa47704395a1ed35bfb173d43dd884caa7881f4206bdae047eab2e815c9f244de400c8cf
@@ -77,7 +77,7 @@ module RTX
77
77
  # rubocop:disable Style/MissingRespondToMissing
78
78
  # rubocop:disable Style/MethodMissingSuper
79
79
  def method_missing(method, *args)
80
- return unless resource_path(method)
80
+ return unless allowed_resource?(method)
81
81
 
82
82
  attrs = {}
83
83
  if args.size.positive?
@@ -93,6 +93,16 @@ module RTX
93
93
  # rubocop:enable Style/MethodMissingSuper
94
94
  # rubocop:enable Lint/RedundantCopDisableDirective
95
95
 
96
+ def allowed_resource?(method)
97
+ unless API::Resources.allowed_resources[method.to_sym] ||
98
+ API::Resources.allowed_builable_resources.key?(method.to_sym)
99
+ raise API::Errors::InvalidResourceError,
100
+ "The resource provided (#{method}) is not allowed"
101
+ end
102
+
103
+ true
104
+ end
105
+
96
106
  def collection(resource_name, attrs = {})
97
107
  request = self.class.get("#{rtx_api_url}/#{resource_path(resource_name)}",
98
108
  options(:get, attrs))
@@ -108,7 +118,7 @@ module RTX
108
118
  end
109
119
 
110
120
  def post(resource_name, attrs = {})
111
- request = self.class.post("#{rtx_api_url}/#{resource_path(resource_name)}",
121
+ request = self.class.post("#{rtx_api_url}/#{resource_path(resource_name, attrs)}",
112
122
  options(:post, attrs))
113
123
  handle_request(request)
114
124
  end
@@ -158,8 +168,10 @@ module RTX
158
168
  end
159
169
  end
160
170
 
161
- def resource_path(resource_name)
171
+ def resource_path(resource_name, attrs = {})
162
172
  path = API::Resources.allowed_resources[resource_name.to_sym]
173
+ path ||= API::Resources.build_resource(resource_name.to_sym, attrs)
174
+
163
175
  if !path
164
176
  raise API::Errors::InvalidResourceError,
165
177
  "The resource provided (#{resource_name}) is not allowed"
@@ -54,6 +54,31 @@ module RTX
54
54
  }.freeze
55
55
  end
56
56
  # rubocop:enable Metrics/MethodLength
57
+
58
+ def self.allowed_builable_resources
59
+ {
60
+ local_search_location_reports: {
61
+ required_values: %i[account_id location_id],
62
+ resource_method: :build_local_search_location_reports_path
63
+ }
64
+ }.freeze
65
+ end
66
+
67
+ def self.build_resource(resource_name, attrs)
68
+ return unless allowed_builable_resources.key?(resource_name)
69
+
70
+ unless allowed_builable_resources[resource_name][:required_values].all? do |v|
71
+ attrs[v]
72
+ end
73
+ raise API::Errors::InvalidResourceError,
74
+ "Missing required params for (#{resource_name})"
75
+ end
76
+ send(allowed_builable_resources[resource_name][:resource_method], attrs)
77
+ end
78
+
79
+ def self.build_local_search_location_reports_path(attrs)
80
+ "local_search/#{attrs[:account_id]}/locations/#{attrs[:location_id]}/reports"
81
+ end
57
82
  end
58
83
  end
59
84
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RTX
4
4
  module API
5
- VERSION = '0.6.5'
5
+ VERSION = '0.6.6'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtx-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Review Trackers Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-23 00:00:00.000000000 Z
11
+ date: 2024-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty