leantesting 1.0.1 → 1.0.2

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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/leantesting.gemspec +1 -1
  4. data/lib/BaseClass/APIRequest.rb +154 -151
  5. data/lib/BaseClass/Entity.rb +25 -24
  6. data/lib/BaseClass/EntityHandler.rb +151 -149
  7. data/lib/BaseClass/EntityList.rb +163 -161
  8. data/lib/Entity/Bug/Bug.rb +10 -8
  9. data/lib/Entity/Bug/BugAttachment.rb +7 -5
  10. data/lib/Entity/Bug/BugComment.rb +7 -5
  11. data/lib/Entity/Platform/PlatformBrowser.rb +9 -7
  12. data/lib/Entity/Platform/PlatformBrowserVersion.rb +7 -5
  13. data/lib/Entity/Platform/PlatformDevice.rb +7 -5
  14. data/lib/Entity/Platform/PlatformOS.rb +9 -7
  15. data/lib/Entity/Platform/PlatformOSVersion.rb +7 -5
  16. data/lib/Entity/Platform/PlatformType.rb +9 -7
  17. data/lib/Entity/Project/Project.rb +24 -22
  18. data/lib/Entity/Project/ProjectBugScheme.rb +7 -5
  19. data/lib/Entity/Project/ProjectSection.rb +7 -5
  20. data/lib/Entity/Project/ProjectUser.rb +7 -5
  21. data/lib/Entity/Project/ProjectVersion.rb +7 -5
  22. data/lib/Entity/User/UserOrganization.rb +7 -5
  23. data/lib/Exception/BaseException/SDKException.rb +15 -13
  24. data/lib/Exception/SDKBadJSONResponseException.rb +13 -11
  25. data/lib/Exception/SDKDuplicateRequestException.rb +15 -13
  26. data/lib/Exception/SDKErrorResponseException.rb +12 -10
  27. data/lib/Exception/SDKIncompleteRequestException.rb +15 -13
  28. data/lib/Exception/SDKInvalidArgException.rb +13 -11
  29. data/lib/Exception/SDKMissingArgException.rb +13 -11
  30. data/lib/Exception/SDKUnexpectedResponseException.rb +13 -11
  31. data/lib/Exception/SDKUnsupportedRequestException.rb +15 -13
  32. data/lib/Handler/Attachment/AttachmentsHandler.rb +14 -12
  33. data/lib/Handler/Auth/OAuth2Handler.rb +102 -100
  34. data/lib/Handler/Bug/BugAttachmentsHandler.rb +44 -42
  35. data/lib/Handler/Bug/BugCommentsHandler.rb +16 -14
  36. data/lib/Handler/Bug/BugsHandler.rb +53 -51
  37. data/lib/Handler/Platform/PlatformBrowserVersionsHandler.rb +16 -14
  38. data/lib/Handler/Platform/PlatformBrowsersHandler.rb +18 -16
  39. data/lib/Handler/Platform/PlatformDevicesHandler.rb +9 -7
  40. data/lib/Handler/Platform/PlatformHandler.rb +20 -18
  41. data/lib/Handler/Platform/PlatformOSHandler.rb +18 -16
  42. data/lib/Handler/Platform/PlatformOSVersionsHandler.rb +16 -14
  43. data/lib/Handler/Platform/PlatformTypeDevicesHandler.rb +16 -14
  44. data/lib/Handler/Platform/PlatformTypesHandler.rb +17 -15
  45. data/lib/Handler/Project/ProjectBugReproducibilitySchemeHandler.rb +16 -14
  46. data/lib/Handler/Project/ProjectBugSeveritySchemeHandler.rb +16 -14
  47. data/lib/Handler/Project/ProjectBugStatusSchemeHandler.rb +16 -14
  48. data/lib/Handler/Project/ProjectBugTypeSchemeHandler.rb +16 -14
  49. data/lib/Handler/Project/ProjectBugsHandler.rb +55 -53
  50. data/lib/Handler/Project/ProjectSectionsHandler.rb +30 -28
  51. data/lib/Handler/Project/ProjectUsersHandler.rb +16 -14
  52. data/lib/Handler/Project/ProjectVersionsHandler.rb +30 -28
  53. data/lib/Handler/Project/ProjectsHandler.rb +34 -32
  54. data/lib/Handler/User/UserHandler.rb +12 -10
  55. data/lib/Handler/User/UserOrganizationsHandler.rb +12 -10
  56. data/tests/APIRequestTest.rb +33 -33
  57. data/tests/BaseClassesTest.rb +28 -28
  58. data/tests/ClientTest.rb +7 -7
  59. data/tests/EntitiesTest.rb +31 -31
  60. data/tests/EntityListTest.rb +13 -13
  61. data/tests/ExceptionsTest.rb +15 -15
  62. data/tests/HandlersRequestsTest.rb +37 -37
  63. data/tests/MockRequestsTest.rb +48 -48
  64. data/tests/OAuth2HandlerTest.rb +19 -19
  65. metadata +2 -1
