Blame view

lib/syspro/api_resource.rb 808 Bytes
dc8aa5b6   Joe Weakley   Rubocop corrections
1
2
3
4
  # frozen_string_literal: true
  
  require 'syspro/syspro_object'
  require 'syspro/api_operations/request'
db76748d   Isaac Lewis   cop a bunch of St...
5
6
  
  module Syspro
3d0157a5   Isaac Lewis   add logoff
7
8
    class ApiResource < SysproObject
      include Syspro::ApiOperations::Request
db76748d   Isaac Lewis   cop a bunch of St...
9
10
  
      def self.class_name
dc8aa5b6   Joe Weakley   Rubocop corrections
11
        name.split('::')[-1]
db76748d   Isaac Lewis   cop a bunch of St...
12
13
14
      end
  
      def self.resource_url
3d0157a5   Isaac Lewis   add logoff
15
        if self == ApiResource
dc8aa5b6   Joe Weakley   Rubocop corrections
16
          raise NotImplementedError, 'APIResource is an abstract class.  You should perform actions on its subclasses (Charge, Customer, etc.)'
db76748d   Isaac Lewis   cop a bunch of St...
17
        end
3d0157a5   Isaac Lewis   add logoff
18
        "/#{CGI.escape(class_name.downcase)}"
db76748d   Isaac Lewis   cop a bunch of St...
19
20
      end
  
db76748d   Isaac Lewis   cop a bunch of St...
21
22
23
24
25
26
27
28
29
30
31
32
33
      def refresh
        resp, opts = request(:get, resource_url, @retrieve_params)
        initialize_from(resp.data, opts)
      end
  
      def self.retrieve(id, opts = {})
        opts = Util.normalize_opts(opts)
        instance = new(id, opts)
        instance.refresh
        instance
      end
    end
  end