flipkart_api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/flipkart_api.rb +123 -15
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfdcfc98743a0e17e28f182ee90ceb022fdf75a7
4
- data.tar.gz: cb709b62d0298a269b3a82b998dfee165978c524
3
+ metadata.gz: 77dcc3556f63ebf346acbf988573222f26babef8
4
+ data.tar.gz: eddb4114f143194e190a8e3f355effa766ccd4aa
5
5
  SHA512:
6
- metadata.gz: acd1c1b250aaf7d32ce5dd050fd98f1d52b422a722f08c10f6ecfb78dd11b0cad1280121a6ff7c71e17889569b91ce156e542ca8e9ed291efa397e96af0e51a9
7
- data.tar.gz: 71b6b3c29b530d7a99b9c22f179fa0228803086de1c222dd6f223f596b0ca15d9aea8b39cdfc2447c06a2af4848c6b79e034abb06ffbf6adad336e940cd7b988
6
+ metadata.gz: 50ed98932f42389403a34091cb8da2d56f75e7a5d5f6c0f0a0229f0026bcd4467af0640e7d1f307206c384b6b1f39b79a1d9a6dd5dd419a9766e680b63be90e8
7
+ data.tar.gz: f07307671dd61939ffa46669f25fba35e6cffc53129df414181924d196f28404dc5a5dcefcb912651d089e107291b7b6d583e59895f56188e24806710e803aad
@@ -1,45 +1,153 @@
1
1
  require "rest-client"
2
2
 
3
3
  class FlipkartApi
4
+
5
+ ##
6
+ #
7
+ # Initialize object with userid and token to send api calls.
8
+ #
4
9
  def initialize(fk_userid, fk_token)
5
10
  @api = "https://affiliate-api.flipkart.net/affiliate"
6
11
  @header = {"Fk-Affiliate-Id" => fk_userid, "Fk-Affiliate-Token" => fk_token}
7
12
  end
8
-
9
- def get_categories
10
- format="json"
13
+
14
+ ##
15
+ #
16
+ # This method will get all the categories list in flipkart with rest url to access products
17
+ # of that particular category in json or xml format. ("json"/"xml")
18
+ # Usage:
19
+ # * fa = FlipkartApi.new(fk_userid, fk_token)
20
+ # * fa.get_categories("json")
21
+ #
22
+ def get_categories(format)
11
23
  rest_url="#{@api}/api/#{@header['Fk-Affiliate-Token']}.#{format}"
12
24
  RestClient.get rest_url
13
25
  end
14
-
26
+
27
+ ##
28
+ #
29
+ # This method will get the api for accessing all the products of a particular category.
30
+ # Usage:
31
+ # * fa = FlipkartApi.new(fk_userid, fk_token)
32
+ # * fa.get_category_porducts_api("bags_wallets_belts")
33
+ # Returns the api to get all the products of the category
34
+ #
35
+ def get_category_porducts_api(category)
36
+ JSON.parse(get_categories("json"))["apiGroups"]["affiliate"]["apiListings"][category]["availableVariants"]["v0.1.0"]["get"]
37
+ end
38
+
39
+ ##
40
+ #
41
+ # This method will get the first 500 products in the json parsed data structure.
42
+ # Output will also contain "nextUrl" which inturn returns next 500 products.
43
+ # Usage:
44
+ # * fa.get_products_by_category("bags_wallets_belts")
45
+ #
15
46
  def get_products_by_category(category)
16
- rest_url = JSON.parse(get_categories)["apiGroups"]["affiliate"]["apiListings"][category]["availableVariants"]["v0.1.0"]["get"]
17
- get_all_products(rest_url)
47
+ get_products(get_category_product_api(category))
18
48
  end
19
49
 
50
+ ##
51
+ #
52
+ # This method will get all the products in the json parsed data structure.
53
+ # The parameter is the output of get_category_products_api("bags_wallets_belts")
54
+ # Usage:
55
+ # * fa.get_all_products(rest_url)
56
+ #
20
57
  def get_all_products(rest_url)
21
- rest_output = RestClient.get rest_url, @header
22
- all_products = [rest_output]
23
- json_data = JSON.parse(rest_output)
58
+ json_arr = []
59
+ json_data = get_products rest_url
60
+ json_arr << [json_data]
24
61
  while json_data["nextUrl"]
