Module: Chargify::Behaviors::Metadata
- Included in:
- CustomerMetafield, SubscriptionMetadata, SubscriptionMetafield
- Defined in:
- lib/chargify_api_ares/behaviors/metadata.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #convert_attributes(attributes) ⇒ Object
- #destroy ⇒ Object
- #element_path(id = nil, pre_options = {}, query_options = {}) ⇒ Object
- #load_attributes_from_response(response) ⇒ Object
- #resource_id=(value) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 4 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#convert_attributes(attributes) ⇒ Object
20 21 22 |
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 20 def convert_attributes(attributes) attributes.is_a?(Array) ? attributes.first : attributes end |
#destroy ⇒ Object
8 9 10 |
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 8 def destroy connection.delete("#{element_path}?current_name=#{URI.encode(current_name)}") end |
#element_path(id = nil, pre_options = {}, query_options = {}) ⇒ Object
16 17 18 |
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 16 def element_path(id = nil, = {}, = {}) collection_path() end |
#load_attributes_from_response(response) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 24 def load_attributes_from_response(response) if (response_code_allows_body?(response.code) && (response['Content-Length'].nil? || response['Content-Length'] != "0") && !response.body.nil? && response.body.strip.size > 0) attributes = self.class.format.decode(response.body) # This is a major hack, but has to be done for metadata / metafields because we return # an array instead of a single object attributes = convert_attributes(attributes) resource = load(attributes, true) resource.current_name = resource.name @persisted = true end end |
#resource_id=(value) ⇒ Object
12 13 14 |
# File 'lib/chargify_api_ares/behaviors/metadata.rb', line 12 def resource_id=(value) self. = {:resource_id => value} end |