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
# File 'lib/monkeylearn/classifiers.rb', line 137

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

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



156
157
158
159
160
161
162
163
164
165
# File 'lib/monkeylearn/classifiers.rb', line 156

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



144
145
146
# File 'lib/monkeylearn/classifiers.rb', line 144

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

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



148
149
150
151
152
153
154
# File 'lib/monkeylearn/classifiers.rb', line 148

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