Class: Hackle::HttpWorkspaceFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/hackle-ruby-sdk/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-ruby-sdk/workspaces/http_workspace_fetcher.rb', line 8

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

Instance Method Details

#fetchObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/hackle-ruby-sdk/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)

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