tiqav 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -14,4 +14,5 @@ script/destroy
14
14
  script/generate
15
15
  test/test_alpha_num.rb
16
16
  test/test_helper.rb
17
- test/test_tiqav.rb
17
+ test/test_tiqav_search.rb
18
+ test/test_tiqav_random.rb
data/README.rdoc CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  * http://github.com/shokai/ruby-tiqav
4
4
 
5
+ == INSTALL:
6
+
7
+ * gem install tiqav
8
+
5
9
  == DESCRIPTION:
6
10
 
7
11
  Search Images on Tiqav.com
@@ -25,10 +29,6 @@ Search Images on Tiqav.com
25
29
 
26
30
  * Ruby 1.8.7+ or 1.9.3+
27
31
 
28
- == INSTALL:
29
-
30
- * gem install tiqav
31
-
32
32
  == LICENSE:
33
33
 
34
34
  (The MIT License)
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ $hoe = Hoe.spec 'tiqav' do
14
14
  self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
15
15
  # self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
16
  self.rubyforge_name = self.name # TODO this is default value
17
- self.extra_deps = [['nokogiri','>= 1.5.2']]
17
+ self.extra_deps = [['json','>= 1.5.4']]
18
18
 
19
19
  end
20
20
 
data/lib/tiqav/image.rb CHANGED
@@ -2,12 +2,13 @@
2
2
  module Tiqav
3
3
 
4
4
  class Image
5
- attr_reader :id, :url, :permalink, :filename
5
+ attr_reader :id, :url, :permalink, :filename, :ext
6
6
 
7
- def initialize(id)
7
+ def initialize(id, ext = 'jpg')
8
8
  @id = id
9
- @filename = "#{@id}.jpg"
10
- @url = URI.parse "http://tiqav.com/#{@filename}"
9
+ @ext = ext
10
+ @filename = "#{@id}.#{@ext}"
11
+ @url = URI.parse "http://img.tiqav.com/#{@filename}"
11
12
  @permalink = URI.parse "http://tiqav.com/#{@id}"
12
13
  end
13
14
 
data/lib/tiqav/search.rb CHANGED
@@ -1,16 +1,11 @@
1
1
 
2
2
  module Tiqav
3
3
  def self.search(word)
4
- uri = URI.parse "http://tiqav.com/search/#{URI.encode word}"
5
- res = Net::HTTP.start(uri.host, uri.port).request(Net::HTTP::Get.new uri.path)
4
+ uri = URI.parse "http://api.tiqav.com/search.json?q=#{URI.encode word}"
5
+ res = Net::HTTP.start(uri.host, uri.port).request(Net::HTTP::Get.new uri.request_uri)
6
6
  raise Error, "HTTP Status #{res.code} at #{uri}" unless res.code.to_i == 200
7
- doc = Nokogiri::HTML res.body
8
- doc.xpath('//a').map{|a|
9
- a['href']
10
- }.reject{|a|
11
- !(a =~ /^\/[a-zA-Z0-9]+$/)
12
- }.map{|a|
13
- Tiqav::Image.new a.scan(/([a-zA-Z0-9]+)/)[0][0]
7
+ JSON.parse(res.body).map{|img|
8
+ Tiqav::Image.new img['id'], img['ext']
14
9
  }
15
10
  end
16
11
 
data/lib/tiqav/tiqav.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'uri'
3
- require 'nokogiri'
3
+ require 'json'
4
4
 
5
5
  module Tiqav
6
6
  class Error < StandardError
data/lib/tiqav.rb CHANGED
@@ -7,5 +7,5 @@ require 'tiqav/search'
7
7
  require 'tiqav/alpha_num'
8
8
 
9
9
  module Tiqav
10
- VERSION = '0.0.1'
10
+ VERSION = '0.0.2'
11
11
  end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path 'test_helper', File.dirname(__FILE__)
3
+ require 'tmpdir'
4
+
5
+ class TestTiqavRandom < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @img = Tiqav.random
9
+ end
10
+
11
+ def test_image_class
12
+ assert @img.class == Tiqav::Image
13
+ end
14
+
15
+ end
@@ -2,14 +2,15 @@
2
2
  require File.expand_path 'test_helper', File.dirname(__FILE__)
3
3
  require 'tmpdir'
4
4
 
5
- class TestTiqav < Test::Unit::TestCase
5
+ class TestTiqavSearch < Test::Unit::TestCase
6
6
 
7
7
  def setup
8
- @img = Tiqav.random
8
+ @imgs = Tiqav.search('ちくわ')
9
+ @img = @imgs[0]
9
10
  end
10
-
11
+
11
12
  def test_search
12
- assert Tiqav.search('ちくわ').size > 0
13
+ assert @imgs.size > 0
13
14
  end
14
15
 
15
16
  def test_image_class
@@ -17,7 +18,7 @@ class TestTiqav < Test::Unit::TestCase
17
18
  end
18
19
 
19
20
  def test_image_exists?
20
- assert @img.exists? == true
21
+ assert @img.exists?
21
22
  end
22
23
 
23
24
  def test_image_url
@@ -29,14 +30,15 @@ class TestTiqav < Test::Unit::TestCase
29
30
  end
30
31
 
31
32
  def test_image_filename
32
- assert @img.filename =~ /.+\.jpe?g/i
33
+ assert @img.filename =~ /^.+\.#{@img.ext}$/
33
34
  end
34
35
 
35
36
  def test_image_save
36
37
  Dir.mktmpdir do |dir|
37
38
  fpath = File.expand_path @img.filename, dir
38
39
  @img.save(fpath)
39
- assert File.exists?(fpath) and File.stat(fpath).size > 0
40
+ assert File.exists?(fpath)
41
+ assert File.stat(fpath).size > 0
40
42
  end
41
43
  end
42
44
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiqav
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sho Hashimoto
@@ -15,22 +15,22 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-09 00:00:00 Z
18
+ date: 2012-06-11 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: nokogiri
21
+ name: json
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 7
28
+ hash: 11
29
29
  segments:
30
30
  - 1
31
31
  - 5
32
- - 2
33
- version: 1.5.2
32
+ - 4
33
+ version: 1.5.4
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
@@ -107,7 +107,8 @@ files:
107
107
  - script/generate
108
108
  - test/test_alpha_num.rb
109
109
  - test/test_helper.rb
110
- - test/test_tiqav.rb
110
+ - test/test_tiqav_search.rb
111
+ - test/test_tiqav_random.rb
111
112
  - .gemtest
112
113
  homepage: http://github.com/shokai/ruby-tiqav
113
114
  licenses: []
@@ -146,4 +147,5 @@ summary: Search Images on Tiqav.com
146
147
  test_files:
147
148
  - test/test_alpha_num.rb
148
149
  - test/test_helper.rb
149
- - test/test_tiqav.rb
150
+ - test/test_tiqav_random.rb
151
+ - test/test_tiqav_search.rb