Module: Crowdin::ApiResources::Labels

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

Instance Method Summary collapse

Instance Method Details

#add_label(query = {}, project_id = config.project_id) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/crowdin-api/api_resources/labels.rb', line 18

def add_label(query = {}, project_id = config.project_id)
  project_id || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :post,
    "#{config.target_api_url}/projects/#{project_id}/labels",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#assign_label_to_screenshots(label_id = nil, query = {}, project_id = config.project_id) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/crowdin-api/api_resources/labels.rb', line 97

def assign_label_to_screenshots(label_id = nil, query = {}, project_id = config.project_id)
  label_id   || raise_parameter_is_required_error(:label_id)
  project_id || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :post,
    "#{config.target_api_url}/projects/#{project_id}/labels/#{label_id}/screenshots",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#assign_label_to_strings(label_id = nil, query = {}, project_id = config.project_id) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/crowdin-api/api_resources/labels.rb', line 67

def assign_label_to_strings(label_id = nil, query = {}, project_id = config.project_id)
  label_id   || raise_parameter_is_required_error(:label_id)
  project_id || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :post,
    "#{config.target_api_url}/projects/#{project_id}/labels/#{label_id}/strings",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#delete_label(label_id = nil, project_id = config.project_id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/crowdin-api/api_resources/labels.rb', line 42

def delete_label(label_id = nil, project_id = config.project_id)
  label_id   || raise_parameter_is_required_error(:label_id)
  project_id || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :delete,
    "#{config.target_api_url}/projects/#{project_id}/labels/#{label_id}"
  )
  Web::SendRequest.new(request).perform
end

#edit_label(label_id = nil, query = {}, project_id = config.project_id) ⇒ Object



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

def edit_label(label_id = nil, query = {}, project_id = config.project_id)
  label_id   || raise_parameter_is_required_error(:label_id)
  project_id || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :patch,
    "#{config.target_api_url}/projects/#{project_id}/labels/#{label_id}",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#get_label(label_id = nil, project_id = config.project_id) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/crowdin-api/api_resources/labels.rb', line 30

def get_label(label_id = nil, project_id = config.project_id)
  label_id   || raise_parameter_is_required_error(:label_id)
  project_id || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/projects/#{project_id}/labels/#{label_id}"
  )
  Web::SendRequest.new(request).perform
end

#list_labels(query = {}, project_id = config.project_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/crowdin-api/api_resources/labels.rb', line 6

def list_labels(query = {}, project_id = config.project_id)
  project_id || raise_project_id_is_required_error

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

#unassign_label_from_screenshots(label_id = nil, query = {}, project_id = config.project_id) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/crowdin-api/api_resources/labels.rb', line 110

def unassign_label_from_screenshots(label_id = nil, query = {}, project_id = config.project_id)
  label_id   || raise_parameter_is_required_error(:label_id)
  project_id || raise_project_id_is_required_error

  response = ::RestClient::Request.execute(
    {
      method: :delete,
      url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}/screenshots",
      payload: query.to_json
    }.merge(@options)
  )

  response.body.empty? ? response.code : JSON.parse(response.body)
rescue StandardError => e
  e.message
end

#unassign_label_from_strings(label_id = nil, query = {}, project_id = config.project_id) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/crowdin-api/api_resources/labels.rb', line 80

def unassign_label_from_strings(label_id = nil, query = {}, project_id = config.project_id)
  label_id   || raise_parameter_is_required_error(:label_id)
  project_id || raise_project_id_is_required_error

  response = ::RestClient::Request.execute(
    {
      method: :delete,
      url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}/strings",
      payload: query.to_json
    }.merge(@options)
  )

  response.body.empty? ? response.code : JSON.parse(response.body)
rescue StandardError => e
  e.message
end