@@ -1,17 +1,19 @@
1
- class AttachmentsHandler < EntityHandler
1
+ module LeanTesting
2
+ class AttachmentsHandler < LeanTesting::EntityHandler
2
3
 
3
- def find(id)
4
- super
4
+ def find(id)
5
+ super
5
6
 
6
- req = APIRequest.new(@origin, '/v1/attachments/' + id.to_s(), 'GET')
7
- BugAttachment.new(@origin, req.exec)
8
- end
7
+ req = APIRequest.new(@origin, '/v1/attachments/' + id.to_s(), 'GET')
8
+ BugAttachment.new(@origin, req.exec)
9
+ end
9
10
 
10
- def delete(id)
11
- super
11
+ def delete(id)
12
+ super
12
13
 
13
- req = APIRequest.new(@origin, '/v1/attachments/' + id.to_s(), 'DELETE')
14
- req.exec
15
- end
14
+ req = APIRequest.new(@origin, '/v1/attachments/' + id.to_s(), 'DELETE')
15
+ req.exec
16
+ end
16
17
 
17
- end
18
+ end
19
+ end
@@ -3,116 +3,118 @@
3
3
  #
4
4
  # leantesting.com/en/api-docs#oauth-flow
5
5
  #
6
- class OAuth2Handler
6
+ module LeanTesting
7
+ class OAuth2Handler
7
8
 
8
- #
9
- # Constructs an OAuth2Handler instance
10
- #
11
- # Arguments:
12
- # origin Client -- Originating client reference
13
- #
14
- def initialize(origin)
15
- @origin = origin
16
- end
17
-
18
- #
19
- # Function that generates link for user to follow in order to request authorization code
20
- #
21
- # Arguments:
22
- # clientID String -- client ID given at application registration
23
- # redirectURI String -- URL to be redirected to after authorization
24
- # scope String -- (optional) comma-separated list of requested scopes (default: 'read')
25
- # state String -- (optional) random string for MITM attack prevention
26
- #
27
- # Exceptions:
28
- # SDKInvalidArgException if provided clientID param is not a string
29
- # SDKInvalidArgException if provided redirectURI param is not a string
30
- # SDKInvalidArgException if provided scope param is not a string
31
- # SDKInvalidArgException if provided state param is not a string
32
- #
33
- # Returns:
34
- # String -- returns URL to follow for authorization code request
35
- #
36
- def generateAuthLink(clientID, redirectURI, scope = 'read', state = nil)
37
- if !clientID.is_a? String
38
- raise SDKInvalidArgException, '`clientID` must be a string'
39
- elsif !redirectURI.is_a? String
40
- raise SDKInvalidArgException, '`redirectURI` must be a string'
41
- elsif !scope.is_a? String
42
- raise SDKInvalidArgException, '`scope` must be a string'
43
- elsif state && !state.is_a?(String)
44
- raise SDKInvalidArgException, '`state` must be a string'
9
+ #
10
+ # Constructs an OAuth2Handler instance
11
+ #
12
+ # Arguments:
13
+ # origin Client -- Originating client reference
14
+ #
15
+ def initialize(origin)
16
+ @origin = origin
45
17
  end
46
18
 
47
- baseURL = 'https://leantesting.com/login/oauth/authorize'
48
-
49
- params = {
50
- 'client_id' => clientID,
51
- 'redirect_uri' => redirectURI,
52
- 'scope' => scope
53
- }
19
+ #
20
+ # Function that generates link for user to follow in order to request authorization code
21
+ #
22
+ # Arguments:
23
+ # clientID String -- client ID given at application registration
24
+ # redirectURI String -- URL to be redirected to after authorization
25
+ # scope String -- (optional) comma-separated list of requested scopes (default: 'read')
26
+ # state String -- (optional) random string for MITM attack prevention
27
+ #
28
+ # Exceptions:
29
+ # SDKInvalidArgException if provided clientID param is not a string
30
+ # SDKInvalidArgException if provided redirectURI param is not a string
31
+ # SDKInvalidArgException if provided scope param is not a string
32
+ # SDKInvalidArgException if provided state param is not a string
33
+ #
34
+ # Returns:
35
+ # String -- returns URL to follow for authorization code request
36
+ #
37
+ def generateAuthLink(clientID, redirectURI, scope = 'read', state = nil)
38
+ if !clientID.is_a? String
39
+ raise SDKInvalidArgException, '`clientID` must be a string'
40
+ elsif !redirectURI.is_a? String
41
+ raise SDKInvalidArgException, '`redirectURI` must be a string'
42
+ elsif !scope.is_a? String
43
+ raise SDKInvalidArgException, '`scope` must be a string'
44
+ elsif state && !state.is_a?(String)
45
+ raise SDKInvalidArgException, '`state` must be a string'
46
+ end
54
47
 
55
- if state
56
- params['state'] = state
57
- end
48
+ baseURL = 'https://leantesting.com/login/oauth/authorize'
58
49
 
59
- baseURL += '?' + Curl::postalize(params)
60
- baseURL
61
- end
50
+ params = {
51
+ 'client_id' => clientID,
52
+ 'redirect_uri' => redirectURI,
53
+ 'scope' => scope
54
+ }
62
55
 
63
- #
64
- # Generates an access token string from the provided authorization code
65
- #
66
- # Arguments:
67
- # clientID String -- client ID given at application registration
68
- # clientSecret String -- client secret given at application registration
69
- # grantType String -- oauth specific grant_type value (i.e.: authorization_code)
70
- # code String -- authorization code obtained from the generated auth link
71
- # redirectURI String -- URL to be redirected to after authorization
56
+ if state
57
+ params['state'] = state
58
+ end
72
59
 
73
- # Exceptions:
74
- # SDKInvalidArgException if provided clientID param is not a string
75
- # SDKInvalidArgException if provided clientSecret param is not a string
76
- # SDKInvalidArgException if provided grantType param is not a string
77
- # SDKInvalidArgException if provided code param is not a string
78
- # SDKInvalidArgException if provided redirectURI param is not a string
79
- #
80
- # Returns:
81
- # String -- returns obtained access token string
82
- #
83
- def exchangeAuthCode(clientID, clientSecret, grantType, code, redirectURI)
84
- if !clientID.is_a? String
85
- raise SDKInvalidArgException, '`clientID` must be a string'
86
- elsif !clientSecret.is_a? String
87
- raise SDKInvalidArgException, '`clientSecret` must be a string'
88
- elsif !grantType.is_a? String
89
- raise SDKInvalidArgException, '`grantType` must be a string'
90
- elsif !code.is_a? String
91
- raise SDKInvalidArgException, '`code` must be a string'
92
- elsif !redirectURI.is_a? String
93
- raise SDKInvalidArgException, '`redirectURI` must be a string'
60
+ baseURL += '?' + Curl::postalize(params)
61
+ baseURL
94
62
  end
95
63
 
96
- params = {
97
- 'grant_type' => grantType,
98
- 'client_id' => clientID,
99
- 'client_secret' => clientSecret,
100
- 'redirect_uri' => redirectURI,
101
- 'code' => code
102
- }
64
+ #
65
+ # Generates an access token string from the provided authorization code
66
+ #
67
+ # Arguments:
68
+ # clientID String -- client ID given at application registration
69
+ # clientSecret String -- client secret given at application registration
70
+ # grantType String -- oauth specific grant_type value (i.e.: authorization_code)
71
+ # code String -- authorization code obtained from the generated auth link
72
+ # redirectURI String -- URL to be redirected to after authorization
103
73
 
