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.
Files changed (121) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile.lock +65 -37
  5. data/README.md +30 -41
  6. data/lib/testdroid-api-client.rb +25 -9
  7. data/lib/testdroid-api-filter-builder.rb +145 -0
  8. data/lib/testdroid_api/admin.rb +25 -0
  9. data/lib/testdroid_api/admin_device_models.rb +10 -0
  10. data/lib/testdroid_api/admin_device_problems.rb +9 -0
  11. data/lib/testdroid_api/admin_device_statuses.rb +12 -0
  12. data/lib/testdroid_api/admin_devices.rb +10 -0
  13. data/lib/testdroid_api/apikey_client.rb +120 -0
  14. data/lib/testdroid_api/client.rb +158 -123
  15. data/lib/testdroid_api/cloud_list_resource.rb +69 -70
  16. data/lib/testdroid_api/cloud_resource.rb +83 -71
  17. data/lib/testdroid_api/device_groups.rb +9 -9
  18. data/lib/testdroid_api/device_session_connections.rb +10 -0
  19. data/lib/testdroid_api/device_sessions.rb +21 -12
  20. data/lib/testdroid_api/devices.rb +8 -11
  21. data/lib/testdroid_api/files.rb +60 -58
  22. data/lib/testdroid_api/frameworks.rb +11 -0
  23. data/lib/testdroid_api/label_groups.rb +9 -10
  24. data/lib/testdroid_api/labels.rb +9 -10
  25. data/lib/testdroid_api/projects.rb +9 -16
  26. data/lib/testdroid_api/properties.rb +13 -0
  27. data/lib/testdroid_api/runs.rb +22 -12
  28. data/lib/testdroid_api/services.rb +18 -0
  29. data/lib/testdroid_api/user.rb +11 -6
  30. data/sample/BitbarSampleApp.apk +0 -0
  31. data/sample/BitbarSampleAppTest.apk +0 -0
  32. data/sample/sample.rb +23 -23
  33. data/spec/client_spec.rb +7 -7
  34. data/spec/device_groups_spec.rb +30 -17
  35. data/spec/files_spec.rb +40 -20
  36. data/spec/fixtures/apk.apk +0 -0
  37. data/spec/fixtures/cassettes/device_groups_authorize.json +1 -0
  38. data/spec/fixtures/cassettes/device_groups_create.json +1 -0
  39. data/spec/fixtures/cassettes/device_groups_delete.json +1 -0
  40. data/spec/fixtures/cassettes/device_groups_get_all.json +1 -0
  41. data/spec/fixtures/cassettes/device_groups_get_one.json +1 -0
  42. data/spec/fixtures/cassettes/files_authorize.json +1 -0
  43. data/spec/fixtures/cassettes/files_delete.json +1 -0
  44. data/spec/fixtures/cassettes/files_get_all.json +1 -0
  45. data/spec/fixtures/cassettes/files_get_one.json +1 -0
  46. data/spec/fixtures/cassettes/files_upload.json +1 -0
  47. data/spec/fixtures/cassettes/files_upload_with_wait.json +1 -0
  48. data/spec/fixtures/cassettes/label_groups_authorize.json +1 -0
  49. data/spec/fixtures/cassettes/label_groups_create.json +1 -0
  50. data/spec/fixtures/cassettes/label_groups_delete.json +1 -0
  51. data/spec/fixtures/cassettes/label_groups_get_all.json +1 -0
  52. data/spec/fixtures/cassettes/label_groups_get_labels.json +1 -0
  53. data/spec/fixtures/cassettes/label_groups_get_one.json +1 -0
  54. data/spec/fixtures/cassettes/projects_authorize.json +1 -0
  55. data/spec/fixtures/cassettes/projects_create.json +1 -0
  56. data/spec/fixtures/cassettes/projects_delete.json +1 -0
  57. data/spec/fixtures/cassettes/projects_get_all.json +1 -0
  58. data/spec/fixtures/cassettes/projects_get_one.json +1 -0
  59. data/spec/fixtures/cassettes/runs_abort_run.json +1 -0
  60. data/spec/fixtures/cassettes/runs_authorize.json +1 -0
  61. data/spec/fixtures/cassettes/runs_get_project_runs.json +1 -0
  62. data/spec/fixtures/cassettes/runs_start_run.json +1 -0
  63. data/spec/fixtures/data.txt +1 -0
  64. data/spec/fixtures/data2.txt +1 -0
  65. data/spec/label_groups_spec.rb +35 -42
  66. data/spec/projects_spec.rb +41 -0
  67. data/spec/runs_spec.rb +41 -0
  68. data/spec/spec_helper.rb +3 -4
  69. data/testdroid-api-client.gemspec +13 -11
  70. metadata +92 -134
  71. data/lib/testdroid_api/config.rb +0 -7
  72. data/lib/testdroid_api/device_runs.rb +0 -20
  73. data/lib/testdroid_api/file_sets.rb +0 -12
  74. data/spec/device_runs_spec.rb +0 -25
  75. data/spec/file_sets_spec.rb +0 -47
  76. data/spec/fixtures/cassettes/dg_all_device_groups.json +0 -1
  77. data/spec/fixtures/cassettes/dg_device_group_4165.json +0 -1
  78. data/spec/fixtures/cassettes/dg_oauth2_auth_device_groups.json +0 -1
  79. data/spec/fixtures/cassettes/dr_all_run_171221_device_runs.json +0 -1
  80. data/spec/fixtures/cassettes/dr_device_run_33044722.json +0 -1
  81. data/spec/fixtures/cassettes/dr_oauth2_auth_device_runs.json +0 -1
  82. data/spec/fixtures/cassettes/dr_run_33044722_device_runs.json +0 -1
  83. data/spec/fixtures/cassettes/f_add_file_set.json +0 -1
  84. data/spec/fixtures/cassettes/f_android_app_file.json +0 -1
  85. data/spec/fixtures/cassettes/f_file_sets.json +0 -1
  86. data/spec/fixtures/cassettes/f_oauth2_auth_files.json +0 -1
  87. data/spec/fixtures/cassettes/f_upload_files.json +0 -1
  88. data/spec/fixtures/cassettes/fs_add_file_set.json +0 -1
  89. data/spec/fixtures/cassettes/fs_add_file_to_fileset.json +0 -1
  90. data/spec/fixtures/cassettes/fs_delete_file_set.json +0 -1
  91. data/spec/fixtures/cassettes/fs_file_sets.json +0 -1
  92. data/spec/fixtures/cassettes/fs_get_file_set.json +0 -1
  93. data/spec/fixtures/cassettes/fs_oauth2_auth_files.json +0 -1
  94. data/spec/fixtures/cassettes/fs_update_file_set.json +0 -1
  95. data/spec/fixtures/cassettes/fu_oauth2_auth_files.json +0 -1
  96. data/spec/fixtures/cassettes/lg_all_label_groups.json +0 -1
  97. data/spec/fixtures/cassettes/lg_get_resources_by_label.json +0 -1
  98. data/spec/fixtures/cassettes/lg_label_group_1058800.json +0 -1
  99. data/spec/fixtures/cassettes/lg_labels_of_group_1058800.json +0 -1
  100. data/spec/fixtures/cassettes/lg_oauth2_auth_label_groups.json +0 -1
  101. data/spec/fixtures/cassettes/p_all_projects.json +0 -1
  102. data/spec/fixtures/cassettes/p_create_project.json +0 -1
  103. data/spec/fixtures/cassettes/p_get_run_devices.json +0 -1
  104. data/spec/fixtures/cassettes/p_oauth2_auth.json +0 -1
  105. data/spec/fixtures/cassettes/p_oauth2_local.json +0 -1
  106. data/spec/fixtures/cassettes/p_project_id_33029366.json +0 -1
  107. data/spec/fixtures/cassettes/p_run_project.json +0 -1
  108. data/spec/fixtures/cassettes/pc_get_current.json +0 -1
  109. data/spec/fixtures/cassettes/pc_oauth2_auth_config.json +0 -1
  110. data/spec/fixtures/cassettes/pc_set_current_config.json +0 -1
  111. data/spec/fixtures/cassettes/pc_validate_config.json +0 -1
  112. data/spec/fixtures/cassettes/r_all_project_33029366_runs.json +0 -1
  113. data/spec/fixtures/cassettes/r_delete_test_run.json +0 -1
  114. data/spec/fixtures/cassettes/r_oauth2_auth_runs.json +0 -1
  115. data/spec/fixtures/cassettes/r_run_171221.json +0 -1
  116. data/spec/fixtures/cassettes/r_run_project.json +0 -1
  117. data/spec/fixtures/cassettes/upload_files.json +0 -1
  118. data/spec/fixtures/project.json +0 -8
  119. data/spec/project_config_spec.rb +0 -36
  120. data/spec/project_spec.rb +0 -56
  121. data/spec/run_spec.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7d86102d4aac9035ffcd04e5b0d355807fb90452
