TACore 4.0.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 +7 -0
- data/lib/exceptions.rb +9 -0
- data/lib/tacore.rb +142 -0
- data/lib/tacore/app.rb +19 -0
- data/lib/tacore/client.rb +47 -0
- data/lib/tacore/device.rb +47 -0
- data/lib/tacore/gateway.rb +42 -0
- data/lib/tacore/venue.rb +51 -0
- metadata +80 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0ec21334daa177ad0be7d4b05f11c57f5f3a91a2
|
|
4
|
+
data.tar.gz: b2c0e09008db885a7c5c468cc4c3638be6e73eaa
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9b26c61ba13a59bf68aa2cffb50e5930dd015b58e5d3ba9adaa974608c352dfd73725c8efb39b590978c1cdac6e568a8fbcf42c801c4ae590d3506c96a1910f1
|
|
7
|
+
data.tar.gz: 694abc8c10680189bf8485b2dffa26f9508cdd1c6d75a202641cdeda676c3e126b395c1d20481d2b163ba7c115f6290db46c24e9151ab2d770b349103aeb2906
|
data/lib/exceptions.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module TACore
|
|
2
|
+
class AuthenticationError < StandardError; end
|
|
3
|
+
|
|
4
|
+
# => TokenError is presented when the access token is no longer valid or there was a communication issue.
|
|
5
|
+
# Error, Token expired or external API is not responding.
|
|
6
|
+
class TokenError < AuthenticationError; end
|
|
7
|
+
|
|
8
|
+
class NotThereError < StandardError; end
|
|
9
|
+
end
|
data/lib/tacore.rb
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# THINAER Core API GEM
|
|
2
|
+
#
|
|
3
|
+
# Author:: Greg Winn (greg.winn@thinaer.io)
|
|
4
|
+
# Copyright:: Copyright (c) 2016 Advantix ThinAer, LLC
|
|
5
|
+
# License:: NONE
|
|
6
|
+
|
|
7
|
+
require 'rest-client'
|
|
8
|
+
require 'exceptions'
|
|
9
|
+
require 'net/http'
|
|
10
|
+
require 'uri'
|
|
11
|
+
require 'json'
|
|
12
|
+
|
|
13
|
+
# This module holds every public class and method need to
|
|
14
|
+
# to authenticate and configure the TACore GEM
|
|
15
|
+
module TACore
|
|
16
|
+
|
|
17
|
+
# Configuration of the config params set in an init file.
|
|
18
|
+
class Configuration
|
|
19
|
+
attr_accessor :api_url
|
|
20
|
+
attr_accessor :client_id
|
|
21
|
+
attr_accessor :client_secret
|
|
22
|
+
attr_accessor :api_key
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
25
|
+
self.api_url = nil
|
|
26
|
+
self.client_id = nil
|
|
27
|
+
self.client_secret = nil
|
|
28
|
+
self.api_key = nil
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.configuration
|
|
33
|
+
@configuration ||= Configuration.new
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.configure
|
|
37
|
+
yield(configuration) if block_given?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class << self
|
|
41
|
+
attr_accessor :api_url
|
|
42
|
+
attr_accessor :client_id
|
|
43
|
+
attr_accessor :client_secret
|
|
44
|
+
attr_accessor :api_key
|
|
45
|
+
def api_key
|
|
46
|
+
raise "api_key is needed to connect" unless @api_key
|
|
47
|
+
@api_key
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def api_url
|
|
51
|
+
raise "api_url is needed to connect" unless @api_url
|
|
52
|
+
@api_url
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def client_id
|
|
56
|
+
raise "client_id is needed to connect" unless @client_id
|
|
57
|
+
@client_id
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def client_secret
|
|
61
|
+
raise "client_secret is needed to connect" unless @client_secret
|
|
62
|
+
@client_secret
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Authorization class that will create the client token and authenticate with the API
|
|
67
|
+
class Auth < Configuration
|
|
68
|
+
attr_accessor :token
|
|
69
|
+
attr_accessor :client
|
|
70
|
+
|
|
71
|
+
# Used to retrieve the TOKEN and Authenticate the application
|
|
72
|
+
def self.login
|
|
73
|
+
|
|
74
|
+
# use rest-client for auth post to get token
|
|
75
|
+
@@token = RestClient::Request.execute(method: :post, url: TACore.configuration.api_url + "/application/token",
|
|
76
|
+
headers: {
|
|
77
|
+
"uid": TACore.configuration.client_id,
|
|
78
|
+
"secret": TACore.configuration.client_secret,
|
|
79
|
+
"x-api-key": TACore.configuration.api_key
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
if JSON.parse(@@token).include? "error"
|
|
84
|
+
# The responce included an error, stop and show it!
|
|
85
|
+
raise JSON.parse(@@token)["error"]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
if @@token.nil?
|
|
89
|
+
raise "Authentication Failed"
|
|
90
|
+
end
|
|
91
|
+
JSON.parse(@@token)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Internal request only.
|
|
95
|
+
# Request method
|
|
96
|
+
# @param method [Symbol<:get, :post, :put, :delete>]
|
|
97
|
+
# @param uri [String]
|
|
98
|
+
# @param payload [Hash] Changes to document object (optional)
|
|
99
|
+
# @param headers [Hash] token, client_id,...
|
|
100
|
+
def self.request(method, uri, payload, headers)
|
|
101
|
+
|
|
102
|
+
# Add static API-KEY to headers from config
|
|
103
|
+
headers["x-api-key"] = TACore.configuration.api_key
|
|
104
|
+
|
|
105
|
+
begin
|
|
106
|
+
response = RestClient::Request.execute(method: method, url: TACore.configuration.api_url + uri, payload: payload, headers: headers)
|
|
107
|
+
case response.code
|
|
108
|
+
when 200
|
|
109
|
+
JSON.parse(response.body)
|
|
110
|
+
else
|
|
111
|
+
return { "error": { "code": response.code, "body": JSON.parse(response.body) }}
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Rest Client exceptions
|
|
115
|
+
rescue RestClient::ExceptionWithResponse => e
|
|
116
|
+
# Raise TokenError on all other exceptions
|
|
117
|
+
raise TACore::TokenError.new "#{e.message}"
|
|
118
|
+
|
|
119
|
+
# Rescue for unauthorized/token expired
|
|
120
|
+
rescue AuthenticationError
|
|
121
|
+
self.login
|
|
122
|
+
# Rescue from rest-client exception due to 410 status from deleted objects
|
|
123
|
+
rescue NotThereError
|
|
124
|
+
{deleted: true}
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
require 'tacore/client'
|
|
131
|
+
require 'tacore/venue'
|
|
132
|
+
require 'tacore/device'
|
|
133
|
+
require 'tacore/gateway'
|
|
134
|
+
require 'tacore/app'
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class Test < Auth
|
|
138
|
+
def initialize
|
|
139
|
+
puts "This is a test of the TACore GEM"
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
data/lib/tacore/app.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module TACore
|
|
2
|
+
# => Application class methods
|
|
3
|
+
class App < Auth
|
|
4
|
+
# Get details on a specific application by token
|
|
5
|
+
# @param token [String] Application Token after Authentication
|
|
6
|
+
# @return [Object] in JSON format
|
|
7
|
+
def self.find(token)
|
|
8
|
+
request(:get, '/application/',{}, {"token": token})
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Get Details on all Applications
|
|
12
|
+
# @param token [String] Application Token after Authentication
|
|
13
|
+
# @return [Object] in JSON format
|
|
14
|
+
def self.all(token)
|
|
15
|
+
request(:get, '/application/all', {}, {"token": token})
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module TACore
|
|
2
|
+
# => Client Class methods.
|
|
3
|
+
# Clients are companies, or groups of users that have access to the same data. When making requests it is important to keep the client api_key
|
|
4
|
+
class Client < Auth
|
|
5
|
+
# Get all Clients that belong to this application
|
|
6
|
+
# @param token [String] Client Token after Authentication
|
|
7
|
+
# @return [Array] in JSON format
|
|
8
|
+
def self.all(token)
|
|
9
|
+
response = request(:get, '/application',{}, {"token": token})
|
|
10
|
+
return response["clients"]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Allows an application to add a Client
|
|
14
|
+
# @param token [String] Client Token after Authentication
|
|
15
|
+
# @param client [Object]
|
|
16
|
+
# @return [Object] in JSON format - the new client
|
|
17
|
+
# @note The new Client will be owned by the application creating it.
|
|
18
|
+
def self.create(token, client = {})
|
|
19
|
+
request(:post, '/client', client, {"token": token})
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Get details on a specific client by client_id
|
|
23
|
+
# @param token [String] Client Token after Authentication
|
|
24
|
+
# @param client_id [String] used from {Client.create}
|
|
25
|
+
# @return [Object] in JSON format
|
|
26
|
+
def self.find(token, client_id)
|
|
27
|
+
request(:get, '/client/',{}, {"token": token, "client-id" => client_id})
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Update a client details via api_key
|
|
31
|
+
# @param token [String] Client Token after Authentication
|
|
32
|
+
# @param client_id [String] used from {Client.create}
|
|
33
|
+
# @param client [Object] Client params
|
|
34
|
+
# @return [Object] in JSON format
|
|
35
|
+
# @note The `client` object currently only supports `name`
|
|
36
|
+
def self.update(token, client_id, client = {})
|
|
37
|
+
request(:put, '/client/', client, {"token": token, "client-id" => client_id})
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Delete a client by id
|
|
41
|
+
# @param token [String] Client Token after Authentication
|
|
42
|
+
# @param client_id [String] used from {Client.create}
|
|
43
|
+
def self.destroy(token, client_id)
|
|
44
|
+
request(:delete, '/client/', {"token": token, "client-id" => client_id})
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module TACore
|
|
2
|
+
# => Device class methods
|
|
3
|
+
class Device < Auth
|
|
4
|
+
|
|
5
|
+
# Update a device's venue_id
|
|
6
|
+
# @param token [String] Client Token after Authentication
|
|
7
|
+
# @param client_id [String] used from {Client.create}
|
|
8
|
+
# @param id [Integer] Device ID
|
|
9
|
+
# @param device [Object] Venue ID as a value
|
|
10
|
+
# @return [Object] in JSON format
|
|
11
|
+
def self.update(token, client_id, device_id, device = {})
|
|
12
|
+
request(:put, '/device/' + device_id.to_s, device, {"client-id" => client_id, "token": token})
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Find device by device_id
|
|
16
|
+
# @param token [String] Client Token after Authentication
|
|
17
|
+
# @param client_id [String] used from {Client.create}
|
|
18
|
+
# @param device_id [Integer] Device ID
|
|
19
|
+
# @return [Object] in JSON format
|
|
20
|
+
def self.find(token, client_id, device_id)
|
|
21
|
+
request(:get, '/device/' + device_id.to_s,{}, {"client-id" => client_id, "token": token})
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Display all devices that belong to this Client
|
|
25
|
+
# @param token [String] Client Token after Authentication
|
|
26
|
+
# @param client_id [String] used from {Client.create}
|
|
27
|
+
# @return [Array<Object, Object>] in JSON format
|
|
28
|
+
def self.all(token, client_id)
|
|
29
|
+
request(:get, '/client/devices/', {}, {"token": token, "client-id" => client_id})
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Display all iris devices that belong to this application
|
|
33
|
+
# @param token [String] Client Token after Authentication
|
|
34
|
+
# @return [Array<Object, Object>] in JSON format
|
|
35
|
+
def self.iris(token)
|
|
36
|
+
request(:get, '/application/iris', {}, {"token": token})
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Display all cirrus devices that belong to this application
|
|
40
|
+
# @param token [String] Client Token after Authentication
|
|
41
|
+
# @return [Array<Object, Object>] in JSON format
|
|
42
|
+
def self.cirrus(token)
|
|
43
|
+
request(:get, '/application/cirrus', {}, {"token": token})
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module TACore
|
|
2
|
+
# => Gateway class methods
|
|
3
|
+
class Gateway < Auth
|
|
4
|
+
|
|
5
|
+
# Get all gateways that belong to a client
|
|
6
|
+
# @param token [String] Client Token after Authentication
|
|
7
|
+
# @param client_id [String] used from {Client.create}
|
|
8
|
+
# @return [Array<Object, Object>] in JSON format
|
|
9
|
+
def self.all(token, client_id)
|
|
10
|
+
request(:get, '/client/gateways/', {}, {token: token, "client-id" => client_id})
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Shows the devices that are seen by the gateway id
|
|
14
|
+
# @param token [String] Client Token after Authentication
|
|
15
|
+
# @param client_id [String] used from {Client.create}
|
|
16
|
+
# @param gateway_id [String] Gateway ID
|
|
17
|
+
# @return [Array<Object, Object>] in JSON format
|
|
18
|
+
def self.sees(token, client_id, gateway_id)
|
|
19
|
+
request(:get, '/gateway/' + gateway_id.to_s + '/sees', {}, {token: token, "client-id" => client_id})
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Gets the Gateway by ID
|
|
23
|
+
# @param token [String] Client Token after Authentication
|
|
24
|
+
# @param client_id [String] used from {Client.create}
|
|
25
|
+
# @param gateway_id [String] Gateway ID
|
|
26
|
+
# @return [Array<Object, Object>] in JSON format
|
|
27
|
+
def self.find(token, client_id, gateway_id)
|
|
28
|
+
request(:get, '/gateway/' + gateway_id.to_s, {}, {token: token, "client-id" => client_id})
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Updates Gateway venue_id
|
|
32
|
+
# @param token [String] Client Token after Authentication
|
|
33
|
+
# @param client_id [String] used from {Client.create}
|
|
34
|
+
# @param gateway_id [String] Gateway ID
|
|
35
|
+
# @param gateway [Object]
|
|
36
|
+
# @return [Array<Object, Object>] in JSON format
|
|
37
|
+
def self.update(token, client_id, gateway_id, gateway = {})
|
|
38
|
+
request(:put, '/gateway/' + gateway_id.to_s, {}, {token: token, "client-id" => client_id})
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/tacore/venue.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module TACore
|
|
2
|
+
# => Venue is used to group devices for Clients, Venue could be a location or an area within a location.
|
|
3
|
+
# It is important to note that all Venue methods require the use a client_id see {Client.create}.
|
|
4
|
+
class Venue < Auth
|
|
5
|
+
# Create a new Venue under a Client.
|
|
6
|
+
# @param token [String] Client Token after Authentication
|
|
7
|
+
# @param client_id [String] used from {Client.create}
|
|
8
|
+
# @param venue [Object] Venue params
|
|
9
|
+
# @note Venue currently only accepts 'name'
|
|
10
|
+
# @return [Object] in JSON format
|
|
11
|
+
def self.create(token, client_id, venue = {})
|
|
12
|
+
request(:post, '/venue', venue, {"client-id" => client_id, "token": token})
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Get back Venue information
|
|
16
|
+
# @param token [String] Client Token after Authentication
|
|
17
|
+
# @param client_id [String] used from {Client.create}
|
|
18
|
+
# @param venue_id [String] used from {Venue.create}
|
|
19
|
+
# @return [Object] in JSON format
|
|
20
|
+
def self.find(token, client_id, venue_id)
|
|
21
|
+
request(:get, '/venue/' + venue_id.to_s,{}, {"client-id" => client_id, "token": token})
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Display all Venues for the client
|
|
25
|
+
# @param token [String] Client Token after Authentication
|
|
26
|
+
# @param client_id [String] used from {Client.create}
|
|
27
|
+
# @return [Array<Object, Object>] in JSON format
|
|
28
|
+
def self.all(token, client_id)
|
|
29
|
+
# returns all venues that belong to this client
|
|
30
|
+
request(:get, '/client/venues', {}, {"token": token, "client-id" => client_id})
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# This method will permanently remove the venue from the API.
|
|
34
|
+
# @param token [String] Client Token after Authentication
|
|
35
|
+
# @param client_id [String] used from {Client.create}
|
|
36
|
+
# @param venue_id [String] the Key of the Venue from {Venue.create}
|
|
37
|
+
# @return [Hash, status: 410] in JSON format
|
|
38
|
+
def self.destroy(token, client_id, venue_id)
|
|
39
|
+
request(:delete, '/venue/' + venue_id.to_s,{}, {"client-id" => client_id, "token": token})
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Get all devices belonging to the given venue
|
|
43
|
+
# @param token [String] Client Token after Authentication
|
|
44
|
+
# @param client_id [String] used from {Client.create}
|
|
45
|
+
# @param venue_id [String] the Key of the Venue from {Venue.create}
|
|
46
|
+
# @return [Hash, status: 410] in JSON format
|
|
47
|
+
def self.devices(token, client_id, venue_id)
|
|
48
|
+
request(:get, '/venue/' + venue_id.to_s + '/devices',{}, {"client-id" => client_id, "token": token})
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: TACore
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 4.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Greg Winn
|
|
8
|
+
- Brandon Criss
|
|
9
|
+
- Shelby Solomon
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: rest-client
|
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
|
+
requirements:
|
|
19
|
+
- - '='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 2.0.0
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - '='
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: 2.0.0
|
|
29
|
+
- !ruby/object:Gem::Dependency
|
|
30
|
+
name: rspec
|
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '0'
|
|
36
|
+
type: :development
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
description: This allows access to the TA Core API
|
|
44
|
+
email: greg.winn@thinaer.io
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- lib/exceptions.rb
|
|
50
|
+
- lib/tacore.rb
|
|
51
|
+
- lib/tacore/app.rb
|
|
52
|
+
- lib/tacore/client.rb
|
|
53
|
+
- lib/tacore/device.rb
|
|
54
|
+
- lib/tacore/gateway.rb
|
|
55
|
+
- lib/tacore/venue.rb
|
|
56
|
+
homepage: http://thinaer.io
|
|
57
|
+
licenses:
|
|
58
|
+
- None
|
|
59
|
+
metadata: {}
|
|
60
|
+
post_install_message:
|
|
61
|
+
rdoc_options: []
|
|
62
|
+
require_paths:
|
|
63
|
+
- lib
|
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
requirements: []
|
|
75
|
+
rubyforge_project:
|
|
76
|
+
rubygems_version: 2.4.6
|
|
77
|
+
signing_key:
|
|
78
|
+
specification_version: 4
|
|
79
|
+
summary: ThinAer Core API for the THINaer Platform
|
|
80
|
+
test_files: []
|