Class: Pingpp::UserBasedResource

Inherits:
APIResource show all
Defined in:
lib/pingpp/user_based_resource.rb

Direct Known Subclasses

Coupon, SettleAccount

Class Method Summary collapse

Methods inherited from APIResource

class_name, #refresh, #resource_url, retrieve, uri_object_name

Methods included from APIOperations::Request

included

Methods inherited from PingppObject

#==, #[], #[]=, #_dump, _load, #as_json, construct_from, #each, #initialize, #inspect, #keys, #refresh_from, #respond_to?, #serialize_params, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Pingpp::PingppObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Pingpp::PingppObject

Class Method Details

.object_nameObject



4
5
6
# File 'lib/pingpp/user_based_resource.rb', line 4

def self.object_name
  class_name.downcase
end

.resource_url(opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pingpp/user_based_resource.rb', line 8

def self.resource_url(opts={})
  if self == UserBasedResource
    raise NotImplementedError.new('UserBasedResource is an abstract class. You should perform actions on its subclasses (BalanceTransaction, 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

  unless user_id = opts[:user]
    raise InvalidRequestError.new("Please pass user_id in opts like {:user => <USER_ID>}", 'user')
  end

  url = "/v1/apps/#{app_id}/users/#{user_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