4
- data.tar.gz: f841eb8742a2e46ae51b51aba77fa616720dac05
2
+ SHA256:
3
+ metadata.gz: 1602073cb6328a9c2b0896a2cb6fd7a4ea55020b7f4b56fba3105c7040df67e9
4
+ data.tar.gz: 512d7c0359a780a73286ebad2723927d5ba0620c584ca19889f0c2513f62a3ed
5
5
  SHA512:
6
- metadata.gz: 6f85f360258df234b25ea50719ddbaae878d40d4681073f28523d6fda17a8be014ab413de0432df50caeacdb293f892b52c09b4bf0b407688299c1062fca6ef9
7
- data.tar.gz: 26c909e798f09712b3e3f726dd75cdccec5c155f6dad0fa3909a29e47019b4a7fd51046f2c6f64302ea85020b99d94457e714318bb353aeef4402e74b353d90b
6
+ metadata.gz: 2035e8b4bc7011bb5e21beda9230effc74575728fe408d2919e6567094fb33fdeb18e70bc62f86973686853a239170124e3d7fcac29e153b8eedc419183b88ad
7
+ data.tar.gz: a400bed6ad4e1d725533006fef57d9741038b7f6810e77c7ef0bf1621fb8cbcc9b0758dd4ea2bb1f4e2e36eb35ee58dad6e2ffc7784a4658cd6284b50530b9e5
data/.gitignore CHANGED
@@ -12,8 +12,13 @@ test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
14
 
