Sha256: 2cdcddd46bea0fc799765aaa486da3b1e77596e3490279af13a61952b4bef2f5

Contents?: true

Size: 834 Bytes

Versions: 5

Compression:

Stored size: 834 Bytes

Contents

module Pingpp
  class AppBasedResource < APIResource

    def self.resource_url(opts={})
      if self == AppBasedResource
        raise NotImplementedError.new('AppBasedResource is an abstract class. You should perform actions on its subclasses (User, etc.)')
      end

      app_id = opts[:app]
      unless app_id ||= Pingpp.app_id
        raise InvalidRequestError.new("Please set app_id using Pingpp.app_id = <APP_ID>", 'app_id')
      end

      url = "/v1/apps/#{app_id}"

      if opts.has_key?(:parents)
        if opts[:parents].is_a?(Array)
          url + "/#{opts[:parents].join('/')}/#{CGI.escape(uri_object_name.downcase)}s"
        else
          raise ArgumentError.new("opts[:parents] should be an Array")
        end
      else
        url + "/#{CGI.escape(uri_object_name.downcase)}s"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pingpp-2.2.4 lib/pingpp/app_based_resource.rb
pingpp-2.2.3 lib/pingpp/app_based_resource.rb
pingpp-2.2.2 lib/pingpp/app_based_resource.rb
pingpp-2.2.1 lib/pingpp/app_based_resource.rb
pingpp-2.2.0 lib/pingpp/app_based_resource.rb