tops_connect 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88806cf795346b8b63cbf0ea928fed4f6605b5df
4
- data.tar.gz: 1dc68fd22180ba05ec4b12ddabe2d480149fd8ae
3
+ metadata.gz: 5867e71a798feb5d737263d749fb3b4dd009a19f
4
+ data.tar.gz: b5510fb2c07a486eac402485f78fdbba12f02134
5
5
  SHA512:
6
- metadata.gz: e46fe7e62ec1b245523965b72f1d87ad8f4e8b72e9fbc9843b649b4bf84ed4d017734d825cf7429801f2144f0a0a94272d4b0552aef04f1541de52d28c7553dd
7
- data.tar.gz: 56e3910e297e441ecf19430ad9c35a364f546e32afdf6e04628c46de0204c9fd46c3a4d6528fbff0e2d5474974b68520d36ebff6da85d1806238c6da94abd32f
6
+ metadata.gz: 80f5fb0f17b286f461ad626600ad4555693955a6b2dd7b1d3c30ab728766ac2c005c86a5335f2c86f068b5bed496c96d22c29c345101ffc8b1adb8bb70ecd589
7
+ data.tar.gz: 1a57806bd996195daba9aa889c64644558c949f53283f167b21135928d5375c9c4b20edae8a529ea63d2eb6d8c559ee93b2157ec69a217279ba20daa0a966cd5
data/README.md CHANGED
@@ -25,15 +25,12 @@ TopsConnect.configure do |config|
25
25
  config.subscription_key = '0123456789abcdef0123456789abcdef'
26
26
  config.client_id = '00000000-1111-2222-3333-444444444444'
27
27
  config.software_key = '55555555-6666-7777-8888-999999999999'
28
- config.community_api_key = 'AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE'
29
28
  config.zone = :broad
30
29
  end
31
30
 
32
- tops = TopsConnect::Client.new
31
+ tops = TopsConnect::Client.new(6, 'AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE')
33
32
 
