Skip to content

Commit 1fedeb4

Browse files
committed
Update Readme
Mostly this updates the `Url` model documentation to reflect its more pythonic nature as a true dictionary. Also update a couple links, don't use `sudo` and fix the RST formatting for a few code blocks.
1 parent 9c7ba5e commit 1fedeb4

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

README.rst

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,55 @@
11
embedly-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

66
Install
77
-------
88
Install 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

1616
Or setuptools::
1717

1818
git clone git://github.com/embedly/embedly-python.git
19-
sudo python setup.py
19+
python setup.py
2020

2121

2222
Getting Started
2323
---------------
2424
This 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::
25+
There are only 2 main objects, the ``Embedly`` client and the ``Url`` response
26+
model. Here is a simple example and then we will go into the objects::
2727

2828
>>> from embedly import Embedly
2929
>>> client = Embedly(:key)
30-
>>> obj = client.oembed('http://instagr.am/p/BL7ti/')
30+
>>> obj = client.oembed('http://instagram.com/p/BL7ti/')
3131
>>> obj['type']
3232
u'photo'
3333
>>> obj['url']
34-
u'http://distillery.s3.amazonaws.com/media/2011/01/24/cdd759a319184cb79793506607ff5746_7.jpg'
34+
u'http://images.ak.instagram.com/media/2011/01/24/cdd759a319184cb79793506607ff5746_7.jpg'
3535

36-
>>> obj = client.oembed('http://instagr.am/p/error')
36+
>>> obj = client.oembed('http://instagram.com/error/error/')
3737
>>> obj['error']
3838
True
3939

4040
Embedly Client
4141
""""""""""""""
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.
42+
The Embedly client is a object that takes in a key and optional User Agent
43+
and timeout parameters then handles all the interactions and HTTP requests
44+
to Embedly. To initialize the object, you'll need the key that you got when
45+
you signed up for Embedly.
46+
::
4647

4748
>>> from embedly import Embedly
48-
>>> client = Embedly('key', 'Mozilla/5.0 (compatible; example-org;)')
49+
>>> client = Embedly('key')
50+
>>> client2 = Embedly('key', 'Mozilla/5.0 (compatible; example-org;)')
51+
>>> client3 = Embedly('key', 'Mozilla/5.0 (compatible; example-org;)', 30)
52+
>>> client4 = Embedly('key', timeout=10, user_agent='Mozilla/5.0 (compatible; example-org;)')
4953

5054
The client object now has a bunch of different methods that you can use.
5155

@@ -92,7 +96,7 @@ keyword arguments that correspond to Embedly's `query arguments
9296
>>> client.oembed(['http://vimeo.com/18150336',
9397
'http://www.youtube.com/watch?v=hD7ydlyhvKs'], maxwidth=500, words=20)
9498

95-
There are some supporting functions that allow you to limit urls before sending
99+
There are some supporting functions that allow you to limit URLs before sending
96100
them to Embedly. Embedly can return metadata for any URL, these just allow a
97101
developer to only pass a subset of Embedly `providers
98102
<http://embed.ly/providers>`_. Note that URL shorteners like bit.ly or t.co are
@@ -116,43 +120,60 @@ not supported through these regexes.
116120

117121
Url Object
118122
""""""""""
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:
123+
The ``Url`` object is basically a response dictionary returned from
124+
one of the Embedly API endpoints.
125+
::
121126

122-
>>> obj = client.oembed('http://vimeo.com/18150336', words=10)
127+
>>> response = client.oembed('http://vimeo.com/18150336', words=10)
123128

124-
Depending on the method you are using, the object has a different set of
129+
Depending on the method you are using, the response will have different
125130
attributes. 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.::
131+
<http://embed.ly/docs>`_ to get the full list of data that is passed back.
132+
::
127133

128-
# Url Object can be accessed like a dictionary
129-
>>> obj['type']
134+
>>> response['type']
130135
u'video'
136+
>>> response['title']
137+
u'Wingsuit Basejumping - The Need 4 Speed: The Art of Flight'
138+
>>> response['provider_name']
139+
u'Vimeo'
140+
>>> response['width']
141+
1280
142+
143+
As you can see the ``Url`` object works like a dictionary, but it's slightly
144+
enhanced. It will always have ``method`` and ``original_url`` attributes,
145+
which represent the Embedly request type and the URL requested.
146+
::
147+
148+
>>> response.method
149+
'oembed'
150+
>>> response.original_url
151+
'http://vimeo.com/18150336'
131152

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'
153+
# useful because the response data itself may not have a URL
154+
# (or it could have a redirected link, querystring params, etc)
155+
>>> response['url']
156+
...
157+
KeyError: 'url'
138158

139-
For the Preview and Objectify endpoints the sub objects can also be accessed in
159+
For the Preview and Objectify endpoints the sub-objects can also be accessed in
140160
the same manner.
161+
::
141162

142163
>>> obj = client.preview('http://vimeo.com/18150336', words=10)
143164
>>> obj['object']['type']
144165
u'video'
145-
>>> obj['images'][0].url
166+
>>> obj['images'][0]['url']
146167
u'http://b.vimeocdn.com/ts/117/311/117311910_1280.jpg'
147168

148169
Error Handling
149170
--------------
150-
If there was an error processing the request, The ``Url`` object will contain
171+
If there was an error processing the request, the ``Url`` object will contain
151172
an error. For example if we use an invalid key, we will get a 401 response back
152173
::
153174

154175
>>> client = Embedly('notakey')
155-
>>> obj = client.preview('http://vimeo.com/18150336', words=10)
176+
>>> obj = client.preview('http://vimeo.com/18150336')
156177
>>> obj['error']
157178
True
158179
>>> obj['error_code']

0 commit comments

Comments
 (0)