Exemplo n.º 1
0
    def track(self, jobid):
        response = self.client.post('tracker', jobid=jobid)
        response = response['result']

        if response['status'] is False:
            raise PostoError(response['message'])
        return response
Exemplo n.º 2
0
    def bookingDetail(self, jobid, rider):
        response = self.client.post('booking/details',
                                    jobid=jobid,
                                    rider=rider)
        response = response['booking_details']

        if response[0]['status'] is False:
            raise PostoError(response[0]['message'])
        return response
Exemplo n.º 3
0
    def estimateByAddress(self, pickup, delivery):
        response = self.client.post('calculator/address',
                                    pickup=pickup,
                                    delivery=delivery)
        response = response['result']

        if response[0]['status'] is False:
            raise PostoError(response[0]['message'])
        return response[0]
Exemplo n.º 4
0
    def execute(self, uri, http_verb, extra_headers=None, **kw):
        if not ('app_id' in self.ACCESS_KEYS and 'token' in self.ACCESS_KEYS):
            raise PostoError('Missing connection credentials %s' %
                             self.ACCESS_KEYS)

        url = uri if uri.startswith(API_ROOT) else API_ROOT + uri

        data = kw or {}

        if http_verb == 'GET' and data:
            url += '?%s' % urlencode(data)
            data = {}

        data.update(self.ACCESS_KEYS)
        data = urlencode(data).encode('utf-8')

        headers = {
            'Content-type':
            'application/x-www-form-urlencoded',

            # Need to have user-agent header because API is behind CloudFlare
            # and CloudFlare will block requests without user-agent header
            'User-Agent':
            'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/38.0',
        }
        headers.update(extra_headers or {})

        request = Request(url, data, headers)

        request.get_method = lambda: http_verb

        try:
            response = urlopen(request, timeout=CONNECTION_TIMEOUT)
        except HTTPError as e:
            raise PostoError(e.read())

        return json.loads(response.read().decode('utf-8'))
Exemplo n.º 5
0
    def book(self, **kw):
        # Required params:
        # - sender_fullname
        # - sender_email
        # - sender_phone
        # - recipient_fullname
        # - recipient_email
        # - recipient_phone
        # - pickup_address
        # - delivery_address
        # - pickup_latlng
        # - delivery_latlng
        # - distance_km
        # - price_myr
        # - trip_type
        # - instruction_notes
        # - datetime_pickup

        response = self.client.post('booking/new', **kw)
        response = response['result']

        if response[0]['status'] is False:
            raise PostoError(response[0]['message'])
        return response
Exemplo n.º 6
0
 def history(self):
     response = self.client.post('history/info')
     response = response['result']
     if response[0]['status'] is False:
         raise PostoError(response[0]['message'])
     return response