Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource refactor #40

Open
ngelx opened this issue Jan 19, 2017 · 0 comments
Open

Resource refactor #40

ngelx opened this issue Jan 19, 2017 · 0 comments

Comments

@ngelx
Copy link

ngelx commented Jan 19, 2017

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant