Module: Crowdin::ApiResources::Storages

Defined in:
lib/crowdin-api/api_resources/storages.rb

Instance Method Summary collapse

Instance Method Details

#add_storage(file = nil) ⇒ Object

Parameters:

  • file (string) (defaults to: nil)

    File path



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/crowdin-api/api_resources/storages.rb', line 22

def add_storage(file = nil)
  file || raise_parameter_is_required_error(:file)

  file = File.open(file, 'r')
  headers = { 'Content-Type' => 'application/octet-stream', 'Crowdin-API-FileName' => File.basename(file) }

  request = Web::Request.new(
    connection,
    :post,
    "#{config.target_api_url}/storages",
    { params: file, headers: headers }
  )
  Web::SendRequest.new(request).perform
end

#delete_storage(storage_id = nil) ⇒ Object

Parameters:

  • storage_id (Integer) (defaults to: nil)

    Storage ID



54
55
56
57
58
59
60
61
62
63
# File 'lib/crowdin-api/api_resources/storages.rb', line 54

def delete_storage(storage_id = nil)
  storage_id || raise_parameter_is_required_error(:storage_id)

  request = Web::Request.new(
    connection,
    :delete,
    "#{config.target_api_url}/storages/#{storage_id}"
  )
  Web::SendRequest.new(request).perform
end

#get_storage(storage_id = nil) ⇒ Object

Parameters:

  • storage_id (Integer) (defaults to: nil)

    Storage ID



40
41
42
43
44
45
46
47
48
49
# File 'lib/crowdin-api/api_resources/storages.rb', line 40

def get_storage(storage_id = nil)
  storage_id || raise_parameter_is_required_error(:storage_id)

  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/storages/#{storage_id}"
  )
  Web::SendRequest.new(request).perform
end

#list_storages(query = {}) ⇒ Object

Parameters:

  • query (Hash) (defaults to: {})

    Request Body



9
10
11
12
13
14
15
16
17
# File 'lib/crowdin-api/api_resources/storages.rb', line 9

def list_storages(query = {})
  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/storages",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end