11embedly-python
22============== 
3- Python Library  for interacting with Embedly's API. To get started sign up for
4- a key at `embed.ly/signup  <http ://embed.ly/signup
3+ Python library  for interacting with Embedly's API. To get started sign up for
4+ a key at `embed.ly/signup  <https ://app. embed.ly/signup
55
66Install
77------- 
88Install with `Pip  <http://www.pip-installer.org >`_ (recommended)::
99
1010  pip install embedly 
1111
12- Or easy_install
12+ Or easy_install:: 
1313
14-   sudo  easy_install Embedly
14+   easy_install Embedly 
1515
1616Or setuptools::
1717
1818  git clone git://github.com/embedly/embedly-python.git 
19-   sudo  python setup.py 
19+   python setup.py 
2020
21+ Setup requires Setuptools 0.7+ or Distribute 0.6.2+ in order to take advantage
22+ of the ``2to3 `` option. Setup will still run on earlier versions but you'll
23+ see a warning and ``2to3 `` won't happen. Read more in the Setuptools
24+ `docs  <http://pythonhosted.org/setuptools/python3.html >`_
2125
2226Getting Started
2327--------------- 
2428This library is meant to be a dead simple way to interact with the Embedly API.
25- There are only 2 main objects, the ``Embedly `` client and the ``Url `` model. 
26- Here is a simple example and then we will go into the objects::
29+ There are only 2 main objects, the ``Embedly `` client and the ``Url `` response 
30+ model.  Here is a simple example and then we will go into the objects::
2731
2832  >>> from embedly import Embedly 
2933  >>> client = Embedly(:key) 
30-   >>> obj = client.oembed('http://instagr.am /p/BL7ti/') 
34+   >>> obj = client.oembed('http://instagram.com /p/BL7ti/') 
3135  >>> obj['type'] 
3236  u'photo' 
3337  >>> obj['url'] 
34-   u'http://distillery.s3.amazonaws .com/media/2011/01/24/cdd759a319184cb79793506607ff5746_7.jpg' 
38+   u'http://images.ak.instagram .com/media/2011/01/24/cdd759a319184cb79793506607ff5746_7.jpg' 
3539
36-   >>> obj = client.oembed('http://instagr.am/p /error') 
40+   >>> obj = client.oembed('http://instagram.com/error /error/ ') 
3741  >>> obj['error'] 
3842  True 
3943
4044Embedly Client
4145"""""""""""""" 
42- The Embedly client is a object that takes in a key and an optional User Agent
43- then handles all the interactions and HTTP requests to Embedly. To initialize
44- the object pass in your key you got from signing up for Embedly and an optional
45- User Agent.
46+ The Embedly client is a object that takes in a key and optional User Agent
47+ and timeout parameters then handles all the interactions and HTTP requests
48+ to Embedly. To initialize the object, you'll need the key that you got when
49+ you signed up for Embedly.
50+ ::
4651
4752  >>> from embedly import Embedly 
48-   >>> client =  Embedly(' key' ' Mozilla/5.0 (compatible; example-org;)'  
53+   >>> client = Embedly('key') 
54+   >>> client2 = Embedly('key', 'Mozilla/5.0 (compatible; example-org;)') 
55+   >>> client3 = Embedly('key', 'Mozilla/5.0 (compatible; example-org;)', 30) 
56+   >>> client4 = Embedly('key', timeout=10, user_agent='Mozilla/5.0 (compatible; example-org;)') 
4957
5058The client object now has a bunch of different methods that you can use.
5159
@@ -92,7 +100,7 @@ keyword arguments that correspond to Embedly's `query arguments
92100  >>> client.oembed([' http://vimeo.com/18150336'  
93101    'http://www.youtube.com/watch?v=hD7ydlyhvKs'], maxwidth=500, words=20) 
94102
95- There are some supporting functions that allow you to limit urls  before sending
103+ There are some supporting functions that allow you to limit URLs  before sending
96104them to Embedly. Embedly can return metadata for any URL, these just allow a
97105developer to only pass a subset of Embedly `providers 
98106<http://embed.ly/providers> `_. Note that URL shorteners like bit.ly or t.co are
@@ -116,43 +124,60 @@ not supported through these regexes.
116124
117125Url Object
118126"""""""""" 
119- The ``Url `` Object is just a smart dictionary that acts more like an object.
120- For example when you run ``oembed `` you get back a Url Object:
127+ The ``Url `` object is basically a response dictionary returned from
128+ one of the Embedly API endpoints.
129+ ::
121130
122-   >>> obj  =  client.oembed(' http://vimeo.com/18150336' words = 10 )
131+   >>> response  = client.oembed('http://vimeo.com/18150336', words=10) 
123132
124- Depending on the method you are using, the object has a  different set of 
133+ Depending on the method you are using, the response will have  different
125134attributes. We will go through a few, but you should read the `documentation 
126- <http://embed.ly/docs> `_ to get the full list of data that is passed back.::
135+ <http://embed.ly/docs> `_ to get the full list of data that is passed back.
136+ ::
127137
128-   # Url Object can be accessed like a dictionary
129-   >>> obj[' type'  
138+   >>> response['type'] 
130139  u'video' 
140+   >>> response['title'] 
141+   u'Wingsuit Basejumping - The Need 4 Speed: The Art of Flight' 
142+   >>> response['provider_name'] 
143+   u'Vimeo' 
144+   >>> response['width'] 
145+   1280 
146+ 
147+ As you can see the ``Url `` object works like a dictionary, but it's slightly
148+ enhanced. It will always have ``method `` and ``original_url `` attributes,
149+ which represent the Embedly request type and the URL requested.
150+ ::
151+ 
152+   >>> response.method 
153+   'oembed' 
154+   >>> response.original_url 
155+   'http://vimeo.com/18150336' 
131156
132-   # The url object always has an ``original_url `` attrbiute.
133-   >>> obj.original_url 
134-   u'http://vimeo.com/18150336' 
135-   # The method used to retrieve the URL is also on the obj 
136-   >>> obj.method 
137-   u'oembed' 
157+   # useful because the response data itself may not have a URL 
158+   # (or it could have a redirected link, querystring params, etc) 
159+   >>> response['url'] 
160+   ... 
161+   KeyError: 'url' 
138162
139- For the Preview and Objectify endpoints the sub  objects can also be accessed in
163+ For the Preview and Objectify endpoints the sub- objects can also be accessed in
140164the same manner.
165+ ::
141166
142167  >>> obj = client.preview('http://vimeo.com/18150336', words=10) 
143168  >>> obj['object']['type'] 
144169  u'video' 
145-   >>> obj[' images' 0 ]. url 
170+   >>> obj['images'][0][' url']  
146171  u'http://b.vimeocdn.com/ts/117/311/117311910_1280.jpg' 
147172
148173Error Handling
149174-------------- 
150- If there was an error processing the request, The  ``Url `` object will contain
175+ If there was an error processing the request, the  ``Url `` object will contain
151176an error. For example if we use an invalid key, we will get a 401 response back
152177::
153178
154179  >>> client = Embedly('notakey') 
155-   >>> obj = client.preview('http://vimeo.com/18150336', words=10 ) 
180+   >>> obj = client.preview('http://vimeo.com/18150336') 
156181  >>> obj['error'] 
157182  True 
158183  >>> obj['error_code'] 
0 commit comments