Giter Club home page Giter Club logo

skroutz.rb's Introduction

skroutz.rb

Gem Version Build Status Code Climate Coverage Status Documentation Status

Ruby API client for Skroutz / Alve / Scrooge

Installation

gem install skroutz

Or add it to your Gemfile

gem 'skroutz'

Resources

Creating a client

  skroutz = Skroutz::Client.new('client_id', 'client_secret')
Note

You may pass the flavor keyword argument upon initialization to target one of the available flavors (skroutz, alve, scrooge), default is skroutz.

Search

  skroutz.search('iphone')

  # => [#<Skroutz::Category id: 40, name: "Κινητά Τηλέφωνα", children_count: 0,
  # image_url: "http://a.scdn.gr/images/categories/large/40.jpg", parent_id:
  # 86, fashion: false, path: "76,1269,2,86,40", show_specifications: true,
  # manufacturer_title: "Κατασκευαστές", match_count: 18>,
  #  #<Skroutz::Category id: 583, name: "Ανταλλακτικά Κινητών τηλεφώνων",
  # children_count: 0, image_url: "http://a.scdn.gr/images/categories/large/583.jpg", parent_id: 86,
  # fashion: false, path: "76,1269,2,86,583", show_specifications: false,
  # manufacturer_title: "Κατασκευαστές", match_count: 4062>
  # ...

Examples

Categories

  skroutz = Skroutz::Client.new('client_id', 'client_secret')

  mobile_phones = skroutz.categories.find 40

  # => #<Skroutz::Category id: 40, name: "Κινητά Τηλέφωνα", children_count: 0,
  # image_url: "http://a.scdn.gr/images/categories/large/40.jpg", parent_id:
  # 86, fashion: false, path: "76,1269,2,86,40", show_specifications: true,
  # manufacturer_title: "Κατασκευαστές">

  # Get all categories, paginated
  skroutz.categories.all
  # => [#<Skroutz::Category id: 1, name: "Σταθερή Τηλεφωνία", children_count: 5, 
  # image_url: "http://a.scdn.gr/images/categories/large/1.jpg", parent_id: 2, 
  # fashion: false, path: "76,1269,2,1", show_specifications: false, 
  # manufacturer_title: "Κατασκευαστές">,
  #  #<Skroutz::Category id: 2, name: "Τηλεφωνία", children_count: 3,
  # image_url: "http://d.scdn.gr/images/categories/large/201501271...",
  # parent_id: 1269, fashion: false, path: "76,1269,2", show_specifications:
  # false, manufacturer_title: "Κατασκευαστές">,
  #  #<Skroutz::Category id: 5, name: "Φωτογραφία & Video", children_count:
  # 3, image_url: "http://a.scdn.gr/images/categories/large/5.jpg",
  # parent_id: 1269, fashion: false, path: "76,1269,5", show_specifications:
  # false, manufacturer_title: "Κατασκευαστές">,
  #  #<Skroutz::Category id: 6, name: "Διάφορα Εικόνας", children_count: 2,
  # image_url: "http://c.scdn.gr/images/categories/large/201501271...",
  # parent_id: 309, fashion: false, path: "76,1269,309,6",
  # show_specifications: false, manufacturer_title: "Κατασκευαστές">,
  # ...

  # Get the SKUs of a Category without intermediate requests
  skroutz.categories(40).skus
  # => [#<Skroutz::Sku id: 2119391, ean: "", pn: "GT-E1200", name: "E1200",
  # display_name: "Samsung E1200", category_id: 40, first_product_shop_info:
  # nil, click_url: nil, price_max: 42.0, price_min: 12.61, reviewscore:
  # 4.39286, shop_count: 20, plain_spec_summary: "Feature Phone,  Single
  # SIM, Οθόνη: 1.52\" ,   Μνήμη...", manufacturer_id: 28, future: false,
  # reviews_count: 28, virtual: false, images:
  # {"main"=>"http://d.scdn.gr/images/sku_main_images/002119/2119391/medium_gr_GT-E1200ZWMVGR_301_Front",
  # "alternatives"=>["http://a.scdn.gr/images/sku_images/012918/12918567/gr_GT-E1200ZWMVGR_309_Dynamic",
  # "http://b.scdn.gr/images/sku_images/012918/12918568/gr_GT-E1200ZWMVGR_304_Left",
  # "http://a.scdn.gr/images/sku_images/012918/12918573/gr_GT-E1200ZWMVGR_323_Right",
  # "http://c.scdn.gr/images/sku_images/012918/12918574/gr_GT-E1200ZWMVGR_322_Back"]}>,
  #  #<Skroutz::Sku id: 3599366, ean: ...
 

