rtx-api 0.4.3 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +58 -0
- data/.travis.yml +3 -3
- data/Gemfile +3 -2
- data/README.md +14 -0
- data/bin/console +5 -3
- data/lib/rtx/api/client.rb +101 -50
- data/lib/rtx/api/collection.rb +19 -10
- data/lib/rtx/api/collection_v2.rb +130 -0
- data/lib/rtx/api/errors/authentication_error.rb +2 -0
- data/lib/rtx/api/errors/client_error.rb +2 -0
- data/lib/rtx/api/errors/invalid_resource_error.rb +2 -0
- data/lib/rtx/api/errors/request_error.rb +2 -0
- data/lib/rtx/api/resources.rb +5 -1
- data/lib/rtx/api/version.rb +1 -1
- data/lib/rtx/api.rb +14 -11
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3fab23dbc7d2054379829a2fa8c0c5889533dc
|
4
|
+
data.tar.gz: fc712c4b1bfbf5efcdff43cca9d217c5f3e7abba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71780b2bf492eb41fcffb6296c26798b775c4f9ce746d1600da1c9cb59ad6e284cc45b1329b531b5b5c8783edc985148606102491047e120127a717a5b4e0e6d
|
7
|
+
data.tar.gz: 98bff0d00cd40422ae374edf0a52c419ea6363151a9eace87e5d1a12283ac74292dd6d1a1ef35bbff08312b60280135cfc86791ba7a26c48551118c9ad39640d
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
StringLiterals:
|
2
|
+
EnforcedStyle: single_quotes
|
3
|
+
|
4
|
+
Style/RegexpLiteral:
|
5
|
+
EnforcedStyle: percent_r
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Naming/VariableName:
|
11
|
+
EnforcedStyle: snake_case
|
12
|
+
|
13
|
+
Naming/PredicateName:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/ParameterLists:
|
17
|
+
Max: 8
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Max: 20
|
24
|
+
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Max: 50
|
27
|
+
|
28
|
+
Metrics/ModuleLength:
|
29
|
+
Max: 100
|
30
|
+
Exclude:
|
31
|
+
- spec/data/**
|
32
|
+
|
33
|
+
Metrics/ClassLength:
|
34
|
+
Max: 200
|
35
|
+
|
36
|
+
Metrics/LineLength:
|
37
|
+
Max: 100
|
38
|
+
IgnoredPatterns: ['\A#']
|
39
|
+
Exclude:
|
40
|
+
- spec/**/**_spec.rb
|
41
|
+
- spec/data/**
|
42
|
+
- bin/**/*
|
43
|
+
|
44
|
+
Style/NumericLiterals:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/NegatedIf:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
AllCops:
|
51
|
+
DisplayCopNames: true
|
52
|
+
TargetRubyVersion: 2.5.0
|
53
|
+
Exclude:
|
54
|
+
- .git/**/*
|
55
|
+
- vendor/**/*
|
56
|
+
- Gemfile
|
57
|
+
- Rakefile
|
58
|
+
- rtx-api.gemspec
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,13 +2,14 @@ source 'https://rubygems.org'
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :development do
|
5
|
-
gem 'pry'
|
6
5
|
gem 'httparty'
|
7
6
|
gem 'oj'
|
7
|
+
gem 'pry'
|
8
8
|
end
|
9
9
|
|
10
10
|
group :development, :test, :rake do
|
11
11
|
gem 'bundler'
|
12
|
+
gem 'rubocop', require: false
|
12
13
|
end
|
13
14
|
|
14
15
|
group :rake do
|
@@ -17,8 +18,8 @@ end
|
|
17
18
|
|
18
19
|
group :test do
|
19
20
|
gem 'minitest'
|
20
|
-
gem 'minitest-spec-context'
|
21
21
|
gem 'minitest-reporters', require: 'minitest/reporters'
|
22
|
+
gem 'minitest-spec-context'
|
22
23
|
gem 'mocha', require: 'mocha/setup'
|
23
24
|
gem 'vcr', require: false
|
24
25
|
gem 'webmock', require: false
|
data/README.md
CHANGED
@@ -18,6 +18,20 @@ By adding `RTX_USER_EMAIL` and `RTX_USER_PASSWORD` to your environment variables
|
|
18
18
|
|
19
19
|
If you using a different url for for the RTX API, you can set the `RTX_API_URL` environment variable to use the appropriate one.
|
20
20
|
|
21
|
+
## Testing locally
|
22
|
+
|
23
|
+
In order to test changes to your gem without having to release, you can update the Gemfile to point to the local version of the Gem
|
24
|
+
|
25
|
+
gem 'rtx-api', require: 'rtx/api', path: '../rtx-api-client-ruby'
|
26
|
+
|
27
|
+
## Releasing new version
|
28
|
+
|
29
|
+
We have a higher expectation of testing in this repo than others due to the lower volume of releases and nature of the product. When you are submitting your PR, take a more conservative approach to testing and make sure you are adding tests for all new/changed methods.
|
30
|
+
|
31
|
+
Bump the version of the gem within `./lib/rtx/api/version.rb` based on the changes you've made. Once your changes have been merged into master, you can release updated version of your gem. In order to release, you will need to be an owner of the RubyGems project and need to have your API credentials setup in your bash profile. Once complete, run the following command release command.
|
32
|
+
|
33
|
+
bundle exec rake release
|
34
|
+
|
21
35
|
## Usage
|
22
36
|
|
23
37
|
The client is lazily loaded, which means it will not authenticate until you make your initial request. Once the request is performed, we'll store the information for future requests. You will want to use the same instance of the client to perform all of your requests.
|
data/bin/console
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# !/usr/bin/env ruby
|
2
4
|
ENV['RACK_ENV'] ||= 'development'
|
3
5
|
# load path
|
4
|
-
lib_path = File.expand_path('
|
5
|
-
(
|
6
|
+
lib_path = File.expand_path('../lib', __dir__)
|
7
|
+
($LOAD_PATH.unshift lib_path) unless $LOAD_PATH.include? lib_path
|
6
8
|
|
7
9
|
# require farm
|
8
10
|
require 'bundler'
|
data/lib/rtx/api/client.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
|
1
5
|
module RTX
|
2
6
|
module API
|
3
7
|
class Client
|
4
8
|
include HTTParty
|
5
|
-
attr_accessor :email, :password, :token, :expires, :account_id, :profile_id
|
9
|
+
attr_accessor :email, :password, :api_url, :token, :expires, :account_id, :profile_id
|
6
10
|
|
7
|
-
def initialize(email = ENV[
|
11
|
+
def initialize(email = ENV['RTX_USER_EMAIL'], password = ENV['RTX_USER_PASSWORD'],
|
12
|
+
api_url = ENV['RTX_API_URL'])
|
8
13
|
@email = email
|
9
14
|
@password = password
|
15
|
+
@api_url = api_url
|
10
16
|
@token = nil
|
11
17
|
@expires = nil
|
12
18
|
end
|
@@ -16,26 +22,36 @@ module RTX
|
|
16
22
|
end
|
17
23
|
|
18
24
|
def authenticate
|
19
|
-
request = self.class.post("#{rtx_api_url}/auth", headers: default_headers,
|
25
|
+
request = self.class.post("#{rtx_api_url}/auth", headers: default_headers,
|
26
|
+
basic_auth: {
|
27
|
+
username: email,
|
28
|
+
password: password
|
29
|
+
})
|
20
30
|
response = Oj.load(request.body, symbol_keys: true)
|
21
31
|
if request.code != 201
|
22
|
-
raise API::Errors::AuthenticationError
|
32
|
+
raise API::Errors::AuthenticationError, "Authentication Login Error: #{response}"
|
23
33
|
end
|
24
|
-
|
34
|
+
|
35
|
+
set_attributes(response[:token], response[:expires_at], response[:account_id],
|
36
|
+
response[:profile_id])
|
25
37
|
end
|
26
38
|
|
27
39
|
def authenticate_as(email, &block)
|
28
40
|
authenticate if !authenticated?
|
29
41
|
response = collection(:users, email: email)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
client.set_attributes(auth_response[:token], auth_response[:expires_at], auth_response[:account_id], auth_response[:profile_id])
|
35
|
-
block.call(client)
|
36
|
-
else
|
37
|
-
raise API::Errors::ClientError.new("User not found with associated email address: #{email}")
|
42
|
+
|
43
|
+
unless response[:_total] == 1
|
44
|
+
raise API::Errors::ClientError,
|
45
|
+
"User not found with associated email address: #{email}"
|
38
46
|
end
|
47
|
+
|
48
|
+
user = response[:_embedded][:users][0]
|
49
|
+
auth_response = post(:auth_tokens, account_id: user[:account_id], user_id: user[:id])
|
50
|
+
client = self.class.new(auth_response[:email], auth_response[:token])
|
51
|
+
client.set_attributes(auth_response[:token], auth_response[:expires_at],
|
52
|
+
auth_response[:account_id], auth_response[:profile_id])
|
53
|
+
block.call(client)
|
54
|
+
|
39
55
|
true
|
40
56
|
end
|
41
57
|
|
@@ -44,76 +60,111 @@ module RTX
|
|
44
60
|
end
|
45
61
|
|
46
62
|
def logout
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@token, @expires, @account_id, @profile_id = nil, nil, nil, nil
|
63
|
+
return unless token
|
64
|
+
|
65
|
+
request = self.class.delete("#{rtx_api_url}/auth", options(:delete))
|
66
|
+
if request.code != 204
|
67
|
+
raise API::Errors::AuthenticationError, "Authentication Logout Error: #{request}"
|
53
68
|
end
|
69
|
+
|
70
|
+
@token = nil
|
71
|
+
@expires = nil
|
72
|
+
@account_id = nil
|
73
|
+
@profile_id = nil
|
54
74
|
end
|
55
75
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
76
|
+
# rubocop:disable Lint/RedundantCopDisableDirective
|
77
|
+
# rubocop:disable Style/MissingRespondToMissing
|
78
|
+
# rubocop:disable Style/MethodMissingSuper
|
79
|
+
def method_missing(method, *args)
|
80
|
+
return unless resource_path(method)
|
81
|
+
|
82
|
+
attrs = {}
|
83
|
+
if args.size.positive?
|
84
|
+
attrs = args.last.is_a?(Hash) ? args.pop : {}
|
63
85
|
end
|
86
|
+
|
87
|
+
# Use V2 Collection if prefixed with V2
|
88
|
+
return RTX::API::CollectionV2.new(self, method, attrs) if method.to_s.start_with?('v2_')
|
89
|
+
|
90
|
+
RTX::API::Collection.new(self, method, attrs)
|
64
91
|
end
|
92
|
+
# rubocop:enable Style/MissingRespondToMissing
|
93
|
+
# rubocop:enable Style/MethodMissingSuper
|
94
|
+
# rubocop:enable Lint/RedundantCopDisableDirective
|
65
95
|
|
66
96
|
def collection(resource_name, attrs = {})
|
67
|
-
request = self.class.get("#{rtx_api_url}/#{resource_path(resource_name)}",
|
97
|
+
request = self.class.get("#{rtx_api_url}/#{resource_path(resource_name)}",
|
98
|
+
options(:get, attrs))
|
68
99
|
handle_request(request)
|
69
100
|
end
|
70
101
|
|
71
102
|
def detail(resource_name, resource_id, attrs = {})
|
72
|
-
raise API::Errors::RequestError
|
73
|
-
|
103
|
+
raise API::Errors::RequestError, 'id was not provided' if resource_id.nil?
|
104
|
+
|
105
|
+
request = self.class.get("#{rtx_api_url}/#{resource_path(resource_name)}/#{resource_id}",
|
106
|
+
options(:get, attrs))
|
74
107
|
handle_request(request)
|
75
108
|
end
|
76
109
|
|
77
110
|
def post(resource_name, attrs = {})
|
78
|
-
request = self.class.post("#{rtx_api_url}/#{resource_path(resource_name)}",
|
111
|
+
request = self.class.post("#{rtx_api_url}/#{resource_path(resource_name)}",
|
112
|
+
options(:post, attrs))
|
79
113
|
handle_request(request)
|
80
114
|
end
|
81
115
|
|
82
116
|
def put(resource_name, resource_id, attrs = {})
|
83
|
-
raise API::Errors::RequestError
|
84
|
-
|
117
|
+
raise API::Errors::RequestError, 'id was not provided' if resource_id.nil?
|
118
|
+
|
119
|
+
request = self.class.put("#{rtx_api_url}/#{resource_path(resource_name)}/#{resource_id}",
|
120
|
+
options(:put, attrs))
|
85
121
|
handle_request(request)
|
86
122
|
end
|
87
123
|
|
88
124
|
def patch(resource_name, resource_id, attrs = {})
|
89
|
-
raise API::Errors::RequestError
|
90
|
-
|
125
|
+
raise API::Errors::RequestError, 'id was not provided' if resource_id.nil?
|
126
|
+
|
127
|
+
request = self.class.patch("#{rtx_api_url}/#{resource_path(resource_name)}/#{resource_id}",
|
128
|
+
options(:patch, attrs))
|
91
129
|
handle_request(request)
|
92
130
|
end
|
93
131
|
|
94
132
|
def delete(resource_name, resource_id)
|
95
|
-
raise API::Errors::RequestError
|
96
|
-
|
133
|
+
raise API::Errors::RequestError, 'id was not provided' if resource_id.nil?
|
134
|
+
|
135
|
+
request = self.class.delete(
|
136
|
+
"#{rtx_api_url}/#{resource_path(resource_name)}/#{resource_id}", options(:delete)
|
137
|
+
)
|
97
138
|
handle_request(request)
|
98
139
|
end
|
99
140
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
103
|
-
end
|
141
|
+
def get(resource_name, attrs = {}, file_type = 'json')
|
142
|
+
request = self.class.get("#{rtx_api_url}/#{resource_path(resource_name)}",
|
143
|
+
options(:get, attrs))
|
104
144
|
|
105
|
-
|
106
|
-
|
107
|
-
|
145
|
+
handle_request(request, file_type)
|
146
|
+
end
|
147
|
+
|
148
|
+
def handle_request(request, file_type = 'json')
|
149
|
+
raise API::Errors::RequestError, request.parsed_response.to_s if !request.success?
|
108
150
|
|
109
|
-
|
151
|
+
return true if request.parsed_response.nil?
|
152
|
+
|
153
|
+
case file_type
|
154
|
+
when 'json'
|
155
|
+
Oj.load(request.body, symbol_keys: true)
|
156
|
+
when 'csv'
|
157
|
+
CSV.parse(request.body)
|
158
|
+
end
|
110
159
|
end
|
111
160
|
|
112
161
|
def resource_path(resource_name)
|
113
162
|
path = API::Resources.allowed_resources[resource_name.to_sym]
|
114
163
|
if !path
|
115
|
-
raise API::Errors::InvalidResourceError
|
164
|
+
raise API::Errors::InvalidResourceError,
|
165
|
+
"The resource provided (#{resource_name}) is not allowed"
|
116
166
|
end
|
167
|
+
|
117
168
|
path
|
118
169
|
end
|
119
170
|
|
@@ -128,14 +179,14 @@ module RTX
|
|
128
179
|
|
129
180
|
def default_headers
|
130
181
|
{
|
131
|
-
'Content-Type' =>
|
132
|
-
'Accept' =>
|
182
|
+
'Content-Type' => 'application/hal+json',
|
183
|
+
'Accept' => 'application/hal+json',
|
133
184
|
'User-Agent' => "rtx-api-client-ruby/#{API::VERSION}"
|
134
185
|
}.freeze
|
135
186
|
end
|
136
187
|
|
137
188
|
def options(action, attrs = {})
|
138
|
-
options = {headers: default_headers, basic_auth: {username: email, password: token}}
|
189
|
+
options = { headers: default_headers, basic_auth: { username: email, password: token } }
|
139
190
|
if write_request?(action)
|
140
191
|
options[:body] = Oj.dump(attrs, mode: :compat)
|
141
192
|
else
|
@@ -145,11 +196,11 @@ module RTX
|
|
145
196
|
end
|
146
197
|
|
147
198
|
def rtx_api_url
|
148
|
-
ENV[
|
199
|
+
api_url || ENV['RTX_API_URL'] || 'https://api-gateway.reviewtrackers.com'
|
149
200
|
end
|
150
201
|
|
151
202
|
def write_request?(action)
|
152
|
-
|
203
|
+
%i[post put patch].include?(action)
|
153
204
|
end
|
154
205
|
end
|
155
206
|
end
|
data/lib/rtx/api/collection.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RTX
|
2
4
|
module API
|
3
5
|
class Collection
|
@@ -40,7 +42,13 @@ module RTX
|
|
40
42
|
delete(symbolize_hash(attrs))
|
41
43
|
end
|
42
44
|
|
43
|
-
|
45
|
+
def get!(attrs = {}, file_type = 'json')
|
46
|
+
client.authenticate if !client.authenticated?
|
47
|
+
get(symbolize_hash(attrs), file_type)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Chainable method that allows you to set the per page number of
|
51
|
+
# the collection for your request
|
44
52
|
def per_page(num)
|
45
53
|
clear if !num.nil?
|
46
54
|
@options[:per_page] = num
|
@@ -65,22 +73,18 @@ module RTX
|
|
65
73
|
def meta
|
66
74
|
client.authenticate if !client.authenticated?
|
67
75
|
collection if !has_response?
|
68
|
-
response.reject {|key,_| key == :_embedded}
|
76
|
+
response.reject { |key, _| key == :_embedded }
|
69
77
|
end
|
70
78
|
|
71
79
|
# For moving forward one page with the collection
|
72
80
|
def next
|
73
|
-
if has_next?
|
74
|
-
page(options[:page] += 1)
|
75
|
-
end
|
81
|
+
page(options[:page] += 1) if has_next?
|
76
82
|
self
|
77
83
|
end
|
78
84
|
|
79
85
|
# For moving backward one page with the collection
|
80
86
|
def prev
|
81
|
-
if has_previous?
|
82
|
-
page(options[:page] -= 1)
|
83
|
-
end
|
87
|
+
page(options[:page] -= 1) if has_previous?
|
84
88
|
self
|
85
89
|
end
|
86
90
|
|
@@ -116,7 +120,8 @@ module RTX
|
|
116
120
|
end
|
117
121
|
end
|
118
122
|
|
119
|
-
# Allows you to loop through all of the resources
|
123
|
+
# Allows you to loop through all of the resources
|
124
|
+
# within the pages specified and retrieve the records
|
120
125
|
def all_resources(initial_page = 1, &block)
|
121
126
|
all_pages(initial_page) do |page|
|
122
127
|
page.each do |resource|
|
@@ -164,12 +169,16 @@ module RTX
|
|
164
169
|
client.delete(resource_name, resource_id)
|
165
170
|
end
|
166
171
|
|
172
|
+
def get(attrs = {}, file_type = 'json')
|
173
|
+
client.get(resource_name, attrs, file_type)
|
174
|
+
end
|
175
|
+
|
167
176
|
def has_response?
|
168
177
|
response != {}
|
169
178
|
end
|
170
179
|
|
171
180
|
def symbolize_hash(hash)
|
172
|
-
Hash[hash.map{|(key,value)| [key.to_sym,value]}]
|
181
|
+
Hash[hash.map { |(key, value)| [key.to_sym, value] }]
|
173
182
|
end
|
174
183
|
end
|
175
184
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RTX
|
4
|
+
module API
|
5
|
+
class CollectionV2
|
6
|
+
attr_accessor :client, :resource_name, :response, :options
|
7
|
+
|
8
|
+
def initialize(client, resource_name, attrs = {})
|
9
|
+
@client = client
|
10
|
+
@resource_name = resource_name.to_sym
|
11
|
+
@options = symbolize_hash(attrs)
|
12
|
+
@response = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Chainable method that allows you to set
|
16
|
+
# the per page number of the collection for your request
|
17
|
+
def per_page(num)
|
18
|
+
clear if !num.nil?
|
19
|
+
@options[:per_page] = num
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns all data associated with the existing response
|
24
|
+
def data
|
25
|
+
client.authenticate if !client.authenticated?
|
26
|
+
collection if !has_response?
|
27
|
+
response[:data]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the paging information about the current response
|
31
|
+
def paging
|
32
|
+
client.authenticate if !client.authenticated?
|
33
|
+
collection if !has_response?
|
34
|
+
response[:paging]
|
35
|
+
end
|
36
|
+
|
37
|
+
# For moving forward one page with the collection
|
38
|
+
def next
|
39
|
+
next_page(after_token) if has_next?
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
# For moving backward one page with the collection
|
44
|
+
def prev
|
45
|
+
previous_page(before_token) if has_previous?
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
# Responds true if the collection has another page ahead of it
|
50
|
+
def has_next?
|
51
|
+
!after_token.nil?
|
52
|
+
end
|
53
|
+
|
54
|
+
# Responds true if the collection has a previous one
|
55
|
+
def has_previous?
|
56
|
+
!before_token.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
# Allows you to loop through all of the pages and retrieve the records
|
60
|
+
def all_pages(&block)
|
61
|
+
loop do
|
62
|
+
# Return first page
|
63
|
+
block.call(data)
|
64
|
+
|
65
|
+
# No need to continue if all data is retrieved
|
66
|
+
break unless has_next?
|
67
|
+
|
68
|
+
# Navigate to the next page
|
69
|
+
self.next
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Allows you to loop through all of
|
74
|
+
# the resources within the pages specified and retrieve the records
|
75
|
+
def all_resources(&block)
|
76
|
+
all_pages do |page|
|
77
|
+
page.each do |resource|
|
78
|
+
block.call(resource)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
protected
|
84
|
+
|
85
|
+
# Chainable method that allows you to get the next page for a given after token
|
86
|
+
def next_page(after_token)
|
87
|
+
clear
|
88
|
+
@options[:after] = after_token
|
89
|
+
self
|
90
|
+
end
|
91
|
+
|
92
|
+
# Chainable method that allows you to get the previous page for a given before token
|
93
|
+
def previous_page(before_token)
|
94
|
+
clear
|
95
|
+
@options[:before] = before_token
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def after_token
|
100
|
+
return nil if paging.nil?
|
101
|
+
return nil if paging[:cursors].nil?
|
102
|
+
|
103
|
+
paging[:cursors][:after]
|
104
|
+
end
|
105
|
+
|
106
|
+
def before_token
|
107
|
+
return nil if paging.nil?
|
108
|
+
return nil if paging[:cursors].nil?
|
109
|
+
|
110
|
+
paging[:cursors][:before]
|
111
|
+
end
|
112
|
+
|
113
|
+
def clear
|
114
|
+
@response = {}
|
115
|
+
end
|
116
|
+
|
117
|
+
def collection
|
118
|
+
@response = client.collection(resource_name, options)
|
119
|
+
end
|
120
|
+
|
121
|
+
def has_response?
|
122
|
+
response != {}
|
123
|
+
end
|
124
|
+
|
125
|
+
def symbolize_hash(hash)
|
126
|
+
Hash[hash.map { |(key, value)| [key.to_sym, value] }]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
data/lib/rtx/api/resources.rb
CHANGED
@@ -21,6 +21,8 @@ module RTX
|
|
21
21
|
items: 'items',
|
22
22
|
layouts: 'layouts',
|
23
23
|
locations: 'locations',
|
24
|
+
metric_locations: 'export/csv/location_metrics',
|
25
|
+
metric_groups: 'export/csv/group_metrics',
|
24
26
|
notes: 'notes',
|
25
27
|
passwords: 'passwords',
|
26
28
|
permissions: 'permissions',
|
@@ -40,7 +42,9 @@ module RTX
|
|
40
42
|
urls: 'urls',
|
41
43
|
users: 'users',
|
42
44
|
user_types: 'user_types',
|
43
|
-
whitelabels: 'whitelabels'
|
45
|
+
whitelabels: 'whitelabels',
|
46
|
+
v2_reviews: 'v2/reviews',
|
47
|
+
v2_reviews_csv: 'v2/reviews_csv'
|
44
48
|
}.freeze
|
45
49
|
end
|
46
50
|
# rubocop:enable Metrics/MethodLength
|
data/lib/rtx/api/version.rb
CHANGED
data/lib/rtx/api.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oj'
|
4
|
+
require 'httparty'
|
5
|
+
require 'rtx/api/version'
|
4
6
|
|
5
7
|
# client
|
6
|
-
require
|
8
|
+
require 'rtx/api/client'
|
7
9
|
|
8
10
|
# resources
|
9
|
-
require
|
10
|
-
require
|
11
|
+
require 'rtx/api/resources'
|
12
|
+
require 'rtx/api/collection'
|
13
|
+
require 'rtx/api/collection_v2'
|
11
14
|
|
12
15
|
# errors
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
16
|
+
require 'rtx/api/errors/client_error'
|
17
|
+
require 'rtx/api/errors/authentication_error'
|
18
|
+
require 'rtx/api/errors/request_error'
|
19
|
+
require 'rtx/api/errors/invalid_resource_error'
|
17
20
|
|
18
21
|
module RTX
|
19
22
|
module API; end
|
20
|
-
end
|
23
|
+
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.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Review Trackers Engineering
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
77
78
|
- ".travis.yml"
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE
|
@@ -83,6 +84,7 @@ files:
|
|
83
84
|
- lib/rtx/api.rb
|
84
85
|
- lib/rtx/api/client.rb
|
85
86
|
- lib/rtx/api/collection.rb
|
87
|
+
- lib/rtx/api/collection_v2.rb
|
86
88
|
- lib/rtx/api/errors/authentication_error.rb
|
87
89
|
- lib/rtx/api/errors/client_error.rb
|
88
90
|
- lib/rtx/api/errors/invalid_resource_error.rb
|
@@ -91,11 +93,11 @@ files:
|
|
91
93
|
- lib/rtx/api/version.rb
|
92
94
|
- pull_request_template.md
|
93
95
|
- rtx-api.gemspec
|
94
|
-
homepage:
|
96
|
+
homepage:
|
95
97
|
licenses:
|
96
98
|
- MIT
|
97
99
|
metadata: {}
|
98
|
-
post_install_message:
|
100
|
+
post_install_message:
|
99
101
|
rdoc_options: []
|
100
102
|
require_paths:
|
101
103
|
- lib
|
@@ -110,9 +112,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
112
|
- !ruby/object:Gem::Version
|
111
113
|
version: '0'
|
112
114
|
requirements: []
|
113
|
-
rubyforge_project:
|
115
|
+
rubyforge_project:
|
114
116
|
rubygems_version: 2.6.8
|
115
|
-
signing_key:
|
117
|
+
signing_key:
|
116
118
|
specification_version: 4
|
117
119
|
summary: Ruby Client for the Review Trackers RTX API.
|
118
120
|
test_files: []
|