cs 0.1.0beta3 → 0.1.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/.travis.yml +8 -0
- data/Gemfile +22 -6
- data/README.md +15 -4
- data/cs.gemspec +7 -7
- data/lib/{commonsense-ruby-lib.rb → cs.rb} +80 -31
- data/lib/{commonsense-ruby-lib → cs}/auth/http.rb +52 -33
- data/lib/{commonsense-ruby-lib → cs}/auth/oauth.rb +28 -28
- data/lib/cs/collection.rb +7 -0
- data/lib/cs/collection/sensor_data_collection.rb +61 -0
- data/lib/{commonsense-ruby-lib → cs}/end_point.rb +36 -24
- data/lib/cs/end_point/group.rb +26 -0
- data/lib/cs/end_point/notification.rb +16 -0
- data/lib/{commonsense-ruby-lib → cs}/end_point/sensor.rb +22 -6
- data/lib/{commonsense-ruby-lib → cs}/end_point/sensor_data.rb +17 -6
- data/lib/cs/end_point/trigger.rb +16 -0
- data/lib/{commonsense-ruby-lib → cs}/end_point/user.rb +8 -4
- data/lib/{commonsense-ruby-lib → cs}/error.rb +7 -1
- data/lib/cs/parameter_processor.rb +99 -0
- data/lib/cs/relation.rb +244 -0
- data/lib/cs/relation/group_relation.rb +24 -0
- data/lib/cs/relation/notification_relation.rb +20 -0
- data/lib/{commonsense-ruby-lib → cs}/relation/sensor_data_relation.rb +7 -52
- data/lib/{commonsense-ruby-lib → cs}/relation/sensor_relation.rb +28 -55
- data/lib/cs/relation/trigger_relation.rb +21 -0
- data/lib/cs/relation/user_relation.rb +20 -0
- data/lib/{commonsense-ruby-lib → cs}/serializer.rb +1 -1
- data/lib/cs/session.rb +170 -0
- data/lib/cs/time.rb +45 -0
- data/lib/cs/version.rb +3 -0
- data/spec/features/sensor_management_spec.rb +146 -45
- data/spec/features/user_management_spec.rb +94 -22
- data/spec/lib/cs/collection/sensor_data_collection_spec.rb +27 -0
- data/spec/lib/cs/end_point/group_spec.rb +120 -0
- data/spec/lib/cs/end_point/sensor_data_spec.rb +110 -0
- data/spec/lib/{commonsense-ruby-lib → cs}/end_point/sensor_spec.rb +6 -6
- data/spec/lib/{commonsense-ruby-lib → cs}/end_point/user_spec.rb +14 -7
- data/spec/lib/{commonsense-ruby-lib → cs}/end_point_spec.rb +25 -12
- data/spec/lib/cs/relation/group_relation_spec.rb +103 -0
- data/spec/lib/cs/relation/sensor_data_relation_spec.rb +184 -0
- data/spec/lib/cs/relation/sensor_relation_spec.rb +192 -0
- data/spec/lib/cs/relation/user_relation_spec.rb +81 -0
- data/spec/lib/cs/relation_spec.rb +151 -0
- data/spec/lib/cs/session_spec.rb +91 -0
- data/spec/lib/cs/time_spec.rb +71 -0
- data/spec/lib/cs_spec.rb +85 -0
- data/spec/spec_helper.rb +6 -26
- metadata +69 -86
- data/lib/commonsense-ruby-lib/end_point/group.rb +0 -28
- data/lib/commonsense-ruby-lib/relation.rb +0 -233
- data/lib/commonsense-ruby-lib/session.rb +0 -105
- data/lib/commonsense-ruby-lib/version.rb +0 -3
- data/spec/lib/commonsense-ruby-lib/end_point/sensor_data_spec.rb +0 -68
- data/spec/lib/commonsense-ruby-lib/relation/sensor_data_relation_spec.rb +0 -444
- data/spec/lib/commonsense-ruby-lib/relation/sensor_relation_spec.rb +0 -165
- data/spec/lib/commonsense-ruby-lib/session_spec.rb +0 -43
- data/spec/lib/commonsense-ruby-lib_spec.rb +0 -51
data/spec/spec_helper.rb
CHANGED
|
@@ -1,40 +1,20 @@
|
|
|
1
1
|
require 'bundler/setup'
|
|
2
2
|
require 'rspec'
|
|
3
|
-
require '
|
|
4
|
-
#require 'vcr'
|
|
3
|
+
require 'cs'
|
|
5
4
|
require 'pry'
|
|
6
5
|
|
|
7
6
|
Dir[File.join(File.dirname(__FILE__),("support/**/*.rb"))].each {|f| require f}
|
|
8
7
|
|
|
9
|
-
CONFIG = YAML.load(File.read(File.expand_path("support/spec_config.yml", File.dirname(__FILE__))))
|
|
10
|
-
|
|
11
8
|
RSpec.configure do |config|
|
|
12
9
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
13
|
-
|
|
14
|
-
# create a single user
|
|
15
|
-
config.before(:all) do
|
|
16
|
-
unless $user
|
|
17
|
-
$username = "user#{Time.now.to_f}@tester.com"
|
|
18
|
-
$password = "password"
|
|
19
|
-
|
|
20
|
-
client = CommonSense::Client.new(base_uri: ENV['spec_base_uri'])
|
|
21
|
-
$user = client.new_user
|
|
22
|
-
$user.username = $username
|
|
23
|
-
$user.email = $user.username
|
|
24
|
-
$user.password = 'password'
|
|
25
|
-
$user.name = 'Jan'
|
|
26
|
-
$user.surname = 'jagger'
|
|
27
|
-
$user.address = 'Lloydstraat 5'
|
|
28
|
-
$user.zipcode = '3024ea'
|
|
29
|
-
$user.country = 'NETHERLANDS'
|
|
30
|
-
$user.mobile = '123456789'
|
|
31
|
-
$user.save
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
10
|
end
|
|
35
11
|
|
|
36
12
|
def create_client
|
|
37
|
-
|
|
13
|
+
CS::Client.new(base_uri: ENV['spec_base_uri'])
|
|
38
14
|
end
|
|
39
15
|
|
|
40
16
|
ENV['spec_base_uri'] ||= 'http://api.dev.sense-os.local'
|
|
17
|
+
|
|
18
|
+
def base_uri
|
|
19
|
+
ENV['spec_base_uri']
|
|
20
|
+
end
|
metadata
CHANGED
|
@@ -1,96 +1,57 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
5
|
-
prerelease: 5
|
|
4
|
+
version: 0.1.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Ahmy Yulrizka
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
|
-
- !ruby/object:Gem::Dependency
|
|
15
|
-
name: rspec
|
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
|
-
requirements:
|
|
19
|
-
- - ~>
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: 2.13.0
|
|
22
|
-
type: :development
|
|
23
|
-
prerelease: false
|
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
|
-
requirements:
|
|
27
|
-
- - ~>
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: 2.13.0
|
|
30
13
|
- !ruby/object:Gem::Dependency
|
|
31
14
|
name: launchy
|
|
32
15
|
requirement: !ruby/object:Gem::Requirement
|
|
33
|
-
none: false
|
|
34
|
-
requirements:
|
|
35
|
-
- - ~>
|
|
36
|
-
- !ruby/object:Gem::Version
|
|
37
|
-
version: 2.3.0
|
|
38
|
-
type: :development
|
|
39
|
-
prerelease: false
|
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
-
none: false
|
|
42
|
-
requirements:
|
|
43
|
-
- - ~>
|
|
44
|
-
- !ruby/object:Gem::Version
|
|
45
|
-
version: 2.3.0
|
|
46
|
-
- !ruby/object:Gem::Dependency
|
|
47
|
-
name: fakeweb
|
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
|
49
|
-
none: false
|
|
50
16
|
requirements:
|
|
51
17
|
- - ~>
|
|
52
18
|
- !ruby/object:Gem::Version
|
|
53
|
-
version:
|
|
19
|
+
version: '2.3'
|
|
54
20
|
type: :development
|
|
55
21
|
prerelease: false
|
|
56
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
-
none: false
|
|
58
23
|
requirements:
|
|
59
24
|
- - ~>
|
|
60
25
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
26
|
+
version: '2.3'
|
|
62
27
|
- !ruby/object:Gem::Dependency
|
|
63
28
|
name: httparty
|
|
64
29
|
requirement: !ruby/object:Gem::Requirement
|
|
65
|
-
none: false
|
|
66
30
|
requirements:
|
|
67
31
|
- - ~>
|
|
68
32
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: 0.
|
|
33
|
+
version: '0.12'
|
|
70
34
|
type: :runtime
|
|
71
35
|
prerelease: false
|
|
72
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
-
none: false
|
|
74
37
|
requirements:
|
|
75
38
|
- - ~>
|
|
76
39
|
- !ruby/object:Gem::Version
|
|
77
|
-
version: 0.
|
|
40
|
+
version: '0.12'
|
|
78
41
|
- !ruby/object:Gem::Dependency
|
|
79
42
|
name: oauth
|
|
80
43
|
requirement: !ruby/object:Gem::Requirement
|
|
81
|
-
none: false
|
|
82
44
|
requirements:
|
|
83
45
|
- - ~>
|
|
84
46
|
- !ruby/object:Gem::Version
|
|
85
|
-
version: 0.4
|
|
47
|
+
version: '0.4'
|
|
86
48
|
type: :runtime
|
|
87
49
|
prerelease: false
|
|
88
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
-
none: false
|
|
90
51
|
requirements:
|
|
91
52
|
- - ~>
|
|
92
53
|
- !ruby/object:Gem::Version
|
|
93
|
-
version: 0.4
|
|
54
|
+
version: '0.4'
|
|
94
55
|
description: CommonSense API client library
|
|
95
56
|
email:
|
|
96
57
|
- ahmy@sense-os.nl
|
|
@@ -99,76 +60,98 @@ extensions: []
|
|
|
99
60
|
extra_rdoc_files: []
|
|
100
61
|
files:
|
|
101
62
|
- .gitignore
|
|
63
|
+
- .travis.yml
|
|
102
64
|
- Gemfile
|
|
103
65
|
- LICENSE
|
|
104
66
|
- README.md
|
|
105
67
|
- Rakefile
|
|
106
68
|
- cs.gemspec
|
|
107
|
-
- lib/
|
|
108
|
-
- lib/
|
|
109
|
-
- lib/
|
|
110
|
-
- lib/
|
|
111
|
-
- lib/
|
|
112
|
-
- lib/
|
|
113
|
-
- lib/
|
|
114
|
-
- lib/
|
|
115
|
-
- lib/
|
|
116
|
-
- lib/
|
|
117
|
-
- lib/
|
|
118
|
-
- lib/
|
|
119
|
-
- lib/
|
|
120
|
-
- lib/
|
|
121
|
-
- lib/
|
|
69
|
+
- lib/cs.rb
|
|
70
|
+
- lib/cs/auth/http.rb
|
|
71
|
+
- lib/cs/auth/oauth.rb
|
|
72
|
+
- lib/cs/collection.rb
|
|
73
|
+
- lib/cs/collection/sensor_data_collection.rb
|
|
74
|
+
- lib/cs/end_point.rb
|
|
75
|
+
- lib/cs/end_point/group.rb
|
|
76
|
+
- lib/cs/end_point/notification.rb
|
|
77
|
+
- lib/cs/end_point/sensor.rb
|
|
78
|
+
- lib/cs/end_point/sensor_data.rb
|
|
79
|
+
- lib/cs/end_point/trigger.rb
|
|
80
|
+
- lib/cs/end_point/user.rb
|
|
81
|
+
- lib/cs/error.rb
|
|
82
|
+
- lib/cs/parameter_processor.rb
|
|
83
|
+
- lib/cs/relation.rb
|
|
84
|
+
- lib/cs/relation/group_relation.rb
|
|
85
|
+
- lib/cs/relation/notification_relation.rb
|
|
86
|
+
- lib/cs/relation/sensor_data_relation.rb
|
|
87
|
+
- lib/cs/relation/sensor_relation.rb
|
|
88
|
+
- lib/cs/relation/trigger_relation.rb
|
|
89
|
+
- lib/cs/relation/user_relation.rb
|
|
90
|
+
- lib/cs/serializer.rb
|
|
91
|
+
- lib/cs/session.rb
|
|
92
|
+
- lib/cs/time.rb
|
|
93
|
+
- lib/cs/version.rb
|
|
122
94
|
- spec/features/sensor_data_management_spec.rb
|
|
123
95
|
- spec/features/sensor_management_spec.rb
|
|
124
96
|
- spec/features/user_management_spec.rb
|
|
125
|
-
- spec/lib/
|
|
126
|
-
- spec/lib/
|
|
127
|
-
- spec/lib/
|
|
128
|
-
- spec/lib/
|
|
129
|
-
- spec/lib/
|
|
130
|
-
- spec/lib/
|
|
131
|
-
- spec/lib/
|
|
132
|
-
- spec/lib/
|
|
97
|
+
- spec/lib/cs/collection/sensor_data_collection_spec.rb
|
|
98
|
+
- spec/lib/cs/end_point/group_spec.rb
|
|
99
|
+
- spec/lib/cs/end_point/sensor_data_spec.rb
|
|
100
|
+
- spec/lib/cs/end_point/sensor_spec.rb
|
|
101
|
+
- spec/lib/cs/end_point/user_spec.rb
|
|
102
|
+
- spec/lib/cs/end_point_spec.rb
|
|
103
|
+
- spec/lib/cs/relation/group_relation_spec.rb
|
|
104
|
+
- spec/lib/cs/relation/sensor_data_relation_spec.rb
|
|
105
|
+
- spec/lib/cs/relation/sensor_relation_spec.rb
|
|
106
|
+
- spec/lib/cs/relation/user_relation_spec.rb
|
|
107
|
+
- spec/lib/cs/relation_spec.rb
|
|
108
|
+
- spec/lib/cs/session_spec.rb
|
|
109
|
+
- spec/lib/cs/time_spec.rb
|
|
110
|
+
- spec/lib/cs_spec.rb
|
|
133
111
|
- spec/spec_helper.rb
|
|
134
112
|
- spec/support/spec_config.yml.sample
|
|
135
113
|
- spec/support/vcr.rb
|
|
136
114
|
homepage: https://github.com/senseobservationsystems/commonsense-ruby-lib
|
|
137
115
|
licenses: []
|
|
116
|
+
metadata: {}
|
|
138
117
|
post_install_message:
|
|
139
118
|
rdoc_options: []
|
|
140
119
|
require_paths:
|
|
141
120
|
- lib
|
|
142
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
|
-
none: false
|
|
144
122
|
requirements:
|
|
145
|
-
- -
|
|
123
|
+
- - '>='
|
|
146
124
|
- !ruby/object:Gem::Version
|
|
147
|
-
version:
|
|
125
|
+
version: 1.9.3
|
|
148
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
|
-
none: false
|
|
150
127
|
requirements:
|
|
151
|
-
- -
|
|
128
|
+
- - '>='
|
|
152
129
|
- !ruby/object:Gem::Version
|
|
153
|
-
version:
|
|
130
|
+
version: '0'
|
|
154
131
|
requirements: []
|
|
155
132
|
rubyforge_project:
|
|
156
|
-
rubygems_version: 1.
|
|
133
|
+
rubygems_version: 2.1.9
|
|
157
134
|
signing_key:
|
|
158
|
-
specification_version:
|
|
135
|
+
specification_version: 4
|
|
159
136
|
summary: Client library to communicate with CommonSense written in ruby
|
|
160
137
|
test_files:
|
|
161
138
|
- spec/features/sensor_data_management_spec.rb
|
|
162
139
|
- spec/features/sensor_management_spec.rb
|
|
163
140
|
- spec/features/user_management_spec.rb
|
|
164
|
-
- spec/lib/
|
|
165
|
-
- spec/lib/
|
|
166
|
-
- spec/lib/
|
|
167
|
-
- spec/lib/
|
|
168
|
-
- spec/lib/
|
|
169
|
-
- spec/lib/
|
|
170
|
-
- spec/lib/
|
|
171
|
-
- spec/lib/
|
|
141
|
+
- spec/lib/cs/collection/sensor_data_collection_spec.rb
|
|
142
|
+
- spec/lib/cs/end_point/group_spec.rb
|
|
143
|
+
- spec/lib/cs/end_point/sensor_data_spec.rb
|
|
144
|
+
- spec/lib/cs/end_point/sensor_spec.rb
|
|
145
|
+
- spec/lib/cs/end_point/user_spec.rb
|
|
146
|
+
- spec/lib/cs/end_point_spec.rb
|
|
147
|
+
- spec/lib/cs/relation/group_relation_spec.rb
|
|
148
|
+
- spec/lib/cs/relation/sensor_data_relation_spec.rb
|
|
149
|
+
- spec/lib/cs/relation/sensor_relation_spec.rb
|
|
150
|
+
- spec/lib/cs/relation/user_relation_spec.rb
|
|
151
|
+
- spec/lib/cs/relation_spec.rb
|
|
152
|
+
- spec/lib/cs/session_spec.rb
|
|
153
|
+
- spec/lib/cs/time_spec.rb
|
|
154
|
+
- spec/lib/cs_spec.rb
|
|
172
155
|
- spec/spec_helper.rb
|
|
173
156
|
- spec/support/spec_config.yml.sample
|
|
174
157
|
- spec/support/vcr.rb
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
module CommonSense
|
|
2
|
-
module EndPoint
|
|
3
|
-
class Group
|
|
4
|
-
include EndPoint
|
|
5
|
-
|
|
6
|
-
attr_accessor :id, :name, :description, :public
|
|
7
|
-
# get groups that user belongs to
|
|
8
|
-
def current_groups(options={})
|
|
9
|
-
res = session.get("/groups.json", options)
|
|
10
|
-
return nil unless res
|
|
11
|
-
|
|
12
|
-
group_list = res['groups']
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
groups =[]
|
|
16
|
-
if group_list
|
|
17
|
-
group_list.each do |group|
|
|
18
|
-
g = Group.new(group)
|
|
19
|
-
g.session = session
|
|
20
|
-
groups << g
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
groups
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
module CommonSense
|
|
2
|
-
module Relation
|
|
3
|
-
module Boolean; end
|
|
4
|
-
|
|
5
|
-
def check_session!
|
|
6
|
-
raise Error::SessionEmptyError unless @session
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def get_url
|
|
10
|
-
raise Error::NotImplementedError, "the class #{self.class} does not respond to 'get_url' "
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def get_data!(params={})
|
|
14
|
-
check_session!
|
|
15
|
-
options = get_options(params)
|
|
16
|
-
session.get(get_url, options)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def parameter(name)
|
|
20
|
-
self.instance_variable_get("@#{name}")
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def get_options(params)
|
|
24
|
-
options = {}
|
|
25
|
-
|
|
26
|
-
params.each do |k,v|
|
|
27
|
-
param_option = self.class.parameters[k]
|
|
28
|
-
|
|
29
|
-
value = v
|
|
30
|
-
value = process_param_integer(k, v, param_option) if param_option[:type] == Integer
|
|
31
|
-
value = process_param_boolean(k, v, param_option) if param_option[:type] == Boolean
|
|
32
|
-
value = process_param_string(k, v, param_option) if param_option[:type] == String
|
|
33
|
-
|
|
34
|
-
if value.kind_of?(Time)
|
|
35
|
-
value = value.to_f
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
options[k] = value
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
options
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def get_data(params={})
|
|
45
|
-
get_data!(params) rescue nil
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def all
|
|
49
|
-
self.to_a
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def count
|
|
53
|
-
check_session!
|
|
54
|
-
resource = get_single_resource
|
|
55
|
-
resource["total"] if resource
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def first
|
|
59
|
-
resource = get_single_resource
|
|
60
|
-
parse_single_resource(resource)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def last
|
|
64
|
-
total = count
|
|
65
|
-
resource = get_single_resource(page: count - 1)
|
|
66
|
-
parse_single_resource(resource)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def inspect
|
|
70
|
-
inspection = self.class.parameters.collect {|k,v| "#{k}: #{parameter(k).inspect}"}.compact.join(", ")
|
|
71
|
-
"#<#{self.class} #{inspection}>"
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def where(params={})
|
|
75
|
-
process_alias!(params)
|
|
76
|
-
params.keep_if {|k| self.class.parameters[k]}
|
|
77
|
-
|
|
78
|
-
params.each do |k,v|
|
|
79
|
-
param_option = self.class.parameters[k]
|
|
80
|
-
|
|
81
|
-
value = process_param_integer(k, v, param_option) if param_option[:type] == Integer
|
|
82
|
-
value = process_param_boolean(k, v, param_option) if param_option[:type] == Boolean
|
|
83
|
-
value = process_param_string(k, v, param_option) if param_option[:type] == String
|
|
84
|
-
value = process_param_time(k, v, param_option) if param_option[:type] == Time
|
|
85
|
-
|
|
86
|
-
self.send("#{k}=", value)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
self
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
module ClassMethod
|
|
93
|
-
def parameter(name, type, *args)
|
|
94
|
-
attr_accessor name
|
|
95
|
-
self.parameters ||= {}
|
|
96
|
-
|
|
97
|
-
param = {type: type}
|
|
98
|
-
unless args.empty?
|
|
99
|
-
param.merge!(args[0])
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
self.parameters[name] = param
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def parameter_alias(name, name_alias)
|
|
106
|
-
attr_accessor name
|
|
107
|
-
self.parameters_alias ||= {}
|
|
108
|
-
self.parameters_alias[name] = name_alias
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def parameters_alias=(parameters_alias)
|
|
112
|
-
@parameters_alias = parameters_alias
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def parameters_alias
|
|
116
|
-
@parameters_alias
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def parameters=(parameters)
|
|
120
|
-
@parameters = parameters
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def parameters
|
|
124
|
-
@parameters
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
protected
|
|
129
|
-
def self.included(base)
|
|
130
|
-
base.send(:include, Enumerable)
|
|
131
|
-
base.extend(ClassMethod)
|
|
132
|
-
base.class_eval do
|
|
133
|
-
attr_accessor :session
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def parse_single_resource(resource)
|
|
138
|
-
raise Error::NotImplementedError, "parse_single_resource is not implemented for class : #{self.class}"
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def get_single_resource(params={})
|
|
142
|
-
raise Error::NotImplementedError, "get_single_resource is not implemented for class : #{self.class}"
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def process_alias!(params)
|
|
146
|
-
return if self.class.parameters_alias.nil?
|
|
147
|
-
|
|
148
|
-
aliases = params.select { |param| self.class.parameters_alias.include?(param) }
|
|
149
|
-
aliases.each do |alias_to, value|
|
|
150
|
-
alias_for = self.class.parameters_alias[alias_to]
|
|
151
|
-
params[alias_for] = value
|
|
152
|
-
params.delete(alias_to)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def process_valid_values(name, value, param_option)
|
|
158
|
-
return value unless param_option[:valid_values]
|
|
159
|
-
|
|
160
|
-
if param_option[:valid_values].include?(value)
|
|
161
|
-
value
|
|
162
|
-
elsif !value.nil?
|
|
163
|
-
raise ArgumentError, "Invalid value for parameter '#{name}'"
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def process_default_value(name, value, param_option)
|
|
169
|
-
value.nil? ? param_option[:default] : value
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def process_param_integer(name, value, param_option)
|
|
173
|
-
if value.kind_of?(Integer)
|
|
174
|
-
retval = value
|
|
175
|
-
retval = process_valid_values(name, value, param_option) if param_option[:valid_values]
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
retval = process_default_value(name, retval, param_option)
|
|
179
|
-
|
|
180
|
-
if !value.nil? && !value.kind_of?(Integer)
|
|
181
|
-
raise ArgumentError, "Received non Integer value for parameter '#{name}'"
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
retval
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def process_param_boolean(name, value, param_option)
|
|
188
|
-
retval = nil
|
|
189
|
-
|
|
190
|
-
if value.nil?
|
|
191
|
-
retval = param_option[:default] ? param_option[:default] : nil
|
|
192
|
-
elsif [0, "0", false, "false"].include?(value)
|
|
193
|
-
retval = 0
|
|
194
|
-
else
|
|
195
|
-
retval = 1
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
retval
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def process_param_string(name, value, param_option)
|
|
202
|
-
retval = value
|
|
203
|
-
retval = process_valid_values(name, value, param_option) if param_option[:valid_values]
|
|
204
|
-
retval = process_default_value(name, retval, param_option)
|
|
205
|
-
|
|
206
|
-
retval
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
# This method prosess assignment for properties with datatype Time.
|
|
210
|
-
# There are 3 type that is valid for this properties:
|
|
211
|
-
#
|
|
212
|
-
# * **Time**
|
|
213
|
-
# * **Numeric**. It will convert this to ruby {Time}
|
|
214
|
-
# * **Obejct that respond to #to_time** and return ruby {Time}
|
|
215
|
-
#
|
|
216
|
-
def process_param_time(name, value, param_option)
|
|
217
|
-
retval = value
|
|
218
|
-
|
|
219
|
-
if !value.nil? && !value.kind_of?(Time)
|
|
220
|
-
if value.kind_of?(Numeric)
|
|
221
|
-
retval = Time.at(retval)
|
|
222
|
-
else
|
|
223
|
-
retval = value.to_time
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
retval = process_default_value(name, retval, param_option)
|
|
228
|
-
retval = process_valid_values(name, value, param_option) if param_option[:valid_values]
|
|
229
|
-
|
|
230
|
-
retval
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
end
|