SKUs

  skroutz = Skroutz::Client.new('client_id', 'client_secret')

  iphone = skroutz.skus.find 390486

  # => #<Skroutz::Sku id: 390486, ean: "", pn: "iPhone 4S 16GB", name: "iPhone
  # 4S (16GB)", display_name: "Apple iPhone 4S (16GB)", category_id: 40,
  # first_product_shop_info: "1521|Kaizer Shop|kaizershop", click_url: nil,
  # price_max: 310.0, price_min: 310.0, reviewscore: 4.43284, shop_count: 1,
  # plain_spec_summary: "SmartPhone,  Single SIM, Οθόνη: 3.5\" , CPU: 1000
  # M...", manufacturer_id: 356, future: false, reviews_count: 67, virtual:
  # false, images:
  # {"main"=>"http://d.scdn.gr/images/sku_main_images/000390/390486/medium_1234.jpg",
  # "alternatives"=>["http://a.scdn.gr/images/sku_images/012928/12928351/Untitled.jpg",
  # "http://b.scdn.gr/images/sku_images/012928/12928352/12345.jpg",
  # "http://a.scdn.gr/images/sku_images/012928/12928353/smartfon-apple-iphone-4s-16gb-white-md239ru-i-a-30014672b.jpg",
  # "http://a.scdn.gr/images/sku_images/012928/12928354/smartfon-apple-iphone-4s-16gb-white-md239ru-i-a-30014672b2.jpg",
  # "http://b.scdn.gr/images/sku_images/012928/12928355/smartfon-apple-iphone-4s-16gb-white-md239ru-i-a-30014672b1.jpg"]}>

Products

  skroutz = Skroutz::Client.new('client_id', 'client_secret')

  iphone_product = skroutz.products.find 12661155

  # => #<Skroutz::Product id: 12661155, name: "APPLE IPHONE 4S 16GB white EU",
  # sku_id: 390486, shop_id: 2032, category_id: 40, availability: "Σε απόθεμα", 
  # click_url: "https://www.skroutz.gr/products/show/12661155?clie...", shop_uid: "312", 
  # price: 364.49>

In this manner you may retrieve most resources.

Pagination

For paginated responses, the following methods will be available:

  • first_page?
  • last_page?
  • first
  • last
  • next
  • previous

You may also use #each_page to iterate through pages.

skroutz = Skroutz::Client.new('client_id', 'client_secret')
skroutz.categories.each_page do |categories|
  # Do something with this page of categories
end

# Get all pages at once
skroutz.categories.each_page.to_a

# each_page without a block returns an Enumerator, so you can use Enumerable methods
# Example: Fetch and return only the first 10 pages from the API
skroutz.categories.each_page.first(10)

Associations

For every Skroutz::Resource the available associations can be inspected with:

  skroutz = Skroutz::Client.new('client_id', 'client_secret')

  iphone = skroutz.skus.find 390486
  iphone.class.associations
  # => [:category, :similar, :products, :reviews, :specifications, :manufacturer]

You may call any of the assocations listed as methods like:

  iphone = skroutz.skus.find 390486

  # entity
  iphone.category
  # => #<Skroutz::Category id: 40, name: "Κινητά Τηλέφωνα", children_count: 0, image_url: "http://a.scdn.gr/images/categories/large/40.jpg", parent_id: 86, fashion: false, path: "76,1269,2,86,40", show_specifications: true, manufacturer_title: "Κατασκευαστές">

  # collection
  iphone.products.all
  # => [#<Skroutz::Product id: 18733068, name: "Nokia 220 Single Sim EU Yellow", sku_id: 5725906, shop_id: 1830, category_id: 40, availability: "Σε απόθεμα", click_url: "https://www.skroutz.gr/products/show/18733068?clie...", shop_uid: "1149024", price: 36.0>,
 #<Skroutz::Product id: 18036272, name: "Nokia 220 Dual Sim Black EU", sku_id: 5725906, shop_id: 941, category_id: 40, availability: "Σε απόθεμα", click_url: "https://www.skroutz.gr/products/show/18036272?clie...", shop_uid: "d30712b4-ed33-475e-9291-f3b3fafc40c9", price: 49.89>]

You may even try more complex things like:

  skroutz.search('nexus').first.skus.all.first.products.page(1, per: 2)
  # => [#<Skroutz::Product id: 14343307, name: "TABLET INTENSO TAB 714
  # 5509852", sku_id: 2690329, shop_id: 514, category_id: 1105, availability: "Σε απόθεμα", 
  # click_url: "https://www.skroutz.gr/products/show/14343307?clie...", shop_uid: "180979", price: 37.99>,
  # #<Skroutz::Product id: 14385461, name: "Intenso - Tablet 714 7''", sku_id: 2690329, 
  # shop_id: 1085, category_id: 1105, availability: "1 έως 3 ημέρες", 
  # click_url: "https://www.skroutz.gr/products/show/14385461?clie...", shop_uid: # "3210", price: 66.9>]

  client.categories(40).skus(q: 'iphone').first.reviews.all
  # => [#<Skroutz::Review id: 49553, user_id: 305635, review: "Αν μπορουσα θα του εβαζα 2.5 αντι για τρια. Αν και...", 
  # rating: 3, created_at: "2015-03-16T22:05:56+02:00", demoted: false>, 
  # #<Skroutz::Review id: 49477, user_id: 187662, review: "To κινητο δεν βρισκεται παρα πολυ καιρο στην κατοχ...", 
  # rating: 5, created_at: "2015-03-15T16:38:38+02:00", demoted: false>,
  # ...]

Configuration

The following configuration options are available upon client initialization:

flavor

Which flavor (eg. country) to target.
Default: skroutz.

# Set `scrooge` as the flavor
client = Skroutz::Client.new('client_id', 'client_secret', flavor: :scrooge)

logger

Which logger to use.
Default: No logging is performed.

Example:

# Log to STDOUT
client = Skroutz::Client.new('client_id', 'client_secret', logger: Logger.new(STDOUT)) 

timeout

How much time (in seconds) to wait for a server response.
Default: 5 seconds

adapter

Which HTTP adapter to use to perform the API requests.
Default: Net::HTTP

Note: You can only pick a faraday compatible adapter.
Make sure you have the gem of the selected adapter installed.

user_agent

The user agent string to use for the API requests.
Default: skroutz.rb

api_endpoint

The root URI of the targeted API.
Default: https://api.skroutz.gr

oauth_endpoint

The endpoint from which to authorize via OAuth2.0.
Default: https://skroutz.gr

authorization_code_endpoint

The endpoint from which to acquire OAuth2.0 authorization code.
Default: /oauth2/authorizations/new

token_endpoint

The endpoint from which to acquire OAuth2.0 access token.
Default: /oauth2/token

media type

The value of the HTTP Accept header to specify the desired media type.
Default: application/vnd.skroutz+json; version=3

application_permissions

The set of permissions to be obtained.
Default: ['public']

Compatibility

The following Ruby implementations are supported:

  • MRI 2.1.0
  • MRI 2.2.0
  • MRI 2.3.0

It may inadvertently work (or seem to work) on other Ruby implementations, however support will only be provided for the versions listed above.

Development

Please take some time to read our contribution guide first.

Running the tests

Run all the tests:

bundle exec rake

Run them continuously with guard:

bundle exec guard

Fix any rubocop offences:

bundle exec rubocop

Console

pry --gem

OAuth2.0 Credentials

In order for the client to make requests against our API, a valid set of OAuth2.0 credentials provided by us has to be used. To get yours send an email at [[email protected]](mailto: [email protected]).

LICENSE

Copyright (c) 2015 Skroutz S.A, MIT Licence. See LICENSE.txt for further details.

skroutz.rb's People

Contributors

apostergiou avatar fotos avatar harrisred avatar zorbash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

apostergiou

skroutz.rb's Issues

Coerce `include`, `embed`, `embed_ids`

Associations may be eagerly fetched as documented.

Current behavior for embed:

locations = client.shops(11).locations(embed: 'address')
address = locations.first.address
# => {"id"=>2, "street_number"=>"1", "street"=>"ΘΕΣΗ ΣΚΛΗΡΙ", "postcode"=>"19600", "city"=>"ΜΑΓΟΥΛΑ",
# "region"=>"Αττικής", "country"=>"Ελλάδα"}

address.class
# => Hash

Expected behavior:

locations = client.shops(11).locations(embed: 'address')
address = locations.first.address
# =>  #<Skroutz::Address id: 2, street_number: "1", street: "ΘΕΣΗ ΣΚΛΗΡΙ", postcode: "19600", city: 
# "ΜΑΓΟΥΛΑ", region: "Αττικής", country: "Ελλάδα">

address.class
# =>  Skroutz::Address

Handle request timeout

A configuration option has to be added to the maximum amount of time to wait for a server response before throwing an exception. For this purpose SkroutzApi::TimeoutError has to be added.

Skroutz::PaginatedCollection doesn't have a next (or previous) page, when it should.

This should return the first page of the category "cases" for "iphone"
arr = @skroutz.categories(579).skus(q: 'iphone')

To be precise, this returns a Skroutz::PaginatedCollection but the methods next? and previous? return false. Of course, if I try to arr.next_page I get nil.

The following also returns a Skroutz::PaginatedCollection but next? and previous? return true and arr.next_page gives me the next page as it should.
arr = @skroutz.search('iphone').first.skus.all.first.products.page(1)

Note that search('iphone').first asks for the first category of the search results, so it's not like I am asking for different things. That's why I chose the 579 category for the first case, which has endless results.

Implement flavors

Currently to create clients for various flavors you have to do the following:

skroutz = Skroutz::Client.new('skroutz_client_id', 'skroutz_client_secret')

alve = Skroutz::Client.new('alve_client_id', 'alve_client_secret', oauth_endpoint: 'https://alve.com', api_endpoint: 'https://api.alve.com', media_type: 'application/vnd.alve+json; version=3')

scrooge = Skroutz::Client.new('scrooge_client_id', 'scrooge_client_secret', oauth_endpoint: 'https://scrooge.co.uk', api_endpoint: 'https://api.scrooge.co.uk', media_type: 'application/vnd.scrooge+json; version=3')

It's apparent that apart from the skroutz client above (which is the default), the rest have many options required.

It would be great if we could just supply a flavor option which would take care of the rest.
Example:

alve = Skroutz::Client.new('client_id', 'client_secret', flavor: :alve)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.