docusign_dtr 0.1.1 → 0.2.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
2
  SHA256:
3
- metadata.gz: 5da087fda3a230a4db8737e07c5dea37eb6f43350b74242366384857e1b69f03
4
- data.tar.gz: 77fd8fd7cf0f4fd3f42087ccbdb122199d93fdb26200dd1a78df24e1d9ebe031
3
+ metadata.gz: 13d3250540c09372453765cfcdf03f65c96f6086669281bc5533c9796372c0e0
4
+ data.tar.gz: ad80189d0f717a1026c8c5fb285db5aca8ab3b38f886009667957aa2640b4ef2
5
5
  SHA512:
6
- metadata.gz: 4d5440a1d3be5c02df50b1abf58920d01b635814d94bd50b9f1e6e3e1144f98ccb25453aae24cd1ced9bf2d624b8ee4cbea1c08c5cdea62e1ac7ec76fc73896a
7
- data.tar.gz: 701e93da058fee1dbd86727da015e819726f6f1c33b89bd21ea48a92db1b9a6214db5199aee4128a6960a96abcbafcbc9d26f93cc3844b2c039bba3415763697
6
+ metadata.gz: 3dcc6ecd775e27f5a1b6923a7fd7d18612a6908a230f1bbd9b265b9ef31ef48dab765938a7aa1e3294b2986713eef40524a61bb48d84dba74691099d670968eb
7
+ data.tar.gz: 92061dcb875c9980a5d1787ea25fd03c7bf0a42fdb1ae1f4047f280cec06f4c4bbde5cbe7de6858d798ab3a86dc230e442ff26df3b39283f8fa42701d75a2a66
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.required_ruby_version = '~> 2.5'
18
18
 
19
19
  raise 'RubyGems 2.5 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
20
+
20
21
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
22
 
22
23
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -30,6 +30,7 @@ require 'docusign_dtr/meta_timezone'
30
30
  require 'docusign_dtr/meta_transaction_side'
31
31
  require 'docusign_dtr/office'
32
32
  require 'docusign_dtr/office'
33
+ require 'docusign_dtr/query_param_helper'
33
34
  require 'docusign_dtr/room'
34
35
  require 'docusign_dtr/task_list'
35
36
  require 'docusign_dtr/title'
@@ -73,11 +73,14 @@ module DocusignDtr
73
73
  when 400
74
74
  # {"error":"invalid_grant"}
75
75
  return DocusignDtr::InvalidGrant if response.parsed_response['error'].match?(/grant/)
76
+
76
77
  DocusignDtr::ConsentRequired # {"error":"consent_required"}
77
78
  when 401
78
79
  DocusignDtr::Unauthorized
79
80
  when 403
80
81
  DocusignDtr::Forbidden
82
+ when 204
83
+ DocusignDtr::NoContent
81
84
  else
82
85
  StandardError
83
86
  end
@@ -19,6 +19,7 @@ module DocusignDtr
19
19
 
20
20
  def request_token(code:, state: nil)
21
21
  raise 'State does ont match. Possible CSRF!' if state && state != @config.state
22
+
22
23
  params = { grant_type: :authorization_code, code: code }
23
24
  response = self.class.post(auth_uri, query: params, headers: headers, timeout: 60)
24
25
  handle_error(response.code) if response.code != 200
@@ -27,6 +28,7 @@ module DocusignDtr
27
28
 
28
29
  def refresh_token
29
30
  raise 'No token to refresh' unless @token_response&.access_token
31
+
30
32
  params = { grant_type: :refresh_token, refresh_token: @token_response.access_token }
31
33
  response = self.class.post("#{base_uri}oauth/token", query: params, headers: headers, timeout: 60)
32
34
  handle_error(response.code) if response.code != 200
@@ -18,12 +18,12 @@ module DocusignDtr
18
18
  def raw(page, params = {})
19
19
  full_path = [base_uri, page].join
20
20
  response = self.class.get(full_path, query: params, headers: headers, timeout: 60)
21
- handle_error(response.code) if response.code != 200
21
+ handle_error(response) if response.code != 200
22
22
  response.parsed_response
23
23
  end
24
24
 
25
- def handle_error(response_code)
26
- raise error_type(response_code), "Error communicating: Response code #{response_code}"
25
+ def handle_error(response)
26
+ raise error_type(response), "Error communicating: Response code #{response.code}"
27
27
  end
28
28
 
29
29
  def Document # rubocop:disable Naming/MethodName
@@ -180,12 +180,19 @@ module DocusignDtr
180
180
  end
181
181
  end
182
182
 
183
- def error_type(response_code)
184
- case response_code
183
+ def error_type(response)
184
+ case response.code
185
+ when 400
186
+ # {"error":"invalid_grant"}
187
+ return DocusignDtr::InvalidGrant if response.parsed_response['error'].match?(/grant/)
188
+
189
+ DocusignDtr::ConsentRequired # {"error":"consent_required"}
185
190
  when 401
186
191
  DocusignDtr::Unauthorized
187
192
  when 403
188
193
  DocusignDtr::Forbidden
194
+ when 204
195
+ DocusignDtr::NoContent
189
196
  else
190
197
  StandardError
191
198
  end
@@ -1,6 +1,8 @@
1
1
  module DocusignDtr
2
2
  class ConsentRequired < StandardError; end
3
3
  class InvalidGrant < StandardError; end
4
+ class InvalidParameter < StandardError; end
4
5
  class Forbidden < StandardError; end
6
+ class NoContent < StandardError; end
5
7
  class Unauthorized < StandardError; end
6
8
  end
@@ -4,6 +4,8 @@ module DocusignDtr
4
4
  include Virtus.model
5
5
  attribute :address, DocusignDtr::Models::Address
6
6
  attribute :auction_details, DocusignDtr::Models::AuctionDetail
7
+ attribute :buyer1, DocusignDtr::Models::Contact
8
+ attribute :buyer2, DocusignDtr::Models::Contact
7
9
  attribute :closed_status_id
8
10
  attribute :company_room_status_id
9
11
  attribute :contract_amount
@@ -22,22 +24,58 @@ module DocusignDtr
22
24
  attribute :room_id
23
25
  attribute :room_image_url
24
26
  attribute :room_name
27
+ attribute :rooms
25
28
  attribute :status
26
29
  attribute :view_link
27
30
  attr_accessor :client
28
31
 
32
+ ACCEPTABLE_VALUES = {
33
+ room_status: %w[
34
+ Active
35
+ Pending
36
+ Closed
37
+ Open
38
+ ],
39
+ transaction_side: %w[
40
+ buy
41
+ sell
42
+ listbuy
43
+ refi
44
+ ],
45
+ sort: [
46
+ 'RoomName',
47
+ 'RoomName desc',
48
+ 'CreatedDate',
49
+ 'CreatedDate desc',
50
+ 'ExpectedClosingDate',
51
+ 'ExpectedClosingDate desc',
52
+ 'LastUpdatedDate',
53
+ 'LastUpdatedDate desc',
54
+ 'ClosedDate',
55
+ 'ClosedDate desc'
56
+ ],
57
+ date_range_type: %w[
58
+ Created
59
+ LastUpdated
60
+ Closed
61
+ ]
62
+ }.freeze
63
+
29
64
  def documents
30
65
  return [] unless room_id
66
+
31
67
  ::DocusignDtr::Document.new(client: client).all_by_room_id(room_id)
32
68
  end
33
69
 
34
70
  def task_lists
35
71
  return [] unless room_id
72
+
36
73
  ::DocusignDtr::TaskList.new(client: client).all_by_room_id(room_id)
37
74
  end
38
75
 
39
76
  def users
40
77
  return [] unless room_id
78
+
41
79
  ::DocusignDtr::User.new(client: client).all_by_room_id(room_id)
42
80
  end
43
81
  end
@@ -49,6 +49,7 @@ module DocusignDtr
49
49
 
50
50
  def activities
51
51
  return [] unless task_id
52
+
52
53
  ::DocusignDtr::Activity.new(client: client).all_by_task_id(task_id)
53
54
  end
54
55
  end
