1
1
embedly-python
2
2
==============
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 >`_.
5
5
6
6
Install
7
7
-------
8
8
Install with `Pip <http://www.pip-installer.org >`_ (recommended)::
9
9
10
10
pip install embedly
11
11
12
- Or easy_install
12
+ Or easy_install::
13
13
14
- sudo easy_install Embedly
14
+ easy_install Embedly
15
15
16
16
Or setuptools::
17
17
18
18
git clone git://github.com/embedly/embedly-python.git
19
- sudo python setup.py
19
+ python setup.py
20
20
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 >`_
21
25
22
26
Getting Started
23
27
---------------
24
28
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::
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::
27
31
28
32
>>> from embedly import Embedly
29
33
>>> client = Embedly(:key)
30
- >>> obj = client.oembed('http://instagr.am /p/BL7ti/')
34
+ >>> obj = client.oembed('http://instagram.com /p/BL7ti/')
31
35
>>> obj['type']
32
36
u'photo'
33
37
>>> 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'
35
39
36
- >>> obj = client.oembed('http://instagr.am/p /error')
40
+ >>> obj = client.oembed('http://instagram.com/error /error/ ')
37
41
>>> obj['error']
38
42
True
39
43
40
44
Embedly Client
41
45
""""""""""""""
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
+ ::
46
51
47
52
>>> 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;)')
49
57
50
58
The client object now has a bunch of different methods that you can use.
51
59
@@ -92,7 +100,7 @@ keyword arguments that correspond to Embedly's `query arguments
92
100
>>> client.oembed([' http://vimeo.com/18150336' ,
93
101
'http://www.youtube.com/watch?v=hD7ydlyhvKs'], maxwidth=500, words=20)
94
102
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
96
104
them to Embedly. Embedly can return metadata for any URL, these just allow a
97
105
developer to only pass a subset of Embedly `providers
98
106
<http://embed.ly/providers> `_. Note that URL shorteners like bit.ly or t.co are
@@ -116,43 +124,60 @@ not supported through these regexes.
116
124
117
125
Url Object
118
126
""""""""""
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
+ ::
121
130
122
- >>> obj = client.oembed(' http://vimeo.com/18150336' , words = 10 )
131
+ >>> response = client.oembed('http://vimeo.com/18150336', words=10)
123
132
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
125
134
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.::
135
+ <http://embed.ly/docs> `_ to get the full list of data that is passed back.
136
+ ::
127
137
128
- # Url Object can be accessed like a dictionary
129
- >>> obj[' type' ]
138
+ >>> response['type']
130
139
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'
131
156
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'
138
162
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
140
164
the same manner.
165
+ ::
141
166
142
167
>>> obj = client.preview('http://vimeo.com/18150336', words=10)
143
168
>>> obj['object']['type']
144
169
u'video'
145
- >>> obj[' images' ][0 ]. url
170
+ >>> obj['images'][0][' url']
146
171
u'http://b.vimeocdn.com/ts/117/311/117311910_1280.jpg'
147
172
148
173
Error Handling
149
174
--------------
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
151
176
an error. For example if we use an invalid key, we will get a 401 response back
152
177
::
153
178
154
179
>>> client = Embedly('notakey')
155
- >>> obj = client.preview('http://vimeo.com/18150336', words=10 )
180
+ >>> obj = client.preview('http://vimeo.com/18150336')
156
181
>>> obj['error']
157
182
True
158
183
>>> obj['error_code']
0 commit comments