trimark 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: e7a54e44b8d0221102a90d6484051c065d40868a
4
+ data.tar.gz: 51a592c1ca165729ca629ba011a0023d4c69ab08
5
+ SHA512:
6
+ metadata.gz: 6547b8e345b174a250323ab6cb70b3f810199287d79b8062fd7480d003a152522f30e334fd5730c4784de49c862aff84f57c9d5b4ed3b48a0450b9748eba81e3
7
+ data.tar.gz: 62cac6de132fd9a9f63f52e60efe64e95afbe4826f328ba195d61dfd1327186ee550d6ecdf1945075c7899e0693c09b5f5292be27eac7e2d0fd019f41c98c7c0
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ *.here
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trimark.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ trimark (0.1.0)
5
+ faraday
6
+ json
7
+ virtus
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.3.8)
13
+ ansi (1.5.0)
14
+ axiom-types (0.1.1)
15
+ descendants_tracker (~> 0.0.4)
16
+ ice_nine (~> 0.11.0)
17
+ thread_safe (~> 0.3, >= 0.3.1)
18
+ builder (3.2.2)
19
+ coderay (1.1.0)
20
+ coercible (1.0.0)
21
+ descendants_tracker (~> 0.0.1)
22
+ crack (0.4.2)
23
+ safe_yaml (~> 1.0.0)
24
+ descendants_tracker (0.0.4)
25
+ thread_safe (~> 0.3, >= 0.3.1)
26
+ equalizer (0.0.11)
27
+ faraday (0.9.2)
28
+ multipart-post (>= 1.2, < 3)
29
+ ice_nine (0.11.1)
30
+ json (1.8.3)
31
+ method_source (0.8.2)
32
+ minitest (5.8.1)
33
+ minitest-reporters (1.1.2)
34
+ ansi
35
+ builder
36
+ minitest (>= 5.0)
37
+ ruby-progressbar
38
+ multipart-post (2.0.0)
39
+ pry (0.10.2)
40
+ coderay (~> 1.1.0)
41
+ method_source (~> 0.8.1)
42
+ slop (~> 3.4)
43
+ rake (10.4.2)
44
+ ruby-progressbar (1.7.5)
45
+ safe_yaml (1.0.4)
46
+ slop (3.6.0)
47
+ thread_safe (0.3.5)
48
+ virtus (1.0.5)
49
+ axiom-types (~> 0.1)
50
+ coercible (~> 1.0)
51
+ descendants_tracker (~> 0.0, >= 0.0.3)
52
+ equalizer (~> 0.0, >= 0.0.9)
53
+ webmock (1.21.0)
54
+ addressable (>= 2.3.6)
55
+ crack (>= 0.3.2)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler (~> 1.10)
62
+ minitest
63
+ minitest-reporters
64
+ pry
65
+ rake (~> 10.0)
66
+ trimark!
67
+ webmock
68
+
69
+ BUNDLED WITH
70
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Edit LLC
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,31 @@
1
+ # TriMark
2
+
3
+ This is a Ruby wrapper for the TriMark JSON API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'trimark'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install trimark
20
+
21
+ ## Usage
22
+
23
+ TBD
24
+
25
+ ## Development
26
+
27
+ TBD
28
+
29
+ ## Contributing
30
+
31
+ TBD
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :console do
11
+ exec 'pry -r trimark -I ./lib'
12
+ end
13
+
14
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trimark"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ require "irb"
14
+ 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,6 @@
1
+ require 'virtus'
2
+ require "trimark/version"
3
+ require "trimark/client"
4
+
5
+ module Trimark
6
+ end
@@ -0,0 +1,83 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'securerandom'
4
+ require 'trimark/connection'
5
+ require 'trimark/site'
6
+ require 'addressable/template'
7
+
8
+ module TriMark
9
+ class AuthError < StandardError; end
10
+ class QueryError < StandardError; end
11
+
12
+ class Client
13
+ include APIConnection
14
+ attr_accessor :username, :password, :device_token, :access_token, :company_id
15
+
16
+ def initialize
17
+ yield(self) if block_given?
18
+ @device_token = SecureRandom.uuid
19
+ end
20
+
21
+ def login_message
22
+ {
23
+ Username: username,
24
+ Password: password,
25
+ DeviceToken: device_token,
26
+ DeviceId: '',
27
+ DeviceType: 'Other'
28
+ }
29
+ end
30
+
31
+ def login_header
32
+ { 'Content-Type' => 'application/json' }
33
+ end
34
+
35
+ def login
36
+ response = JSON.parse((conn.post 'login', login_message.to_json, login_header).body)
37
+ if response['AccessToken'].nil?
38
+ fail AuthError, "Login Failed! #{response['Message']}"
39
+ else
40
+ self.access_token = response['AccessToken']
41
+ end
42
+ end
43
+
44
+ def site_info_url(site_id)
45
+ "company/#{company_id}/site/#{site_id}"
46
+ end
47
+
48
+ def site_history_url(site_id, query_hash)
49
+ Addressable::Template.new(
50
+ "company/#{company_id}/site/#{site_id}/history/{?query*}"
51
+ ).expand(query_hash)
52
+ end
53
+
54
+ def url_picker(*args)
55
+ if args.length <= 2
56
+ args.length == 2 ? site_history_url(*args) : site_info_url(*args)
57
+ else
58
+ fail QueryError, "#{args.length} Arguments Entered! Max 2"
59
+ end
60
+ end
61
+
62
+ def query_headers
63
+ fail QueryError, 'Login to set access token!' if access_token.nil?
64
+ {
65
+ 'Content-Type' => 'application/json',
66
+ 'access_token' => access_token,
67
+ 'device_token' => device_token
68
+ }
69
+ end
70
+
71
+ # Returns site attributes and history data if an optional query_hash is supplied
72
+ # @client.site_query(x) will return the attributes of site x
73
+ # @client.site_query(x, query_hash) will return historical data from site x instrumentation
74
+ def site_query(*args)
75
+ response = (conn.get url_picker(*args), {}, query_headers)
76
+ if response.body['SiteId'] || response.body['PointId']
77
+ return JSON.parse(response.body)
78
+ else
79
+ fail QueryError, "Query Failed! HTTPStatus: #{response.status}"
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ module APIConnection
2
+ def conn
3
+ @connection = Faraday.new(url: 'https://vantage.trimarkassoc.com/api/')
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ module TriMark
2
+ class AuthError < StandardError; end
3
+ class QueryError < StandardError; end
4
+
5
+ class Site
6
+ include APIConnection
7
+ include Virtus.model
8
+
9
+ attribute :site_id, Integer
10
+ attribute :name, String
11
+ attribute :site_type, String
12
+ attribute :longitude, Float
13
+ attribute :latitude, Float
14
+ attribute :status_raw_value, Integer
15
+ attribute :status, String
16
+ attribute :status_type, String
17
+ attribute :is_available, Boolean
18
+ attribute :location, String
19
+
20
+ def initialize(params = {})
21
+ super(params)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Trimark
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trimark/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trimark"
8
+ spec.version = Trimark::VERSION
9
+ spec.authors = ["Tyler Whitsett"]
10
+ spec.email = ["whitsett.tyler@gmail.com"]
11
+
12
+ spec.summary = %q{A Ruby wrapper for the TriMark JSON API}
13
+ spec.description = %q{Eventually}
14
+ spec.homepage = "https://github.com/EditLLC/trimark-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "minitest-reporters"
26
+ spec.add_development_dependency "webmock"
27
+
28
+ spec.add_runtime_dependency 'faraday'
29
+ spec.add_runtime_dependency 'json'
30
+ spec.add_runtime_dependency 'virtus'
31
+ spec.add_runtime_dependency 'addressable'
32
+
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trimark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Whitsett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-19 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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
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: minitest-reporters
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: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: virtus
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: addressable
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Eventually
140
+ email:
141
+ - whitsett.tyler@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - CODE_OF_CONDUCT.md
148
+ - Gemfile
149
+ - Gemfile.lock
150
+ - LICENSE
151
+ - README.md
152
+ - Rakefile
153
+ - bin/console
154
+ - bin/setup
155
+ - lib/trimark.rb
156
+ - lib/trimark/client.rb
157
+ - lib/trimark/connection.rb
158
+ - lib/trimark/site.rb
159
+ - lib/trimark/version.rb
160
+ - trimark.gemspec
161
+ homepage: https://github.com/EditLLC/trimark-ruby
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.4.5
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: A Ruby wrapper for the TriMark JSON API
185
+ test_files: []