cs 0.1.1beta → 0.1.3
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 +4 -4
- data/.travis.yml +1 -2
- data/Gemfile +9 -1
- data/README.md +74 -0
- data/bin/cs +58 -0
- data/bin/cs-console +154 -0
- data/bin/cs-password +44 -0
- data/cs.gemspec +4 -1
- data/lib/cs.rb +31 -4
- data/lib/cs/auth/http.rb +23 -7
- data/lib/cs/cli/cli.rb +29 -0
- data/lib/cs/collection.rb +7 -0
- data/lib/cs/collection/sensor_data_collection.rb +62 -0
- data/lib/cs/end_point.rb +2 -0
- data/lib/cs/end_point/notification.rb +16 -0
- data/lib/cs/end_point/sensor.rb +31 -3
- data/lib/cs/end_point/sensor_data.rb +7 -2
- data/lib/cs/end_point/trigger.rb +16 -0
- data/lib/cs/relation.rb +2 -3
- data/lib/cs/relation/notification_relation.rb +20 -0
- data/lib/cs/relation/sensor_data_relation.rb +12 -0
- data/lib/cs/relation/sensor_relation.rb +27 -0
- data/lib/cs/relation/trigger_relation.rb +21 -0
- data/lib/cs/session.rb +29 -8
- data/lib/cs/version.rb +1 -1
- data/spec/features/user_management_spec.rb +2 -3
- data/spec/lib/cs/collection/sensor_data_collection_spec.rb +27 -0
- data/spec/lib/cs/end_point/sensor_spec.rb +28 -0
- data/spec/lib/cs/relation/group_relation_spec.rb +0 -9
- data/spec/lib/cs/relation/sensor_data_relation_spec.rb +0 -11
- data/spec/lib/cs/relation/sensor_relation_spec.rb +18 -9
- data/spec/lib/cs/session_spec.rb +16 -2
- data/spec/lib/cs_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +37 -8
data/lib/cs/version.rb
CHANGED
@@ -7,7 +7,6 @@ describe "User management" do
|
|
7
7
|
|
8
8
|
let!(:user) do
|
9
9
|
username = "user1@tester.com"
|
10
|
-
password = "password"
|
11
10
|
|
12
11
|
client = CS::Client.new(base_uri: base_uri)
|
13
12
|
user = client.new_user
|
@@ -25,7 +24,7 @@ describe "User management" do
|
|
25
24
|
|
26
25
|
let!(:logged_in_client) do
|
27
26
|
client = CS::Client.new(base_uri: base_uri)
|
28
|
-
client.session_id = '
|
27
|
+
client.session_id = '123488'
|
29
28
|
client
|
30
29
|
end
|
31
30
|
|
@@ -90,7 +89,7 @@ describe "User management" do
|
|
90
89
|
}
|
91
90
|
|
92
91
|
stub_request(:get, "http://api.dev.sense-os.local/users/current.json?").
|
93
|
-
with(:headers => {'Content-Type'=>'application/json', 'X-Session-Id'=>'
|
92
|
+
with(:headers => {'Content-Type'=>'application/json', 'X-Session-Id'=>'123488'}).
|
94
93
|
to_return(:status => 200, :body => body.to_json, :headers => {'Content-Type'=>'application/json'})
|
95
94
|
|
96
95
|
client = logged_in_client
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -93,6 +93,34 @@ module CS
|
|
93
93
|
sensor.delete!.should be_true
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
describe "copy_data" do
|
98
|
+
it "should copy data from other sensor" do
|
99
|
+
# create sensor_a
|
100
|
+
session_a = CS::Session.new
|
101
|
+
session_a.session_id = 1
|
102
|
+
sensor_a = Sensor.new(id: 1)
|
103
|
+
sensor_a.session = session_a
|
104
|
+
|
105
|
+
# create sensor_b
|
106
|
+
session_b = CS::Session.new
|
107
|
+
session_b.session_id = 2
|
108
|
+
sensor_b = Sensor.new(id: 2)
|
109
|
+
sensor_b.session = session_b
|
110
|
+
|
111
|
+
# session_a should recice get with parameter corrent start_date and end_date
|
112
|
+
data = {"data" => [{"id"=>"1_1401381426.400", "sensor_id"=>1, "value"=> "1", "date"=>1402032192.4}]}
|
113
|
+
session_a.should_receive(:get)
|
114
|
+
.with("/sensors/1/data.json", {:page=>0, :per_page=>1000, :start_date=>1402032192.0, :end_date=>1402032200.0, sensor_id: 1})
|
115
|
+
.and_return(data)
|
116
|
+
|
117
|
+
# session_b should receive post with data
|
118
|
+
session_b.should_receive(:post)
|
119
|
+
.with("/sensors/data.json", {:sensors=>[{:sensor_id=>2, :data=>[{:date=>1402032192.4, :value=>"1"}]}]})
|
120
|
+
sensor_b.copy_data(sensor_a, start_date: 1402032192, end_date: 1402032200)
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
96
124
|
end
|
97
125
|
end
|
98
126
|
end
|
@@ -57,15 +57,6 @@ 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
|
-
|
69
60
|
describe "each" do
|
70
61
|
it "should get all users group and yield each" do
|
71
62
|
session = double('Session')
|
@@ -78,17 +78,6 @@ 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
|
-
|
92
81
|
describe "each_batch" do
|
93
82
|
it "should yield data to with multiple pages" do
|
94
83
|
sensor_id = 1
|
@@ -32,15 +32,6 @@ 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
|
-
|
44
35
|
describe "each" do
|
45
36
|
it "should get all sensor and yield each" do
|
46
37
|
session = double('Session')
|
@@ -196,6 +187,24 @@ module CS
|
|
196
187
|
end
|
197
188
|
end
|
198
189
|
end
|
190
|
+
|
191
|
+
describe "clone_from" do
|
192
|
+
it "should copy properties from other sensor and assign the session_id" do
|
193
|
+
attributes = {name: 'sensor1', display_name: 'Sensor1',
|
194
|
+
device_type: 'Android', pager_type: 'pager1',
|
195
|
+
data_type: 'json', data_structure: {"foo" => 'integer'}}
|
196
|
+
|
197
|
+
source = EndPoint::Sensor.new(attributes)
|
198
|
+
cloned = relation.clone_from(source)
|
199
|
+
|
200
|
+
cloned.name.should eq(attributes[:name])
|
201
|
+
cloned.display_name.should eq(attributes[:display_name])
|
202
|
+
cloned.device_type.should eq(attributes[:device_type])
|
203
|
+
cloned.pager_type.should eq(attributes[:pager_type])
|
204
|
+
cloned.data_type.should eq(attributes[:data_type])
|
205
|
+
cloned.data_structure.should eq(attributes[:data_structure])
|
206
|
+
end
|
207
|
+
end
|
199
208
|
end
|
200
209
|
end
|
201
210
|
end
|
data/spec/lib/cs/session_spec.rb
CHANGED
@@ -6,7 +6,6 @@ describe "session" do
|
|
6
6
|
|
7
7
|
let!(:user) do
|
8
8
|
username = "user1@tester.com"
|
9
|
-
password = "password"
|
10
9
|
|
11
10
|
client = CS::Client.new(base_uri: base_uri)
|
12
11
|
user = client.new_user
|
@@ -69,9 +68,24 @@ describe "session" do
|
|
69
68
|
client = create_client
|
70
69
|
CS::Auth::OAuth.should_receive(:new).with('CS_CONSUMER_KEY', 'CS_CONSUMER_SECRET',
|
71
70
|
'CS_ACCESS_TOKEN', 'CS_ACCESS_TOKEN_SECRET', base_uri)
|
72
|
-
|
71
|
+
client.oauth('CS_CONSUMER_KEY', 'CS_CONSUMER_SECRET',
|
73
72
|
'CS_ACCESS_TOKEN', 'CS_ACCESS_TOKEN_SECRET')
|
74
73
|
end
|
75
74
|
end
|
76
75
|
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
|
77
91
|
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.3
|
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-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: launchy
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.12.6
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.12.6
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: httparty
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ~>
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
47
|
+
version: '0.12'
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ~>
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
54
|
+
version: '0.12'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: oauth
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,7 +69,10 @@ dependencies:
|
|
55
69
|
description: CommonSense API client library
|
56
70
|
email:
|
57
71
|
- ahmy@sense-os.nl
|
58
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- cs
|
74
|
+
- cs-console
|
75
|
+
- cs-password
|
59
76
|
extensions: []
|
60
77
|
extra_rdoc_files: []
|
61
78
|
files:
|
@@ -65,21 +82,31 @@ files:
|
|
65
82
|
- LICENSE
|
66
83
|
- README.md
|
67
84
|
- Rakefile
|
85
|
+
- bin/cs
|
86
|
+
- bin/cs-console
|
87
|
+
- bin/cs-password
|
68
88
|
- cs.gemspec
|
69
89
|
- lib/cs.rb
|
70
90
|
- lib/cs/auth/http.rb
|
71
91
|
- lib/cs/auth/oauth.rb
|
92
|
+
- lib/cs/cli/cli.rb
|
93
|
+
- lib/cs/collection.rb
|
94
|
+
- lib/cs/collection/sensor_data_collection.rb
|
72
95
|
- lib/cs/end_point.rb
|
73
96
|
- lib/cs/end_point/group.rb
|
97
|
+
- lib/cs/end_point/notification.rb
|
74
98
|
- lib/cs/end_point/sensor.rb
|
75
99
|
- lib/cs/end_point/sensor_data.rb
|
100
|
+
- lib/cs/end_point/trigger.rb
|
76
101
|
- lib/cs/end_point/user.rb
|
77
102
|
- lib/cs/error.rb
|
78
103
|
- lib/cs/parameter_processor.rb
|
79
104
|
- lib/cs/relation.rb
|
80
105
|
- lib/cs/relation/group_relation.rb
|
106
|
+
- lib/cs/relation/notification_relation.rb
|
81
107
|
- lib/cs/relation/sensor_data_relation.rb
|
82
108
|
- lib/cs/relation/sensor_relation.rb
|
109
|
+
- lib/cs/relation/trigger_relation.rb
|
83
110
|
- lib/cs/relation/user_relation.rb
|
84
111
|
- lib/cs/serializer.rb
|
85
112
|
- lib/cs/session.rb
|
@@ -88,6 +115,7 @@ files:
|
|
88
115
|
- spec/features/sensor_data_management_spec.rb
|
89
116
|
- spec/features/sensor_management_spec.rb
|
90
117
|
- spec/features/user_management_spec.rb
|
118
|
+
- spec/lib/cs/collection/sensor_data_collection_spec.rb
|
91
119
|
- spec/lib/cs/end_point/group_spec.rb
|
92
120
|
- spec/lib/cs/end_point/sensor_data_spec.rb
|
93
121
|
- spec/lib/cs/end_point/sensor_spec.rb
|
@@ -115,12 +143,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
143
|
requirements:
|
116
144
|
- - '>='
|
117
145
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
146
|
+
version: 1.9.3
|
119
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
148
|
requirements:
|
121
|
-
- - '
|
149
|
+
- - '>='
|
122
150
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
151
|
+
version: '0'
|
124
152
|
requirements: []
|
125
153
|
rubyforge_project:
|
126
154
|
rubygems_version: 2.1.9
|
@@ -131,6 +159,7 @@ test_files:
|
|
131
159
|
- spec/features/sensor_data_management_spec.rb
|
132
160
|
- spec/features/sensor_management_spec.rb
|
133
161
|
- spec/features/user_management_spec.rb
|
162
|
+
- spec/lib/cs/collection/sensor_data_collection_spec.rb
|
134
163
|
- spec/lib/cs/end_point/group_spec.rb
|
135
164
|
- spec/lib/cs/end_point/sensor_data_spec.rb
|
136
165
|
- spec/lib/cs/end_point/sensor_spec.rb
|