Class: Hackle::HttpWorkspaceFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/hackle/workspaces/http_workspace_fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(config:, sdk_info:) ⇒ HttpWorkspaceFetcher

Returns a new instance of HttpWorkspaceFetcher.



8
9
10
11
# File 'lib/hackle/workspaces/http_workspace_fetcher.rb', line 8

def initialize(config:, sdk_info:)
  @client = HTTP.client(base_uri: config.base_uri)
  @headers = HTTP.sdk_headers(sdk_info: sdk_info)
end

Instance Method Details

#fetchObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/hackle/workspaces/http_workspace_fetcher.rb', line 13

def fetch
  request = Net::HTTP::Get.new('/api/v1/workspaces', @headers)
  response = @client.request(request)

  status_code = response.code.to_i
  HTTP.check_successful(status_code: status_code)

  response_body = JSON.parse(response.body, symbolize_names: true)
  Workspace.create(data: response_body)
end