Class: Google::APIClient::Resource
- Inherits:
-
Object
- Object
- Google::APIClient::Resource
- Defined in:
- lib/google/api_client/discovery/resource.rb
Overview
A resource that has been described by a discovery document.
Instance Attribute Summary collapse
-
#discovery_document ⇒ String
readonly
Unparsed discovery document for the resource.
-
#method_base ⇒ Addressable::URI
Returns the base URI for this resource.
-
#name ⇒ String
readonly
Returns the identifier for the resource.
Instance Method Summary collapse
-
#description ⇒ Hash
Returns a human-readable description of the resource.
-
#discovered_methods ⇒ Array
A list of methods available on this resource.
-
#discovered_resources ⇒ Array
A list of sub-resources available on this resource.
-
#initialize(api, method_base, resource_name, discovery_document) ⇒ Google::APIClient::Resource
constructor
Creates a description of a particular version of a resource.
-
#inspect ⇒ String
Returns a
String
representation of the resource’s state. -
#to_h ⇒ Hash
Converts the resource to a flat mapping of RPC names and method objects.
Constructor Details
#initialize(api, method_base, resource_name, discovery_document) ⇒ Google::APIClient::Resource
Creates a description of a particular version of a resource.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/google/api_client/discovery/resource.rb', line 41 def initialize(api, method_base, resource_name, discovery_document) @api = api @method_base = method_base @name = resource_name @discovery_document = discovery_document = (class <<self; self; end) self.discovered_resources.each do |resource| method_name = ActiveSupport::Inflector.underscore(resource.name).to_sym if !self.respond_to?(method_name) .send(:define_method, method_name) { resource } end end self.discovered_methods.each do |method| method_name = ActiveSupport::Inflector.underscore(method.name).to_sym if !self.respond_to?(method_name) .send(:define_method, method_name) { method } end end end |
Instance Attribute Details
#discovery_document ⇒ String (readonly)
Returns unparsed discovery document for the resource.
62 63 64 |
# File 'lib/google/api_client/discovery/resource.rb', line 62 def discovery_document @discovery_document end |
#method_base ⇒ Addressable::URI
Returns the base URI for this resource.
74 75 76 |
# File 'lib/google/api_client/discovery/resource.rb', line 74 def method_base @method_base end |
#name ⇒ String (readonly)
Returns the identifier for the resource.
68 69 70 |
# File 'lib/google/api_client/discovery/resource.rb', line 68 def name @name end |
Instance Method Details
#description ⇒ Hash
Returns a human-readable description of the resource.
80 81 82 |
# File 'lib/google/api_client/discovery/resource.rb', line 80 def description return @discovery_document['description'] end |
#discovered_methods ⇒ Array
A list of methods available on this resource.
118 119 120 121 122 123 124 125 |
# File 'lib/google/api_client/discovery/resource.rb', line 118 def discovered_methods return @discovered_methods ||= ( (@discovery_document['methods'] || []).inject([]) do |accu, (k, v)| accu << Google::APIClient::Method.new(@api, self.method_base, k, v) accu end ) end |
#discovered_resources ⇒ Array
A list of sub-resources available on this resource.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/google/api_client/discovery/resource.rb', line 103 def discovered_resources return @discovered_resources ||= ( (@discovery_document['resources'] || []).inject([]) do |accu, (k, v)| accu << Google::APIClient::Resource.new( @api, self.method_base, k, v ) accu end ) end |
#inspect ⇒ String
Returns a String
representation of the resource’s state.
149 150 151 152 153 |
# File 'lib/google/api_client/discovery/resource.rb', line 149 def inspect sprintf( "#<%s:%#0x NAME:%s>", self.class.to_s, self.object_id, self.name ) end |
#to_h ⇒ Hash
Converts the resource to a flat mapping of RPC names and method objects.
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/google/api_client/discovery/resource.rb', line 132 def to_h return @hash ||= (begin methods_hash = {} self.discovered_methods.each do |method| methods_hash[method.id] = method end self.discovered_resources.each do |resource| methods_hash.merge!(resource.to_h) end methods_hash end) end |