Skip to content

A Clojure client for Skroutz API (v3 and above)

Notifications You must be signed in to change notification settings

skroutz/clj-skroutz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clj-skroutz

Dependencies Status

A Clojure client for Skroutz API (v3 and above). Please check the documentation for more information.

Installation

lein:

[clj_skroutz "0.0.1"]

Clojars

Configuration options

  • :token-url The url to grab app tokens. Can be https://www.skroutz.gr/oauth2/token or https://www.alve.com/oauth2/token.

  • :scope The scope of client access. Check here for details.

  • :grant-type The grant type of oauth access. Can be client_credentials or authorization_code.

  • :redirect-uri The redirect uri for callbacks.

  • :accept-header The accept header. Can be application/vnd.skroutz+json;version=3 or application/vnd.alve+json;version=3.

  • :user-agent The user agent info.

  • :url The url to consume api calls. Can be https://api.skroutz.gr/ or https://api.alve.com/

  • :client-id The client id. See here for details.

  • :client-secret The client secret. See here for details.

  • :app-token The generated app token.

  • :auth-prefix The authorization prefix. Must be "Bearer "

  • :user-code The user code. See here for details.

Profiles

To simplify working with multiple users or flavors (Skroutz, Alve, Scrooge) one can use the macro with-profile. Each profile should be a hashmap with the appropriate configuration options.

  (use 'clj_skroutz.core)
  (require 'clj_skroutz.categories)

  ; Suppose we use carica for loading configs
  (def skroutz-public (carica.core/config :skroutz-public))
  (with-profile skroutz-public (clj_skroutz.categories/all))

How to get an application token

Before proceed read documentation here.

  1. Application token:

Once you have client-id and client-secret:

(require 'clj_skroutz.oauth)
(use 'clj_skroutz.core)

(def my-profile {:redirect-uri "http://example.com/callback",
  :grant-type "client_credentials", :client-id "your-client-id",
  :user-agent "awesome client", :scope "public",
  :token-url "https://www.skroutz.gr/oauth2/token",
  :url "https://api.skroutz.gr/",
  :accept-header "application/vnd.skroutz+json;version=3",
  :client-secret "your-client-secret", :auth-prefix "Bearer "})

(with-profile my-profile (clj_skroutz.oauth/app-token))

You should see a response with an access-token. Grab this token and you are ready to consume Skroutz API v3.

  1. User token:

Once you get a user code:

  (require 'clj_skroutz.oauth)

  ; Decodes user code
  (def code (clj_skroutz.oauth/decode-user-code your-code-here))

  ; Continue from the previous example
  (def my-profile (conj my-profile {:user-code code, :grant-type "authorization_code"}))

  ; Grab app token
  (clj_skroutz.oauth/user-token code)

Examples of Usage

  1. Categories
  ; Continue from the previous examples
  (require '[clj_skroutz.categories :as skroutz-categories])

  ; Gets specific category
  (with-profile my-profle (skroutz-categories/category 40))

  ; Gets root
  (with-profile my-profile (skroutz-categories/root))

  ; Lists skus for category
  (with-profile my-profile (skroutz-categories/skus 40))

  ; Lists skus for categories with ordering
  ; Available orderings are `popularity` and `pricevat`
  (with-profile my-profile (skroutz-categories/skus 40 [:order_by "popularity" :order_dir "desc"]))

References

Skroutz API documentation

License

Distributed under the Eclipse Public License, the same as Clojure.

About

A Clojure client for Skroutz API (v3 and above)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published