Sha256: 57872e0366f9da4c338f1c531ac1156c87dccc073c4cbc90966db5be3fc61c84

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

module ChartMogul
  module API
    module Actions
      module Custom
        def self.included(base)
          base.extend ClassMethods
        end

        def custom_without_assign!(http_method, http_path, body_data = {})
          self.class.custom_without_assign!(http_method, http_path, body_data)
        end

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

        module ClassMethods
          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

          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
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chartmogul-ruby-0.1.3 lib/chartmogul/api/actions/custom.rb
chartmogul-ruby-0.1.2 lib/chartmogul/api/actions/custom.rb