Class: Telnyx::APIResource
- Inherits:
-
TelnyxObject
- Object
- TelnyxObject
- Telnyx::APIResource
- Includes:
- Telnyx::APIOperations::Request
- Defined in:
- lib/telnyx/api_resource.rb
Direct Known Subclasses
AccessIPAddress, AccessIPRange, Address, AlphanumericSenderId, AuthenticationProviders, AvailablePhoneNumber, BatchMdrReport, BillingGroup, Brand, BulkCreation, BulkCredential, BulkSimCardAction, BusinessIdentitie, Call, CallControlApplication, CallEvent, CallRecording, Campaign, CdrUsageReport, ChannelZone, Comment, Conference, Connection, CredentialConnection, CsvDownload, CustomStorageCredential, DetailRecord, DialogflowConnection, Documents, DynamicEmergencyEndpoint, Embedding, Enum, Event, FQDN, FQDNConnection, Fax, FaxApplication, GlobalIp, GlobalIpAllowedPort, GlobalIpAssignment, GlobalIpAssignmentHealth, GlobalIpAssignmentUsage, GlobalIpLatency, GlobalIpProtocol, GlobalIpUsage, IP, IPConnection, Inference, InventoryCoverage, LedgerBillingGroupReport, ManagedAccount, MdrUsageReport, Media, Message, MessageNumberPool, MessagingHostedNumber, MessagingHostedNumberOrder, MessagingPhoneNumber, MessagingProfile, MessagingTollfreeVerification, MessagingUrlDomain, MobileOperatorNetwork, MobilePushCredential, Network, NotificationChannel, NotificationEvent, NotificationEventCondition, NotificationProfile, NotificationSetting, NumberBlockOrder, NumberLookup, NumberOrder, NumberOrderDocument, NumberReservation, OtaUpdate, OutboundVoiceProfile, PartnerCampaign, PhoneNumber, PhoneNumberAssignmentByProfile, PhoneNumberBlockJob, PhoneNumberCampaign, PhoneNumberRegulatoryRequirement, PortabilityCheck, PortingOrder, Portout, PrivateWirelessGateway, PublicInternetGateway, Queue, QueueCall, Region, RegulatoryRequirement, Requirement, RequirementType, Room, RoomComposition, RoomParticipant, RoomRecording, RoomSession, ShortCode, SimCard, SimCardAction, SimCardDataUsageNotification, SimCardGroup, SimCardGroupAction, SimCardOrder, SingletonAPIResource, Summary, TelephonyCredential, TexmlApplication, Verification, VerifiedCallsDisplayProfile, VerifyProfile, VirtualCrossConnect, VirtualCrossConnectRegion, Wdr, WebhookDeliverie, WireguardInterface, WireguardPeer, WirelessDetailRecordsReport
Class Attribute Summary collapse
-
.descendants ⇒ Object
readonly
Returns the value of attribute descendants.
Instance Attribute Summary collapse
-
#save_with_parent ⇒ Object
A flag that can be set a behavior that will cause this resource to be encoded and sent up along with an update of its parent resource.
Class Method Summary collapse
- .class_name ⇒ Object
- .identified_resource_url(id) ⇒ Object
- .inherited(subclass) ⇒ Object
- .resource_url(inner_id = nil) ⇒ Object
- .retrieve(id, opts = {}) ⇒ Object
-
.save_nested_resource(name) ⇒ Object
A metaprogramming call that specifies that a field of a resource can be its own type of API resource (say a nested card under an account for example), and if that resource is set, it should be transmitted to the API on a create or update.
Instance Method Summary collapse
Methods included from Telnyx::APIOperations::Request
Methods inherited from TelnyxObject
#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values
Constructor Details
This class inherits a constructor from Telnyx::TelnyxObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Telnyx::TelnyxObject
Class Attribute Details
.descendants ⇒ Object (readonly)
Returns the value of attribute descendants.
20 21 22 |
# File 'lib/telnyx/api_resource.rb', line 20 def descendants @descendants end |
Instance Attribute Details
#save_with_parent ⇒ Object
A flag that can be set a behavior that will cause this resource to be encoded and sent up along with an update of its parent resource. This is usually not desirable because resources are updated individually on their own endpoints, but there are certain cases where this is allowed.
11 12 13 |
# File 'lib/telnyx/api_resource.rb', line 11 def save_with_parent @save_with_parent end |
Class Method Details
.class_name ⇒ Object
23 24 25 |
# File 'lib/telnyx/api_resource.rb', line 23 def self.class_name name.split("::")[-1] end |
.identified_resource_url(id) ⇒ Object
42 43 44 45 46 |
# File 'lib/telnyx/api_resource.rb', line 42 def self.identified_resource_url(id) return "/v2/#{resource_path(id)}" if respond_to?("resource_path") "#{resource_url}/#{CGI.escape(id)}" end |
.inherited(subclass) ⇒ Object
14 15 16 17 18 |
# File 'lib/telnyx/api_resource.rb', line 14 def inherited(subclass) super @descendants ||= [] @descendants << subclass end |
.resource_url(inner_id = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/telnyx/api_resource.rb', line 27 def self.resource_url(inner_id = nil) if self == APIResource raise NotImplementedError, "APIResource is an abstract class. You should perform actions on its subclasses" end # Namespaces are separated in object names with periods (.) and in URLs # with forward slashes (/), so replace the former with the latter. return "/v2/#{resource_path(inner_id)}" if respond_to?("resource_path") return "/v2/#{self::RESOURCE_PATH}" if const_defined?("RESOURCE_PATH") object_name = self::OBJECT_NAME.downcase keywords = %w[generate summarize global_ip_usage global_ip_latency global_ip_assignment_usage global_ip_assignment_health sub_request campaign] url_segment = object_name.tr(".", "/") keywords.any? { |keyword| url_segment.include?(keyword) } ? "/v2/#{url_segment}" : "/v2/#{url_segment}s" end |
.retrieve(id, opts = {}) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/telnyx/api_resource.rb', line 86 def self.retrieve(id, opts = {}) opts = Util.normalize_opts(opts) instance = new(id, **opts) instance.refresh instance end |
.save_nested_resource(name) ⇒ Object
A metaprogramming call that specifies that a field of a resource can be its own type of API resource (say a nested card under an account for example), and if that resource is set, it should be transmitted to the API on a create or update. Doing so is not the default behavior because API resources should normally be persisted on their own RESTful endpoints.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/telnyx/api_resource.rb', line 54 def self.save_nested_resource(name) define_method(:"#{name}=") do |value| super(value) # The parent setter will perform certain useful operations like # converting to an APIResource if appropriate. Refresh our argument # value to whatever it mutated to. value = send(name) # Note that the value may be subresource, but could also be a scalar # (like a tokenized card's ID for example), so we check the type before # setting #save_with_parent here. value.save_with_parent = true if value.is_a?(APIResource) value end end |
Instance Method Details
#refresh ⇒ Object
81 82 83 84 |
# File 'lib/telnyx/api_resource.rb', line 81 def refresh resp, opts = request(:get, resource_url, @retrieve_params, @opts) initialize_from(resp.data[:data], opts) end |
#resource_url ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/telnyx/api_resource.rb', line 72 def resource_url unless (id = self["id"]) raise InvalidRequestError, "Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}" end return self.class.resource_url(id).to_s if self.class.respond_to?("resource_path") # Use resource_path defined paths "#{self.class.resource_url}/#{CGI.escape(id)}" end |