Sha256: 4594bf5b43fa529bd9c54b599cebf7dc391fed8996cc7440e23f193cac31fe23

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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)
            new_from_json(json)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
chartmogul-ruby-1.6.6 lib/chartmogul/api/actions/custom.rb
chartmogul-ruby-1.6.4 lib/chartmogul/api/actions/custom.rb
chartmogul-ruby-1.6.3 lib/chartmogul/api/actions/custom.rb
chartmogul-ruby-1.6.2 lib/chartmogul/api/actions/custom.rb
chartmogul-ruby-1.6.1 lib/chartmogul/api/actions/custom.rb