Skip to content

Commit 0de33f1

Browse files
authored
Merge pull request #2 from caineers:improve/0623
Improve/0623
2 parents 4992bec + d8e315e commit 0de33f1

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

lib/caido/helpers/project.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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

lib/caido/instance.rb

+27-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,33 @@ module Caido
1111
class Instance
1212
attr_reader :graphql_url, :authorization
1313

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 ')
2141
end
2242

2343
def query(query)

0 commit comments

Comments
 (0)