@@ -15,42 +15,49 @@ class Client < TildaRuby::Internal::Transport::BaseClient
1515 # Default max retry delay in seconds.
1616 DEFAULT_MAX_RETRY_DELAY = 8.0
1717
18+ # Tilda API public key
1819 # @return [String, nil]
19- attr_reader :api_key
20+ attr_reader :publickey
2021
21- # @return [TildaRuby::Resources::Getpage]
22- attr_reader :getpage
23-
24- # @return [TildaRuby::Resources::Getpageexport]
25- attr_reader :getpageexport
26-
27- # @return [TildaRuby::Resources::Getpagefull]
28- attr_reader :getpagefull
22+ # Tilda API secret key
23+ # @return [String, nil]
24+ attr_reader :secretkey
2925
30- # @return [TildaRuby::Resources::Getpagefullexport ]
31- attr_reader :getpagefullexport
26+ # @return [TildaRuby::Resources::Projects ]
27+ attr_reader :projects
3228
33- # @return [TildaRuby::Resources::Getpageslist ]
34- attr_reader :getpageslist
29+ # @return [TildaRuby::Resources::Pages ]
30+ attr_reader :pages
3531
36- # @return [TildaRuby::Resources::Getprojectinfo ]
37- attr_reader :getprojectinfo
32+ # @return [TildaRuby::Resources::Export ]
33+ attr_reader :export
3834
39- # @return [TildaRuby::Resources::Getprojectslist]
40- attr_reader :getprojectslist
35+ # @api private
36+ #
37+ # @return [Hash{String=>String}]
38+ private def auth_query
39+ { **public_key_auth , **secret_key_auth }
40+ end
4141
4242 # @api private
4343 #
4444 # @return [Hash{String=>String}]
45- private def auth_headers
46- return { } if @api_key . nil?
45+ private def public_key_auth
46+ { "publickey" => @publickey }
47+ end
4748
48- { "authorization" => "Bearer #{ @api_key } " }
49+ # @api private
50+ #
51+ # @return [Hash{String=>String}]
52+ private def secret_key_auth
53+ { "secretkey" => @secretkey }
4954 end
5055
5156 # Creates and returns a new client for interacting with the API.
5257 #
53- # @param api_key [String, nil] Defaults to `ENV["TILDA_API_KEY"]`
58+ # @param publickey [String, nil] Tilda API public key
59+ #
60+ # @param secretkey [String, nil] Tilda API secret key
5461 #
5562 # @param base_url [String, nil] Override the default base URL for the API, e.g.,
5663 # `"https://api.example.com/v2/"`. Defaults to `ENV["TILDA_BASE_URL"]`
@@ -63,7 +70,8 @@ class Client < TildaRuby::Internal::Transport::BaseClient
6370 #
6471 # @param max_retry_delay [Float]
6572 def initialize (
66- api_key : ENV [ "TILDA_API_KEY" ] ,
73+ publickey : nil ,
74+ secretkey : nil ,
6775 base_url : ENV [ "TILDA_BASE_URL" ] ,
6876 max_retries : self . class ::DEFAULT_MAX_RETRIES ,
6977 timeout : self . class ::DEFAULT_TIMEOUT_IN_SECONDS ,
@@ -72,7 +80,8 @@ def initialize(
7280 )
7381 base_url ||= "https://api.tildacdn.info"
7482
75- @api_key = api_key &.to_s
83+ @publickey = publickey &.to_s
84+ @secretkey = secretkey &.to_s
7685
7786 super (
7887 base_url : base_url ,
@@ -82,13 +91,9 @@ def initialize(
8291 max_retry_delay : max_retry_delay
8392 )
8493
85- @getpage = TildaRuby ::Resources ::Getpage . new ( client : self )
86- @getpageexport = TildaRuby ::Resources ::Getpageexport . new ( client : self )
87- @getpagefull = TildaRuby ::Resources ::Getpagefull . new ( client : self )
88- @getpagefullexport = TildaRuby ::Resources ::Getpagefullexport . new ( client : self )
89- @getpageslist = TildaRuby ::Resources ::Getpageslist . new ( client : self )
90- @getprojectinfo = TildaRuby ::Resources ::Getprojectinfo . new ( client : self )
91- @getprojectslist = TildaRuby ::Resources ::Getprojectslist . new ( client : self )
94+ @projects = TildaRuby ::Resources ::Projects . new ( client : self )
95+ @pages = TildaRuby ::Resources ::Pages . new ( client : self )
96+ @export = TildaRuby ::Resources ::Export . new ( client : self )
9297 end
9398 end
9499end
0 commit comments