tops_connect 0.4.3.2 → 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: fb05758fdcdd83dc6d3725967b6434e9803da78c
4
- data.tar.gz: cc16acf78a5ea7cec0e14019faad1efe3e3f1b40
2
+ SHA256:
3
+ metadata.gz: e693e4f20693b51e9ef1729c307abae6e8e49cd0d92a04fa8f79a9c83ab43c60
4
+ data.tar.gz: cc1f4bcc3c10588236114facebba06c693eafa5a20f930a109510ce6c2fd2828
5
5
  SHA512:
6
- metadata.gz: 78f8612c3baffacf861dcf6146e2fb2022eb165ebeb74991d30458a58fe0c9acbebf61d23dfe743311acc187333137cfd622fceb94c0c1dd1df0c0e0a0db8280
7
- data.tar.gz: 1a7906c8abdeec9cb18cbd99eb59c4b013b91b05f86f641675214ab14ee29a1319d54448910d600dec37086dfbb23eb0b7039f09417bc751c0f7458cd49252c2
6
+ metadata.gz: 8d27cd2cfbfc12ca9e3199fb2893ce1540e5f0c6de448306d346b93a053879e8b7621811fadf0de1ba6541f8d2c80cc507e9a642857251d66c099ef16476b1ea
7
+ data.tar.gz: 90b74c5944b310533fc7b521340712c550c3369c74f42fd3dc6afe6e181d6bae41df4288ee7f192165126c0adf32eb93035eb554bd1b2fb5f1bbb4db9513d726
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ AllCops:
2
2
  Include:
3
3
  - Gemfile
4
4
  - Rakefile
5
- TargetRubyVersion: 2.3
5
+ TargetRubyVersion: 2.5
6
6
 
7
7
  Metrics/AbcSize:
8
8
  Enabled: false
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Steven Hoffman
3
+ Copyright (c) 2018 Steven Hoffman
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/lib/tops_connect.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'base64'
3
4
  require 'httparty'
4
5
  require 'json'
6
+ require 'time'
5
7
 
6
8
  require 'tops_connect/errors'
7
9
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  class Base
4
5
  attr_reader :data
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  class Client
4
5
  include HTTParty
@@ -9,9 +10,8 @@ module TopsConnect
9
10
  attr_reader :community_id, :community_api_key
10
11
 
11
12
  headers 'Content-Type' => 'application/json'
12
- headers 'api-version' => '1'
13
13
 
14
- base_uri 'https://topsconnectapi.azure-api.net'
14
+ base_uri 'https://topsconnectapi.azure-api.net/v2'
15
15
 
16
16
  def initialize(community_id, community_api_key)
