flipkart_api 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flipkart_api.rb +105 -13
- metadata +12 -8
- checksums.yaml +0 -7
data/lib/flipkart_api.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require "rest-client"
|
3
|
+
require "pry"
|
4
|
+
require "logger"
|
2
5
|
|
3
6
|
class FlipkartApi
|
4
7
|
|
5
8
|
##
|
6
9
|
#
|
7
10
|
# Initialize object with userid and token to send api calls.
|
11
|
+
# One optional 3rd parameter to specify api version. It is default to v0.1.0.
|
8
12
|
#
|
9
|
-
def initialize(fk_userid, fk_token)
|
13
|
+
def initialize(fk_userid, fk_token, version='v0.1.0')
|
10
14
|
@api = "https://affiliate-api.flipkart.net/affiliate"
|
11
15
|
@header = {"Fk-Affiliate-Id" => fk_userid, "Fk-Affiliate-Token" => fk_token}
|
16
|
+
@version = version
|
12
17
|
end
|
13
18
|
|
14
19
|
##
|
@@ -20,8 +25,8 @@ class FlipkartApi
|
|
20
25
|
# * fa.get_categories("json")
|
21
26
|
#
|
22
27
|
def get_categories(format)
|
23
|
-
rest_url="#{@api}/api/#{@header['Fk-Affiliate-
|
24
|
-
RestClient.get rest_url
|
28
|
+
rest_url="#{@api}/api/#{@header['Fk-Affiliate-Id']}.#{format}"
|
29
|
+
RestClient.get rest_url, @header
|
25
30
|
end
|
26
31
|
|
27
32
|
##
|
@@ -32,8 +37,46 @@ class FlipkartApi
|
|
32
37
|
# * fa.get_category_porducts_api("bags_wallets_belts")
|
33
38
|
# Returns the api to get all the products of the category
|
34
39
|
#
|
35
|
-
def
|
36
|
-
JSON.parse(get_categories("json"))["apiGroups"]["affiliate"]["apiListings"][
|
40
|
+
def get_category_products_api(category_name)
|
41
|
+
JSON.parse(get_categories("json"))["apiGroups"]["affiliate"]["apiListings"][category_name]["availableVariants"][@version]["get"]
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
#
|
46
|
+
# This method will get the api for accessing all the products that have changed after perticular version of a category.
|
47
|
+
# This api is also used to pull the current version.
|
48
|
+
# Usage:
|
49
|
+
# * fa = FlipkartApi.new(fk_userid, fk_token)
|
50
|
+
# * fa.get_category_delta_version_api("bags_wallets_belts")
|
51
|
+
# Returns the api of the category to pull the changed products after perticular version.
|
52
|
+
#
|
53
|
+
def get_category_delta_version_api(category_name)
|
54
|
+
JSON.parse(get_categories("json"))["apiGroups"]["affiliate"]["apiListings"][category_name]["availableVariants"][@version]["deltaGet"]
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
#
|
59
|
+
# This method will get the current version of a particular category after which products have changed.
|
60
|
+
# Usage:
|
61
|
+
# * fa = FlipkartApi.new(fk_userid, fk_token)
|
62
|
+
# * fa.get_category_delta_porducts_api("bags_wallets_belts")
|
63
|
+
# Returns the verstion number of the category
|
64
|
+
#
|
65
|
+
def get_current_delta_version(version_api)
|
66
|
+
JSON.parse(RestClient.get(version_api, @header))['version']
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# This method will get the api to access all the products that have changed after current version or the version number passed.
|
71
|
+
# Usage:
|
72
|
+
# * fa = FlipkarApi.new(fk_userid, fk_token)
|
73
|
+
# * fa.get_category_delta_products_api("bags_wallets_belts")
|
74
|
+
# Returns the api to get products that have changed after perticular version.
|
75
|
+
#
|
76
|
+
def get_category_delta_products_api(category_name, version=nil)
|
77
|
+
version_api = get_category_delta_version_api(category_name)
|
78
|
+
version = get_current_delta_version(version_api) unless version
|
79
|
+
version_api.gsub(".json","/fromVersion/#{version}.json")
|
37
80
|
end
|
38
81
|
|
39
82
|
##
|
@@ -43,10 +86,19 @@ class FlipkartApi
|
|
43
86
|
# Usage:
|
44
87
|
# * fa.get_products_by_category("bags_wallets_belts")
|
45
88
|
#
|
46
|
-
def get_products_by_category(
|
47
|
-
get_products(
|
89
|
+
def get_products_by_category(category_name)
|
90
|
+
get_products(get_category_products_api(category_name))
|
48
91
|
end
|
49
|
-
|
92
|
+
|
93
|
+
##
|
94
|
+
#
|
95
|
+
# This method will get the first 500 products in the json parsed data structure.
|
96
|
+
# Usage:
|
97
|
+
# * fa.get_delta_products_by_category("bags_wallets_belts")
|
98
|
+
#
|
99
|
+
def get_delta_products_by_category(category_name, version=nil)
|
100
|
+
get_products(get_category_delta_products_api(category_name, version))
|
101
|
+
end
|
50
102
|
##
|
51
103
|
#
|
52
104
|
# This method will get all the products in the json parsed data structure.
|
@@ -76,6 +128,46 @@ class FlipkartApi
|
|
76
128
|
json_data = JSON.parse(rest_output)
|
77
129
|
end
|
78
130
|
|
131
|
+
##
|
132
|
+
#
|
133
|
+
# This method will get all the categories list in flipkart with rest url to access books
|
134
|
+
# of that particular category in json or xml format. ("json"/"xml")
|
135
|
+
# Usage:
|
136
|
+
# * fa = FlipkartApi.new(fk_userid, fk_token)
|
137
|
+
# * fa.get_books_categories("json")
|
138
|
+
#
|
139
|
+
def get_book_categories(format)
|
140
|
+
rest_url="#{@api}/1.0/booksApi/#{@header['Fk-Affiliate-Id']}.#{format}"
|
141
|
+
RestClient.get rest_url, @header
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
#
|
146
|
+
# This method will get the api for accessing books of a particular category.
|
147
|
+
# Since flipkart returns categories in tree structure. This method takes parameter in array to find the category in parent child order.
|
148
|
+
# Usage:
|
149
|
+
# * fa = FlipkartApi.new(fk_userid, fk_token)
|
150
|
+
# * fa.get_category_books_api(["books", "Fiction & Non-Fiction Books", "Children Books"])
|
151
|
+
# Returns the api to get bookds of the category
|
152
|
+
#
|
153
|
+
def get_category_books_api(categories)
|
154
|
+
json_categories = JSON.parse(get_book_categories("json"))["booksCategory"]
|
155
|
+
return json_categories["url"] if categories.size==1 && categories.first=="Books"
|
156
|
+
categories.drop(1).inject(json_categories){|json_categories, category| json_categories["subCategories"].select{|sub_category| sub_category["name"]==category}.first}["url"]
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
#
|
161
|
+
# This method will get the first 500 books from the given category in the json parsed data structure.
|
162
|
+
# Usage:
|
163
|
+
# * fa.get_books_by_category(["Books", "Fiction & Non-Fiction Books", "Children Books", "Activity Books", "Cursive Writing"])
|
164
|
+
# Returns the books from 'Cursive Writing' category
|
165
|
+
#
|
166
|
+
def get_books_by_category(categories)
|
167
|
+
rest_output = RestClient.get get_category_books_api(categories), @header
|
168
|
+
JSON.parse(rest_output)
|
169
|
+
end
|
170
|
+
|
79
171
|
##
|
80
172
|
#
|
81
173
|
# This method will get the deals of the day in json or xml format.
|
@@ -92,7 +184,7 @@ class FlipkartApi
|
|
92
184
|
#
|
93
185
|
def get_dotd_offers(format)
|
94
186
|
rest_url = "#{@api}/offers/v1/dotd/#{format}"
|
95
|
-
RestClient.get rest_url, @header
|
187
|
+
JSON.parse(RestClient.get rest_url, @header)
|
96
188
|
end
|
97
189
|
|
98
190
|
##
|
@@ -111,7 +203,7 @@ class FlipkartApi
|
|
111
203
|
#
|
112
204
|
def get_top_offers(format)
|
113
205
|
rest_url = "#{@api}/offers/v1/top/#{format}"
|
114
|
-
RestClient.get rest_url, @header
|
206
|
+
JSON.parse(RestClient.get rest_url, @header)
|
115
207
|
end
|
116
208
|
|
117
209
|
##
|
@@ -119,7 +211,7 @@ class FlipkartApi
|
|
119
211
|
# This method will get the full deatials of a particualar product.
|
120
212
|
# Output will json or xml depending on format parameter (json, xml)
|
121
213
|
# Usage:
|
122
|
-
# * fa.
|
214
|
+
# * fa.get_product_by_id("TVSDD2DSPYU3BFZY", "json")
|
123
215
|
#
|
124
216
|
def get_product_by_id(product_id, format)
|
125
217
|
rest_url = "#{@api}/product/#{format}?id=#{product_id}"
|
@@ -133,8 +225,8 @@ class FlipkartApi
|
|
133
225
|
#Usage:
|
134
226
|
# * fa.search("product name", "json", 5)
|
135
227
|
#
|
136
|
-
def
|
137
|
-
rest_url = "#{@api}/search
|
228
|
+
def search(key, format, max_result=10)
|
229
|
+
rest_url = "#{@api}/search/#{format}?query=#{key}&resultCount=#{max_result}"
|
138
230
|
RestClient.get rest_url, @header
|
139
231
|
end
|
140
232
|
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipkart_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Deepak HB
|
@@ -9,11 +10,12 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2017-01-29 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rest-client
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
20
|
- - '='
|
19
21
|
- !ruby/object:Gem::Version
|
@@ -21,6 +23,7 @@ dependencies:
|
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
28
|
- - '='
|
26
29
|
- !ruby/object:Gem::Version
|
@@ -35,25 +38,26 @@ files:
|
|
35
38
|
homepage: https://github.com/deepakhb2/flipkart_api
|
36
39
|
licenses:
|
37
40
|
- MIT
|
38
|
-
metadata: {}
|
39
41
|
post_install_message:
|
40
42
|
rdoc_options: []
|
41
43
|
require_paths:
|
42
44
|
- lib
|
43
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
44
47
|
requirements:
|
45
|
-
- - '>='
|
48
|
+
- - ! '>='
|
46
49
|
- !ruby/object:Gem::Version
|
47
50
|
version: 1.9.3
|
48
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
49
53
|
requirements:
|
50
|
-
- - '>='
|
54
|
+
- - ! '>='
|
51
55
|
- !ruby/object:Gem::Version
|
52
56
|
version: '0'
|
53
57
|
requirements: []
|
54
58
|
rubyforge_project:
|
55
|
-
rubygems_version:
|
59
|
+
rubygems_version: 1.8.23.2
|
56
60
|
signing_key:
|
57
|
-
specification_version:
|
58
|
-
summary: This gem
|
61
|
+
specification_version: 3
|
62
|
+
summary: This gem will help you to pull data from flipkart using flipkart api
|
59
63
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 77dcc3556f63ebf346acbf988573222f26babef8
|
4
|
-
data.tar.gz: eddb4114f143194e190a8e3f355effa766ccd4aa
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 50ed98932f42389403a34091cb8da2d56f75e7a5d5f6c0f0a0229f0026bcd4467af0640e7d1f307206c384b6b1f39b79a1d9a6dd5dd419a9766e680b63be90e8
|
7
|
-
data.tar.gz: f07307671dd61939ffa46669f25fba35e6cffc53129df414181924d196f28404dc5a5dcefcb912651d089e107291b7b6d583e59895f56188e24806710e803aad
|