Class: FlipkartApi

Inherits:
Object
  • Object
show all
Defined in:
lib/flipkart_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(fk_userid, fk_token) ⇒ FlipkartApi

Returns a new instance of FlipkartApi.



4
5
6
7
# File 'lib/flipkart_api.rb', line 4

def initialize(fk_userid, fk_token)
  @api = "https://affiliate-api.flipkart.net/affiliate"
  @header = {"Fk-Affiliate-Id" => fk_userid, "Fk-Affiliate-Token" => fk_token}
end

Instance Method Details

#get_all_products(rest_url) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/flipkart_api.rb', line 20

def get_all_products(rest_url)
  rest_output = RestClient.get rest_url, @header
  all_products = [rest_output]
  json_data = JSON.parse(rest_output)
  while json_data["nextUrl"]
    rest_output = RestClient.get json_data["nextUrl"], @header
    all_products<<[rest_output]
    json_data = JSON.parse(rest_output)
  end
end

#get_categories ⇒ Object



9
10
11
12
13
# File 'lib/flipkart_api.rb', line 9

def get_categories
  format="json"
  rest_url="#{@api}/api/#{@header['Fk-Affiliate-Token']}.#{format}"
  RestClient.get rest_url
end

#get_dotd_offers(format) ⇒ Object



31
32
33
34
# File 'lib/flipkart_api.rb', line 31

def get_dotd_offers(format)
  rest_url = "#{@api}/offers/v1/dotd/#{format}"
  RestClient.get rest_url, @header
end

#get_product_by_id(product_id) ⇒ Object



41
42
43
44
# File 'lib/flipkart_api.rb', line 41

def get_product_by_id(product_id)
  rest_url = "#{@api}/product/json?id=#{product_id}"
  RestClient.get rest_url, @header
end

#get_products_by_category(category) ⇒ Object



15
16
17
18
# File 'lib/flipkart_api.rb', line 15

def get_products_by_category(category)
  rest_url = JSON.parse(get_categories)["apiGroups"]["affiliate"]["apiListings"][category]["availableVariants"]["v0.1.0"]["get"]
  get_all_products(rest_url)
end

#get_top_offers(format) ⇒ Object



36
37
38
39
# File 'lib/flipkart_api.rb', line 36

def get_top_offers(format)
  rest_url = "#{@api}/offers/v1/top/#{format}"
  RestClient.get rest_url, @header
end