stsplatform 0.0.1
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/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +191 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/examples/advanced_example.rb +49 -0
- data/examples/simple_example.rb +28 -0
- data/lib/stsplatform/client.rb +14 -0
- data/lib/stsplatform/data.rb +11 -0
- data/lib/stsplatform/fields.rb +11 -0
- data/lib/stsplatform/orgs.rb +11 -0
- data/lib/stsplatform/requesthandler.rb +142 -0
- data/lib/stsplatform/sensors.rb +11 -0
- data/lib/stsplatform/stsplatformerror.rb +4 -0
- data/lib/stsplatform/stsplatformresponse.rb +16 -0
- data/lib/stsplatform/version.rb +3 -0
- data/lib/stsplatform.rb +9 -0
- data/stsplatform.gemspec +36 -0
- metadata +122 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: a790360dbbb27d700ed672b733e5bddba655d1e8
|
|
4
|
+
data.tar.gz: c3b8fd632274ef52429f68d983510272c587c5eb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8795c5ab4e6b944f0892415f54fa550e5f523d8a1f22d9e4414b40fa2c4420d5e3192af130d20c308659a6e94556f0386c21c659542c0c1518f7f2e671c449bc
|
|
7
|
+
data.tar.gz: b6a9ef01aa5c5d41b90dfee813690ea5ffe3fe698adb400dd0bb61a9fcd8de5f81ae9fd1a4e1f6ceaa811dd30e121dfbbcc403c28abb86d5c9db8cfd267c5b83
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Roberto
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Stsplatform
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/stsplatform`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Dependencies
|
|
8
|
+
|
|
9
|
+
* Ruby > 2.2.1
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'stsplatform'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
$ bundle
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
$ gem install stsplatform
|
|
26
|
+
|
|
27
|
+
## Getting Started
|
|
28
|
+
|
|
29
|
+
Require the stsplatform gem. Make sure to install it
|
|
30
|
+
To install from source run: "bundle exec rake install"
|
|
31
|
+
to install from RubyGems run : "gem install stsplatform"
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
require 'stsplatform'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Create an STS Platform client:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
c = STSPlatform::Client.new()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Print a sensor hosted in the platform:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
s = STSPlatform::Sensors.new(c, 'calderonroberto.demo')
|
|
48
|
+
res = s.get()
|
|
49
|
+
puts res.data
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Print some data (last data point):
|
|
53
|
+
|
|
54
|
+
To acccess data from a sensor create a data object that uses the sensor object
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
d = STSPlatform::Data.new(s)
|
|
58
|
+
res = d.get({beforeE:1})
|
|
59
|
+
puts res.data
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Using the Library
|
|
63
|
+
|
|
64
|
+
All methods rely on the Client Class. The parameter CONF is not required, but allows you to configure your client to specify your credentials and url of the STS Platform instance you want to access. By default the client will use the community edition of the STS Platform (WoTKit):
|
|
65
|
+
|
|
66
|
+
A common configuration object is:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
CONF = {
|
|
70
|
+
url:"http://wotkit.sensetecnic.com/api",
|
|
71
|
+
auth:{key_id:YOURKEYID,key_password:YOURKEYPASSWORD}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
You can then instantiate your client like this:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
c = STSPlatform::Client.new(CONF)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
To access resources you build them hierarchically. A sensor lives in an STS Platform Server:
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
c = STSPlatform::Client.new(CONF)
|
|
86
|
+
s = STSPlatform::Sensors.new(c, 'SENSORNAME')
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Sensor data lives in a Sensor:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
c = STSPlatform::Client.new(CONF)
|
|
93
|
+
s = STSPlatform::Sensors.new(c, 'SENSORNAME')
|
|
94
|
+
d = STSPlatform::Data .new(s)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
And so on. Each element that uses the Client class can access GET, POST, PUT and DELETE methods. These methods take parameters and return a STSPlatformResponse object containing "data" and "code". Data is the parsed response from the STS Platform server. Code is a string response code from the STS Platform server:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
c = STSPlatform::Client.new(CONF)
|
|
101
|
+
s = STSPlatform::Sensors.new(c, 'SENSORNAME')
|
|
102
|
+
d = STSPlatform::Data .new(s)
|
|
103
|
+
response = d.get({parameter:parametervalue})
|
|
104
|
+
|
|
105
|
+
puts response.code
|
|
106
|
+
puts response.data
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
For more information on the API, support and examples visit [http://developers.sensetecnic.com](http://developers.sensetecnic.com)
|
|
110
|
+
|
|
111
|
+
## Supported Resources
|
|
112
|
+
|
|
113
|
+
To get started first require the library
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
require 'stsplatform'
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Configuring the Client
|
|
120
|
+
|
|
121
|
+
By default the library does not need a configuration to access public sensors. You can configure the client to use a different STS Platform URL (in this case the free version 'WoTKit'). You can also configure it to use a username and password or a valid key_id and key_password:
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
conf = {
|
|
125
|
+
url:"http://wotkit.sensetecnic.com/api",
|
|
126
|
+
#auth:{key_id:YOURKEYID,key_password:YOURKEYPASSWORD}
|
|
127
|
+
#auth:{username:USERNAME,password:PASSWORD}
|
|
128
|
+
}
|
|
129
|
+
client = STSPlatform::Client.new(conf)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Get Sensors
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
c = STSPlatform::Client.new(config)
|
|
136
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
137
|
+
puts s.get().data
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Get Data
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
c = STSPlatform::Client.new(config)
|
|
144
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
145
|
+
d = STSPlatform::Data.new(s)
|
|
146
|
+
puts d.get({beforeE:1}).data
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Publish Data
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
c = STSPlatform::Client.new(config)
|
|
153
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
154
|
+
d = STSPlatform::Data.new(s)
|
|
155
|
+
puts d.post({value:100}).code #print response code
|
|
156
|
+
puts d.get({beforeE:1}).data
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Get Sensor Fields
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
c = STSPlatform::Client.new(config)
|
|
163
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
164
|
+
fs = STSPlatform::Fields.new(s)
|
|
165
|
+
puts fs.get().data
|
|
166
|
+
f = STSPlatform::Fields.new(s, "value")
|
|
167
|
+
puts f.get().data
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Organizations
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
c = STSPlatform::Client.new(config)
|
|
174
|
+
o = STSPlatform::Orgs.new(c, 'sensetecnic')
|
|
175
|
+
puts o.get().data
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Development
|
|
179
|
+
|
|
180
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
181
|
+
|
|
182
|
+
* To install this gem onto your local machine, run `bundle exec rake install`.
|
|
183
|
+
* 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).
|
|
184
|
+
|
|
185
|
+
## Contributing
|
|
186
|
+
|
|
187
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SenseTecnic/stsplatform-lib-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "stsplatform"
|
|
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
|
data/bin/setup
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'stsplatform'
|
|
2
|
+
|
|
3
|
+
#TODO: Configure your credentials and sensor
|
|
4
|
+
SENSOR_NAME = ''
|
|
5
|
+
KEY_ID = ''
|
|
6
|
+
KEY_PASSWORD = ''
|
|
7
|
+
|
|
8
|
+
config = {auth:{key_id:KEY_ID,key_password:KEY_PASSWORD}}
|
|
9
|
+
|
|
10
|
+
### Get Sensors
|
|
11
|
+
|
|
12
|
+
puts "\nGet Sensors"
|
|
13
|
+
c = STSPlatform::Client.new(config)
|
|
14
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
15
|
+
puts s.get().data
|
|
16
|
+
|
|
17
|
+
### Get Data
|
|
18
|
+
|
|
19
|
+
puts "\nGet Data"
|
|
20
|
+
c = STSPlatform::Client.new(config)
|
|
21
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
22
|
+
d = STSPlatform::Data.new(s)
|
|
23
|
+
puts d.get({beforeE:1}).data
|
|
24
|
+
|
|
25
|
+
### Publish Data
|
|
26
|
+
|
|
27
|
+
puts "\nPublish Data"
|
|
28
|
+
c = STSPlatform::Client.new(config)
|
|
29
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
30
|
+
d = STSPlatform::Data.new(s)
|
|
31
|
+
puts d.post({value:100}).code #print response code
|
|
32
|
+
puts d.get({beforeE:1}).data
|
|
33
|
+
|
|
34
|
+
### Get Sensor Fields
|
|
35
|
+
|
|
36
|
+
puts "\nSensor Fields"
|
|
37
|
+
c = STSPlatform::Client.new(config)
|
|
38
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
39
|
+
fs = STSPlatform::Fields.new(s)
|
|
40
|
+
puts fs.get().data
|
|
41
|
+
f = STSPlatform::Fields.new(s, "value")
|
|
42
|
+
puts f.get().data
|
|
43
|
+
|
|
44
|
+
### Organizations
|
|
45
|
+
|
|
46
|
+
puts "\nGet Organization"
|
|
47
|
+
c = STSPlatform::Client.new(config)
|
|
48
|
+
o = STSPlatform::Orgs.new(c, 'sensetecnic')
|
|
49
|
+
puts o.get().data
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Require the stsplatform gem. Make sure to install it
|
|
2
|
+
# To install from source run: "bundle exec rake install"
|
|
3
|
+
# to install from RubyGems run : "gem install stsplatform"
|
|
4
|
+
require 'stsplatform'
|
|
5
|
+
|
|
6
|
+
# A sensor to use for this example. We will use
|
|
7
|
+
SENSOR_NAME = 'calderonroberto.demo'
|
|
8
|
+
|
|
9
|
+
# First, create a client that will handle all the REST calls
|
|
10
|
+
c = STSPlatform::Client.new()
|
|
11
|
+
|
|
12
|
+
# Create a sensor object, that uses the client:
|
|
13
|
+
s = STSPlatform::Sensors.new(c, SENSOR_NAME)
|
|
14
|
+
|
|
15
|
+
# Print the sensor object:
|
|
16
|
+
res = s.get()
|
|
17
|
+
puts res.data
|
|
18
|
+
puts res.code
|
|
19
|
+
|
|
20
|
+
# To acccess data from a sensor create a data object that uses the sensor object
|
|
21
|
+
d = STSPlatform::Data.new(s)
|
|
22
|
+
|
|
23
|
+
# Print the last data point. Do a get request on the data resource, passing
|
|
24
|
+
# a parameter: "beforeE", according to:
|
|
25
|
+
# http://wotkit.readthedocs.org/en/latest/api_v1/api_sensor_data.html#raw-data-retrieval
|
|
26
|
+
res = d.get({beforeE:1})
|
|
27
|
+
puts res.data
|
|
28
|
+
puts res.code
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
require "stsplatform/version"
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module STSPlatform
|
|
6
|
+
|
|
7
|
+
#TODO: move classes onto their own files
|
|
8
|
+
class RequestHandler
|
|
9
|
+
attr_accessor :url, :_successor, :resource, :auth
|
|
10
|
+
|
|
11
|
+
def initialize(successor=nil,id="")
|
|
12
|
+
@url = "http://wotkit.sensetecnic.com/api"
|
|
13
|
+
@_successor = successor
|
|
14
|
+
resource = self.class.name.downcase.split('::').last || ''
|
|
15
|
+
@resource = "/#{resource}/#{id.to_s}"
|
|
16
|
+
@auth = nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def set_config(config)
|
|
20
|
+
if config.has_key?(:url)
|
|
21
|
+
unless /http:\/\//.match(config[:url]).nil?
|
|
22
|
+
@url = config[:url]
|
|
23
|
+
else
|
|
24
|
+
raise STSPlatform::STSPlatformError.new("Malformed URL string")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
if config.has_key?(:auth)
|
|
28
|
+
unless config[:auth].has_key?(:username) || config[:auth].has_key?(:key_id)
|
|
29
|
+
raise STSPlatform::STSPlatformError.new("Malformed Auth Hash. Must contain username or key_id")
|
|
30
|
+
end
|
|
31
|
+
if config[:auth].has_key?(:username)
|
|
32
|
+
@auth = {key_id:config[:auth][:username],key_password:config[:auth][:password]}
|
|
33
|
+
elsif config[:auth].has_key?(:key_id)
|
|
34
|
+
@auth = config[:auth]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def set_handler(handler)
|
|
41
|
+
@_successor = handler
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get(params=nil,resource="")
|
|
45
|
+
unless @_successor.nil?
|
|
46
|
+
return @_successor.get(params,@resource + resource)
|
|
47
|
+
else
|
|
48
|
+
uri = URI.parse(@url+resource)
|
|
49
|
+
uri.query = URI.encode_www_form(handle_params(params))
|
|
50
|
+
req = Net::HTTP::Get.new(uri)
|
|
51
|
+
unless handle_authentication().nil?
|
|
52
|
+
req.basic_auth auth[:key_id].to_s, auth[:key_password].to_s
|
|
53
|
+
end
|
|
54
|
+
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
|
|
55
|
+
http.request(req)
|
|
56
|
+
}
|
|
57
|
+
return handle_response(res)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def post(payload=nil,resource="")
|
|
62
|
+
unless @_successor.nil?
|
|
63
|
+
return @_successor.post(payload,@resource + resource)
|
|
64
|
+
else
|
|
65
|
+
uri = URI.parse(@url+resource)
|
|
66
|
+
req = Net::HTTP::Post.new(uri, initheader={'Content-Type'=>'application/json'})
|
|
67
|
+
req.body = handle_payload(payload)
|
|
68
|
+
unless handle_authentication().nil?
|
|
69
|
+
req.basic_auth auth[:key_id].to_s, auth[:key_password].to_s
|
|
70
|
+
end
|
|
71
|
+
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
|
|
72
|
+
http.request(req)
|
|
73
|
+
}
|
|
74
|
+
return handle_response(res)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def put(payload=nil,resource="")
|
|
79
|
+
unless @_successor.nil?
|
|
80
|
+
return @_successor.put(payload,@resource + resource)
|
|
81
|
+
else
|
|
82
|
+
uri = URI.parse(@url+resource)
|
|
83
|
+
req = Net::HTTP::Put.new(uri, initheader={'Content-Type'=>'application/json'})
|
|
84
|
+
req.body = handle_payload(payload)
|
|
85
|
+
unless handle_authentication().nil?
|
|
86
|
+
req.basic_auth auth[:key_id].to_s, auth[:key_password].to_s
|
|
87
|
+
end
|
|
88
|
+
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
|
|
89
|
+
http.request(req)
|
|
90
|
+
}
|
|
91
|
+
return handle_response(res)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def delete(payload=nil,resource="")
|
|
96
|
+
unless @_successor.nil?
|
|
97
|
+
return @_successor.delete(payload,@resource + resource)
|
|
98
|
+
else
|
|
99
|
+
uri = URI.parse(@url+resource)
|
|
100
|
+
req = Net::HTTP::Delete.new(uri, initheader={'Content-Type'=>'application/json'})
|
|
101
|
+
req.body = handle_payload(payload)
|
|
102
|
+
unless handle_authentication().nil?
|
|
103
|
+
req.basic_auth auth[:key_id].to_s, auth[:key_password].to_s
|
|
104
|
+
end
|
|
105
|
+
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
|
|
106
|
+
http.request(req)
|
|
107
|
+
}
|
|
108
|
+
return handle_response(res)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def handle_response(response)
|
|
115
|
+
return STSPlatform::STSPlatformResponse.new(response)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def handle_authentication()
|
|
119
|
+
#if need handle authentication do it here
|
|
120
|
+
return @auth
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def handle_params(params)
|
|
124
|
+
if params.nil?
|
|
125
|
+
return {}
|
|
126
|
+
else
|
|
127
|
+
return params
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def handle_payload(payload)
|
|
132
|
+
pay = handle_params(payload)
|
|
133
|
+
begin
|
|
134
|
+
return JSON.generate(pay)
|
|
135
|
+
rescue
|
|
136
|
+
raise STSPlatform::STSPlatformError.new("Malformed payload")
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
module STSPlatform
|
|
4
|
+
class STSPlatformResponse
|
|
5
|
+
attr_accessor :data, :code
|
|
6
|
+
def initialize(response)
|
|
7
|
+
begin
|
|
8
|
+
@data = JSON.parse(response.body)
|
|
9
|
+
rescue
|
|
10
|
+
@data = nil
|
|
11
|
+
ensure
|
|
12
|
+
@code = response.code
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/stsplatform.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'stsplatform/requesthandler'
|
|
2
|
+
require 'stsplatform/client'
|
|
3
|
+
require 'stsplatform/stsplatformerror'
|
|
4
|
+
require 'stsplatform/stsplatformresponse'
|
|
5
|
+
#resources:
|
|
6
|
+
require 'stsplatform/sensors'
|
|
7
|
+
require 'stsplatform/data'
|
|
8
|
+
require 'stsplatform/fields'
|
|
9
|
+
require 'stsplatform/orgs'
|
data/stsplatform.gemspec
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'stsplatform/version'
|
|
5
|
+
#Bundler.require(:default, :development)
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "stsplatform"
|
|
9
|
+
spec.version = Stsplatform::VERSION
|
|
10
|
+
spec.authors = ["SenseTecnic"]
|
|
11
|
+
spec.email = ["rcalderon@sensetecnic.com"]
|
|
12
|
+
|
|
13
|
+
spec.summary = "Allows developers to use the STS Platform API"
|
|
14
|
+
spec.description = "This gem allows you to access the STS Platform API. For more information visit http://developers.sensetecnic.com"
|
|
15
|
+
spec.homepage = "http://developers.sensetecnic.com"
|
|
16
|
+
spec.license = "MIT"
|
|
17
|
+
|
|
18
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
|
19
|
+
# delete this section to allow pushing this gem to any host.
|
|
20
|
+
if spec.respond_to?(:metadata)
|
|
21
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
|
22
|
+
else
|
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
27
|
+
spec.bindir = "exe"
|
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ["lib"]
|
|
30
|
+
|
|
31
|
+
spec.add_dependency "json", "~> 1.8"
|
|
32
|
+
|
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.8.1"
|
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
|
36
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: stsplatform
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- SenseTecnic
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: json
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.8'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.8'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.8.1
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.8.1
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.2'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.2'
|
|
69
|
+
description: This gem allows you to access the STS Platform API. For more information
|
|
70
|
+
visit http://developers.sensetecnic.com
|
|
71
|
+
email:
|
|
72
|
+
- rcalderon@sensetecnic.com
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- ".gitignore"
|
|
78
|
+
- Gemfile
|
|
79
|
+
- LICENSE.txt
|
|
80
|
+
- README.md
|
|
81
|
+
- Rakefile
|
|
82
|
+
- bin/console
|
|
83
|
+
- bin/setup
|
|
84
|
+
- examples/advanced_example.rb
|
|
85
|
+
- examples/simple_example.rb
|
|
86
|
+
- lib/stsplatform.rb
|
|
87
|
+
- lib/stsplatform/client.rb
|
|
88
|
+
- lib/stsplatform/data.rb
|
|
89
|
+
- lib/stsplatform/fields.rb
|
|
90
|
+
- lib/stsplatform/orgs.rb
|
|
91
|
+
- lib/stsplatform/requesthandler.rb
|
|
92
|
+
- lib/stsplatform/sensors.rb
|
|
93
|
+
- lib/stsplatform/stsplatformerror.rb
|
|
94
|
+
- lib/stsplatform/stsplatformresponse.rb
|
|
95
|
+
- lib/stsplatform/version.rb
|
|
96
|
+
- stsplatform.gemspec
|
|
97
|
+
homepage: http://developers.sensetecnic.com
|
|
98
|
+
licenses:
|
|
99
|
+
- MIT
|
|
100
|
+
metadata:
|
|
101
|
+
allowed_push_host: https://rubygems.org
|
|
102
|
+
post_install_message:
|
|
103
|
+
rdoc_options: []
|
|
104
|
+
require_paths:
|
|
105
|
+
- lib
|
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
|
+
requirements:
|
|
113
|
+
- - ">="
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: '0'
|
|
116
|
+
requirements: []
|
|
117
|
+
rubyforge_project:
|
|
118
|
+
rubygems_version: 2.4.6
|
|
119
|
+
signing_key:
|
|
120
|
+
specification_version: 4
|
|
121
|
+
summary: Allows developers to use the STS Platform API
|
|
122
|
+
test_files: []
|