34
- tops.communities.each do |community|
35
- puts community['Name']
36
- end
33
+ puts "Loaded #{tops.community.name}"
37
34
  ```
38
35
 
39
36
  ## Development
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  module TopsConnect
3
3
  class Base
4
- class << self
5
- attr_accessor :client
4
+ def initialize(client)
5
+ @client = client
6
6
  end
7
7
 
8
8
  def get(*args)
9
- TopsConnect::Base.client.get(*args)
9
+ @client.get(*args)
10
10
  end
11
11
  end
12
12
  end
@@ -5,31 +5,31 @@ module TopsConnect
5
5
  include TopsConnect::Communities
6
6
  include TopsConnect::Owners
7
7
 
8
+ attr_reader :community_id, :community_api_key
9
+
8
10
  headers 'Content-Type' => 'application/json'
9
11
  headers 'api-version' => '1'
10
12
 
11
13
  base_uri 'https://topsconnectapi.azure-api.net'
12
14
 
13
- def initialize
15
+ def initialize(community_id, community_api_key)
14
16
  authorization = Base64.strict_encode64 [
15
17
  TopsConnect.configuration.client_id,
16
18
  TopsConnect.configuration.software_key
17
19
  ].join(':')
18
20
 
19
- self.class.headers(
20
- 'authorization' => "Basic #{authorization}",
21
- 'community-api-key' => TopsConnect.configuration.community_api_key
22
- )
21
+ self.class.headers('authorization' => "Basic #{authorization}")
23
22
 
24
23
  @subscription_key = TopsConnect.configuration.subscription_key
25
-
26
- TopsConnect::Base.client = self
24
+ @community_id = community_id
25
+ @community_api_key = community_api_key
27
26
  end
28
27
 
29
- def get(endpoint, parameters = {})
28
+ def get(endpoint, headers: {}, query: {})
30
29
  response = self.class.get(
31
30
  "/#{TopsConnect.configuration.zone}/api#{endpoint}",
32
- query: parameters.merge('subscription-key' => @subscription_key)
31
+ query: query.merge('subscription-key' => @subscription_key),
32
+ headers: headers.merge('community-api-key' => @community_api_key)
33
33
  )
34
34
 
35
35
  case response.code
@@ -3,16 +3,16 @@ module TopsConnect
3
3
  module Communities
4
4
  # Method: GET
5
5
  # Endpoint: Community_GetList
6
+ # Returns: Array<Hash>
6
7
  def communities
7
- get('/community').map do |community|
8
- TopsConnect::Community.new community['CommunityKey'], community
9
- end
8
+ get('/community')
10
9
  end
11
10
 
12
11
  # Method: GET
13
12
  # Endpoint: Community_Get
14
- def community(community_id)
15
- TopsConnect::Community.new community_id
13
+ # Returns: TopsConnect::Community
14
+ def community
15
+ TopsConnect::Community.new self
16
16
  end
17
17
  end
18
18
  end
@@ -3,9 +3,10 @@ module TopsConnect
3
3
  class Community < Base
4
4
  attr_reader :id
5
5
 
6
- def initialize(id, data = nil)
7
- @id = id.to_i
6
+ def initialize(client, data = nil)
8
7
  @data = data
8
+
9
+ super client
9
10
  end
10
11
 
11
12
  def data
@@ -13,7 +14,7 @@ module TopsConnect
13
14
  end
14
15
 
15
16
  def reload!
16
- @data = get "/community/#{@id}"
17
+ @data = get "/community/#{@client.community_id}"
17
18
  end
18
19
 
19
20
  def code
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module TopsConnect
3
3
  class Configuration
4
- attr_reader :subscription_key, :client_id, :software_key,
5
- :community_api_key, :zone
4
+ attr_reader :subscription_key, :client_id, :software_key, :zone
6
5
 
7
6
  def initialize
8
7
  end
@@ -31,14 +30,6 @@ module TopsConnect
31
30
  @software_key = key.upcase
32
31
  end
33
32
 
34
- def community_api_key=(key)
35
- unless key =~ /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
36
- raise 'Invalid TOPS Community API Key. Expected a GUID.'
37
- end
38
-
39
- @community_api_key = key.upcase
40
- end
41
-
42
33
  def zone=(new_zone)
43
34
  unless %i(broad limited sandbox).include?(new_zone.to_sym)
44
35
  raise 'Invalid TOPS Zone. Accepted values are broad, limited, sandbox.'
@@ -3,9 +3,11 @@ module TopsConnect
3
3
  class Owner < Base
4
4
  attr_reader :id
5
5
 
6
- def initialize(id, data = nil)
6
+ def initialize(client, id, data = nil)
7
7
  @id = id.to_i
8
8
  @data = data
9
+
10
+ super client
9
11
  end
10
12
 
11
13
  def data
@@ -4,17 +4,17 @@ module TopsConnect
4
4
  # Method: GET
5
5
  # Endpoint: Owner_Get
6
6
  def owner(owner_id)
7
- TopsConnect::Owner.new owner_id
7
+ TopsConnect::Owner.new self, owner_id, get("/owner/#{owner_id}")
8
8
  end
9
9
 
10
10
  # Method: GET
11
11
  # Endpoint: Owner_GetList
12
12
  def owners(property_id = nil)
13
- parameters = {}
14
- parameters['PropertyKey'] = property_id.to_i if property_id
13
+ query = {}
14
+ query['PropertyKey'] = property_id.to_i if property_id
15
15
 
16
- get('/owner', parameters).map do |owner|
17
- TopsConnect::Owner.new owner['OwnerKey'], owner
16
+ get('/owner', query: query).map do |owner|
17
+ TopsConnect::Owner.new self, owner['OwnerKey'], owner
18
18
  end
19
19
  end
20
20
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TopsConnect
3
- VERSION = '0.1.4'
3
+ VERSION = '0.2.0'
4
4
  end
data/tops_connect.gemspec CHANGED
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.10'
24
- spec.add_development_dependency 'rake', '>= 10'
25
- spec.add_development_dependency 'rspec'
26
- spec.add_development_dependency 'webmock'
24
+ spec.add_development_dependency 'rake', '~> 10'
25
+ spec.add_development_dependency 'rspec', '~> 3.4'
26
+ spec.add_development_dependency 'webmock', '~> 2.0'
27
27
 
28
28
  spec.add_dependency 'httparty', '~> 0.13'
29
29
  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.1.4
4
+ version: 0.2.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: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,44 +28,44 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httparty
71
71
  requirement: !ruby/object:Gem::Requirement