Module: TicketEvolution::Modules::Create

Instance Method Summary collapse

Instance Method Details

#build_for_create(response) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ticket_evolution/modules/create.rb', line 18

def build_for_create(response)
  entries = response.body[endpoint_name].collect do |body|
    singular_class.new(body.merge({
      :status_code => response.response_code,
      :server_message => response.server_message,
      :connection => response.body[:connection]
    }))
  end
  if entries.size == 1
    entries.first
  else
    TicketEvolution::Collection.new(:entries => entries, :status_code => response.response_code)
  end
end

#create(params = nil, &handler) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ticket_evolution/modules/create.rb', line 4

def create(params = nil, &handler)
  handler ||= method(:build_for_create)
  if params.present?
    if params.is_a?(Array)
      params = { endpoint_name.to_sym => params }
    else
      if !params[endpoint_name.to_sym].present?
        params = { endpoint_name.to_sym => [params] }
      end
    end
  end
  request(:POST, nil, params, &handler)
end