rtx-api 0.4.1 → 0.5.1

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
- SHA1:
3
- metadata.gz: 1cb8509c76c825a79bc394284067d1828e9255f5
4
- data.tar.gz: 6a2162d1c63900e40ad4f3d6358e370eb8333434
2
+ SHA256:
3
+ metadata.gz: 9501dcc7112fefb26fa0cfea1259aa23e1b8cc45b64971e39f426cf11913bc13
4
+ data.tar.gz: d4b91f77fb51cca1d8dd067e8ab87372921c72c380d3bf210091132e8adf44da
5
5
  SHA512:
6
- metadata.gz: 0b63e7b806a601be000451c64ceedad226c18a6a58a25b4b262ccb012b65d9aa151b6574fd9850ccb6a4a3216c74b7b1f537088534038c30f723147ce1685eea
7
- data.tar.gz: 1b4744b8ac44f42061911d9ae7dbb64a81c906f39bc0c59625902d437479fb432bfc7bb1481a827f164d2d12edfb33938c909c295db2692511adf1a7bf9f0f46
6
+ metadata.gz: fd462a434c9feced48e18a238d5edef6a1e84b64c4763e1f8fe0b6ed8c4a10bcb17bf95b7b834264aa4082aebb785cfd4324e125f7df5b209f9e56852dbc8e00
7
+ data.tar.gz: ec4008817753110b2d22d8fd4eee9262182cc2c0d97ae673bb22d37c6368a6dde3dc7c8db738b3518ea6a0422c6f77763647053dfce35df0b0b2fc6ac81bd173
data/README.md CHANGED
@@ -18,6 +18,18 @@ 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
+ 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.
30
+
31
+ bundle exec rake release
32
+
21
33
  ## Usage
22
34
 
23
35
  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/lib/rtx/api.rb CHANGED
@@ -8,6 +8,7 @@ require "rtx/api/client"
8
8
  # resources
9
9
  require "rtx/api/resources"
10
10
  require "rtx/api/collection"
11
+ require "rtx/api/collection_v2"
11
12
 
12
13
  # errors
13
14
  require "rtx/api/errors/client_error"
@@ -2,11 +2,12 @@ module RTX
2
2
  module API
3
3
  class Client
4
4
  include HTTParty
5
- attr_accessor :email, :password, :token, :expires, :account_id, :profile_id
5
+ attr_accessor :email, :password, :api_url, :token, :expires, :account_id, :profile_id
6
6
 
7
- def initialize(email = ENV["RTX_USER_EMAIL"], password = ENV["RTX_USER_PASSWORD"])
7
+ def initialize(email = ENV["RTX_USER_EMAIL"], password = ENV["RTX_USER_PASSWORD"], api_url = ENV["RTX_API_URL"])
8
8
  @email = email
9
9
  @password = password
10
+ @api_url = api_url
10
11
  @token = nil
11
12
  @expires = nil
12
13
  end
@@ -59,6 +60,10 @@ module RTX
59
60
  if args.size > 0
60
61
  attrs = args.last.is_a?(Hash) ? args.pop : {}
61
62
  end
63
+
64
+ # Use V2 Collection if prefixed with V2
65
+ return RTX::API::CollectionV2.new(self, method, attrs) if method.to_s.start_with?('v2_')
66
+
62
67
  RTX::API::Collection.new(self, method, attrs)
63
68
  end
64
69
  end
@@ -145,7 +150,7 @@ module RTX
145
150
  end
146
151
 
147
152
  def rtx_api_url
148
- ENV["RTX_API_URL"] || "https://api-gateway.reviewtrackers.com"
153
+ api_url || ENV["RTX_API_URL"] || "https://api-gateway.reviewtrackers.com"
149
154
  end
150
155
 
151
156
  def write_request?(action)
