Class: GeoAPI::View
Direct Known Subclasses
Class Attribute Summary collapse
-
.path_prefix ⇒ Object
Class methods.
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#view_type ⇒ Object
Returns the value of attribute view_type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs) ⇒ View
constructor
Instance methods.
- #load ⇒ Object
- #setup(attrs) ⇒ Object
- #to_json(options = nil) ⇒ Object
Methods inherited from GeoObject
api_key_from_parameters, delete, entity_type, get, post, search
Constructor Details
#initialize(attrs) ⇒ View
Instance methods
53 54 55 |
# File 'lib/geoapi/view.rb', line 53 def initialize attrs setup(attrs) end |
Class Attribute Details
.path_prefix ⇒ Object
Class methods
16 17 18 |
# File 'lib/geoapi/view.rb', line 16 def path_prefix @path_prefix end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
4 5 6 |
# File 'lib/geoapi/view.rb', line 4 def entries @entries end |
#guid ⇒ Object
Returns the value of attribute guid.
4 5 6 |
# File 'lib/geoapi/view.rb', line 4 def guid @guid end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/geoapi/view.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/geoapi/view.rb', line 4 def name @name end |
#view_type ⇒ Object
Returns the value of attribute view_type.
4 5 6 |
# File 'lib/geoapi/view.rb', line 4 def view_type @view_type end |
Class Method Details
.find(*args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/geoapi/view.rb', line 24 def self.find(*args) #raise ArgumentError, "First argument must be symbol (:all or :get)" unless args.first.kind_of?(Symbol) params = args. params = params == {} ? nil : params results = nil params[:guid] = "user-#{GeoAPI::API_KEY}-#{params[:id]}" unless params[:id].blank? raise ArgumentError, "Arguments should include a entity :guid or an :id" if params[:guid].blank? && params[:id].blank? raise ArgumentError, "Arguments should include a view :name" if params[:name].blank? begin debugger response = get("/e/#{params[:guid]}/#{self.class.path_prefix}/#{params[:name]}") rescue raise BadRequest, "There was a problem communicating with the API" end entries = {'entries' => response['result']} # There are no entries in this view results = View.new(entries.merge({'guid'=>params[:guid], 'name'=>params[:name]})) unless response['result'].blank? #the api doesn't return a guid in json?! results end |
Instance Method Details
#load ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/geoapi/view.rb', line 74 def load raise ArgumentError, "Properties should include a .guid or .id" if self.guid.blank? && self.id.blank? raise ArgumentError, "Properties should include a .name" if self.name.blank? the_guid = self.guid the_guid ||= "user-#{GeoAPI::API_KEY}-#{self.id}" begin response = self.class.get("/e/#{the_guid}/#{self.class.path_prefix}/#{self.name}") rescue raise BadRequest, "There was a problem communicating with the API" end entries = {'entries' => response['result']} # There are no entries in this view self.setup(entries.merge({'guid'=>self.guid, 'name'=>self.name })) self end |
#setup(attrs) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/geoapi/view.rb', line 57 def setup attrs self.name = attrs['name'] self.guid = attrs['guid'] self.view_type = attrs['type'] self.entries = [] unless attrs['entries'].blank? if attrs['entries'].size > 0 attrs['entries'].each do |entry| self.entries << GeoAPI::Entry.new({'properties'=>entry}) end self.entries.reverse! end end end |
#to_json(options = nil) ⇒ Object
95 96 97 |
# File 'lib/geoapi/view.rb', line 95 def to_json =nil {:name=>name, :guid=>guid, :type=>view_type}.to_json end |