Peter Sanchez avatar Peter Sanchez committed 8423c10

Working NSZone class. Still needs hosts integration but have to build NZHost class first

Comments (0)

Files changed (1)

         self.element = ''
         self.response_headers = {}
         
-        if data:
+        if isinstance(data, dict):
             self.load(data)
     
     def _is_protected(self, name):
             except KeyError:
                 return super(ZerigoDNS, self).__getattribute__(name)
     
-    def load(self, data):
+    def load(self, data, reset=True):
+        if reset:
+            self.vals = {}  # Reset vals
+
         for k, v in data.iteritems():
             setattr(self, k, v)
     
             if id is not None:
                 call_path = urlparse.urljoin(
                     self.api_path,
-                    '%s/%i.xml' % (self.element, id),
+                    '%s/%s.xml' % (self.element, str(id)),
                 )
             else:
                 call_path = urlparse.urljoin(
         return self.parse(self.send_request(path=api_path))
     
     def build_blank_zone(self):
-        self.load(self.get_blank_zone()['zone'])
+        self.load(self.get_blank_zone()['zone'])
+    
+    def create(self, data, load_blank=False):
+        if data.has_key('zone'):
+            data = data.get('zone')
+        zone = NSZone(
+            self.user,
+            self.key,
+            data=data,
+            is_secure=self.is_secure,
+            is_debug=self.is_debug,
+        )
+        if load_blank:
+            zone.build_blank_zone()
+            zone.load(data, reset=False)
+        zone.save()
+        return zone
+    
+    def find_all(self, opts={}):
+        return self.zones(opts=opts)
+    
+    def zones(self, opts={}):
+        xml = self.send_request(opts=opts)
+        data = self.parse(xml)
+        return [
+            NSZone(
+                self.user,
+                self.key,
+                data=zdata['zone'],
+                is_secure=self.is_secure,
+                is_debug=self.is_debug,
+            ) for zdata in data.get('zones', [])
+        ]
+    
+    def reload(self):
+        if not hasattr(self, 'id'):
+            raise ZerigoError('Cannot retrieve zone without a valid id')
+        xml = self.send_request(method='GET', id=int(self.id))
+        data = self.parse(xml)
+        self.load(data['zone'])
+        return self
+    
+    def find(self, id):
+        zone = NSZone(
+            self.user,
+            self.key,
+            data={'id': id,},
+            is_secure=self.is_secure,
+            is_debug=self.is_debug
+        )
+        zone.reload()
+        return zone
+    
+    def find_by_domain(self, domain):
+        zone = NSZone(
+            self.user,
+            self.key,
+            is_secure=self.is_secure,
+            is_debug=self.is_debug
+        )
+        xml = zone.send_request(method='GET', id=domain)
+        data = self.parse(xml)
+        zone.load(data['zone'])
+        return zone
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.