@@ -0,0 +1,130 @@
1
+ module RTX
2
+ module API
3
+ class CollectionV2
4
+ attr_accessor :client, :resource_name, :response, :options
5
+
6
+ def initialize(client, resource_name, attrs = {})
7
+ @client = client
8
+ @resource_name = resource_name.to_sym
9
+ @options = symbolize_hash(attrs)
10
+ @response = {}
11
+ end
12
+
13
+ # Chainable method that allows you to set the per page number of the collection for your request
14
+ def per_page(num)
15
+ clear if !num.nil?
16
+ @options[:per_page] = num
17
+ self
18
+ end
19
+
20
+ # Returns all data associated with the existing response
21
+ def data
22
+ client.authenticate if !client.authenticated?
23
+ collection if !has_response?
24
+ response[:data]
25
+ end
26
+
27
+ # Returns the paging information about the current response
28
+ def paging
29
+ client.authenticate if !client.authenticated?
30
+ collection if !has_response?
31
+ response[:paging]
32
+ end
33
+
34
+ # For moving forward one page with the collection
35
+ def next
36
+ if has_next?
37
+ next_page(after_token)
38
+ end
39
+ self
40
+ end
41
+
42
+ # For moving backward one page with the collection
43
+ def prev
44
+ if has_previous?
45
+ previous_page(before_token)
46
+ end
47
+ self
48
+ end
49
+
50
+ # Responds true if the collection has another page ahead of it
51
+ def has_next?
52
+ !after_token.nil?
53
+ end
54
+
55
+ # Responds true if the collection has a previous one
56
+ def has_previous?
57
+ !before_token.nil?
58
+ end
59
+
60
+ # Allows you to loop through all of the pages and retrieve the records
61
+ def all_pages(&block)
62
+ loop do
63
+ # Return first page
64
+ block.call(data)
65
+
66
+ # No need to continue if all data is retrieved
67
+ break unless has_next?
68
+
69
+ # Navigate to the next page
70
+ self.next
71
+ end
72
+ end
73
+
74
+ # Allows you to loop through all of 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
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RTX
2
4
  module API
3
5
  class Resources
6
+ # rubocop:disable Metrics/MethodLength
4
7
  def self.allowed_resources
5
8
  {
6
9
  accounts: 'accounts',
10
+ account_settings: 'account_settings',
7
11
  alerts: 'alerts',
8
12
  alert_frequencies: 'alert_frequencies',
9
13
  alert_types: 'alert_types',
@@ -18,7 +22,9 @@ module RTX
18
22
  layouts: 'layouts',
19
23
  locations: 'locations',
20
24
  notes: 'notes',
25
+ passwords: 'passwords',
21
26
  permissions: 'permissions',
27
+ plan_changes: 'plan_changes',
22
28
  profiles: 'profiles',
23
29
  requests: 'requests',
24
30
  request_pages: 'request_pages',
@@ -34,9 +40,12 @@ module RTX
34
40
  urls: 'urls',
35
41
  users: 'users',
36
42
  user_types: 'user_types',
37
- whitelabels: 'whitelabels'
43
+ whitelabels: 'whitelabels',
44
+ v2_reviews: 'v2/reviews',
45
+ v2_reviews_csv: 'v2/reviews_csv'
38
46
  }.freeze
39
47
  end
48
+ # rubocop:enable Metrics/MethodLength
40
49
  end
41
50
  end
42
51
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RTX
2
4
  module API
3
- VERSION = "0.4.1"
5
+ VERSION = '0.5.1'
4
6
  end
5
7
  end
@@ -0,0 +1,18 @@
1
+ # Title
2
+ [Link to passing hydra (unless you're triggering through this PR)]
3
+
4
+ [Description]
5
+
6
+ #### Do you have tests for your changes?
7
+ - [ ] Yes
8
+ - [ ] No (if no, why not?)
9
+
10
+ # Proof
11
+
12
+ ## Before
13
+ [Attach prior behavior if applicable]
14
+
15
+ ## After
16
+ [Attach new behavior proof]
17
+
18
+ - [ ] Zach's Checkbox (aka: I've manually regression tested any large changes)
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.1
4
+ version: 0.5.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: 2019-03-12 00:00:00.000000000 Z
11
+ date: 2021-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -83,18 +83,20 @@ files:
83
83
  - lib/rtx/api.rb
84
84
  - lib/rtx/api/client.rb
85
85
  - lib/rtx/api/collection.rb
86
+ - lib/rtx/api/collection_v2.rb
86
87
  - lib/rtx/api/errors/authentication_error.rb
87
88
  - lib/rtx/api/errors/client_error.rb
88
89
  - lib/rtx/api/errors/invalid_resource_error.rb
89
90
  - lib/rtx/api/errors/request_error.rb
90
91
  - lib/rtx/api/resources.rb
91
92
  - lib/rtx/api/version.rb
93
+ - pull_request_template.md
92
94
  - rtx-api.gemspec
93
- homepage:
95
+ homepage:
94
96
  licenses:
95
97
  - MIT
96
98
  metadata: {}
97
- post_install_message:
99
+ post_install_message:
98
100
  rdoc_options: []
99
101
  require_paths:
100
102
  - lib
@@ -109,9 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
111
  - !ruby/object:Gem::Version
110
112
  version: '0'
111
113
  requirements: []
112
- rubyforge_project:
113
- rubygems_version: 2.6.8
114
- signing_key:
114
+ rubygems_version: 3.1.1
115
+ signing_key:
115
116
  specification_version: 4
116
117
  summary: Ruby Client for the Review Trackers RTX API.
117
118
  test_files: []