<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -91,13 +91,13 @@ FE_SERVER    = 'fireeagle.yahoo.net'
 
 # Calling templates
 API_URL_TEMPLATE   = string.Template(
-    '${proto}://${server}/api/' + API_VERSION + '/${method}'
+    '${server}/api/' + API_VERSION + '/${method}'
 )
 OAUTH_URL_TEMPLATE = string.Template(
-    '${proto}://${server}/oauth/${method}'
+    '${server}/oauth/${method}'
 )
 AUTHORIZE_URL_TEMPLATE = string.Template(
-    '${proto}://${server}/oauth/${method}?oauth_token=${token}'
+    '${server}/oauth/${method}?oauth_token=${token}'
 )
 POST_HEADERS = {
     'Content-type': 'application/x-www-form-urlencoded',
@@ -247,27 +247,6 @@ FIREEAGLE_METHODS = {
     }
 }
 
-
-def read_consumer_tokens():
-    info = {}
-
-    # try reading key and secret from ~/.fireeaglerc
-    fn = os.path.expanduser(&quot;~/.fireeaglerc&quot;)
-    if os.path.exists(fn):
-        for line in open(fn).readlines():
-            p = line.find(&quot;#&quot;)
-            if p != -1: line = line[:p]
-            line = line.strip()
-            if not line: continue
-            k, v = line.split(&quot;=&quot;, 1)
-            info[k.strip()] = v.strip()
-
-    # if we couldn't find them from .fireeaglerc, ask
-    if not info.has_key('consumer_key'): info['consumer_key'] = raw_input(&quot;Enter consumer key: &quot;)
-    if not info.has_key('consumer_secret'): info['consumer_secret'] = raw_input(&quot;Enter consumer secret: &quot;)
-
-    return (info['consumer_key'], info['consumer_secret'])
-
 class FireEagleException( Exception ):
     pass
 
@@ -287,21 +266,63 @@ class FireEagleAccumulator:
     
 
 class FireEagle:
-    def __init__( self, consumer_key, consumer_secret ):
+    def __init__( self, rc_or_consumer_key, consumer_secret=None ):
+        &quot;&quot;&quot;
+        syntax: FireEagle( os.path.expanduser( &quot;~/.fireeaglerc&quot; ) )
+        or FireEagle( CONSUMER_KEY, CONSUMER_SECRET )
+        &quot;&quot;&quot;
+
         # Prepare object lifetime variables
-        self.consumer_key     = consumer_key
-        self.consumer_secret  = consumer_secret
+        self.read_config( rc_or_consumer_key, consumer_secret )            
         self.oauth_consumer   = oauth.OAuthConsumer(
             self.consumer_key, 
             self.consumer_secret
         )
         self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
-        self.http_connection  = (API_PROTOCOL == 'https' and httplib.HTTPSConnection or httplib.HTTPConnection)( API_SERVER )
+        proto, host, port = re.search(r&quot;^(https?)://([a-z\.0-9]+)(?:\:(\d+))?$&quot;, self.api_server).groups()
+        self.http_connection = (proto == 'https' and httplib.HTTPSConnection or httplib.HTTPConnection)( host, port )
         
         # Prepare the accumulators for each method
         for method, _ in FIREEAGLE_METHODS.items():
             if not hasattr( self, method ):
                 setattr( self, method, FireEagleAccumulator( self, method ))
+
+    def read_config( self, rc_or_consumer_key, consumer_secret ):
+        if consumer_secret is None:
+            info = {}
+            for line in open( rc_or_consumer_key ).readlines():
+                p = line.find( &quot;#&quot; )
+                if p != -1: line = line[:p]
+                line = line.strip()
+                if not line: continue
+                k, v = line.split(&quot;=&quot;, 1)
+                info[ k.strip() ] = v.strip()
+        else:
+            info = {
+                'consumer_key': rc_or_consumer_key,
+                'consumer_secret': consumer_secret,
+                }
+
+        info.setdefault(&quot;api_server&quot;, API_SERVER)
+        info.setdefault(&quot;api_protocol&quot;, API_PROTOCOL)
+        self.api_server = self._build_server_url(info, 'api')
+
+        info.setdefault(&quot;auth_server&quot;, FE_SERVER)
+        info.setdefault(&quot;auth_protocol&quot;, FE_PROTOCOL)
+        self.auth_server = self._build_server_url(info, 'auth')
+
+        self.consumer_key, self.consumer_secret = info['consumer_key'], info['consumer_secret']
+
+    def _build_server_url( self, info, role ):
+        proto = info['%s_protocol' % role]
+        default_port = (proto == 'https') and 443 or 80
+        port = int(info.get('%s_port' % role, default_port))
+        url = '%s://%s%s' % (
+            proto,
+            info['%s_server' % role],
+            (port != default_port) and (':%d' % port) or '',
+            )
+        return url
     
     def fetch_response( self, http_method, url, \
             body = None, headers = None ):
@@ -419,7 +440,7 @@ class FireEagle:
         # (without a signature) and return it witout executing
         # anything.
         if 'request_url' == meta['returns']:
-            return meta['url_template'].substitute( method=method, proto=FE_PROTOCOL, server=FE_SERVER, token=token.key )
+            return meta['url_template'].substitute( method=method, server=self.auth_server, token=token.key )
         
         # Build and sign the oauth_request
         # NOTE: If ( token == None ), it's handled silently
@@ -428,7 +449,7 @@ class FireEagle:
             self.oauth_consumer,
             token       = token,
             http_method = meta['http_method'],
-            http_url    = meta['url_template'].substitute( method=method, proto=API_PROTOCOL, server=API_SERVER ),
+            http_url    = meta['url_template'].substitute( method=method, server=self.api_server ),
             parameters  = kw
         )
         oauth_request.sign_request(</diff>
      <filename>fireeagle_api.py</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,17 @@
 import fireeagle_api
+import os.path
 from pprint import pprint
 
-consumer_key, consumer_secret = fireeagle_api.read_consumer_tokens()
-fe = fireeagle_api.FireEagle( consumer_key, consumer_secret )
+&quot;&quot;&quot;
+
+First, paste your consumer key and secret into ~/.fireeaglerc, in the following format:
+
+consumer_key = YNqmPYEMEOzA
+consumer_secret = 7W6t7UwHXhe7UtAVo2KO5VGbK6I1UjOS
+
+&quot;&quot;&quot;
+
+fe = fireeagle_api.FireEagle( os.path.expanduser( '~/.fireeaglerc' ) )
 
 print &quot;Getting a request token&quot;
 request_token = fe.request_token()</diff>
      <filename>test.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>09d4d6064af560052e5cf0298c0d9dda0a6fd382</id>
    </parent>
  </parents>
  <author>
    <name>Phillip Pearson</name>
    <email>pp@myelin.co.nz</email>
  </author>
  <url>http://github.com/SteveMarshall/fire-eagle-python-binding/commit/9f40e6d4d0264eb107ae527a3ade2422be23465c</url>
  <id>9f40e6d4d0264eb107ae527a3ade2422be23465c</id>
  <committed-date>2008-08-08T01:41:26-07:00</committed-date>
  <authored-date>2008-08-08T01:41:26-07:00</authored-date>
  <message>now you can store your key info in ~/.fireeaglerc</message>
  <tree>382bef6f51e285f1fc2b9a18285977bad17de903</tree>
  <committer>
    <name>Phillip Pearson</name>
    <email>pp@myelin.co.nz</email>
  </committer>
</commit>
