Package pyperry :: Package adapter :: Module http :: Class RestfulHttpAdapter
[frames] | no frames]

Class RestfulHttpAdapter

source code

                      object --+    
                               |    
abstract_adapter.AbstractAdapter --+
                                   |
                                  RestfulHttpAdapter

Adapter for communicating with REST web services over HTTP

Required configuration keywords:

Optional configuration keywords:

Instance Methods
 
read(self, **kwargs)
Performs an HTTP GET request and uses the relation dict to construct the query string parameters
source code
 
write(self, **kwargs)
Write object's attributes to the datastore
source code
 
delete(self, **kwargs)
Delete the object from the datastore
source code
 
persistence_request(self, http_method, **kwargs) source code
 
response(self, http_response, response_body) source code
 
http_request(self, http_method, url, params, **kwargs) source code
 
url_for(self, http_method, model=None)
Constructs the URL for the request
source code
 
params_for(self, model)
Builds and encodes a parameters dict for the request
source code
 
query_string_for(self, relation)
Encodes the relation and any query modifiers into a query string suitable for use in a URL.
source code
 
config_value(self, option, default=None)
Returns the value of the configuration option named by option.
source code
 
restful_params(self, params, key_prefix='')
Recursively flattens nested dicts into a list of (key, value) tuples so they can be encoded as a query string that can be understood by our webservices.
source code
 
params_for_dict(self, params, params_list, key_prefix='') source code
 
params_for_list(self, params, params_list, key_prefix='') source code
 
key_for_params(self, key, value, key_prefix='') source code
 
params_value(self, value) source code

Inherited from abstract_adapter.AbstractAdapter: __call__, __init__, execute, reset

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables

Inherited from abstract_adapter.AbstractAdapter: adapter_types

Properties

Inherited from abstract_adapter.AbstractAdapter: stack

Inherited from object: __class__

Method Details

read(self, **kwargs)

source code 

Performs an HTTP GET request and uses the relation dict to construct the query string parameters

Overrides: abstract_adapter.AbstractAdapter.read

write(self, **kwargs)

source code 

Write object's attributes to the datastore

Overrides: abstract_adapter.AbstractAdapter.write
(inherited documentation)

delete(self, **kwargs)

source code 

Delete the object from the datastore

Overrides: abstract_adapter.AbstractAdapter.delete
(inherited documentation)

query_string_for(self, relation)

source code 

Encodes the relation and any query modifiers into a query string suitable for use in a URL. Includes the '?' as part of the query string and returns None if there are no parameters.

config_value(self, option, default=None)

source code 

Returns the value of the configuration option named by option.

If the option is not configured, this method will use the default value if given. Otherwise a ConfigurationError will be thrown.

restful_params(self, params, key_prefix='')

source code 

Recursively flattens nested dicts into a list of (key, value) tuples so they can be encoded as a query string that can be understood by our webservices.

In particular, our webservices require nested dicts to be transformed to a format where the nesting is indiciated by a key naming syntax where there are no nested dicts. Instead, the nested dicts are 'flattened' by using a key naming syntax where the nested keys are enclosed in brackets and preceded by the non-nested key.

The best way to understand this format is by example:

Example input:

   {
     'key': 'value',
     'foo': {
       'list': [1, 2, 3],
       'bar': {
         'double-nested': 'value'
       }
     }
   }

Example output:

   [
     ('key', 'value'),
     ('foo[list][]', 1), ('foo[list][]', 2), ('foo[list][]', 3),
     ('foo[bar][double-nested]', 'value')
   ]

When calling the urlencode on the result of this method, you will generate a query string similar to the following. The order of the parameters may vary except that successive array elements will also be successive in the query string:

   'key=value&foo[list][]=1&foo[list][]=2&foo[list][]=3&foo[bar][double-nested]=value'