User:LesOrchard/BandwagonAPI: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 155: Line 155:
** Status: <tt>200 OK</tt>
** Status: <tt>200 OK</tt>
** Content-Type: [[#Addon Collection]]
** Content-Type: [[#Addon Collection]]
===== PUT - Update collection details =====
Note that this update is limited to collection-specific details, and cannot
modify any of the other data that makes up an addon document.
* Request
** Content-Type: <tt>application/x-www-form-urlencoded</tt>
** Parameters:
*** <tt>name</tt> - human readable name for the collection
*** <tt>description</tt> - human readable longer description for the collection
*** <tt>nickname</tt> - unique nickname for collection usable in URLs
*** <tt>listed</tt> - whether the collection should be listed in the directory (<tt>1</tt>) or not (<tt>0</tt>)
* Response (on success)
** Status: <tt>200 OK</tt>
** Content-Type: [[#Addon Collection]]
** Response content reflects changes to collection


===== DELETE - Delete a collection =====
===== DELETE - Delete a collection =====
Line 192: Line 210:
A concrete URL for this kind of resource can be acquired from an [[#Addon Collection]].
A concrete URL for this kind of resource can be acquired from an [[#Addon Collection]].


Note that the GET method is not currently implemented, because the parent
===== GET - Fetch details on an addon =====
collection doc provides the information that would conceivably be made
 
available.
* Response (on success)
** Status: <tt>200 OK</tt>
** Content-Type: [[#Addon]]
 
===== PUT - Update addon details =====


===== PUT - Update addon details in a collection =====
Note that this update is limited to collection-specific details, and cannot
modify any of the other data that makes up an addon document.


* Request  
* Request  
Line 553: Line 576:
      
      
Note the <tt>xml:base</tt> attribute on <tt>sharing</tt> and the <tt>href</tt>
Note the <tt>xml:base</tt> attribute on <tt>sharing</tt> and the <tt>href</tt>
attribute on <tt>collections</tt>.  Use those together to come up with an  
attribute on <tt>collections</tt>.  Use those together to resolve an  
absolute URL, and that's the collections resource URL:
absolute URL, and that's the collections resource URL:


Line 569: Line 592:
     X-Powered-By: PHP/5.2.6
     X-Powered-By: PHP/5.2.6
     X-AMO-ServedBy: quadshot-2.local
     X-AMO-ServedBy: quadshot-2.local
     Location: http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109
     Location: http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/
     Content-Length: 0
     Content-Length: 0
     Content-Type: text/html
     Content-Type: text/html
Line 599: Line 622:
         creator="Sancus"
         creator="Sancus"
         listed="yes" writable="yes" subscribed="no"  
         listed="yes" writable="yes" subscribed="no"  
         lastmodified="2009-02-19T17:02:37-05:00">
         lastmodified="2009-02-19T19:05:55-05:00">
          
   
        <addons href="addons/">
           
         </addons>
   
     </collection>
     </collection>
      
      
==== Adding an addon to a collection ====
==== Adding an addon to a collection ====


Adding an addon to a collection is very similar to creating a collection:
Notice that the new collection offers an <tt>addon</tt> element with an
<tt>href</tt> attribute.  Once resolved using <tt>xml:base</tt>, you can POST
to this URL to add an addon:


     $ curl -sD - -u "$USER:$PASSWD" -XPOST \
     $ curl -sD - -u "$USER:$PASSWD" -XPOST \
         -d 'guid=farming%40microfarmer.org&comments=I+really+like+this+addon' \
         -d 'guid=farming%40microfarmer.org&comments=I+really+like+this+addon' \
         'http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/'
         'http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/addons/'
      
      
     HTTP/1.1 201 Created
     HTTP/1.1 201 Created
Line 620: Line 649:
     Content-Type: text/html
     Content-Type: text/html


And you can fetch the URL in the <tt>Location:</tt> header:
And you can GET the URL in the <tt>Location:</tt> header:


     $ curl -sD - -u "$USER:$PASSWD" -XGET \
     $ curl -sD - -u "$USER:$PASSWD" -XGET \
Line 654: Line 683:
         <!-- details omitted... -->
         <!-- details omitted... -->
     </addon>
     </addon>
   
Note that there's a <tt>collection</tt> element with an <tt>href</tt> attribute
pointing to the parent collection, when resolved using the <tt>xml:base</tt>
URL.


You can also fetch the collection again and see the addon has appeared:
A GET request to the collection will show that the addon has been added:


     $ curl -sD - -u "$USER:$PASSWD" -XGET \
     $ curl -sD - -u "$USER:$PASSWD" -XGET \
Line 665: Line 690:
      
      
     HTTP/1.1 200 OK
     HTTP/1.1 200 OK
     Date: Thu, 19 Feb 2009 22:13:34 GMT
     Date: Thu, 19 Feb 2009 22:12:15 GMT
     Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.6
     Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.6
     X-Powered-By: PHP/5.2.6
     X-Powered-By: PHP/5.2.6
     X-AMO-ServedBy: quadshot-2.local
     X-AMO-ServedBy: quadshot-2.local
     Cache-Control: public, max-age=3600
     Cache-Control: public, max-age=3600
     Last-modified: Thu, 19 Feb 2009 22:13:34 GMT
     Last-modified: Thu, 19 Feb 2009 22:12:15 GMT
     Expires: Thu, 19 Feb 2009 23:13:34 GMT
     Expires: Thu, 19 Feb 2009 23:12:15 GMT
     Transfer-Encoding: chunked
     Transfer-Encoding: chunked
     Content-Type: text/xml
     Content-Type: text/xml
   
       
     <?xml version="1.0" encoding="utf-8" ?>
     <?xml version="1.0" encoding="utf-8" ?>
     <collection xmlns="http://addons.mozilla.org/"  
     <collection xmlns="http://addons.mozilla.org/"  
         xml:base="http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109//"
         xml:base="http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/"
         name="Foo Bar"
         name="Foo Bar"
         description="collection of foobar addons"
         description="collection of foobar addons"
         creator="Sancus"
         creator="Sancus"
         listed="yes" writable="yes" subscribed="no"  
         listed="yes" writable="yes" subscribed="no"  
         lastmodified="2009-02-19T17:02:37-05:00">
         lastmodified="2009-02-19T19:05:55-05:00">
   
        <addons href="addons/">
   
            <addon href="addons/farming%40microfarmer.org">
                <meta>
                    <added>2009-02-19T17:10:50-05:00</added>
                    <addedby>Sancus</addedby>
                    <comments>I really like this addon</comments>
                </meta>
                <categories>
                    <category id="12">Organizer</category>
                    <category id="13">Web Data</category>
                </categories>
                <name>MicroFarmer</name>
                <type id='1'>Extension</type>
                <guid>farming@microfarmer.org</guid>
                <version>9</version>
                <!-- details omitted... -->
            </addon>
           
        </addons>
   
    </collection>
 
==== Updating an addon in a collection ====
 
Later, if you want to make an update to this addon in the collection, you
can make a PUT request to the addon URL:
 
    $ curl -sD - -u "$USER:$PASSWD" -XPUT \
        -d 'comments=This+addon+is+really+swell' \
        'http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/addons/farming%40microfarmer.org'
   
    HTTP/1.1 200 OK
    Date: Fri, 20 Feb 2009 00:10:32 GMT
    Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.6
    X-Powered-By: PHP/5.2.6
    X-AMO-ServedBy: quadshot-2.local
    Cache-Control: public, max-age=3600
    Last-modified: Fri, 20 Feb 2009 00:10:32 GMT
    Expires: Fri, 20 Feb 2009 01:10:32 GMT
    Transfer-Encoding: chunked
    Content-Type: text/xml
          
          
        <addon href="addons/farming%40microfarmer.org">
    <?xml version="1.0" encoding="utf-8" ?>
            <meta>
    <addon xml:base="http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/addons/farming%40microfarmer.org">
                <added>2009-02-19T17:10:50-05:00</added>
        <meta>
                <addedby>Sancus</addedby>
            <added>2009-02-19T17:10:50-05:00</added>
                <comments>I really like this addon</comments>
            <addedby>Sancus</addedby>
             </meta>
            <comments>This addon is really swell</comments>
            <categories>
             <collection href=".." />   
                <category id="12">Organizer</category>
        </meta>
                <category id="13">Web Data</category>
        <categories>
            </categories>
            <category id="12">Organizer</category>
            <name>MicroFarmer</name>
            <category id="13">Web Data</category>
            <type id='1'>Extension</type>
        </categories>
            <guid>farming@microfarmer.org</guid>
        <name>MicroFarmer</name>
            <version>9</version>
        <type id='1'>Extension</type>
            <!-- details omitted... -->
        <guid>farming@microfarmer.org</guid>
        </addon>
        <version>9</version>
          
        <!-- details omitted... -->
     </collection>
    </addon>
 
==== Deleting an addon from a collection ====
 
Finally, if you want to remove this addon from the collection, make a DELETE
request to the addon URL:
 
    $ curl -sD - -u "$USER:$PASSWD" -XDELETE \
         'http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/129/addons/farming%40microfarmer.org'
   
     HTTP/1.1 410 Gone
    Date: Fri, 20 Feb 2009 00:12:18 GMT
    Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.6
    X-Powered-By: PHP/5.2.6
    X-AMO-ServedBy: quadshot-2.local
    Content-Length: 0
    Content-Type: text/html
   
The addon URL can no longer be found:
 
    $ curl -sD - -u "$USER:$PASSWD" -XGET \
        'http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/addons/farming%40microfarmer.org'
   
    HTTP/1.1 404 Not Found
    Date: Fri, 20 Feb 2009 00:12:57 GMT
    Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.6
    X-Powered-By: PHP/5.2.6
    X-AMO-ServedBy: quadshot-2.local
    Cache-Control: public, max-age=3600
    Last-modified: Fri, 20 Feb 2009 00:12:58 GMT
    Expires: Fri, 20 Feb 2009 01:12:58 GMT
    Content-Length: 120
    Content-Type: text/xml
      
      
Note that there's an <tt>href</tt> attribute on the <tt>addon</tt> element
    <?xml version="1.0" encoding="utf-8" ?>
pointing to the addon, when resolved using the <tt>xml:base</tt>
    <error xmlns="http://addons.mozilla.org/" reason="addon_not_in_collection" />
URL.


=== Open Questions ===
And, the addon no longer appears in the collection:


* Product spec calls for ability to create collections for "auto-publishers" to sync with list of addons in browser. How is this distinguished from creating a collection in general, or is a distinction even necessary?  Seems like the distinction of an auto-publisher lies mainly in the extension.
    $ curl -sD - -u "$USER:$PASSWD" -XGET \
** There should probably be a field that says what type of collection something is (normal, editors pick, auto-publisher), but apart from that field, there's no difference on the API side of CRUD operations. Right now, we're only expecting auto-publishers to use the API for creation. [[User:Fligtar|Fligtar]] 22:10, 5 February 2009 (UTC)
        'http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/'
*** Can we get details on that field added to the product spec, along with maybe how it would affect the web frontend? [[User:LesOrchard|LesOrchard]] 22:24, 5 February 2009 (UTC)
   
    HTTP/1.1 200 OK
    Date: Fri, 20 Feb 2009 00:13:55 GMT
    Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.7l DAV/2 PHP/5.2.6
    X-Powered-By: PHP/5.2.6
    X-AMO-ServedBy: quadshot-2.local
    Cache-Control: public, max-age=3600
    Last-modified: Fri, 20 Feb 2009 00:13:55 GMT
    Expires: Fri, 20 Feb 2009 01:13:55 GMT
    Content-Length: 440
    Content-Type: text/xml
   
    <?xml version="1.0" encoding="utf-8" ?>
    <collection xmlns="http://addons.mozilla.org/"
        xml:base="http://dev-bandwagon.addons.mozilla.org/en-US/firefox/api/1.3/sharing/collections/109/"
        name="Foo Bar"
        description="collection of foobar addons"
        creator="Sancus"
        listed="yes" writable="yes" subscribed="no"
        lastmodified="2009-02-19T19:05:55-05:00">
   
        <addons href="addons/">
           
        </addons>
   
    </collection>
Confirmed users
920

edits