15
+ sample/results
16
+
15
17
  # YARD artifacts
16
18
  .yardoc
17
19
  _yardoc
18
20
  doc/
19
21
  .DS_Store
22
+
23
+ # IDE
24
+ .idea
@@ -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
@@ -1,62 +1,90 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testdroid-api-client (0.2.0)
5
- faraday (~> 0.8.8, >= 0.8.8)
6
- oauth2 (~> 0.9)
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.3.6)
12
- bump (0.5.1)
13
- crack (0.4.2)
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
- faraday (0.8.9)
17
- multipart-post (~> 1.2.0)
18
- jwt (1.2.0)
19
- multi_json (1.10.1)
20
- multi_xml (0.5.5)
21
- multipart-post (1.2.0)
22
- oauth2 (0.9.4)
23
- faraday (>= 0.8, < 0.10)
24
- jwt (~> 1.0)
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 (~> 1.2)
28
- rack (1.5.2)
29
- rake (10.4.0)
30
- rspec (3.1.0)
31
- rspec-core (~> 3.1.0)
32
- rspec-expectations (~> 3.1.0)
33
- rspec-mocks (~> 3.1.0)
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.1.7)
37
- rspec-support (~> 3.1.0)
38
- rspec-expectations (3.1.2)
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.1.0)
41
- rspec-mocks (3.1.3)
42
- rspec-support (~> 3.1.0)
43
- rspec-support (3.1.2)
44
- safe_yaml (1.0.4)
45
- vcr (2.9.3)
46
- webmock (1.20.4)
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
- yard (0.8.7.6)
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.5)
80
+ bump (~> 0.8)
56
81
  rake
57
82
  rspec
58
83
  rspec-collection_matchers
59
84
  testdroid-api-client!
60
- vcr (~> 2.9)
61
- webmock (~> 1.9)
62
- yard (~> 0.8)
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
- Testdroid API Client for Ruby
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
- android_project = @user.projects.list.detect {|project| project.name.casecmp("Android Project") == 0 }
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
- test_run = project123.run
47
+ frameworks = @user.available_frameworks.list
43
48
  ```
44
49
 
45
- ## Check test run status
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
- test_run.device_runs.list({:params => {:limit => 100}}).each { |drun| drun.download_logs("#{drun.id}_log") }
52
+ framework = @user.available_frameworks.list({:filter => "s_osType_eq_ANDROID;s_name_like_%Instrumentation"})[0]
53
53
  ```
54
54
 
55
- ## Using device labels
55
+ ## Upload files
56
56
  ```ruby
57
- #Get label for android os version 2.1
58
- lg_android_version_2_1 = client.label_groups.list.detect {|lg| lg.display_name.casecmp("android version") == 0 }
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
- #create a new device session:
74
- device_session = @user.device_sessions.create({:params => {'deviceModelId' => '1'}})
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
- #get project and update project configuration
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.testdroid.com/swagger/index.html for more details about API V2
82
+ See https://cloud.bitbar.com/cloud/swagger-ui.html for more details about API V2
@@ -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/device_groups'
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/file_sets'
17
- require 'testdroid_api/config'
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 'oauth2'
20
- require 'logger'
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