Skip to content

Resource refactor #40

@ngelx

Description

@ngelx

As the promisepay API resources are standard REST, almost all the classes *Resource do pretty much the same. There is no need of that such amount of code repetition that degrade the code quality and increase complexity.
What i'm talking is doing something like:

module Promisepay
  class RestResource < BaseResource
        def find_all(options = {})
          response = JSON.parse(@client.get(resource_key_name, options).body)
          resources = response.key?(resource_key_name) ? response[resource_key_name] : []
          resources.map { |attributes| model.new(@client, attributes) }
         end
         # So on for all the others rest actions.
  end
end

module Promisepay
  # Resource for the Users API
  class UserResource < RestResource
    def model
      Promisepay::User
    end
    def resource_key_name
      "users"
    end
    # any extra method needed.
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions