Showing posts with label lisp. Show all posts
Showing posts with label lisp. Show all posts

29 May 2011

Examples on how to use cl-odesk

First of all you need to get keys to use oDesk API.

Let's load cl-odesk. There are 2 ways: to use quicklisp (as of now, 29 May 2011, quicklisp version of cl-odesk has no all the features) or to do it by hand.
Quicklisp way:
(ql:quickload 'odesk)

By hand: fetch latest version from github. Than run at your repl:
(load "odesk.asd")
(require :odesk)


Now let's do some queries to odesk. First we need to define connection. You will need PUBLIC_KEY, PRIVATE_KEY and TOKEN. The last one you can get only by authenticating yourself in your favourite web browser. You can check the logic of this at restas-odesk. Pleas see routes.lisp file.

Let's imagine you already have that token.
We can create connection by instantiating API class:

(defparameter *test-connection*
(make-instance 'odesk:api-json
:public-key "PUBLIC"
:secret-key "SECRET"
:api-token "TOKEN"))


Here is macro that can ease your life a lot:

(with-odesk (:connection con
:public-key "PUBLIC"
:secret-key "SECRET"
:api-token "TOKEN")
(print con))


And another macro that can help too:

(connect-odesk (:public-key "PUBLIC"
:secret-key "SECRET"
:api-token "TOKEN"))


Now let's do request to get info about user.
1) If we go first way and created variable *test-connection*

CL-USER> (odesk:hr/get-user :connection *test-connection*)
("{\"server_time\":\"1306690187\",\"auth_user\":{\"first_name\":\"Dmitriy\",
\"last_name\":\"Budashny\",\"uid\":\"dbudashny\",\"mail\":\"dbudashny@odesk.com\",
\"messenger_id\":\"\",\"messenger_type\":\"\",\"timezone\":\"EET\",
\"timezone_offset\":\"10800\"},\"user\":{\"timezone\":\"UTC+02:00 Eastern Europe\",
\"status\":\"active\",\"timezone_offset\":\"10800\",
\"public_url\":\"https:\\/\\/www.odesk.com\\/users\\/~~d6114868dcf921c5\",
\"last_name\":\"Budashny\",\"email\":\"dbudashny@odesk.com\",\"reference\":\"1001150\",
\"id\":\"dbudashny\",\"is_provider\":\"1\",\"first_name\":\"Dmitriy\"}}")

2) If we go the second way and will use with-odesk macro.
a) subvariant with defining connection explicitly:

CL-USER> (odesk:with-odesk
(:connection my-con
:public-key "PUBLIC"
:secret-key "SECRET"
:api-token "TOKEN")
(odesk:hr/get-user :connection my-con))
("{\"server_time\":\"1306690187\",\"auth_user\":{\"first_name\":\"Dmitriy\",
\"last_name\":\"Budashny\",\"uid\":\"dbudashny\",\"mail\":\"dbudashny@odesk.com\",
\"messenger_id\":\"\",\"messenger_type\":\"\",\"timezone\":\"EET\",
\"timezone_offset\":\"10800\"},\"user\":{\"timezone\":\"UTC+02:00 Eastern Europe\",
\"status\":\"active\",\"timezone_offset\":\"10800\",
\"public_url\":\"https:\\/\\/www.odesk.com\\/users\\/~~d6114868dcf921c5\",
\"last_name\":\"Budashny\",\"email\":\"dbudashny@odesk.com\",\"reference\":\"1001150\",
\"id\":\"dbudashny\",\"is_provider\":\"1\",\"first_name\":\"Dmitriy\"}}")

b) subvariant with default connection key:

CL-USER> (odesk:with-odesk
(:public-key "PUBLIC"
:secret-key "SECRET"
:api-token "TOKEN")
(odesk:hr/get-user))
("{\"server_time\":\"1306690187\",\"auth_user\":{\"first_name\":\"Dmitriy\",
\"last_name\":\"Budashny\",\"uid\":\"dbudashny\",\"mail\":\"dbudashny@odesk.com\",
\"messenger_id\":\"\",\"messenger_type\":\"\",\"timezone\":\"EET\",
\"timezone_offset\":\"10800\"},\"user\":{\"timezone\":\"UTC+02:00 Eastern Europe\",
\"status\":\"active\",\"timezone_offset\":\"10800\",
\"public_url\":\"https:\\/\\/www.odesk.com\\/users\\/~~d6114868dcf921c5\",
\"last_name\":\"Budashny\",\"email\":\"dbudashny@odesk.com\",\"reference\":\"1001150\",
\"id\":\"dbudashny\",\"is_provider\":\"1\",\"first_name\":\"Dmitriy\"}}")


3) Third way is for those who want to create connection globally and then use it in the code with-out the need to use with-odesk macro:

CL-USER> (odesk:connect-odesk (:public-key "PUBLIC"
:secret-key "SECRET"
:api-token "TOKEN"))
#<ODESK:API-JSON {CB4EF11}>
CL-USER> (odesk:hr/get-user)
("{\"server_time\":\"1306690187\",\"auth_user\":{\"first_name\":\"Dmitriy\",
\"last_name\":\"Budashny\",\"uid\":\"dbudashny\",\"mail\":\"dbudashny@odesk.com\",
\"messenger_id\":\"\",\"messenger_type\":\"\",\"timezone\":\"EET\",
\"timezone_offset\":\"10800\"},\"user\":{\"timezone\":\"UTC+02:00 Eastern Europe\",
\"status\":\"active\",\"timezone_offset\":\"10800\",
\"public_url\":\"https:\\/\\/www.odesk.com\\/users\\/~~d6114868dcf921c5\",
\"last_name\":\"Budashny\",\"email\":\"dbudashny@odesk.com\",\"reference\":\"1001150\",
\"id\":\"dbudashny\",\"is_provider\":\"1\",\"first_name\":\"Dmitriy\"}}")

05 April 2011

Common Lisp bindings for oDesk API

Today I've released cl-odesk 0.1.0 and few days ago was also released restas-odesk 0.1.0.



UPD: You can find examples here.

25 October 2010

PyCon Ukraine. How Emacs-user can hack oDesk and get a job :)


(defmacro hack-odesk ()
'(http-post "http://spreadsheets.google.com/formResponse?formkey=dGVtN19mWlpLUDA2THJVU1U5a1h4NlE6MQ&ifq"
(list (cons "entry.3.group" "Emacs")
(cons "entry.4.group" "Emacs")
(cons "entry.5.group" "Emacs")
(cons "entry.6.group" "Emacs")
(cons "entry.7.group" "Emacs")
(cons "entry.8.group" "Emacs")
(cons "entry.9.group" "Emacs")
(cons "entry.10.single" (read-from-minibuffer "Enter how we can contact you: "))
(cons "pageNumber" "0")
(cons "backupCache" "")
(cons "submit" "True"))
'utf-8
'(("User-Agent" . "Mozilla/5.0 (X11; U; Linux i686; uk; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10."))))

Total Pageviews

Followers