book_finder_api 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,11 +11,25 @@ class BookFinder
11
11
  # Example :
12
12
  # book_details = BookFinder.flipkart(9788120305960)
13
13
  def self.flipkart(isbn)
14
+ #setting the url
14
15
  search_url="http://www.flipkart.com/search/a/all?query=#{isbn}"
16
+
17
+ #initiating the Mechanize
15
18
  result=Hash.new
16
19
  agent =Mechanize.new
20
+
21
+ #for following redirect
17
22
  agent.redirect_ok
23
+
24
+ #getting the page
18
25
  page = agent.get(search_url)
26
+
27
+ #getting the titles and author
28
+ title_div=page.search(".mprod-summary-title")
29
+ result["Book"]=title_div.search("h1").text()
30
+ result["Author"]=title_div.search("h2").text()
31
+
32
+ #storing the resluts
19
33
  page.search(".fk-specs-type2 tr").each do |tr|
20
34
  fk_key=tr.search(".specs-key").text()
21
35
  fk_val=tr.search(".specs-value").text()
@@ -23,19 +37,28 @@ class BookFinder
23
37
  result[fk_key]=fk_val
24
38
  end
25
39
  end
26
- college = page.search(".fk-lbreadbcrumb a")[4]
27
- if college
28
- result['college']=college.search("span").text()
29
- end
30
- stream = page.search(".fk-lbreadbcrumb a")[5]
31
- if stream
32
- result['stream']= stream.search("span").text()
40
+
41
+ #storing the colleges from breadcrumb
42
+ breadcrumb = page.search(".fk-lbreadbcrumb a")
43
+ generals = ['Other General','Others Engineering']
44
+
45
+ if breadcrumb.count >0
46
+ result['college']=breadcrumb[4].search("span").text()
47
+ result['stream']= breadcrumb[5].search("span").text()
48
+ if generals.include? (result['college'])
49
+ result['college']=breadcrumb[5].search("span").text()
50
+ result['stream']= breadcrumb[6].search("span").text()
51
+ end
33
52
  end
53
+
54
+ #storing the image
34
55
  page.search("#main-image-id").each do |img_id|
35
56
  img_tag=img_id.search("img")
36
57
  img_url=img_tag.attribute("src")
37
58
  result["img_url"]=img_url.to_s
38
59
  end
60
+
61
+ #storing the price
39
62
  price=page.search("#fk-mprod-list-id").text()
40
63
  if price ==""
41
64
  price = page.search("#fk-mprod-our-id").text()
@@ -44,6 +67,7 @@ class BookFinder
44
67
  result["price"]=price
45
68
  result["availability"]=page.search("#fk-stock-info-id").text()
46
69
  result["description"]=page.search("#description").inner_html().force_encoding("UTF-8")
70
+ result["description"].gsub!('<a href="#">top</a>',"")
47
71
  result
48
72
  end
49
73
  end
@@ -1,3 +1,3 @@
1
1
  module BookFinderApi
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: book_finder_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri