flipkart 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -0
- data/Gemfile.lock +59 -0
- data/flipkart.gemspec +25 -0
- data/lib/flipkart.rb +55 -0
- data/lib/flipkart/version.rb +3 -0
- data/spec/fixtures/vcr_cassettes/orders_report.yml +52 -0
- data/spec/orders_spec.rb +75 -0
- data/spec/spec_helper.rb +15 -0
- metadata +29 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77738838ef4158622459c4007ae32e42b03e8bdc
|
4
|
+
data.tar.gz: cf7ad8e812b83bd52b5f052c237d82232f7de283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: def2d52cef024d83f630afe89f8519b0a9a7b5532c3b716f9443335bf6b5bf4f3cf3c5c16fa07f4c3e4bd73dd79008302c5f9e3a66a7e098c0f226c62efe8e2e
|
7
|
+
data.tar.gz: 8cee04189d59e113c448b04486fbd93b9ac50bcdb8137d74d2b88b0664cf2344df74dac324829ba39a271ebec74f6ef6281eb9e52386e20ab72926d0bcb08ead
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.2.1)
|
5
|
+
i18n (~> 0.7)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
9
|
+
tzinfo (~> 1.1)
|
10
|
+
addressable (2.3.7)
|
11
|
+
coderay (1.1.0)
|
12
|
+
crack (0.4.2)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.2.5)
|
15
|
+
httparty (0.13.3)
|
16
|
+
json (~> 1.8)
|
17
|
+
multi_xml (>= 0.5.2)
|
18
|
+
i18n (0.7.0)
|
19
|
+
json (1.8.2)
|
20
|
+
method_source (0.8.2)
|
21
|
+
minitest (5.5.1)
|
22
|
+
multi_xml (0.5.5)
|
23
|
+
pry (0.10.1)
|
24
|
+
coderay (~> 1.1.0)
|
25
|
+
method_source (~> 0.8.1)
|
26
|
+
slop (~> 3.4)
|
27
|
+
rspec (3.2.0)
|
28
|
+
rspec-core (~> 3.2.0)
|
29
|
+
rspec-expectations (~> 3.2.0)
|
30
|
+
rspec-mocks (~> 3.2.0)
|
31
|
+
rspec-core (3.2.2)
|
32
|
+
rspec-support (~> 3.2.0)
|
33
|
+
rspec-expectations (3.2.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.2.0)
|
36
|
+
rspec-mocks (3.2.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.2.0)
|
39
|
+
rspec-support (3.2.2)
|
40
|
+
safe_yaml (1.0.4)
|
41
|
+
slop (3.6.0)
|
42
|
+
thread_safe (0.3.5)
|
43
|
+
tzinfo (1.2.2)
|
44
|
+
thread_safe (~> 0.1)
|
45
|
+
vcr (2.9.3)
|
46
|
+
webmock (1.20.4)
|
47
|
+
addressable (>= 2.3.6)
|
48
|
+
crack (>= 0.3.2)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
activesupport
|
55
|
+
httparty
|
56
|
+
pry
|
57
|
+
rspec
|
58
|
+
vcr
|
59
|
+
webmock
|
data/flipkart.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'flipkart/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'flipkart'
|
8
|
+
s.version = Flipkart::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ['Rohit Paul Kuruvilla']
|
11
|
+
s.email = ['rohitpaulk@live.com']
|
12
|
+
s.homepage = ''
|
13
|
+
s.summary = "A wrapper around Flipkart's API"
|
14
|
+
s.description = "A wrapper around Flipkart's API"
|
15
|
+
|
16
|
+
s.add_runtime_dependency 'httparty'
|
17
|
+
s.add_runtime_dependency 'activesupport'
|
18
|
+
s.add_development_dependency 'rspec'
|
19
|
+
s.add_development_dependency 'webmock'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
data/lib/flipkart.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_support/time'
|
2
|
+
require 'httparty'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
class Flipkart
|
6
|
+
class Orders
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
base_uri 'https://affiliate-api.flipkart.net/affiliate'
|
10
|
+
|
11
|
+
def initialize(affiliate_id, affiliate_token)
|
12
|
+
@affiliate_id = affiliate_id
|
13
|
+
@affiliate_token = affiliate_token
|
14
|
+
@raw_responses = []
|
15
|
+
@records = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def all(*args)
|
19
|
+
fetch_orders(*args) if @records.empty?
|
20
|
+
@records
|
21
|
+
end
|
22
|
+
|
23
|
+
def fetch_orders(start_date = 1.month.ago, end_date = Time.now, status = 'pending')
|
24
|
+
query_options = {
|
25
|
+
'startDate' => start_date.strftime('%Y-%m-%d'),
|
26
|
+
'endDate' => end_date.strftime('%Y-%m-%d'),
|
27
|
+
'status' => status,
|
28
|
+
'offset' => 0
|
29
|
+
}
|
30
|
+
headers = {
|
31
|
+
'Fk-Affiliate-Id' => @affiliate_id,
|
32
|
+
'Fk-Affiliate-Token' => @affiliate_token
|
33
|
+
}
|
34
|
+
get_url = '/report/orders/detail/json'
|
35
|
+
@raw_responses << self.class.get('/report/orders/detail/json', { query: query_options, headers: headers }).parsed_response
|
36
|
+
@records += @raw_responses.last['orderList']
|
37
|
+
while @raw_responses.last['next'].to_s != '' do
|
38
|
+
@raw_responses << self.class.get(@raw_responses.last['next'], { headers: headers }).parsed_response
|
39
|
+
@records += @raw_responses.last['orderList']
|
40
|
+
end
|
41
|
+
@records.each { |record| rubyify_keys!(record) }
|
42
|
+
@records = @records.each.map { |record| OpenStruct.new(record) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def rubyify_keys!(record)
|
46
|
+
record.keys.each { |k|
|
47
|
+
v = record.delete(k)
|
48
|
+
new_key = k.to_s.underscore
|
49
|
+
record[new_key] = v
|
50
|
+
rubyify_keys!(v) if v.is_a?(Hash)
|
51
|
+
v.each{|p| rubyify_keys!(p) if p.is_a?(Hash)} if v.is_a?(Array)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://affiliate-api.flipkart.net/affiliate/report/orders/detail/json?endDate=2015-03-24&offset=0&startDate=2015-02-24&status=pending
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Fk-Affiliate-Id:
|
11
|
+
- rohitkuruv
|
12
|
+
Fk-Affiliate-Token:
|
13
|
+
- dummy-token
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Server:
|
20
|
+
- nginx/1.4.1 (Ubuntu)
|
21
|
+
Date:
|
22
|
+
- Mon, 23 Mar 2015 23:41:00 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: "{\"orderList\":[{\"price\":949.0,\"category\":\"Pen Drives\",\"title\":\"Sandisk
|
32
|
+
Ultra USB 3.0 32 GB Utility Pendrive\",\"productId\":\"ACCDSYDFMHUKZX9H\",\"quantity\":1,\"sales\":{\"amount\":949.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18065900\",\"orderDate\":\"24-02-2015\",\"commissionRate\":1.0,\"tentativeCommission\":{\"amount\":9.49,\"currency\":\"INR\"},\"affExtParam1\":\"3575\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":678.0,\"category\":\"Pen
|
33
|
+
Drives\",\"title\":\"Sandisk Cruzer Blade 32 GB\",\"productId\":\"ACCD9XW3YU6VYCYS\",\"quantity\":1,\"sales\":{\"amount\":678.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18080476\",\"orderDate\":\"24-02-2015\",\"commissionRate\":1.0,\"tentativeCommission\":{\"amount\":6.78,\"currency\":\"INR\"},\"affExtParam1\":\"3576\",\"affExtParam2\":\"\",\"salesChannel\":\"MOBILE_SITE\",\"customerType\":\"EXISTING\"},{\"price\":161.0,\"category\":\"Mobile
|
34
|
+
Accessories\",\"title\":\"Motorola Grip Back Cover for Moto E\",\"productId\":\"ACCDVGRZPZXNKTNE\",\"quantity\":1,\"sales\":{\"amount\":161.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18080477\",\"orderDate\":\"24-02-2015\",\"commissionRate\":2.0,\"tentativeCommission\":{\"amount\":3.22,\"currency\":\"INR\"},\"affExtParam1\":\"3576\",\"affExtParam2\":\"\",\"salesChannel\":\"MOBILE_SITE\",\"customerType\":\"EXISTING\"},{\"price\":159.0,\"category\":\"Bags,
|
35
|
+
Wallets & Belts\",\"title\":\"Travel Additions Soft Eye Mask Eye Shade\",\"productId\":\"NPEDBTY7PHZYE5RT\",\"quantity\":1,\"sales\":{\"amount\":159.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18168762\",\"orderDate\":\"26-02-2015\",\"commissionRate\":8.0,\"tentativeCommission\":{\"amount\":12.72,\"currency\":\"INR\"},\"affExtParam1\":\"3593\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":99.0,\"category\":\"Mobile
|
36
|
+
Accessories\",\"title\":\"Motorola Back Replacement Cover for Moto E\",\"productId\":\"ACCDVGRZW8XUZCFF\",\"quantity\":1,\"sales\":{\"amount\":99.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18205108\",\"orderDate\":\"27-02-2015\",\"commissionRate\":2.0,\"tentativeCommission\":{\"amount\":1.98,\"currency\":\"INR\"},\"affExtParam1\":\"3596\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":99.0,\"category\":\"Mobile
|
37
|
+
Accessories\",\"title\":\"Motorola Grip Back Cover for Moto E\",\"productId\":\"ACCDVGSMYG6JXMR8\",\"quantity\":1,\"sales\":{\"amount\":99.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18205109\",\"orderDate\":\"27-02-2015\",\"commissionRate\":2.0,\"tentativeCommission\":{\"amount\":1.98,\"currency\":\"INR\"},\"affExtParam1\":\"3596\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":2799.0,\"category\":\"Men
|
38
|
+
Footwear\",\"title\":\"Reebok Trail Running Shoes\",\"productId\":\"SHODVGH8FCEZFGQT\",\"quantity\":1,\"sales\":{\"amount\":2799.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18301949\",\"orderDate\":\"01-03-2015\",\"commissionRate\":8.0,\"tentativeCommission\":{\"amount\":223.92,\"currency\":\"INR\"},\"affExtParam1\":\"3603\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":539.0,\"category\":\"Women
|
39
|
+
Clothing\",\"title\":\"Biba Solid Women's Kurta\",\"productId\":\"KTADZB48T3PRUEGN\",\"quantity\":1,\"sales\":{\"amount\":539.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18376143\",\"orderDate\":\"03-03-2015\",\"commissionRate\":8.0,\"tentativeCommission\":{\"amount\":43.12,\"currency\":\"INR\"},\"affExtParam1\":\"3615\",\"affExtParam2\":\"\",\"salesChannel\":\"MOBILE_SITE\",\"customerType\":\"EXISTING\"},{\"price\":559.0,\"category\":\"Women
|
40
|
+
Clothing\",\"title\":\"Abhishti Casual Full Sleeve Solid Women's Kurti\",\"productId\":\"KRTDZMCDZS4DRZEY\",\"quantity\":1,\"sales\":{\"amount\":559.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18527397\",\"orderDate\":\"08-03-2015\",\"commissionRate\":8.0,\"tentativeCommission\":{\"amount\":44.72,\"currency\":\"INR\"},\"affExtParam1\":\"3655\",\"affExtParam2\":\"\",\"salesChannel\":\"MOBILE_SITE\",\"customerType\":\"EXISTING\"},{\"price\":12999.0,\"category\":\"Moto
|
41
|
+
G Phones\",\"title\":\"Moto G (2nd Gen)\",\"productId\":\"MOBDYGZ6SHNB7RFC\",\"quantity\":1,\"sales\":{\"amount\":12999.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18609334\",\"orderDate\":\"10-03-2015\",\"commissionRate\":1.5,\"tentativeCommission\":{\"amount\":194.985,\"currency\":\"INR\"},\"affExtParam1\":\"3671\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":9999.0,\"category\":\"Asus
|
42
|
+
Zenfone 5 Phones\",\"title\":\"Asus Zenfone 5 A501CG\",\"productId\":\"MOBDXZ9WZNZBG79S\",\"quantity\":1,\"sales\":{\"amount\":9999.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18613282\",\"orderDate\":\"10-03-2015\",\"commissionRate\":1.0,\"tentativeCommission\":{\"amount\":99.99,\"currency\":\"INR\"},\"affExtParam1\":\"3672\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":12999.0,\"category\":\"Moto
|
43
|
+
G Phones\",\"title\":\"Moto G (2nd Gen)\",\"productId\":\"MOBDYGZ6SHNB7RFC\",\"quantity\":1,\"sales\":{\"amount\":12999.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18664057\",\"orderDate\":\"13-01-2015\",\"commissionRate\":1.5,\"tentativeCommission\":{\"amount\":194.985,\"currency\":\"INR\"},\"affExtParam1\":\"3320\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":412.0,\"category\":\"Books\",\"title\":\"Discrete
|
44
|
+
and Combinatorial Mathematics (English) 5th Edition\",\"productId\":\"9788177584240\",\"quantity\":1,\"sales\":{\"amount\":412.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18669988\",\"orderDate\":\"12-03-2015\",\"commissionRate\":10.0,\"tentativeCommission\":{\"amount\":41.2,\"currency\":\"INR\"},\"affExtParam1\":\"3678\",\"affExtParam2\":\"\",\"salesChannel\":\"MOBILE_SITE\",\"customerType\":\"EXISTING\"},{\"price\":6980.0,\"category\":\"Mobile
|
45
|
+
Phones\",\"title\":\"Karbonn Titanium S2 Plus\",\"productId\":\"MOBDXZ9WHGFH8ZGM\",\"quantity\":1,\"sales\":{\"amount\":6980.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18711046\",\"orderDate\":\"13-03-2015\",\"commissionRate\":3.0,\"tentativeCommission\":{\"amount\":209.4,\"currency\":\"INR\"},\"affExtParam1\":\"3684\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"NEW\"},{\"price\":1579.0,\"category\":\"Mobile
|
46
|
+
Phones\",\"title\":\"Nokia 130\",\"productId\":\"MOBEFYX4XP4V9XH3\",\"quantity\":1,\"sales\":{\"amount\":1579.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18774702\",\"orderDate\":\"16-03-2015\",\"commissionRate\":1.0,\"tentativeCommission\":{\"amount\":15.79,\"currency\":\"INR\"},\"affExtParam1\":\"3699\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":2702.0,\"category\":\"Watches\",\"title\":\"Titan
|
47
|
+
2455BM01 Raga Analog Watch - For Women\",\"productId\":\"WATDE8JAQDRR3AZY\",\"quantity\":1,\"sales\":{\"amount\":2702.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18930184\",\"orderDate\":\"21-03-2015\",\"commissionRate\":8.0,\"tentativeCommission\":{\"amount\":216.16,\"currency\":\"INR\"},\"affExtParam1\":\"3728\",\"affExtParam2\":\"\",\"salesChannel\":\"WEBSITE\",\"customerType\":\"EXISTING\"},{\"price\":5999.0,\"category\":\"Moto
|
48
|
+
E Phones\",\"title\":\"Moto E (1st Gen)\",\"productId\":\"MOBDVHC6TH4PZGSM\",\"quantity\":1,\"sales\":{\"amount\":5999.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18957470\",\"orderDate\":\"22-03-2015\",\"commissionRate\":1.0,\"tentativeCommission\":{\"amount\":59.99,\"currency\":\"INR\"},\"affExtParam1\":\"3749\",\"affExtParam2\":\"\",\"salesChannel\":\"MOBILE_SITE\",\"customerType\":\"EXISTING\"},{\"price\":176.0,\"category\":\"Mobile
|
49
|
+
Accessories\",\"title\":\"Toshiba MicroSD Card 8 GB 15 MB/s Class 4\",\"productId\":\"ACCDG8X5CW6VGPX2\",\"quantity\":1,\"sales\":{\"amount\":176.0,\"currency\":\"INR\"},\"status\":\"tentative\",\"affiliateOrderItemId\":\"18957471\",\"orderDate\":\"22-03-2015\",\"commissionRate\":3.0,\"tentativeCommission\":{\"amount\":5.28,\"currency\":\"INR\"},\"affExtParam1\":\"3749\",\"affExtParam2\":\"\",\"salesChannel\":\"MOBILE_SITE\",\"customerType\":\"EXISTING\"}],\"previous\":\"\",\"next\":\"\",\"first\":\"https://affiliate-api.flipkart.net/affiliate/report/orders/detail/json?startDate=2015-02-24&endDate=2015-03-24&status=pending&offset=0\",\"last\":\"https://affiliate-api.flipkart.net/affiliate/report/orders/detail/json?startDate=2015-02-24&endDate=2015-03-24&status=pending&offset=0\"}"
|
50
|
+
http_version:
|
51
|
+
recorded_at: Mon, 23 Mar 2015 23:41:03 GMT
|
52
|
+
recorded_with: VCR 2.9.3
|
data/spec/orders_spec.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Flipkart::Orders do
|
4
|
+
it "sets base_uri to flipkart's API url" do
|
5
|
+
expect(described_class.base_uri).to eq("https://affiliate-api.flipkart.net/affiliate")
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "initialization" do
|
9
|
+
it "should throw error if not provided arguments" do
|
10
|
+
expect { described_class.new() }.to raise_error
|
11
|
+
expect { described_class.new("abcd") }.to raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not throw error with valid parameters" do
|
15
|
+
expect { described_class.new('affiliate_id', 'affiliate_token') }.to_not raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#all" do
|
20
|
+
let(:flipkart_orders) { described_class.new('rohitkuruv', 'dummy-token') }
|
21
|
+
let(:valid_body_with_next) {
|
22
|
+
{
|
23
|
+
'orderList' => [{
|
24
|
+
'price' => 10.0
|
25
|
+
}],
|
26
|
+
'next' => 'http://flipkart.next'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
let(:valid_body_without_next) {
|
30
|
+
{
|
31
|
+
'orderList' => [{
|
32
|
+
'price' => 12.0
|
33
|
+
}],
|
34
|
+
'next' => ''
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
it "should return an array" do
|
39
|
+
VCR.use_cassette "orders_report" do
|
40
|
+
response = flipkart_orders.all
|
41
|
+
expect(response).to be_an(Array)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "only fetches orders the first time" do
|
46
|
+
VCR.use_cassette "orders_report" do
|
47
|
+
expect { flipkart_orders.all }.to_not raise_error
|
48
|
+
stub_request(:any, /flipkart.net/).to_timeout
|
49
|
+
expect { flipkart_orders.all }.to_not raise_error
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should fetch next page if a next parameter is present", focus: true do
|
54
|
+
stub_request(:any, /flipkart.net/).to_return(
|
55
|
+
body: valid_body_with_next.to_json,
|
56
|
+
headers: {'Content-Type' => 'application/json'}
|
57
|
+
)
|
58
|
+
stub_request(:any, /flipkart.next/).to_return(
|
59
|
+
body: valid_body_without_next.to_json,
|
60
|
+
headers: {'Content-Type' => 'application/json'}
|
61
|
+
)
|
62
|
+
expect(flipkart_orders.all.count).to eq(2)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should contain valid objects" do
|
66
|
+
VCR.use_cassette "orders_report" do
|
67
|
+
record = flipkart_orders.all.first
|
68
|
+
expect(record).to be_an(OpenStruct)
|
69
|
+
expect(record.price).to be_a(Float)
|
70
|
+
expect(record.category).to be_a(String)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "../lib/flipkart"
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'vcr'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
VCR.configure do |config|
|
9
|
+
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
10
|
+
config.hook_into :webmock
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.color = true
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipkart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rohit Paul Kuruvilla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: webmock
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,7 +72,15 @@ email:
|
|
58
72
|
executables: []
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
|
-
files:
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- flipkart.gemspec
|
79
|
+
- lib/flipkart.rb
|
80
|
+
- lib/flipkart/version.rb
|
81
|
+
- spec/fixtures/vcr_cassettes/orders_report.yml
|
82
|
+
- spec/orders_spec.rb
|
83
|
+
- spec/spec_helper.rb
|
62
84
|
homepage: ''
|
63
85
|
licenses: []
|
64
86
|
metadata: {}
|