Class: ApigeePlatform::Objects::Base

Inherits:
ActiveResource::Base
  • Object
show all
Includes:
Associations
Defined in:
lib/apigee-platform/objects/base.rb

Direct Known Subclasses

Api, Apiproduct, App, Company, Developer, Key

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Associations

included

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
# File 'lib/apigee-platform/objects/base.rb', line 5

def initialize(*args)
  super(*args)
  @id = self.attributes[self.class.primary_key]
  self
end

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



36
37
38
# File 'lib/apigee-platform/objects/base.rb', line 36

def config
  @config
end

Class Method Details

.collection_path(prefix_options = {}, query_options = nil) ⇒ Object



73
74
75
76
77
# File 'lib/apigee-platform/objects/base.rb', line 73

def collection_path(prefix_options = {}, query_options = nil)
  check_prefix_options(prefix_options)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
end

.configure(config) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/apigee-platform/objects/base.rb', line 38

def configure(config)
  @config = config.symbolize_keys.slice(:user, :password, :organization, :url)
  @config[:url] ||= 'https://api.enterprise.apigee.com'

  self.site = @config[:url] + '/v1/o/' + @config[:organization]
  self.user = @config[:user]
  self.password = @config[:password]

  require 'apigee-platform/objects/api'
  require 'apigee-platform/objects/apiproduct'
  require 'apigee-platform/objects/app'
  require 'apigee-platform/objects/key'
  require 'apigee-platform/objects/company'
  require 'apigee-platform/objects/company_app'
  require 'apigee-platform/objects/company_app_key'
  require 'apigee-platform/objects/developer'
  require 'apigee-platform/objects/developer_app'
  require 'apigee-platform/objects/developer_app_key'

  self
end

.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object



79
80
81
82
83
# File 'lib/apigee-platform/objects/base.rb', line 79

def element_path(id, prefix_options = {}, query_options = nil)
  check_prefix_options(prefix_options)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{collection_name}/#{URI.parser.escape id.to_s}#{query_string(query_options)}"
end

.instantiate_record(record, prefix_options = {}) ⇒ Object



68
69
70
71
# File 'lib/apigee-platform/objects/base.rb', line 68

def instantiate_record(record, prefix_options = {})
  return record unless record.is_a?(Hash)
  super(record, prefix_options)
end

.prefix_optionsObject



64
65
66
# File 'lib/apigee-platform/objects/base.rb', line 64

def prefix_options
  @prefix_options || []
end

.set_prefix_options(options) ⇒ Object



60
61
62
# File 'lib/apigee-platform/objects/base.rb', line 60

def set_prefix_options(options)
  @prefix_options = options
end

Instance Method Details

#custom_attributesObject



11
12
13
# File 'lib/apigee-platform/objects/base.rb', line 11

def custom_attributes
  @custom_attributes ||= ApigeePlatform::CustomAttributes.new(self)
end

#encode(options = {}) ⇒ Object



15
16
17
# File 'lib/apigee-platform/objects/base.rb', line 15

def encode(options={}) 
  super options.merge(:root => false)
end

#idObject



30
31
32
33
# File 'lib/apigee-platform/objects/base.rb', line 30

def id 
  # need that to get correct element_path when update resource object
  @id ||= self.attributes[self.class.primary_key]
end

#load(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/apigee-platform/objects/base.rb', line 19

def load(*args)
  super(*args)
  self.attributes['attributes'].map!{|r| {'name' => r.name, 'value' => r.value}} if self.attributes['attributes']

  self.class.prefix_options.each do |k,v|
    self.prefix_options[k] = self.attributes[v]
  end
  self.onload if self.respond_to?(:onload)
  self
end