Module: ChartMogul::API::Actions::Custom::ClassMethods

Defined in:
lib/chartmogul/api/actions/custom.rb

Instance Method Summary collapse

Instance Method Details

#custom!(http_method, http_path, body_data = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/chartmogul/api/actions/custom.rb', line 29

def custom!(http_method, http_path, body_data = {})
  json = custom_without_assign!(http_method, http_path, body_data)

  if resource_root_key && json.key?(resource_root_key)
    json[resource_root_key].map { |attributes| new_from_json(attributes) }
  else
    new_from_json(json)
  end
end

#custom_without_assign!(http_method, http_path, body_data = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/chartmogul/api/actions/custom.rb', line 19

def custom_without_assign!(http_method, http_path, body_data = {})
  resp = handling_errors do
    connection.send(http_method, http_path) do |req|
      req.headers['Content-Type'] = 'application/json'
      req.body = JSON.dump(body_data)
    end
  end
  ChartMogul::Utils::JSONParser.parse(resp.body)
end