tops_connect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef41f896def4a415b9352eac45c108d3df881897
4
+ data.tar.gz: 79e157ba0b46043b4ef3442b0e31367ca1bde6c0
5
+ SHA512:
6
+ metadata.gz: be7a999606f4e2d71483ed54a063cdb6d8c5361d260c81ee7bc42d93f2d4df20f48a225a00a3b579468b89def7a320dbce5804df44486ef2ad55cac95f244dd0
7
+ data.tar.gz: d69fae0bc8c97f2209f0e47f4e3761d4d68759d42c124757970a95c60cf02bcc1317b31df8315b2e005b6159000dcf545c79e93dafce064772ffd0cd0808449d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ Include:
3
+ - Gemfile
4
+ - Rakefile
5
+ TargetRubyVersion: 2.3
6
+
7
+ Metrics/AbcSize:
8
+ Enabled: false
9
+
10
+ Metrics/CyclomaticComplexity:
11
+ Enabled: false
12
+
13
+ Metrics/MethodLength:
14
+ Max: 32
15
+
16
+ Metrics/PerceivedComplexity:
17
+ Enabled: false
18
+
19
+ Style/Documentation:
20
+ Enabled: false
21
+
22
+ Style/MultilineMethodCallIndentation:
23
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in tops_connect.gemspec
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Steven Hoffman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # TopsConnect
2
+
3
+ TopsConnect is a Ruby gem for accessing the Tops Connect API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tops_connect'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tops_connect
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ TopsConnect.configure do |config|
25
+ config.subscription_key = '0123456789abcdef0123456789abcdef'
26
+ config.client_id = '00000000-1111-2222-3333-444444444444'
27
+ config.software_key = '55555555-6666-7777-8888-999999999999'
28
+ config.community_api_key = 'AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE'
29
+ config.zone = :broad
30
+ end
31
+
32
+ tops = TopsConnect::Client.new
33
+
34
+ tops.communities.each do |community|
35
+ puts community['Name']
36
+ end
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ValenciaMgmt/tops_connect.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ require 'rspec/core/rake_task'
3
+ require 'bundler/gem_tasks'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'tops_connect'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'base64'
3
+ require 'httparty'
4
+ require 'json'
5
+
6
+ require 'tops_connect/communities'
7
+ require 'tops_connect/owners'
8
+
9
+ require 'tops_connect/configuration'
10
+ require 'tops_connect/client'
11
+ require 'tops_connect/version'
12
+
13
+ module TopsConnect
14
+ class << self
15
+ attr_accessor :configuration
16
+
17
+ def configure
18
+ self.configuration ||= Configuration.new
19
+
20
+ yield(configuration) if block_given?
21
+
22
+ configuration
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+ module TopsConnect
3
+ class Client
4
+ include HTTParty
5
+ include TopsConnect::Communities
6
+ include TopsConnect::Owners
7
+
8
+ headers 'Content-Type' => 'application/json'
9
+ headers 'api-version' => '1'
10
+
11
+ base_uri 'https://topsconnectapi.azure-api.net'
12
+
13
+ def initialize
14
+ authorization = Base64.encode64 [
15
+ TopsConnect.configuration.client_id,
16
+ TopsConnect.configuration.software_key
17
+ ].join(':')
18
+
19
+ self.class.headers(
20
+ 'authorization' => "Basic #{authorization}",
21
+ 'community-api-key' => TopsConnect.configuration.community_api_key
22
+ )
23
+
24
+ @subscription_key = TopsConnect.configuration.subscription_key
25
+ end
26
+
27
+ def get(endpoint, parameters = {})
28
+ response = self.class.get(
29
+ "/#{TopsConnect.configuration.zone}/api#{endpoint}",
30
+ query: parameters.merge('subscription-key' => @subscription_key)
31
+ )
32
+
33
+ case response.code
34
+ when 200
35
+ response.parsed_response
36
+ when 400
37
+ raise BadRequest, response.parsed_response['Message']
38
+ else
39
+ raise "#{response.code}: #{response.parsed_response['Message']}"
40
+ end
41
+ end
42
+
43
+ class BadRequest < Exception
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ module TopsConnect
3
+ module Communities
4
+ # Method: GET
5
+ # Endpoint: Community_GetList
6
+ def communities
7
+ get '/community'
8
+ end
9
+
10
+ # Method: GET
11
+ # Endpoint: Community_Get
12
+ def community(community_id)
13
+ get "/community/#{community_id.to_i}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ module TopsConnect
3
+ class Configuration
4
+ attr_reader :subscription_key, :client_id, :software_key,
5
+ :community_api_key, :zone
6
+
7
+ def initialize
8
+ end
9
+
10
+ def subscription_key=(key)
11
+ unless key =~ /\A\h{32}\z/i
12
+ raise 'Invalid TOPS Subscription Key. Expected 32 hex characters.'
13
+ end
14
+
15
+ @subscription_key = key.downcase
16
+ end
17
+
18
+ def client_id=(key)
19
+ unless key =~ /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
20
+ raise 'Invalid TOPS Client ID. Expected a GUID.'
21
+ end
22
+
23
+ @client_id = key.upcase
24
+ end
25
+
26
+ def software_key=(key)
27
+ unless key =~ /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
28
+ raise 'Invalid TOPS Software Key. Expected a GUID.'
29
+ end
30
+
31
+ @software_key = key.upcase
32
+ end
33
+
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
+ def zone=(new_zone)
43
+ unless %i(broad limited sandbox).include?(new_zone)
44
+ raise 'Invalid TOPS Zone. Accepted values are broad, limited, sandbox.'
45
+ end
46
+
47
+ @zone = new_zone
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module TopsConnect
3
+ module Owners
4
+ # Method: GET
5
+ # Endpoint: Owner_Get
6
+ def owner(owner_id)
7
+ get "/owner/#{owner_id.to_i}"
8
+ end
9
+
10
+ # Method: GET
11
+ # Endpoint: Owner_GetList
12
+ def owners(property_id = nil)
13
+ parameters = {}
14
+ parameters['PropertyKey'] = property_id.to_i if property_id
15
+
16
+ get '/owner', parameters
17
+ end
18
+
19
+ # Method: GET
20
+ # Endpoint: Balance_Get
21
+ def balance(owner_id)
22
+ get "/balance/#{owner_id.to_i}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module TopsConnect
3
+ VERSION = '0.1.0'
4
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'tops_connect/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'tops_connect'
9
+ spec.version = TopsConnect::VERSION
10
+ spec.authors = ['Steven Hoffman']
11
+ spec.email = ['shoffman@valenciamgmt.com']
12
+
13
+ spec.summary = 'Make use of the Tops Connect API'
14
+ spec.homepage = 'https://github.com/ValenciaMgmt/tops_connect'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ .reject { |f| f.match(%r{^spec/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
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'
27
+
28
+ spec.add_dependency 'httparty', '~> 0.13'
29
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tops_connect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steven Hoffman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
83
+ description:
84
+ email:
85
+ - shoffman@valenciamgmt.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/tops_connect.rb
100
+ - lib/tops_connect/client.rb
101
+ - lib/tops_connect/communities.rb
102
+ - lib/tops_connect/configuration.rb
103
+ - lib/tops_connect/owners.rb
104
+ - lib/tops_connect/version.rb
105
+ - tops_connect.gemspec
106
+ homepage: https://github.com/ValenciaMgmt/tops_connect
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Make use of the Tops Connect API
130
+ test_files: []