cs 0.1.0 → 0.1.1beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Gemfile +1 -9
- data/cs.gemspec +1 -3
- data/lib/cs.rb +4 -31
- data/lib/cs/auth/http.rb +7 -23
- data/lib/cs/end_point/sensor.rb +3 -9
- data/lib/cs/end_point/sensor_data.rb +2 -7
- data/lib/cs/relation.rb +3 -2
- data/lib/cs/relation/sensor_relation.rb +0 -22
- data/lib/cs/session.rb +3 -17
- data/lib/cs/version.rb +1 -1
- data/spec/features/user_management_spec.rb +3 -2
- data/spec/lib/cs/relation/group_relation_spec.rb +9 -0
- data/spec/lib/cs/relation/sensor_data_relation_spec.rb +11 -0
- data/spec/lib/cs/relation/sensor_relation_spec.rb +9 -0
- data/spec/lib/cs/session_spec.rb +2 -16
- data/spec/lib/cs_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +7 -15
- data/lib/cs/collection.rb +0 -7
- data/lib/cs/collection/sensor_data_collection.rb +0 -61
- data/lib/cs/end_point/notification.rb +0 -16
- data/lib/cs/end_point/trigger.rb +0 -16
- data/lib/cs/relation/notification_relation.rb +0 -20
- data/lib/cs/relation/trigger_relation.rb +0 -21
- data/spec/lib/cs/collection/sensor_data_collection_spec.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da893437e3bafdedfc45e0ee607d2bf923faa73c
|
4
|
+
data.tar.gz: 4c63a68ad28063ce2a61968ec71da47c7e41fb94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab95c33150cc511f53a057280e83fe35eafcdd61b48acab6ef6bce312511af17c295945e06412b36c98446fc012c60df6aebd7e03017a8cc275e866461bdd36
|
7
|
+
data.tar.gz: 3973ad261722529b962970e5c956eb921045820cde9ccff0d268824024ffa3cddd487a9bca7faa56f1430320bbd93c8ac45453af135371aa70e1cead6debbd0a
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,15 +3,7 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in cs.gemspec
|
4
4
|
gemspec
|
5
5
|
gem "time-lord"
|
6
|
-
gem 'json'
|
7
|
-
|
8
|
-
#
|
9
|
-
# Rubinius does not load ruby stdlib by default
|
10
|
-
#
|
11
|
-
|
12
|
-
platforms :rbx do
|
13
|
-
gem 'rubysl'
|
14
|
-
end
|
6
|
+
gem 'json', '~> 1.7.7'
|
15
7
|
|
16
8
|
group :test do
|
17
9
|
gem "rake", "~> 10.1.0"
|
data/cs.gemspec
CHANGED
@@ -8,8 +8,6 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.summary = %q{Client library to communicate with CommonSense written in ruby}
|
9
9
|
gem.homepage = "https://github.com/senseobservationsystems/commonsense-ruby-lib"
|
10
10
|
|
11
|
-
gem.required_ruby_version = '>= 1.9.3'
|
12
|
-
|
13
11
|
gem.files = `git ls-files`.split($\)
|
14
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
@@ -17,6 +15,6 @@ Gem::Specification.new do |gem|
|
|
17
15
|
gem.require_paths = ["lib"]
|
18
16
|
gem.version = CS::VERSION
|
19
17
|
gem.add_development_dependency("launchy", "~> 2.3")
|
20
|
-
gem.add_dependency('httparty', '~> 0.
|
18
|
+
gem.add_dependency('httparty', '~> 0.11')
|
21
19
|
gem.add_dependency('oauth', '~> 0.4')
|
22
20
|
end
|
data/lib/cs.rb
CHANGED
@@ -9,17 +9,12 @@ require "cs/end_point/user"
|
|
9
9
|
require "cs/end_point/group"
|
10
10
|
require "cs/end_point/sensor"
|
11
11
|
require "cs/end_point/sensor_data"
|
12
|
-
require "cs/end_point/trigger"
|
13
|
-
require "cs/end_point/notification"
|
14
12
|
require "cs/parameter_processor"
|
15
13
|
require "cs/relation"
|
16
14
|
require "cs/relation/sensor_relation"
|
17
15
|
require "cs/relation/sensor_data_relation"
|
18
16
|
require "cs/relation/user_relation"
|
19
17
|
require "cs/relation/group_relation"
|
20
|
-
require "cs/relation/trigger_relation"
|
21
|
-
require "cs/relation/notification_relation"
|
22
|
-
require "cs/collection/sensor_data_collection"
|
23
18
|
|
24
19
|
module CS
|
25
20
|
|
@@ -70,10 +65,10 @@ module CS
|
|
70
65
|
#
|
71
66
|
# client = CS::Client.new
|
72
67
|
# client.login!('username', 'password')
|
73
|
-
def login!(user, password
|
68
|
+
def login!(user, password)
|
74
69
|
@session = Session.new(base_uri: @base_uri)
|
75
70
|
@session.logger = logger
|
76
|
-
@session.login(user, password
|
71
|
+
@session.login(user, password)
|
77
72
|
end
|
78
73
|
|
79
74
|
# Create a new session to CommonSense using username and plain text password
|
@@ -81,8 +76,8 @@ module CS
|
|
81
76
|
#
|
82
77
|
# client = CS::Client.new
|
83
78
|
# client.login('username', 'password')
|
84
|
-
def login(user, password
|
85
|
-
login!(user, password
|
79
|
+
def login(user, password)
|
80
|
+
login!(user, password) rescue false
|
86
81
|
end
|
87
82
|
|
88
83
|
# Create a new session to CommonSense using OAuth credentials
|
@@ -105,16 +100,6 @@ module CS
|
|
105
100
|
@session.session_id = session_id
|
106
101
|
end
|
107
102
|
|
108
|
-
# Create new session by specifying api_key
|
109
|
-
#
|
110
|
-
# client = CS::Client.new
|
111
|
-
# client.session_id = '12345'
|
112
|
-
def api_key=(api_key)
|
113
|
-
@session = Session.new(base_uri: @base_uri)
|
114
|
-
@session.logger = logger
|
115
|
-
@session.api_key = api_key
|
116
|
-
end
|
117
|
-
|
118
103
|
# Retrun logged in user
|
119
104
|
def current_user
|
120
105
|
user = EndPoint::User.new
|
@@ -148,14 +133,6 @@ module CS
|
|
148
133
|
Relation::GroupRelation.new(@session)
|
149
134
|
end
|
150
135
|
|
151
|
-
def triggers
|
152
|
-
Relation::TriggerRelation.new(@session)
|
153
|
-
end
|
154
|
-
|
155
|
-
def notifications
|
156
|
-
Relation::NotificationRelation.new(@session)
|
157
|
-
end
|
158
|
-
|
159
136
|
def current_groups
|
160
137
|
group = EndPoint::Group.new
|
161
138
|
group.session = @session
|
@@ -168,9 +145,5 @@ module CS
|
|
168
145
|
return @session.errors if @session
|
169
146
|
end
|
170
147
|
end
|
171
|
-
|
172
|
-
def self.load_CLI
|
173
|
-
require "cs/cli/cli"
|
174
|
-
end
|
175
148
|
end
|
176
149
|
|
data/lib/cs/auth/http.rb
CHANGED
@@ -7,11 +7,10 @@ module CS
|
|
7
7
|
include HTTParty
|
8
8
|
|
9
9
|
attr_accessor :response_body, :response_code, :response_headers, :errors
|
10
|
-
attr_reader :session_id
|
10
|
+
attr_reader :session_id
|
11
11
|
|
12
|
-
def initialize(base_uri = nil
|
12
|
+
def initialize(base_uri = nil)
|
13
13
|
self.base_uri = base_uri
|
14
|
-
@api_key = api_key
|
15
14
|
@session_id = nil
|
16
15
|
reset
|
17
16
|
end
|
@@ -23,23 +22,10 @@ module CS
|
|
23
22
|
@response_body
|
24
23
|
end
|
25
24
|
|
26
|
-
def process_api_key(path)
|
27
|
-
return path if @api_key.nil?
|
28
|
-
|
29
|
-
if URI(path).query.nil?
|
30
|
-
path += "?API_KEY=#{@api_key}"
|
31
|
-
else
|
32
|
-
path += "&API_KEY=#{@api_key}"
|
33
|
-
end
|
34
|
-
|
35
|
-
path
|
36
|
-
end
|
37
|
-
|
38
25
|
def get(path, query={}, headers = {})
|
39
26
|
execute do
|
40
27
|
headers = default_headers.merge(headers)
|
41
28
|
options = {query: query, headers: headers}
|
42
|
-
path = process_api_key(path)
|
43
29
|
self.class.get(path, options)
|
44
30
|
end
|
45
31
|
end
|
@@ -80,7 +66,7 @@ module CS
|
|
80
66
|
header = self.class.default_options[:headers] || {}
|
81
67
|
header.merge!({"Content-Type" => "application/json"})
|
82
68
|
if @session_id
|
83
|
-
header
|
69
|
+
header.merge!('X-SESSION_ID' => self.session_id)
|
84
70
|
end
|
85
71
|
header
|
86
72
|
end
|
@@ -93,19 +79,18 @@ module CS
|
|
93
79
|
@session_id = session_id
|
94
80
|
end
|
95
81
|
|
82
|
+
|
96
83
|
# login to commonsense
|
97
84
|
# @return [String] session_id
|
98
|
-
def login(username, password
|
99
|
-
|
100
|
-
password = Digest::MD5.hexdigest password
|
101
|
-
end
|
85
|
+
def login(username, password)
|
86
|
+
password = Digest::MD5.hexdigest password
|
102
87
|
post('/login.json', {:username => username, :password => password})
|
103
88
|
|
104
89
|
if @response_code == 200
|
105
90
|
self.session_id = response_body['session_id']
|
106
91
|
else
|
107
92
|
self.session_id = false
|
108
|
-
|
93
|
+
errors = [response_body['error']]
|
109
94
|
end
|
110
95
|
|
111
96
|
session_id
|
@@ -119,7 +104,6 @@ module CS
|
|
119
104
|
end
|
120
105
|
|
121
106
|
def parse_response
|
122
|
-
return unless @response_body
|
123
107
|
@response_code = @response_body.response.code.to_i
|
124
108
|
@response_headers = @response_body.headers
|
125
109
|
if @response_code >= 400
|
data/lib/cs/end_point/sensor.rb
CHANGED
@@ -26,8 +26,8 @@ module CS
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
def
|
29
|
+
# overide Endpoint#to_parameters
|
30
|
+
def to_parameters
|
31
31
|
param = self.to_h(false)
|
32
32
|
if param[:data_type] == "json"
|
33
33
|
if param[:data_structure] && !param[:data_structure].kind_of?(String)
|
@@ -35,13 +35,7 @@ module CS
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
param
|
39
|
-
end
|
40
|
-
|
41
|
-
# overide Endpoint#to_parameters
|
42
|
-
def to_parameters
|
43
|
-
|
44
|
-
{sensor: to_cs_sensor}
|
38
|
+
{sensor: param}
|
45
39
|
end
|
46
40
|
|
47
41
|
def data
|
@@ -26,7 +26,7 @@ module CS
|
|
26
26
|
resources "data"
|
27
27
|
resource "data"
|
28
28
|
|
29
|
-
def
|
29
|
+
def to_parameters
|
30
30
|
param = self.to_h(false)
|
31
31
|
param.delete(:sensor_id)
|
32
32
|
value = param[:value]
|
@@ -35,12 +35,7 @@ module CS
|
|
35
35
|
end
|
36
36
|
|
37
37
|
param[:date] = CS::Time.new(date).to_f if param[:date]
|
38
|
-
|
39
|
-
param
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_parameters
|
43
|
-
{data: [to_cs_point]}
|
38
|
+
{data: [param]}
|
44
39
|
end
|
45
40
|
|
46
41
|
def date_human
|
data/lib/cs/relation.rb
CHANGED
@@ -45,7 +45,7 @@ module CS
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def get_data(params={})
|
48
|
-
get_data!(params)
|
48
|
+
get_data!(params) rescue nil
|
49
49
|
end
|
50
50
|
|
51
51
|
def all
|
@@ -94,6 +94,7 @@ module CS
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def last
|
97
|
+
total = count
|
97
98
|
resource = get_single_resource(page: count - 1)
|
98
99
|
parse_single_resource(resource)
|
99
100
|
end
|
@@ -145,7 +146,7 @@ module CS
|
|
145
146
|
options[:page] = self.page
|
146
147
|
data = get_data(options)
|
147
148
|
|
148
|
-
data = data[resource_class.resources_name]
|
149
|
+
data = data[resource_class.resources_name]
|
149
150
|
if !data.nil? && !data.empty?
|
150
151
|
yield data
|
151
152
|
self.page += 1
|
@@ -100,18 +100,6 @@ module CS
|
|
100
100
|
self.select { |sensor| sensor.name =~ regex }
|
101
101
|
end
|
102
102
|
|
103
|
-
def triggers()
|
104
|
-
Relation::SensorTriggersRelation.new(@session)
|
105
|
-
end
|
106
|
-
|
107
|
-
def clone_from(other_sensor)
|
108
|
-
sensor = Sensor.new(other_sensor.to_parameters[:sensor])
|
109
|
-
sensor.id = nil
|
110
|
-
sensor.session = self.session
|
111
|
-
|
112
|
-
sensor
|
113
|
-
end
|
114
|
-
|
115
103
|
private
|
116
104
|
def resource_class
|
117
105
|
EndPoint::Sensor
|
@@ -121,15 +109,5 @@ module CS
|
|
121
109
|
"/sensors.json"
|
122
110
|
end
|
123
111
|
end
|
124
|
-
|
125
|
-
class SensorTriggersRelation
|
126
|
-
include Relation
|
127
|
-
|
128
|
-
parameter :page, Integer, default: 0, required: true
|
129
|
-
|
130
|
-
def get_url
|
131
|
-
"/sensors/triggers.json"
|
132
|
-
end
|
133
|
-
end
|
134
112
|
end
|
135
113
|
end
|
data/lib/cs/session.rb
CHANGED
@@ -13,9 +13,9 @@ module CS
|
|
13
13
|
|
14
14
|
# login to commonsense
|
15
15
|
# @return [String] session_id
|
16
|
-
def login(username, password
|
16
|
+
def login(username, password)
|
17
17
|
@auth_proxy = CS::Auth::HTTP.new(@base_uri)
|
18
|
-
@auth_proxy.login(username, password
|
18
|
+
@auth_proxy.login(username, password)
|
19
19
|
end
|
20
20
|
|
21
21
|
def oauth(consumer_key, consumer_secret, access_token, access_token_secret)
|
@@ -28,20 +28,11 @@ module CS
|
|
28
28
|
auth_proxy.session_id
|
29
29
|
end
|
30
30
|
|
31
|
-
def api_key
|
32
|
-
auth_proxy.api_key
|
33
|
-
end
|
34
|
-
|
35
31
|
def session_id=(session_id)
|
36
32
|
@auth_proxy = CS::Auth::HTTP.new(@base_uri)
|
37
33
|
@auth_proxy.session_id = session_id
|
38
34
|
end
|
39
35
|
|
40
|
-
def api_key=(api_key)
|
41
|
-
@api_key = api_key
|
42
|
-
@auth_proxy = CS::Auth::HTTP.new(@base_uri, api_key)
|
43
|
-
end
|
44
|
-
|
45
36
|
def auth_proxy
|
46
37
|
raise 'The session is not logged in' unless @auth_proxy
|
47
38
|
@auth_proxy
|
@@ -155,12 +146,7 @@ module CS
|
|
155
146
|
end
|
156
147
|
|
157
148
|
def to_s
|
158
|
-
|
159
|
-
return "SESSION_ID \"#{session_id}\""
|
160
|
-
elsif api_key
|
161
|
-
return "API_KEY \"#{api_key}\""
|
162
|
-
end
|
163
|
-
return ""
|
149
|
+
"\"#{self.session_id}\""
|
164
150
|
end
|
165
151
|
|
166
152
|
def inspect
|
data/lib/cs/version.rb
CHANGED
@@ -7,6 +7,7 @@ describe "User management" do
|
|
7
7
|
|
8
8
|
let!(:user) do
|
9
9
|
username = "user1@tester.com"
|
10
|
+
password = "password"
|
10
11
|
|
11
12
|
client = CS::Client.new(base_uri: base_uri)
|
12
13
|
user = client.new_user
|
@@ -24,7 +25,7 @@ describe "User management" do
|
|
24
25
|
|
25
26
|
let!(:logged_in_client) do
|
26
27
|
client = CS::Client.new(base_uri: base_uri)
|
27
|
-
client.session_id = '
|
28
|
+
client.session_id = '1234'
|
28
29
|
client
|
29
30
|
end
|
30
31
|
|
@@ -89,7 +90,7 @@ describe "User management" do
|
|
89
90
|
}
|
90
91
|
|
91
92
|
stub_request(:get, "http://api.dev.sense-os.local/users/current.json?").
|
92
|
-
with(:headers => {'Content-Type'=>'application/json', 'X-Session-Id'=>'
|
93
|
+
with(:headers => {'Content-Type'=>'application/json', 'X-Session-Id'=>'1234'}).
|
93
94
|
to_return(:status => 200, :body => body.to_json, :headers => {'Content-Type'=>'application/json'})
|
94
95
|
|
95
96
|
client = logged_in_client
|
@@ -57,6 +57,15 @@ module CS
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
describe "get_data" do
|
61
|
+
it "should not throw an exception" do
|
62
|
+
relation = GroupRelation.new
|
63
|
+
relation.stub(:get_data!).and_return { raise Error }
|
64
|
+
|
65
|
+
expect { relation.get_data }.to_not raise_error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
60
69
|
describe "each" do
|
61
70
|
it "should get all users group and yield each" do
|
62
71
|
session = double('Session')
|
@@ -78,6 +78,17 @@ module CS
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
describe "get_data" do
|
82
|
+
it "call get_data! and not throw exception" do
|
83
|
+
sensor_id = 1
|
84
|
+
relation = SensorDataRelation.new(sensor_id)
|
85
|
+
relation.stub(:get_data!).and_return { raise Error }
|
86
|
+
|
87
|
+
expect { relation.get_data }.to_not raise_error
|
88
|
+
relation.get_data.should be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
81
92
|
describe "each_batch" do
|
82
93
|
it "should yield data to with multiple pages" do
|
83
94
|
sensor_id = 1
|
@@ -32,6 +32,15 @@ module CS
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe "get_data" do
|
36
|
+
it "should not throw an exception" do
|
37
|
+
relation = SensorRelation.new
|
38
|
+
relation.stub(:get_data!).and_return { raise Error }
|
39
|
+
|
40
|
+
expect { relation.get_data }.to_not raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
35
44
|
describe "each" do
|
36
45
|
it "should get all sensor and yield each" do
|
37
46
|
session = double('Session')
|
data/spec/lib/cs/session_spec.rb
CHANGED
@@ -6,6 +6,7 @@ describe "session" do
|
|
6
6
|
|
7
7
|
let!(:user) do
|
8
8
|
username = "user1@tester.com"
|
9
|
+
password = "password"
|
9
10
|
|
10
11
|
client = CS::Client.new(base_uri: base_uri)
|
11
12
|
user = client.new_user
|
@@ -68,24 +69,9 @@ describe "session" do
|
|
68
69
|
client = create_client
|
69
70
|
CS::Auth::OAuth.should_receive(:new).with('CS_CONSUMER_KEY', 'CS_CONSUMER_SECRET',
|
70
71
|
'CS_ACCESS_TOKEN', 'CS_ACCESS_TOKEN_SECRET', base_uri)
|
71
|
-
client.oauth('CS_CONSUMER_KEY', 'CS_CONSUMER_SECRET',
|
72
|
+
session = client.oauth('CS_CONSUMER_KEY', 'CS_CONSUMER_SECRET',
|
72
73
|
'CS_ACCESS_TOKEN', 'CS_ACCESS_TOKEN_SECRET')
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
76
|
-
|
77
|
-
describe "API_KEY" do
|
78
|
-
it "should append API key in the url" do
|
79
|
-
client = create_client
|
80
|
-
client.api_key = '123456'
|
81
|
-
CS::Auth::HTTP.should_receive(:get).
|
82
|
-
with("/sensors.json?API_KEY=123456",
|
83
|
-
{:query=>{:page=>0, :per_page=>1000},
|
84
|
-
:headers=>{"Content-Type"=>"application/json"}}
|
85
|
-
)
|
86
|
-
|
87
|
-
result = client.sensors
|
88
|
-
result.to_a
|
89
|
-
end
|
90
|
-
end
|
91
77
|
end
|
data/spec/lib/cs_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmy Yulrizka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: launchy
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.11'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.11'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: oauth
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,23 +69,17 @@ files:
|
|
69
69
|
- lib/cs.rb
|
70
70
|
- lib/cs/auth/http.rb
|
71
71
|
- lib/cs/auth/oauth.rb
|
72
|
-
- lib/cs/collection.rb
|
73
|
-
- lib/cs/collection/sensor_data_collection.rb
|
74
72
|
- lib/cs/end_point.rb
|
75
73
|
- lib/cs/end_point/group.rb
|
76
|
-
- lib/cs/end_point/notification.rb
|
77
74
|
- lib/cs/end_point/sensor.rb
|
78
75
|
- lib/cs/end_point/sensor_data.rb
|
79
|
-
- lib/cs/end_point/trigger.rb
|
80
76
|
- lib/cs/end_point/user.rb
|
81
77
|
- lib/cs/error.rb
|
82
78
|
- lib/cs/parameter_processor.rb
|
83
79
|
- lib/cs/relation.rb
|
84
80
|
- lib/cs/relation/group_relation.rb
|
85
|
-
- lib/cs/relation/notification_relation.rb
|
86
81
|
- lib/cs/relation/sensor_data_relation.rb
|
87
82
|
- lib/cs/relation/sensor_relation.rb
|
88
|
-
- lib/cs/relation/trigger_relation.rb
|
89
83
|
- lib/cs/relation/user_relation.rb
|
90
84
|
- lib/cs/serializer.rb
|
91
85
|
- lib/cs/session.rb
|
@@ -94,7 +88,6 @@ files:
|
|
94
88
|
- spec/features/sensor_data_management_spec.rb
|
95
89
|
- spec/features/sensor_management_spec.rb
|
96
90
|
- spec/features/user_management_spec.rb
|
97
|
-
- spec/lib/cs/collection/sensor_data_collection_spec.rb
|
98
91
|
- spec/lib/cs/end_point/group_spec.rb
|
99
92
|
- spec/lib/cs/end_point/sensor_data_spec.rb
|
100
93
|
- spec/lib/cs/end_point/sensor_spec.rb
|
@@ -122,12 +115,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
115
|
requirements:
|
123
116
|
- - '>='
|
124
117
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
118
|
+
version: '0'
|
126
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
120
|
requirements:
|
128
|
-
- - '
|
121
|
+
- - '>'
|
129
122
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
123
|
+
version: 1.3.1
|
131
124
|
requirements: []
|
132
125
|
rubyforge_project:
|
133
126
|
rubygems_version: 2.1.9
|
@@ -138,7 +131,6 @@ test_files:
|
|
138
131
|
- spec/features/sensor_data_management_spec.rb
|
139
132
|
- spec/features/sensor_management_spec.rb
|
140
133
|
- spec/features/user_management_spec.rb
|
141
|
-
- spec/lib/cs/collection/sensor_data_collection_spec.rb
|
142
134
|
- spec/lib/cs/end_point/group_spec.rb
|
143
135
|
- spec/lib/cs/end_point/sensor_data_spec.rb
|
144
136
|
- spec/lib/cs/end_point/sensor_spec.rb
|
data/lib/cs/collection.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'delegate'
|
2
|
-
|
3
|
-
module CS
|
4
|
-
module Collection
|
5
|
-
class SensorDataCollection < SimpleDelegator
|
6
|
-
attr_accessor :session
|
7
|
-
attr_accessor :batch_size
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@batch_size = 1000
|
11
|
-
super([])
|
12
|
-
end
|
13
|
-
|
14
|
-
def save!
|
15
|
-
check_session!
|
16
|
-
|
17
|
-
# group batch
|
18
|
-
self.each_slice(@batch_size) do |batch|
|
19
|
-
body = process_batch(batch)
|
20
|
-
@session.post(get_url, body)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
##
|
25
|
-
# Given array of sensor data it will group the data by sensor_id
|
26
|
-
# and construct payload for multiple sensor upload
|
27
|
-
def process_batch(batch)
|
28
|
-
sensors = {}
|
29
|
-
batch.each do |point|
|
30
|
-
next if point.nil? || point.sensor_id.nil?
|
31
|
-
sensor_id = point.sensor_id
|
32
|
-
|
33
|
-
if !sensors[sensor_id]
|
34
|
-
sensors[sensor_id] = {
|
35
|
-
sensor_id: sensor_id,
|
36
|
-
data: []
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
sensors[sensor_id][:data].push(point.to_cs_point)
|
41
|
-
end
|
42
|
-
|
43
|
-
retval = []
|
44
|
-
sensors.each do |k, v|
|
45
|
-
retval.push(v)
|
46
|
-
end
|
47
|
-
|
48
|
-
{sensors: retval}
|
49
|
-
end
|
50
|
-
|
51
|
-
def get_url
|
52
|
-
"/sensors/data.json"
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
def check_session!
|
57
|
-
raise Error::SessionEmptyError unless @session
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
data/lib/cs/end_point/trigger.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module CS
|
2
|
-
module Relation
|
3
|
-
class NotificationRelation
|
4
|
-
include Relation
|
5
|
-
|
6
|
-
parameter :page, Integer, default: 0, required: true
|
7
|
-
parameter :per_page, Integer, default: 1000, required: true, maximum: 1000
|
8
|
-
parameter :total, Boolean
|
9
|
-
|
10
|
-
private
|
11
|
-
def resource_class
|
12
|
-
EndPoint::Notification
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_url
|
16
|
-
"/notifications.json"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module CS
|
2
|
-
module Relation
|
3
|
-
class TriggerRelation
|
4
|
-
include Relation
|
5
|
-
|
6
|
-
parameter :page, Integer, default: 0, required: true
|
7
|
-
parameter :per_page, Integer, default: 1000, required: true, maximum: 1000
|
8
|
-
parameter :total, Boolean
|
9
|
-
|
10
|
-
|
11
|
-
private
|
12
|
-
def resource_class
|
13
|
-
EndPoint::Trigger
|
14
|
-
end
|
15
|
-
|
16
|
-
def get_url
|
17
|
-
"/triggers.json"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CS
|
4
|
-
module Collection
|
5
|
-
describe SensorDataCollection do
|
6
|
-
describe "process_batch" do
|
7
|
-
it "should convert into multi data payload" do
|
8
|
-
sdc = SensorDataCollection.new
|
9
|
-
sdc.batch_size = 2
|
10
|
-
|
11
|
-
current_batch = [
|
12
|
-
EndPoint::SensorData.new(sensor_id: 1, value: 1),
|
13
|
-
EndPoint::SensorData.new(sensor_id: 1, value: 2),
|
14
|
-
EndPoint::SensorData.new(sensor_id: 2, value: 1),
|
15
|
-
EndPoint::SensorData.new(sensor_id: 2, value: 2),
|
16
|
-
EndPoint::SensorData.new(sensor_id: 1, value: 3),
|
17
|
-
EndPoint::SensorData.new(sensor_id: 1, value: 4),
|
18
|
-
EndPoint::SensorData.new(sensor_id: 2, value: 3),
|
19
|
-
EndPoint::SensorData.new(sensor_id: 2, value: 4)
|
20
|
-
]
|
21
|
-
|
22
|
-
sdc.process_batch(current_batch)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|