Module: Monkeylearn::Tags

Extended by:
Requests
Defined in:
lib/monkeylearn/classifiers.rb

Class Method Summary collapse

Methods included from Requests

get_connection, get_exception_class, raise_for_status, request, throttled?

Class Method Details

.build_endpoint(module_id, *args) ⇒ Object



133
134
135
# File 'lib/monkeylearn/classifiers.rb', line 133

def build_endpoint(module_id, *args)
  File.join('classifiers', module_id, 'tags', *args.collect { |x| x.to_s }) + '/'
end

.create(module_id, name, options = {}) ⇒ Object



137
138
139
140
141
142
143
144
145
# File 'lib/monkeylearn/classifiers.rb', line 137

def create(module_id, name, options = {})
  data = {
    name: name,
  }
  if options[:parent_id]
    data[:parent_id] = options[:parent_id]
  end
  request(:post, build_endpoint(module_id), data)
end

.delete(module_id, tag_id, options = {}) ⇒ Object



160
161
162
163
164
165
166
167
168
169
# File 'lib/monkeylearn/classifiers.rb', line 160

def delete(module_id, tag_id, options = {})
  endpoint = build_endpoint(module_id, tag_id)

  data = nil
  if options.key?(:move_data_to)
    data = {move_data_to: options[:move_data_to]}
  end

  request(:delete, endpoint, data)
end

.detail(module_id, tag_id) ⇒ Object



147
148
149
# File 'lib/monkeylearn/classifiers.rb', line 147

def detail(module_id, tag_id)
  request :get, build_endpoint(module_id, tag_id)
end

.edit(module_id, tag_id, options = {}) ⇒ Object



151
152
153
154
155
156
157
158
# File 'lib/monkeylearn/classifiers.rb', line 151

def edit(module_id, tag_id, options = {})
  endpoint = build_endpoint(module_id, tag_id)
  data = {
    name: options[:name],
    parent_id: options[:parent_id]
  }.delete_if { |k,v| v.nil? }
  request :patch, endpoint, data
end