17
17
  authorization = Base64.strict_encode64 [
@@ -22,6 +22,11 @@ module TopsConnect
22
22
  self.class.headers('authorization' => "Basic #{authorization}")
23
23
 
24
24
  @subscription_key = TopsConnect.configuration.subscription_key
25
+
26
+ switch_community(community_id, community_api_key)
27
+ end
28
+
29
+ def switch_community(community_id, community_api_key)
25
30
  @community_id = community_id
26
31
  @community_api_key = community_api_key
27
32
  end
@@ -38,6 +43,32 @@ module TopsConnect
38
43
  response.parsed_response
39
44
  end
40
45
 
46
+ def put(endpoint, body: {}, headers: {}, query: {})
47
+ response = self.class.put(
48
+ "/#{TopsConnect.configuration.zone}/api#{endpoint}",
49
+ query: query.merge('subscription-key' => @subscription_key),
50
+ headers: headers.merge('community-api-key' => @community_api_key),
51
+ body: body
52
+ )
53
+
54
+ raise_exception(response) unless response.code == 204
55
+
56
+ response.parsed_response
57
+ end
58
+
59
+ def post(endpoint, body: {}, headers: {}, query: {})
60
+ response = self.class.post(
61
+ "/#{TopsConnect.configuration.zone}/api#{endpoint}",
62
+ query: query.merge('subscription-key' => @subscription_key),
63
+ headers: headers.merge('community-api-key' => @community_api_key),
64
+ body: body
65
+ )
66
+
67
+ raise_exception(response) unless response.code == 200
68
+
69
+ response.parsed_response
70
+ end
71
+
41
72
  protected
42
73
 
43
74
  def raise_exception(response)
@@ -54,7 +85,7 @@ module TopsConnect
54
85
 
55
86
  raise TopsConnect::InternalError, response
56
87
  else
57
- # As far as I'm aware, Tops does not return 100 - 199 or 201 - 399.
88
+ # As far as I'm aware, Tops does not return 100 - 199 or 205 - 399.
58
89
  raise TopsConnect::ApiError, response
59
90
  end
60
91
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  module Communities
4
5
  # Method: GET
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  class Community < Base
4
5
  def community_key
@@ -28,13 +29,13 @@ module TopsConnect
28
29
  end
29
30
 
30
31
  def last_synced_at
31
- DateTime.parse data['LastSyncTime'] if data['LastSyncTime']
32
+ Time.parse data['LastSyncTime'] if data['LastSyncTime']
32
33
  end
33
34
 
34
35
  def modified_date
35
36
  return unless data['Metadata']['ModifiedDate']
36
37
 
37
- DateTime.parse data['Metadata']['ModifiedDate']
38
+ Time.parse data['Metadata']['ModifiedDate']
38
39
  end
39
40
  alias updated_at modified_date
40
41
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  class Configuration
4
5
  attr_reader :subscription_key, :client_id, :software_key, :zone
5
6
 
6
7
  def subscription_key=(key)
7
- unless key =~ /\A\h{32}\z/i
8
+ unless key.match?(/\A\h{32}\z/i)
8
9
  raise 'Invalid TOPS Subscription Key. Expected 32 hex characters.'
9
10
  end
10
11
 
@@ -12,7 +13,7 @@ module TopsConnect
12
13
  end
13
14
 
14
15
  def client_id=(key)
15
- unless key =~ /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
16
+ unless key.match?(/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/)
16
17
  raise 'Invalid TOPS Client ID. Expected a GUID.'
17
18
  end
18
19
 
@@ -20,7 +21,7 @@ module TopsConnect
20
21
  end
21
22
 
22
23
  def software_key=(key)
23
- unless key =~ /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
24
+ unless key.match?(/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/)
24
25
  raise 'Invalid TOPS Software Key. Expected a GUID.'
25
26
  end
26
27
 
@@ -28,7 +29,7 @@ module TopsConnect
28
29
  end
29
30
 
30
31
  def zone=(new_zone)
31
- unless %i(broad limited sandbox).include?(new_zone.to_sym)
32
+ unless %i[broad limited sandbox].include?(new_zone.to_sym)
32
33
  raise 'Invalid TOPS Zone. Accepted values are broad, limited, sandbox.'
33
34
  end
34
35
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  class ApiError < ::RuntimeError
4
5
  def initialize(response)
@@ -7,7 +8,7 @@ module TopsConnect
7
8
 
8
9
  def to_s
9
10
  format(
10
- '%{code}: %{message} (%{uri})',
11
+ '%<code>s: %<message>s (%<uri>s)',
11
12
  code: @response.code,
12
13
  message: @response.parsed_response&.dig('Message'),
13
14
  uri: @response.request.last_uri.to_s
@@ -1,32 +1,31 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  class Owner < Base
4
5
  def owner_key
5
- data['OwnerKey']
6
+ data['Key']
6
7
  end
7
8
  alias id owner_key
8
9
 
9
10
  def alternate_mailing_addresses
10
- [1, 2].map do |n|
11
+ data['Addresses'].map do |row|
12
+ next unless row['Type']['Name'] == 'Alternate'
13
+
11
14
  lines = []
12
15
 
13
- if data["AltMailing#{n}AddressLine1"] =~ /[[:graph:]]/
14
- lines << data["AltMailing#{n}AddressLine1"].strip
16
+ if row['AddressLine1'].match?(/[[:graph:]]/)
17
+ lines << row['AddressLine1']
15
18
  end
16
19
 
17
- if data["AltMailing#{n}AddressLine2"] =~ /[[:graph:]]/
18
- lines << data["AltMailing#{n}AddressLine2"].strip
20
+ if row['AddressLine2'].match?(/[[:graph:]]/)
21
+ lines << row['AddressLine2']
19
22
  end
20
23
 
21
24
  next if lines.empty?
22
25
 
23
- city = data["AltMailing#{n}City"]
24
- state = data["AltMailing#{n}State"]
25
- zip = data["AltMailing#{n}Zip"]
26
-
27
- lines << "#{city}, #{state} #{zip}".strip
26
+ lines << "#{row['City']}, #{row['State']} #{row['Zip']}"
28
27
 
29
- lines.join("\n")
28
+ lines.map(&:strip).join("\n")
30
29
  end.compact
31
30
  end
32
31
 
@@ -47,25 +46,33 @@ module TopsConnect
47
46
  end
48
47
 
49
48
  def home_phone
50
- data['PhoneHome']
49
+ phone = data['Phones'].find { |row| row['Type']['Name'] == 'Home' }
50
+
51
+ phone['PhoneNumber'] if phone
51
52
  end
52
53
 
53
54
  def alternate_phone
54
- data['PhoneAlt']
55
+ phone = data['Phones'].find { |row| row['Type']['Name'] == 'Alternate' }
56
+
57
+ phone['PhoneNumber'] if phone
55
58
  end
56
59
 
57
60
  def fax
58
- data['PhoneFax']
61
+ phone = data['Phones'].find { |row| row['Type']['Name'] == 'Fax' }
62
+
63
+ phone['PhoneNumber'] if phone
59
64
  end
60
65
 
61
66
  def work_phone
62
- data['PhoneWork']
67
+ phone = data['Phones'].find { |row| row['Type']['Name'] == 'Work' }
68
+
69
+ phone['PhoneNumber'] if phone
63
70
  end
64
71
 
65
72
  def updated_at
66
73
  return unless data['Metadata']['ModifiedDate']
67
74
 
68
- DateTime.parse data['Metadata']['ModifiedDate']
75
+ Time.parse data['Metadata']['ModifiedDate']
69
76
  end
70
77
 
71
78
  def owner?
@@ -79,19 +86,23 @@ module TopsConnect
79
86
  def move_out_date
80
87
  return unless data['MoveOutDate']
81
88
 
82
- DateTime.parse data['MoveOutDate']
89
+ Time.parse data['MoveOutDate']
83
90
  end
84
91
 
85
92
  def settlement_date
86
93
  return unless data['SettlementDate']
87
94
 
88
- DateTime.parse data['SettlementDate']
95
+ Time.parse data['SettlementDate']
89
96
  end
90
97
 
91
98
  def hold_payment?
92
99
  data['Metadata']['HoldPayment']
93
100
  end
94
101
 
102
+ def hold_collection?
103
+ data['Metadata']['HoldCollection']
104
+ end
105
+
95
106
  # The internal key used by Tops Pro - property number, homeowner type,
96
107
  # owner number in the format PPPPPPTOOO.
97
108
  def tops_id
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  module Owners
4
5
  # Method: GET
@@ -24,7 +25,7 @@ module TopsConnect
24
25
  # Endpoint: Balance_Get
25
26
  # Returns: Hash
26
27
  def balance(owner_key)
27
- get "/balance/#{owner_key}"
28
+ get "/owner/#{owner_key}/balance"
28
29
  end
29
30
 
30
31
  # Method: GET
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  module Properties
4
5
  # Method: GET
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
4
  class Property < Base
4
5
  def property_key
5
- data['PropertyKey']
6
+ data['Key']
6
7
  end
7
8
  alias id property_key
8
9
 
@@ -11,42 +12,30 @@ module TopsConnect
11
12
  end
12
13
 
13
14
  def address
14
- ["#{address_number} #{street}", unit_number].compact.join(' #')
15
- end
16
-
17
- def city
18
- data['City']
19
- end
20
-
21
- def state
22
- data['State']
23
- end
15
+ property = data['Addresses']
16
+ .find { |row| row['Type']['Name'] == 'Property' }
24
17
 
25
- def address_number
26
- data['AddressNumber']
27
- end
28
-
29
- def unit_number
30
- data['AptNumber'] unless data['AptNumber'].blank?
31
- end
32
-
33
- def street
34
- data['Street']
35
- end
18
+ lines = [
19
+ property['AddressLine1'],
20
+ property['AddressLine2'],
21
+ "#{property['City']}, #{property['State']} #{property['Zip']}"
22
+ ]
36
23
 
37
- def zip
38
- data['Zip']
24
+ lines
25
+ .map(&:strip)
26
+ .select { |line| line.match?(/[[:graph:]]/) }
27
+ .join("\n")
39
28
  end
40
29
 
41
30
  def community_key
42
31
  data['CommunityKey']
43
32
  end
44
33
 
45
- def updated_at
34
+ def modified_date
46
35
  return unless data['Metadata']['ModifiedDate']
47
36
 
48
- DateTime.parse data['Metadata']['ModifiedDate']
37
+ Time.parse data['Metadata']['ModifiedDate']
49
38
  end
50
- alias modified_date updated_at
39
+ alias updated_at modified_date
51
40
  end
52
41
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module TopsConnect
3
- VERSION = '0.4.3.2'
4
+ VERSION = '0.5.0'
4
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tops_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Hoffman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-16 00:00:00.000000000 Z
11
+ date: 2018-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.6.8
132
+ rubygems_version: 2.7.3
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Make use of the Tops Connect API