Last active
August 29, 2015 14:05
-
-
Save zorbash/668c813e2c1e2fd65773 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'oauth2' | |
require 'net/http' | |
require 'json' | |
CID = 'my_cid' | |
PAS = 'my_pass' | |
RDR = 'rdr_url' | |
# OAuth2 client object | |
def client | |
client = OAuth2::Client.new(CID, PAS, site: 'https://skroutz.gr', authorize_url: "/oauth2/authorizations/new",token_url: "/oauth2/token", user_agent: 'pritory') | |
end | |
# Request token | |
def get_token | |
begin | |
t = client.client_credentials.get_token(scope: 'public') # public is required here | |
rescue OAuth2::Error => e | |
e.response.status == 404 ? "Not Found: 404" : e | |
end | |
end | |
# Skroutz search product | |
def skroutz_search_product | |
begin | |
access_token = get_token | |
p access_token.get('https://api.skroutz.gr/products/12176638', headers: { 'Accept' => 'application/vnd.skroutz+json; version=3' }) | |
# p JSON.parse(access_token.get("/categories/40/skus").body) | |
rescue OAuth2::Error => e | |
# puts "\nNot Found: 404" if e.response.status == 404 | |
puts "\nResponse headers: #{e.response.headers}" | |
end | |
end | |
skroutz_search_product |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment