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

Parameters:

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

    Request Body



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

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

Parameters:

  • label_id (Integer) (defaults to: nil) —

    Label Identifier

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

    Request Body



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/crowdin-api/api_resources/labels.rb', line 125

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

Parameters:

  • label_id (Integer) (defaults to: nil) —

    Label Identifier

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

    Request Body



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/crowdin-api/api_resources/labels.rb', line 87

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

Parameters:

  • label_id (Integer) (defaults to: nil) —

    Label Identifier



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

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

Parameters:

  • label_id (Integer) (defaults to: nil) —

    Label Identifier

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

    Request Body



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/crowdin-api/api_resources/labels.rb', line 70

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

Parameters:

  • label_id (Integer) (defaults to: nil) —

    Label Identifier



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

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

Parameters:

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

    Request Query Parameters



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

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

Parameters:

  • label_id (Integer) (defaults to: nil) —

    Label Identifier

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

    Request Query Parameters



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/crowdin-api/api_resources/labels.rb', line 142

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

Parameters:

  • label_id (Integer) (defaults to: nil) —

    Label Identifier

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

    Request Query Parameters



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/crowdin-api/api_resources/labels.rb', line 104

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