Sha256: 304d9982f0cf635d5d929f6ef5c384e895f5a835ca3666fd864f1715013165bd

Contents?: true

Size: 782 Bytes

Versions: 5

Compression:

Stored size: 782 Bytes

Contents

# frozen_string_literal: true

class RocketfuelApi::Resource
  def initialize(json, service)
    @json = json
    @service = service
  end

  def update(route_params = {}, body_params = {})
    resource = @service.update(id, route_params, body_params)
    @json = resource.raw_json

    self
  end

  def delete(route_params = {})
    @service.delete(id, route_params)
  end

  def raw_json
    @json
  end

  def method_missing(sym, *args, &block)
    if @json.respond_to?(sym)
      @json.public_send(sym, *args, &block)
    elsif @json.key?(sym.to_s)
      @json[sym.to_s]
    else
      super
    end
  end

  def respond_to_missing?(method_name, include_private = false)
    @json.respond_to?(sym) || @json.key?(sym.to_s) || super
  end

  def to_s
    @json.inspect
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rocketfuel_api-0.2.0 lib/rocketfuel_api/resource.rb
rocketfuel_api-0.1.3 lib/rocketfuel_api/resource.rb
rocketfuel_api-0.1.2 lib/rocketfuel_api/resource.rb
rocketfuel_api-0.1.1 lib/rocketfuel_api/resource.rb
rocketfuel_api-0.1.0 lib/rocketfuel_api/resource.rb