104
- req = APIRequest.new(
105
- @origin,
106
- '/login/oauth/access_token',
107
- 'POST',
108
- {
109
- 'base_uri' => 'https://leantesting.com',
110
- 'params' => params
74
+ # Exceptions:
75
+ # SDKInvalidArgException if provided clientID param is not a string
76
+ # SDKInvalidArgException if provided clientSecret param is not a string
77
+ # SDKInvalidArgException if provided grantType param is not a string
78
+ # SDKInvalidArgException if provided code param is not a string
79
+ # SDKInvalidArgException if provided redirectURI param is not a string
80
+ #
81
+ # Returns:
82
+ # String -- returns obtained access token string
83
+ #
84
+ def exchangeAuthCode(clientID, clientSecret, grantType, code, redirectURI)
85
+ if !clientID.is_a? String
86
+ raise SDKInvalidArgException, '`clientID` must be a string'
87
+ elsif !clientSecret.is_a? String
88
+ raise SDKInvalidArgException, '`clientSecret` must be a string'
89
+ elsif !grantType.is_a? String
90
+ raise SDKInvalidArgException, '`grantType` must be a string'
91
+ elsif !code.is_a? String
92
+ raise SDKInvalidArgException, '`code` must be a string'
93
+ elsif !redirectURI.is_a? String
94
+ raise SDKInvalidArgException, '`redirectURI` must be a string'
95
+ end
96
+
97
+ params = {
98
+ 'grant_type' => grantType,
99
+ 'client_id' => clientID,
100
+ 'client_secret' => clientSecret,
101
+ 'redirect_uri' => redirectURI,
102
+ 'code' => code
111
103
  }
112
- )
113
104
 
114
- resp = req.exec
115
- resp['access_token']
116
- end
105
+ req = APIRequest.new(
106
+ @origin,
107
+ '/login/oauth/access_token',
108
+ 'POST',
109
+ {
110
+ 'base_uri' => 'https://leantesting.com',
111
+ 'params' => params
112
+ }
113
+ )
117
114
 
118
- end
115
+ resp = req.exec
116
+ resp['access_token']
117
+ end
118
+
119
+ end
120
+ end
@@ -1,51 +1,53 @@
1
- class BugAttachmentsHandler < EntityHandler
1
+ module LeanTesting
2
+ class BugAttachmentsHandler < LeanTesting::EntityHandler
2
3
 
3
- def initialize(origin, bugID)
4
- super(origin)
4
+ def initialize(origin, bugID)
5
+ super(origin)
5
6
 
6
- @bugID = bugID
7
- end
7
+ @bugID = bugID
8
+ end
8
9
 
9
- #
10
- # Uploads given file as an attachment for specified bug.
11
- #
12
- # Arguments:
13
- # filepath String -- an absolute path of the file to be uploaded
14
- # example: /home/path/to/file.txt (Linux), C:\\Users\\Documents\\file.txt (Windows)
15
- #
16
- # Exceptions:
17
- # SDKInvalidArgException if filepath is not a string
18
- #
19
- # Returns:
20
- # BugAttachment -- the newly uploaded attachment
21
- #
22
- def upload(filepath)
23
- if !filepath.is_a? String
24
- raise SDKInvalidArgException, '`filepath` must be of type string'
10
+ #
11
+ # Uploads given file as an attachment for specified bug.
12
+ #
13
+ # Arguments:
14
+ # filepath String -- an absolute path of the file to be uploaded
15
+ # example: /home/path/to/file.txt (Linux), C:\\Users\\Documents\\file.txt (Windows)
16
+ #
17
+ # Exceptions:
18
+ # SDKInvalidArgException if filepath is not a string
19
+ #
20
+ # Returns:
21
+ # BugAttachment -- the newly uploaded attachment
22
+ #
23
+ def upload(filepath)
24
+ if !filepath.is_a? String
25
+ raise SDKInvalidArgException, '`filepath` must be of type string'
26
+ end
27
+
28
+ req = APIRequest.new(
29
+ @origin,
30
+ '/v1/bugs/' + @bugID.to_s() + '/attachments',
31
+ 'POST',
32
+ {
33
+ 'form_data' => true,
34
+ 'file_path' => filepath
35
+ }
36
+ )
37
+
38
+ BugAttachment.new(@origin, req.exec)
25
39
  end
26
40
 
27
- req = APIRequest.new(
28
- @origin,
29
- '/v1/bugs/' + @bugID.to_s() + '/attachments',
30
- 'POST',
31
- {
32
- 'form_data' => true,
33
- 'file_path' => filepath
34
- }
35
- )
36
-
37
- BugAttachment.new(@origin, req.exec)
38
- end
41
+ def all(filters = nil)
42
+ if !filters
43
+ filters = {}
44
+ end
39
45
 
40
- def all(filters = nil)
41
- if !filters
42
- filters = {}
43
- end
46
+ super
44
47
 
45
- super
48
+ request = APIRequest.new(@origin, '/v1/bugs/' + @bugID.to_s() + '/attachments', 'GET')
49
+ EntityList.new(@origin, request, BugAttachment, filters)
50
+ end
46
51
 
47
- request = APIRequest.new(@origin, '/v1/bugs/' + @bugID.to_s() + '/attachments', 'GET')
48
- EntityList.new(@origin, request, BugAttachment, filters)
49
52
  end
50
-
51
- end
53
+ end
@@ -1,20 +1,22 @@
1
- class BugCommentsHandler < EntityHandler
1
+ module LeanTesting
2
+ class BugCommentsHandler < LeanTesting::EntityHandler
2
3
 
3
- def initialize(origin, bugID)
4
- super(origin)
4
+ def initialize(origin, bugID)
5
+ super(origin)
5
6
 
6
- @bugID = bugID
7
- end
8
-
9
- def all(filters = nil)
10
- if !filters
11
- filters = {}
7
+ @bugID = bugID
12
8
  end
13
9
 
14
- super
10
+ def all(filters = nil)
11
+ if !filters
12
+ filters = {}
13
+ end
15
14
 
16
- request = APIRequest.new(@origin, '/v1/bugs/' + @bugID.to_s() + '/comments', 'GET')
17
- EntityList.new(@origin, request, BugComment, filters)
18
- end
15
+ super
19
16
 
20
- end
17
+ request = APIRequest.new(@origin, '/v1/bugs/' + @bugID.to_s() + '/comments', 'GET')
18
+ EntityList.new(@origin, request, BugComment, filters)
19
+ end
20
+
21
+ end
22
+ end
@@ -1,57 +1,59 @@
1
- class BugsHandler < EntityHandler
2
-
3
- def find(id)
4
- super
5
-
6
- req = APIRequest.new(
7
- @origin,
8
- '/v1/bugs/' + id.to_s(),
9
- 'GET',
10
- {
11
- 'params' => {
12
- 'include' => 'steps,platform,attachments,comments,tags'
1
+ module LeanTesting
2
+ class BugsHandler < LeanTesting::EntityHandler
3
+
4
+ def find(id)
5
+ super
6
+
7
+ req = APIRequest.new(
8
+ @origin,
9
+ '/v1/bugs/' + id.to_s(),
10
+ 'GET',
11
+ {
12
+ 'params' => {
13
+ 'include' => 'steps,platform,attachments,comments,tags'
14
+ }
13
15
  }
14
- }
15
- )
16
- Bug.new(@origin, req.exec)
17
- end
16
+ )
17
+ Bug.new(@origin, req.exec)
18
+ end
18
19
 
19
- def delete(id)
20
- super
20
+ def delete(id)
21
+ super
21
22
 
22
- req = APIRequest.new(@origin, '/v1/bugs/' + id.to_s(), 'DELETE')
23
- req.exec
24
- end
23
+ req = APIRequest.new(@origin, '/v1/bugs/' + id.to_s(), 'DELETE')
24
+ req.exec
25
+ end
25
26
 
26
- def update(id, fields)
27
- super
28
-
29
- supports = {
30
- 'title' => false,
31
- 'status_id' => false,
32
- 'severity_id' => false,
33
- 'project_version_id' => false,
34
- 'project_section_id' => false,
35
- 'type_id' => false,
36
- 'assigned_user_id' => false,
37
- 'description' => false,
38
- 'expected_results' => false,
39
- 'steps' => false,
40
- 'platform' => false
41
- # 'device_model' => false,
42
- # 'device_model_id' => false,
43
- # 'os' => false,
44
- # 'os_version' => false,
45
- # 'os_version_id' => false,
46
- # 'browser_version_id' => false
47
- }
48
-
49
- if enforce(fields, supports)
50
- fields = {'include' => 'steps,platform'}.merge(fields)
51
-
52
- req = APIRequest.new(@origin, '/v1/bugs/' + id.to_s(), 'PUT', {'params' => fields})
53
- Bug.new(@origin, req.exec)
27
+ def update(id, fields)
28
+ super
29
+
30
+ supports = {
31
+ 'title' => false,
32
+ 'status_id' => false,
33
+ 'severity_id' => false,
34
+ 'project_version_id' => false,
35
+ 'project_section_id' => false,
36
+ 'type_id' => false,
37
+ 'assigned_user_id' => false,
38
+ 'description' => false,
39
+ 'expected_results' => false,
40
+ 'steps' => false,
41
+ 'platform' => false
42
+ # 'device_model' => false,
43
+ # 'device_model_id' => false,
44
+ # 'os' => false,
45
+ # 'os_version' => false,
46
+ # 'os_version_id' => false,
47
+ # 'browser_version_id' => false
48
+ }
49
+
50
+ if enforce(fields, supports)
51
+ fields = {'include' => 'steps,platform'}.merge(fields)
52
+
53
+ req = APIRequest.new(@origin, '/v1/bugs/' + id.to_s(), 'PUT', {'params' => fields})
54
+ Bug.new(@origin, req.exec)
55
+ end
54
56
  end
55
- end
56
57
 
57
- end
58
+ end
59
+ end