testdroid-api-client 0.2.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +5 -0
- data/.travis.yml +11 -0
- data/Gemfile.lock +65 -37
- data/README.md +30 -41
- data/lib/testdroid-api-client.rb +25 -9
- data/lib/testdroid-api-filter-builder.rb +145 -0
- data/lib/testdroid_api/admin.rb +25 -0
- data/lib/testdroid_api/admin_device_models.rb +10 -0
- data/lib/testdroid_api/admin_device_problems.rb +9 -0
- data/lib/testdroid_api/admin_device_statuses.rb +12 -0
- data/lib/testdroid_api/admin_devices.rb +10 -0
- data/lib/testdroid_api/apikey_client.rb +120 -0
- data/lib/testdroid_api/client.rb +158 -123
- data/lib/testdroid_api/cloud_list_resource.rb +69 -70
- data/lib/testdroid_api/cloud_resource.rb +83 -71
- data/lib/testdroid_api/device_groups.rb +9 -9
- data/lib/testdroid_api/device_session_connections.rb +10 -0
- data/lib/testdroid_api/device_sessions.rb +21 -12
- data/lib/testdroid_api/devices.rb +8 -11
- data/lib/testdroid_api/files.rb +60 -58
- data/lib/testdroid_api/frameworks.rb +11 -0
- data/lib/testdroid_api/label_groups.rb +9 -10
- data/lib/testdroid_api/labels.rb +9 -10
- data/lib/testdroid_api/projects.rb +9 -16
- data/lib/testdroid_api/properties.rb +13 -0
- data/lib/testdroid_api/runs.rb +22 -12
- data/lib/testdroid_api/services.rb +18 -0
- data/lib/testdroid_api/user.rb +11 -6
- data/sample/BitbarSampleApp.apk +0 -0
- data/sample/BitbarSampleAppTest.apk +0 -0
- data/sample/sample.rb +23 -23
- data/spec/client_spec.rb +7 -7
- data/spec/device_groups_spec.rb +30 -17
- data/spec/files_spec.rb +40 -20
- data/spec/fixtures/apk.apk +0 -0
- data/spec/fixtures/cassettes/device_groups_authorize.json +1 -0
- data/spec/fixtures/cassettes/device_groups_create.json +1 -0
- data/spec/fixtures/cassettes/device_groups_delete.json +1 -0
- data/spec/fixtures/cassettes/device_groups_get_all.json +1 -0
- data/spec/fixtures/cassettes/device_groups_get_one.json +1 -0
- data/spec/fixtures/cassettes/files_authorize.json +1 -0
- data/spec/fixtures/cassettes/files_delete.json +1 -0
- data/spec/fixtures/cassettes/files_get_all.json +1 -0
- data/spec/fixtures/cassettes/files_get_one.json +1 -0
- data/spec/fixtures/cassettes/files_upload.json +1 -0
- data/spec/fixtures/cassettes/files_upload_with_wait.json +1 -0
- data/spec/fixtures/cassettes/label_groups_authorize.json +1 -0
- data/spec/fixtures/cassettes/label_groups_create.json +1 -0
- data/spec/fixtures/cassettes/label_groups_delete.json +1 -0
- data/spec/fixtures/cassettes/label_groups_get_all.json +1 -0
- data/spec/fixtures/cassettes/label_groups_get_labels.json +1 -0
- data/spec/fixtures/cassettes/label_groups_get_one.json +1 -0
- data/spec/fixtures/cassettes/projects_authorize.json +1 -0
- data/spec/fixtures/cassettes/projects_create.json +1 -0
- data/spec/fixtures/cassettes/projects_delete.json +1 -0
- data/spec/fixtures/cassettes/projects_get_all.json +1 -0
- data/spec/fixtures/cassettes/projects_get_one.json +1 -0
- data/spec/fixtures/cassettes/runs_abort_run.json +1 -0
- data/spec/fixtures/cassettes/runs_authorize.json +1 -0
- data/spec/fixtures/cassettes/runs_get_project_runs.json +1 -0
- data/spec/fixtures/cassettes/runs_start_run.json +1 -0
- data/spec/fixtures/data.txt +1 -0
- data/spec/fixtures/data2.txt +1 -0
- data/spec/label_groups_spec.rb +35 -42
- data/spec/projects_spec.rb +41 -0
- data/spec/runs_spec.rb +41 -0
- data/spec/spec_helper.rb +3 -4
- data/testdroid-api-client.gemspec +13 -11
- metadata +92 -134
- data/lib/testdroid_api/config.rb +0 -7
- data/lib/testdroid_api/device_runs.rb +0 -20
- data/lib/testdroid_api/file_sets.rb +0 -12
- data/spec/device_runs_spec.rb +0 -25
- data/spec/file_sets_spec.rb +0 -47
- data/spec/fixtures/cassettes/dg_all_device_groups.json +0 -1
- data/spec/fixtures/cassettes/dg_device_group_4165.json +0 -1
- data/spec/fixtures/cassettes/dg_oauth2_auth_device_groups.json +0 -1
- data/spec/fixtures/cassettes/dr_all_run_171221_device_runs.json +0 -1
- data/spec/fixtures/cassettes/dr_device_run_33044722.json +0 -1
- data/spec/fixtures/cassettes/dr_oauth2_auth_device_runs.json +0 -1
- data/spec/fixtures/cassettes/dr_run_33044722_device_runs.json +0 -1
- data/spec/fixtures/cassettes/f_add_file_set.json +0 -1
- data/spec/fixtures/cassettes/f_android_app_file.json +0 -1
- data/spec/fixtures/cassettes/f_file_sets.json +0 -1
- data/spec/fixtures/cassettes/f_oauth2_auth_files.json +0 -1
- data/spec/fixtures/cassettes/f_upload_files.json +0 -1
- data/spec/fixtures/cassettes/fs_add_file_set.json +0 -1
- data/spec/fixtures/cassettes/fs_add_file_to_fileset.json +0 -1
- data/spec/fixtures/cassettes/fs_delete_file_set.json +0 -1
- data/spec/fixtures/cassettes/fs_file_sets.json +0 -1
- data/spec/fixtures/cassettes/fs_get_file_set.json +0 -1
- data/spec/fixtures/cassettes/fs_oauth2_auth_files.json +0 -1
- data/spec/fixtures/cassettes/fs_update_file_set.json +0 -1
- data/spec/fixtures/cassettes/fu_oauth2_auth_files.json +0 -1
- data/spec/fixtures/cassettes/lg_all_label_groups.json +0 -1
- data/spec/fixtures/cassettes/lg_get_resources_by_label.json +0 -1
- data/spec/fixtures/cassettes/lg_label_group_1058800.json +0 -1
- data/spec/fixtures/cassettes/lg_labels_of_group_1058800.json +0 -1
- data/spec/fixtures/cassettes/lg_oauth2_auth_label_groups.json +0 -1
- data/spec/fixtures/cassettes/p_all_projects.json +0 -1
- data/spec/fixtures/cassettes/p_create_project.json +0 -1
- data/spec/fixtures/cassettes/p_get_run_devices.json +0 -1
- data/spec/fixtures/cassettes/p_oauth2_auth.json +0 -1
- data/spec/fixtures/cassettes/p_oauth2_local.json +0 -1
- data/spec/fixtures/cassettes/p_project_id_33029366.json +0 -1
- data/spec/fixtures/cassettes/p_run_project.json +0 -1
- data/spec/fixtures/cassettes/pc_get_current.json +0 -1
- data/spec/fixtures/cassettes/pc_oauth2_auth_config.json +0 -1
- data/spec/fixtures/cassettes/pc_set_current_config.json +0 -1
- data/spec/fixtures/cassettes/pc_validate_config.json +0 -1
- data/spec/fixtures/cassettes/r_all_project_33029366_runs.json +0 -1
- data/spec/fixtures/cassettes/r_delete_test_run.json +0 -1
- data/spec/fixtures/cassettes/r_oauth2_auth_runs.json +0 -1
- data/spec/fixtures/cassettes/r_run_171221.json +0 -1
- data/spec/fixtures/cassettes/r_run_project.json +0 -1
- data/spec/fixtures/cassettes/upload_files.json +0 -1
- data/spec/fixtures/project.json +0 -8
- data/spec/project_config_spec.rb +0 -36
- data/spec/project_spec.rb +0 -56
- data/spec/run_spec.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1602073cb6328a9c2b0896a2cb6fd7a4ea55020b7f4b56fba3105c7040df67e9
|
4
|
+
data.tar.gz: 512d7c0359a780a73286ebad2723927d5ba0620c584ca19889f0c2513f62a3ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2035e8b4bc7011bb5e21beda9230effc74575728fe408d2919e6567094fb33fdeb18e70bc62f86973686853a239170124e3d7fcac29e153b8eedc419183b88ad
|
7
|
+
data.tar.gz: a400bed6ad4e1d725533006fef57d9741038b7f6810e77c7ef0bf1621fb8cbcc9b0758dd4ea2bb1f4e2e36eb35ee58dad6e2ffc7784a4658cd6284b50530b9e5
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
before_install:
|
2
|
+
- yes | gem update --system --force
|
3
|
+
- gem install bundler
|
4
|
+
deploy:
|
5
|
+
provider: rubygems
|
6
|
+
api_key:
|
7
|
+
secure: ZFKOZzwgB1s4/vD9BDb7lFWCO7xXP3ikG2DBZSdASii5iHM46X9ox2wt8h2XZd9RFKe9pyenJP9RsXmRVGanFgZ0wGu+oveWfA7oIKp6Eb6pNOBPs8MG0ZifAGUc7Ih1JUMuvNuOPRJ+QGc5FwPsu0EoxZn3gQCZNqdMNBRe17o=
|
8
|
+
on:
|
9
|
+
tags: true
|
10
|
+
gem: testdroid-api-client
|
11
|
+
script: bundle exec rspec
|
data/Gemfile.lock
CHANGED
@@ -1,62 +1,90 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
testdroid-api-client (0.
|
5
|
-
|
6
|
-
|
4
|
+
testdroid-api-client (0.5.0)
|
5
|
+
deep_merge (~> 1.2)
|
6
|
+
faraday (~> 0.17, >= 0.17)
|
7
|
+
oauth2 (~> 1.4)
|
8
|
+
rest-client (~> 2.1)
|
7
9
|
|
8
10
|
GEM
|
9
11
|
remote: https://rubygems.org/
|
10
12
|
specs:
|
11
|
-
addressable (2.
|
12
|
-
|
13
|
-
|
13
|
+
addressable (2.7.0)
|
14
|
+
public_suffix (>= 2.0.2, < 5.0)
|
15
|
+
bump (0.8.0)
|
16
|
+
crack (0.4.3)
|
14
17
|
safe_yaml (~> 1.0.0)
|
18
|
+
deep_merge (1.2.1)
|
15
19
|
diff-lcs (1.2.5)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
domain_name (0.5.20190701)
|
21
|
+
unf (>= 0.0.5, < 1.0.0)
|
22
|
+
faraday (0.17.3)
|
23
|
+
multipart-post (>= 1.2, < 3)
|
24
|
+
hashdiff (1.0.0)
|
25
|
+
http-accept (1.7.0)
|
26
|
+
http-cookie (1.0.3)
|
27
|
+
domain_name (~> 0.5)
|
28
|
+
jwt (2.2.1)
|
29
|
+
mime-types (3.3.1)
|
30
|
+
mime-types-data (~> 3.2015)
|
31
|
+
mime-types-data (3.2020.0512)
|
32
|
+
multi_json (1.15.0)
|
33
|
+
multi_xml (0.6.0)
|
34
|
+
multipart-post (2.1.1)
|
35
|
+
netrc (0.11.0)
|
36
|
+
oauth2 (1.4.4)
|
37
|
+
faraday (>= 0.8, < 2.0)
|
38
|
+
jwt (>= 1.0, < 3.0)
|
25
39
|
multi_json (~> 1.3)
|
26
40
|
multi_xml (~> 0.5)
|
27
|
-
rack (
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
41
|
+
rack (>= 1.2, < 3)
|
42
|
+
public_suffix (4.0.1)
|
43
|
+
rack (2.2.3)
|
44
|
+
rake (12.3.3)
|
45
|
+
rest-client (2.1.0)
|
46
|
+
http-accept (>= 1.7.0, < 2.0)
|
47
|
+
http-cookie (>= 1.0.2, < 2.0)
|
48
|
+
mime-types (>= 1.16, < 4.0)
|
49
|
+
netrc (~> 0.8)
|
50
|
+
rspec (3.5.0)
|
51
|
+
rspec-core (~> 3.5.0)
|
52
|
+
rspec-expectations (~> 3.5.0)
|
53
|
+
rspec-mocks (~> 3.5.0)
|
34
54
|
rspec-collection_matchers (1.1.2)
|
35
55
|
rspec-expectations (>= 2.99.0.beta1)
|
36
|
-
rspec-core (3.
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-expectations (3.
|
56
|
+
rspec-core (3.5.4)
|
57
|
+
rspec-support (~> 3.5.0)
|
58
|
+
rspec-expectations (3.5.0)
|
39
59
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-mocks (3.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
60
|
+
rspec-support (~> 3.5.0)
|
61
|
+
rspec-mocks (3.5.0)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.5.0)
|
64
|
+
rspec-support (3.5.0)
|
65
|
+
safe_yaml (1.0.5)
|
66
|
+
unf (0.1.4)
|
67
|
+
unf_ext
|
68
|
+
unf_ext (0.0.7.7)
|
69
|
+
vcr (5.0.0)
|
70
|
+
webmock (3.7.6)
|
47
71
|
addressable (>= 2.3.6)
|
48
72
|
crack (>= 0.3.2)
|
49
|
-
|
73
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
74
|
+
yard (0.9.20)
|
50
75
|
|
51
76
|
PLATFORMS
|
52
77
|
ruby
|
53
78
|
|
54
79
|
DEPENDENCIES
|
55
|
-
bump (~> 0.
|
80
|
+
bump (~> 0.8)
|
56
81
|
rake
|
57
82
|
rspec
|
58
83
|
rspec-collection_matchers
|
59
84
|
testdroid-api-client!
|
60
|
-
vcr (~>
|
61
|
-
webmock (~>
|
62
|
-
yard (~> 0.
|
85
|
+
vcr (~> 5.0)
|
86
|
+
webmock (~> 3.7)
|
87
|
+
yard (~> 0.9.20)
|
88
|
+
|
89
|
+
BUNDLED WITH
|
90
|
+
2.0.2
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/testdroid-api-client.svg)](https://badge.fury.io/rb/testdroid-api-client)
|
2
|
+
[![Build Status](https://travis-ci.org/bitbar/testdroid-api-client-ruby.svg?branch=master)](https://travis-ci.org/bitbar/testdroid-api-client-ruby)
|
3
|
+
|
3
4
|
|
5
|
+
Testdroid API Client for Ruby
|
6
|
+
=============================
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -12,17 +15,20 @@ gem "testdroid-api-client"
|
|
12
15
|
```bash
|
13
16
|
> bundle install
|
14
17
|
```
|
18
|
+
|
15
19
|
## Sample client usage - Authenticate
|
16
20
|
```ruby
|
17
21
|
require 'testdroid-api-client'
|
18
22
|
|
19
23
|
client = TestdroidAPI::Client.new('admin@localhost', 'admin')
|
20
24
|
```
|
25
|
+
|
21
26
|
## Sample usage - get projects
|
22
27
|
```ruby
|
23
28
|
@user = client.authorize
|
24
29
|
projects = @user.projects.list
|
25
30
|
```
|
31
|
+
|
26
32
|
## Get project by id
|
27
33
|
```ruby
|
28
34
|
project_id = 123
|
@@ -33,61 +39,44 @@ p "Project name #{project123.name}"
|
|
33
39
|
|
34
40
|
## Get project by name
|
35
41
|
```ruby
|
36
|
-
|
42
|
+
project = @user.projects.list({:filter => "s_name_eq_MyProject"})[0]
|
37
43
|
```
|
38
44
|
|
39
|
-
|
40
|
-
## Start project
|
45
|
+
## Get available frameworks
|
41
46
|
```ruby
|
42
|
-
|
47
|
+
frameworks = @user.available_frameworks.list
|
43
48
|
```
|
44
49
|
|
45
|
-
##
|
46
|
-
```ruby
|
47
|
-
p "Project state #{test_run.state}"
|
48
|
-
|
49
|
-
```
|
50
|
-
## Download all logs from test run
|
50
|
+
## Find specific framework
|
51
51
|
```ruby
|
52
|
-
|
52
|
+
framework = @user.available_frameworks.list({:filter => "s_osType_eq_ANDROID;s_name_like_%Instrumentation"})[0]
|
53
53
|
```
|
54
54
|
|
55
|
-
##
|
55
|
+
## Upload files
|
56
56
|
```ruby
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
os_v2_1 = client.label_groups.get(lg_android_versions.id).labels.list.detect {|l| l.display_name.casecmp("2.1") == 0 }
|
61
|
-
|
62
|
-
#get all devices with android os level 2.1
|
63
|
-
devices = client.label_groups.get(lg_android_versions.id).labels.get(os_v2_1.id).devices
|
64
|
-
#get spefici device from devices list
|
65
|
-
lenovo_a820 = devices.list.detect {|d| d.display_name == "Lenovo A820"}
|
66
|
-
|
57
|
+
file_app = @user.files.upload(File.join(File.dirname(__FILE__), "BitbarSampleApp.apk"))
|
58
|
+
file_test = @user.files.upload(File.join(File.dirname(__FILE__), "BitbarSampleAppTest.apk"))
|
67
59
|
```
|
68
60
|
|
69
|
-
|
70
|
-
Device Sessions
|
71
|
-
----
|
61
|
+
## Start test run
|
72
62
|
```ruby
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
#release device session:
|
77
|
-
device_session.release()
|
63
|
+
test_run = @user.runs.create("{\"osType\": \"ANDROID\", \"projectId\": #{project.id}, \"frameworkId\":#{framework_id},
|
64
|
+
\"deviceIds\": #{id_list}, \"files\": [{\"id\": #{file_app.id}, \"action\": \"INSTALL\" },
|
65
|
+
{\"id\": #{file_test.id}, \"action\": \"RUN_TEST\" }]}")
|
78
66
|
|
67
|
+
#See full list of params: https://docs.bitbar.com/testing/api/tests/index.html#details-about-the-configuration-fields
|
79
68
|
```
|
80
69
|
|
81
|
-
|
82
|
-
Project configuration
|
83
|
-
----
|
70
|
+
## Download all files from test run
|
84
71
|
```ruby
|
85
|
-
|
86
|
-
android_project = @user.projects.list.detect {|project| project.name.casecmp("Android Project") == 0 }
|
87
|
-
android_project.config.update({:params => {'instrumentationRunner' => 'abc'}})
|
88
|
-
#See full list of params: http://docs.testdroid.com/_pages/client.html#update-project-config
|
89
|
-
|
72
|
+
test_run.device_sessions.list({:limit => 0}).each { |ds| ds.download_all_files("YOUR_PATH") }
|
90
73
|
```
|
91
74
|
|
75
|
+
## Get all input files
|
76
|
+
```ruby
|
77
|
+
files = @user.files
|
78
|
+
files.list({:limit => 40,:filter => "s_direction_eq_INPUT"}).each {
|
79
|
+
|f| puts "File id: #{f.id} name: #{f.name}" }
|
80
|
+
```
|
92
81
|
|
93
|
-
See https://cloud.
|
82
|
+
See https://cloud.bitbar.com/cloud/swagger-ui.html for more details about API V2
|
data/lib/testdroid-api-client.rb
CHANGED
@@ -1,20 +1,36 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
require 'json'
|
3
|
+
require 'logger'
|
4
|
+
require 'rest-client'
|
5
|
+
require 'deep_merge'
|
6
|
+
require 'oauth2'
|
7
|
+
require 'timeout'
|
8
|
+
require 'set'
|
9
|
+
|
3
10
|
require 'testdroid_api/client'
|
11
|
+
require 'testdroid_api/apikey_client'
|
12
|
+
|
4
13
|
require 'testdroid_api/cloud_resource'
|
5
14
|
require 'testdroid_api/cloud_list_resource'
|
15
|
+
|
6
16
|
require 'testdroid_api/user'
|
7
|
-
require 'testdroid_api/
|
17
|
+
require 'testdroid_api/frameworks'
|
8
18
|
require 'testdroid_api/projects'
|
9
19
|
require 'testdroid_api/runs'
|
10
|
-
require 'testdroid_api/device_runs'
|
11
|
-
require 'testdroid_api/label_groups'
|
12
|
-
require 'testdroid_api/labels'
|
13
|
-
require 'testdroid_api/files'
|
14
20
|
require 'testdroid_api/devices'
|
21
|
+
require 'testdroid_api/device_groups'
|
15
22
|
require 'testdroid_api/device_sessions'
|
16
|
-
require 'testdroid_api/
|
17
|
-
require 'testdroid_api/
|
23
|
+
require 'testdroid_api/device_session_connections'
|
24
|
+
require 'testdroid_api/labels'
|
25
|
+
require 'testdroid_api/label_groups'
|
26
|
+
require 'testdroid_api/files'
|
27
|
+
require 'testdroid_api/properties'
|
28
|
+
require 'testdroid_api/services'
|
18
29
|
|
19
|
-
require '
|
20
|
-
require '
|
30
|
+
require 'testdroid_api/admin'
|
31
|
+
require 'testdroid_api/admin_devices'
|
32
|
+
require 'testdroid_api/admin_device_models'
|
33
|
+
require 'testdroid_api/admin_device_statuses'
|
34
|
+
require 'testdroid_api/admin_device_problems'
|
35
|
+
|
36
|
+
require 'testdroid-api-filter-builder'
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module TestdroidAPI
|
2
|
+
class FilterBuilder
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def check_type(subject)
|
10
|
+
if !!subject == subject # check if it's boolean
|
11
|
+
return 'b'
|
12
|
+
elsif (/^[0-9]{13}$/ =~ subject) != nil # check if it's timestamp
|
13
|
+
return 'd'
|
14
|
+
elsif (/^[0-9]+(?:\.[0-9]+)?$/ =~ subject) != nil # check if it's number
|
15
|
+
return 'n'
|
16
|
+
else
|
17
|
+
return 's'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def add(name, value, operand, type, check_nil=false)
|
22
|
+
unless value.is_a? Array
|
23
|
+
value = [value]
|
24
|
+
end
|
25
|
+
|
26
|
+
if value.length == 0
|
27
|
+
return self
|
28
|
+
end
|
29
|
+
|
30
|
+
# auto-convert
|
31
|
+
value.each_with_index do |val, index|
|
32
|
+
if val.is_a? Time
|
33
|
+
value[index] = val.to_i.to_s
|
34
|
+
elsif val.is_a? Fixnum
|
35
|
+
value[index] = val.to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# auto-check type
|
40
|
+
if type.nil?
|
41
|
+
value.each do |val|
|
42
|
+
next if val.nil?
|
43
|
+
type = check_type(val)
|
44
|
+
break
|
45
|
+
end
|
46
|
+
|
47
|
+
if operand == 'in'
|
48
|
+
type = 'l'+type
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# check nil existence
|
53
|
+
if check_nil
|
54
|
+
is_nil = false
|
55
|
+
value.each do |val|
|
56
|
+
next unless val.nil?
|
57
|
+
is_nil = true
|
58
|
+
end
|
59
|
+
|
60
|
+
if is_nil
|
61
|
+
value = value.select { |item| !item.nil? }
|
62
|
+
operand += 'ornull'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# add filter
|
67
|
+
@filters.push(FilterItem.new(name, value, operand, type))
|
68
|
+
end
|
69
|
+
|
70
|
+
public
|
71
|
+
def gt(name, value)
|
72
|
+
add(name, value, 'gt', 'n')
|
73
|
+
end
|
74
|
+
|
75
|
+
def lt(name, value)
|
76
|
+
add(name, value, 'lt', 'n')
|
77
|
+
end
|
78
|
+
|
79
|
+
def after(name, value)
|
80
|
+
add(name, value, 'after', 'd', true)
|
81
|
+
end
|
82
|
+
|
83
|
+
def before(name, value)
|
84
|
+
add(name, value, 'before', 'd', true)
|
85
|
+
end
|
86
|
+
|
87
|
+
def on(name, value)
|
88
|
+
add(name, value, 'on', 'd')
|
89
|
+
end
|
90
|
+
|
91
|
+
def eq(name, value)
|
92
|
+
add(name, value, 'eq', nil)
|
93
|
+
end
|
94
|
+
|
95
|
+
def contains(name, value)
|
96
|
+
add(name, value, 'contains', 's')
|
97
|
+
end
|
98
|
+
|
99
|
+
def like(name, value)
|
100
|
+
nil # TODO (waiting for BE support)
|
101
|
+
end
|
102
|
+
|
103
|
+
def empty(name, value)
|
104
|
+
nil # TODO (waiting for BE support)
|
105
|
+
end
|
106
|
+
|
107
|
+
def isnull(name, operand)
|
108
|
+
add(name, nil, 'isnull', operand)
|
109
|
+
end
|
110
|
+
|
111
|
+
def in(name, value)
|
112
|
+
add(name, value, 'in', nil, true)
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
def to_s
|
117
|
+
parts = []
|
118
|
+
@filters.each do |filter|
|
119
|
+
val = ''
|
120
|
+
if filter.value.length > 1 or not filter.value.nil?
|
121
|
+
val = '_' + filter.values
|
122
|
+
end
|
123
|
+
parts.push( filter.to_s + val )
|
124
|
+
end
|
125
|
+
parts.join(';')
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
class FilterItem
|
131
|
+
attr_accessor :name, :value, :operand, :type
|
132
|
+
|
133
|
+
def initialize(name, value, operand, type)
|
134
|
+
@name, @value, @operand, @type = name, value, operand, type
|
135
|
+
end
|
136
|
+
|
137
|
+
def values
|
138
|
+
@value.join('|')
|
139
|
+
end
|
140
|
+
|
141
|
+
def to_s
|
142
|
+
"#{@type}_#{@name}_#{@operand}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|