@@ -0,0 +1,135 @@
1
+ module DocusignDtr
2
+ # rubocop:disable Metrics/ClassLength
3
+ class QueryParamHelper
4
+ # rubocop:disable Naming/PredicateName
5
+ QUERY_PARAMS = {
6
+ search: :search,
7
+ count: :count,
8
+ end_date: :endDate,
9
+ start_position: :startPosition,
10
+ room_status: :roomStatus,
11
+ owned_only: :ownedOnly,
12
+ transaction_side: :transactionSide,
13
+ is_under_contract: :isUnderContract,
14
+ region_id: :regionId,
15
+ office_id: :officeId,
16
+ has_submitted_task_list: :hasSubmittedTaskList,
17
+ has_contract_amount: :hasContractAmount,
18
+ sort: :sort,
19
+ date_range_type: :dateRangeType,
20
+ start_date: :startDate
21
+ }.freeze
22
+
23
+ class << self
24
+ def call(options)
25
+ @options = options
26
+ QUERY_PARAMS.each_with_object({}) do |(key, value), memo|
27
+ memo[value] = send(key) if @options.key? key
28
+ end
29
+ end
30
+
31
+ def search
32
+ @options[:search].to_s
33
+ end
34
+
35
+ def count
36
+ @options[:count].to_i
37
+ end
38
+
39
+ def start_position
40
+ @options[:start_position].to_i
41
+ end
42
+
43
+ def room_status
44
+ unless acceptable_value?(:room_status, @options[:room_status])
45
+ raise DocusignDtr::InvalidParameter.new("value #{@options[:room_status]} is not valid for #{__method__}")
46
+ end
47
+
48
+ @options[:room_status].to_s
49
+ end
50
+
51
+ def owned_only
52
+ to_boolean(@options[:owned_only], __method__)
53
+ end
54
+
55
+ def transaction_side
56
+ unless acceptable_value?(:transaction_side, @options[:transaction_side])
57
+ raise DocusignDtr::InvalidParameter.new("value #{@options[:transaction_side]} is not valid for #{__method__}")
58
+ end
59
+
60
+ @options[:transaction_side].to_s
61
+ end
62
+
63
+ def is_under_contract
64
+ to_boolean(@options[:is_under_contract], __method__)
65
+ end
66
+
67
+ def region_id
68
+ @options[:region_id].to_i
69
+ end
70
+
71
+ def office_id
72
+ @options[:office_id].to_i
73
+ end
74
+
75
+ def has_submitted_task_list
76
+ to_boolean(@options[:has_submitted_task_list], __method__)
77
+ end
78
+
79
+ def has_contract_amount
80
+ to_boolean(@options[:has_contract_amount], __method__)
81
+ end
82
+
83
+ def sort
84
+ unless acceptable_value?(:sort, @options[:sort].to_s)
85
+ raise DocusignDtr::InvalidParameter.new("value #{@options[:sort]} is not valid for #{__method__}")
86
+ end
87
+
88
+ @options[:sort].to_s
89
+ end
90
+
91
+ def date_range_type
92
+ unless acceptable_value?(:date_range_type, @options[:date_range_type])
93
+ raise DocusignDtr::InvalidParameter.new(
94
+ "value #{@options[:date_range_type]} is not valid for #{__method__}"
95
+ )
96
+ end
97
+
98
+ @options[:date_range_type].to_s
99
+ end
100
+
101
+ def start_date
102
+ to_date(@options[:start_date].to_s, __method__)
103
+ end
104
+
105
+ def end_date
106
+ to_date(@options[:end_date].to_s, __method__)
107
+ end
108
+
109
+ def to_boolean(value, key)
110
+ unless value.is_a?(FalseClass) || value.is_a?(TrueClass)
111
+ raise DocusignDtr::InvalidParameter.new("value #{value} is not valid for #{key}")
112
+ end
113
+
114
+ value
115
+ end
116
+
117
+ def to_date(value, key)
118
+ DateTime.parse(value)
119
+ value
120
+ rescue ArgumentError
121
+ raise DocusignDtr::InvalidParameter.new("#{value} is not a valid #{key}")
122
+ end
123
+
124
+ def acceptable_value?(key, value)
125
+ query_acceptable_values[key].include?(value)
126
+ end
127
+
128
+ def query_acceptable_values
129
+ DocusignDtr::Models::Room::ACCEPTABLE_VALUES
130
+ end
131
+ end
132
+ end
133
+ # rubocop:enable Naming/PredicateName
134
+ # rubocop:enable Metrics/ClassLength
135
+ end
@@ -2,16 +2,36 @@ module DocusignDtr
2
2
  class Room
3
3
  attr_accessor :client
4
4
 
5
+ MAX_ROOMS = 100
6
+ MAX_BATCHES = 10_000
7
+
5
8
  def initialize(client:)
6
9
  @client = client
7
10
  end
8
11
 
9
- def all
10
- @client.get('/rooms')['rooms'].map do |room_attrs|
12
+ def all(options = {})
13
+ options[:count] ||= MAX_ROOMS
14
+ rooms = []
15
+ (1..MAX_BATCHES).each do
16
+ current_batch = batch(options)
17
+ rooms += current_batch
18
+ break if current_batch.size < options[:count]
19
+ end
20
+ rooms
21
+ end
22
+
23
+ def batch(options = {})
24
+ @client.get('/rooms', query_params(options))['rooms'].map do |room_attrs|
11
25
  room = DocusignDtr::Models::Room.new(room_attrs)
12
26
  room.client = client
13
27
  room
14
28
  end
29
+ rescue DocusignDtr::NoContent
30
+ []
31
+ end
32
+
33
+ def query_params(options)
34
+ DocusignDtr::QueryParamHelper.call(options)
15
35
  end
16
36
 
17
37
  def find(id)
@@ -1,3 +1,3 @@
1
1
  module DocusignDtr
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docusign_dtr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loft47
@@ -34,7 +34,7 @@ cert_chain:
34
34
  WPTyTwBv5qAL48mT3OBIV99mY13XurTi2s2OCJAgkQZIQlGsFzmT/4IDYivCoABO
35
35
  QVWtuf6LfMkXYW5shBsTlpiGbXeVlm0QW2Av3w==
36
36
  -----END CERTIFICATE-----
37
- date: 2018-08-29 00:00:00.000000000 Z
37
+ date: 2018-10-10 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: coveralls
@@ -303,6 +303,7 @@ files:
303
303
  - lib/docusign_dtr/models/user.rb
304
304
  - lib/docusign_dtr/office.rb
305
305
  - lib/docusign_dtr/profile.rb
306
+ - lib/docusign_dtr/query_param_helper.rb
306
307
  - lib/docusign_dtr/region.rb
307
308
  - lib/docusign_dtr/room.rb
308
309
  - lib/docusign_dtr/task_list.rb
metadata.gz.sig CHANGED
Binary file