File tree 2 files changed +44
-7
lines changed
2 files changed +44
-7
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module Caido
4
+ # Instance class
5
+ class Instance
6
+ def projects
7
+ query ( 'query {
8
+ projects{
9
+ id
10
+ name
11
+ version
12
+ updatedAt
13
+ }
14
+ }' ) [ 'projects' ]
15
+ end
16
+ end
17
+ end
Original file line number Diff line number Diff line change @@ -11,13 +11,33 @@ module Caido
11
11
class Instance
12
12
attr_reader :graphql_url , :authorization
13
13
14
- def initialize ( graphql_url , authorization )
15
- @graphql_url = graphql_url
16
- @authorization = if 'Bearer ' . include? ( authorization )
17
- authorization
18
- else
19
- "Bearer #{ authorization } "
20
- end
14
+ def initialize ( *args )
15
+ @graphql_url = 'http://localhost:8080/graphql'
16
+ @authorization = nil
17
+
18
+ case args . size
19
+ when 0
20
+ # Initialize with default values
21
+ when 1
22
+ # Initialize with graphql_url
23
+ @graphql_url = args [ 0 ]
24
+ when 2
25
+ # Initialize with graphql_url and authorization
26
+ @graphql_url , authorization = args
27
+ @authorization = if authorization . include? ( 'Bearer ' )
28
+ authorization
29
+ else
30
+ "Bearer #{ authorization } "
31
+ end
32
+ else
33
+ raise ArgumentError , 'Too many arguments provided'
34
+ end
35
+
36
+ auth_from_env if @authorization . nil?
37
+ end
38
+
39
+ def auth_from_env
40
+ @auth_from_env ||= ENV . fetch ( 'CAIDO_AUTH_TOKEN' , 'Bearer ' )
21
41
end
22
42
23
43
def query ( query )
You can’t perform that action at this time.
0 commit comments