rtx-api 0.4.3 → 0.5.0

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: e0b63f758c0c2bca1e1d6746d9b046c7a8d39bdc
4
- data.tar.gz: 57790164cc08bfdd07d12e8a60a01eb0b2daf605
2
+ SHA256:
3
+ metadata.gz: f814c532170891e526790baba2601785abab70e68d528d205636193ef0307eec
4
+ data.tar.gz: 1d95ed32188e0b5adb877df739508ef8e42308656b62df1ee4fec660d5fb17d5
5
5
  SHA512:
6
- metadata.gz: 8bdbccc1be110d39ac17238786d4c6612a2d21a678a3122677cf206caa329e2783029cc4b50d95ded4fe06555bb01951b68ba713824981eea2c6a5fe2f7a71ac
7
- data.tar.gz: 83cb2bf41ed17f9d8afa9c072be126d4b23221c0b689081e058a3b9d0e435cdaebab82d47f795bd27e85542d574dbad8f994c1179ac75910730770d9f5231f05
6
+ metadata.gz: 57841fbfd405bbcda5f12c04b120720b1a4e9808c403cb160e1c5dc636475e263823bb769af66f7a3ae74acbbd0a767d8612d6fcaed76d00ac2f1aad17593bd7
7
+ data.tar.gz: a9e930cce3c9654c32e6944ff0e5872a8a97494f6e4dcc12210bc79f67379791a5e347587358dedfa56b011d7f06a2dd63382386f71b2c2029609335e544386d
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.
@@ -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"
@@ -59,6 +59,10 @@ module RTX
59
59
  if args.size > 0
60
60
  attrs = args.last.is_a?(Hash) ? args.pop : {}
61
61
  end
62
+
63
+ # Use V2 Collection if prefixed with V2
64
+ return RTX::API::CollectionV2.new(self, method, attrs) if method.to_s.start_with?('v2_')
65
+
62
66
  RTX::API::Collection.new(self, method, attrs)
63
67
  end
64
68
  end
@@ -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
@@ -40,7 +40,9 @@ module RTX
40
40
  urls: 'urls',
41
41
  users: 'users',
42
42
  user_types: 'user_types',
43
- whitelabels: 'whitelabels'
43
+ whitelabels: 'whitelabels',
44
+ v2_reviews: 'v2/reviews',
45
+ v2_reviews_csv: 'v2/reviews_csv'
44
46
  }.freeze
45
47
  end
46
48
  # rubocop:enable Metrics/MethodLength
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RTX
4
4
  module API
5
- VERSION = '0.4.3'
5
+ VERSION = '0.5.0'
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.4.3
4
+ version: 0.5.0
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: 2020-06-01 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -83,6 +83,7 @@ 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
@@ -110,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.6.8
114
+ rubygems_version: 3.1.1
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Ruby Client for the Review Trackers RTX API.