25
- rest_output = RestClient.get json_data["nextUrl"], @header
26
- all_products<<[rest_output]
27
- json_data = JSON.parse(rest_output)
62
+ json_data = get_products json_data["nextUrl"]
63
+ json_arr << [json_data]
28
64
  end
65
+ jsonout = json_arr.to_json
66
+ end
67
+
68
+ ##
69
+ #
70
+ # This method will get the first 500 products from the given rest api in the json parsed data structure.
71
+ # Usage:
72
+ # * fa.get_products(rest_url)
73
+ #
74
+ def get_products(rest_url)
75
+ rest_output = RestClient.get rest_url, @header
76
+ json_data = JSON.parse(rest_output)
29
77
  end
30
78
 
79
+ ##
80
+ #
81
+ # This method will get the deals of the day in json or xml format.
82
+ # Usage:
83
+ # * fa.get_dotd_offes("json") Can accept "xml" .
84
+ #
85
+ # Output
86
+ # Details on dotdList:
87
+ # * title - Title of the offer
88
+ # * description - Description about the offer
89
+ # * url - URL for the offer
90
+ # * imageUrls - List of Image URLs corresponding to the Offer
91
+ # * availability - Either “In-stock” / “Out-of-stock” about the products with offer.
92
+ #
31
93
  def get_dotd_offers(format)
32
94
  rest_url = "#{@api}/offers/v1/dotd/#{format}"
33
95
  RestClient.get rest_url, @header
34
96
  end
35
97
 
98
+ ##
99
+ #
100
+ # This method will get the top offers in xml or json format
101
+ # Usage:
102
+ # * fa.get_top_offers("json") Can accept "xml".
103
+ #
104
+ # Output:
105
+ # Details on topOffersList:
106
+ # * title - Title of the offer
107
+ # * description - Description about the offer
108
+ # * url - URL for the offer
109
+ # * imageUrls - List of Image URLs corresponding to the Offer
110
+ # * availability - Either “In-stock” / “Out-of-stock” about the products with offer.
111
+ #
36
112
  def get_top_offers(format)
37
113
  rest_url = "#{@api}/offers/v1/top/#{format}"
38
114
  RestClient.get rest_url, @header
39
115
  end
40
-
41
- def get_product_by_id(product_id)
42
- rest_url = "#{@api}/product/json?id=#{product_id}"
116
+
117
+ ##
118
+ #
119
+ # This method will get the full deatials of a particualar product.
120
+ # Output will json or xml depending on format parameter (json, xml)
121
+ # Usage:
122
+ # * fa.getproduct_by_id("TVSDD2DSPYU3BFZY", "json")
123
+ #
124
+ def get_product_by_id(product_id, format)
125
+ rest_url = "#{@api}/product/#{format}?id=#{product_id}"
126
+ RestClient.get rest_url, @header
127
+ end
128
+
129
+ ##
130
+ #
131
+ #This method will get all the products accross those matches the key sent as parameters.
132
+ #Output will be json or xml depending on the parameter passed.
133
+ #Usage:
134
+ # * fa.search("product name", "json", 5)
135
+ #
136
+ def searh(key, formate, max_result=10)
137
+ rest_url = "#{@api}/search/format?query=#{key}&resultCount=#{max_result}"
138
+ RestClient.get rest_url, @header
139
+ end
140
+
141
+ ##
142
+ #
143
+ # This method will get all the orders of perticular status. Output will be json or xml depending on parameter
144
+ # Usage:
145
+ # * fa.orders_report("yyyy-MM-dd", "yyyy-MM-dd", "Pending", "json")
146
+ #
147
+ # status = Pending/Approved/Cancelled/Disapproved
148
+ #
149
+ def orders_report(start_date, end_date, status, format, offset=0)
150
+ rest_url = "#{@api}/report/orders/detail/#{format}?startDate=#{start_date}&endDate=#{end_date}&status=#{status}&offset=#{offset}"
43
151
  RestClient.get rest_url, @header
44
152
  end
45
153
  end
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipkart_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepak HB
8
+ - Girish Nair
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
@@ -51,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  version: '0'
52
53
  requirements: []
53
54
  rubyforge_project:
54
- rubygems_version: 2.2.2
55
+ rubygems_version: 2.4.6
55
56
  signing_key:
56
57
  specification_version: 4
57
58
  summary: This gem is to pull data from flipkart using flipkart api