tiqav 0.0.2 → 0.0.3

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.
@@ -6,7 +6,7 @@ lib/tiqav.rb
6
6
  lib/tiqav/alpha_num.rb
7
7
  lib/tiqav/image.rb
8
8
  lib/tiqav/search.rb
9
- lib/tiqav/tiqav.rb
9
+ lib/tiqav/error.rb
10
10
  samples/sample.rb
11
11
  samples/search.rb
12
12
  script/console
@@ -14,5 +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_image.rb
17
18
  test/test_tiqav_search.rb
18
- test/test_tiqav_random.rb
@@ -24,6 +24,9 @@ Search Images on Tiqav.com
24
24
 
25
25
  img = Tiqav.random
26
26
  puts img.url
27
+ puts img.thumbnail
28
+ puts img.glitch
29
+
27
30
 
28
31
  == REQUIREMENTS:
29
32
 
@@ -1,11 +1,14 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
- require 'tiqav/tiqav'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'json'
7
+ require 'tiqav/error'
5
8
  require 'tiqav/image'
6
9
  require 'tiqav/search'
7
10
  require 'tiqav/alpha_num'
8
11
 
9
12
  module Tiqav
10
- VERSION = '0.0.2'
13
+ VERSION = '0.0.3'
11
14
  end
@@ -1,6 +1,3 @@
1
- require 'net/http'
2
- require 'uri'
3
- require 'json'
4
1
 
5
2
  module Tiqav
6
3
  class Error < StandardError
@@ -2,7 +2,7 @@
2
2
  module Tiqav
3
3
 
4
4
  class Image
5
- attr_reader :id, :url, :permalink, :filename, :ext
5
+ attr_reader :id, :url, :permalink, :filename, :ext, :thumbnail, :glitch
6
6
 
7
7
  def initialize(id, ext = 'jpg')
8
8
  @id = id
@@ -10,6 +10,8 @@ module Tiqav
10
10
  @filename = "#{@id}.#{@ext}"
11
11
  @url = URI.parse "http://img.tiqav.com/#{@filename}"
12
12
  @permalink = URI.parse "http://tiqav.com/#{@id}"
13
+ @thumbnail = URI.parse "http://img.tiqav.com/#{@id}.th.#{ext}"
14
+ @glitch = URI.parse "http://img.tiqav.com/#{@id}.glitch"
13
15
  end
14
16
 
15
17
  def save(fname)
@@ -9,8 +9,10 @@ puts img.exists?
9
9
  puts img.url
10
10
 
11
11
  img = Tiqav.random
12
- puts img.id
12
+ puts "id : #{img.id}"
13
13
  puts img.permalink
14
14
  puts img.url
15
+ puts img.thumbnail
16
+ puts img.glitch
15
17
  img.save img.filename
16
18
  puts "saved!! => #{img.filename}"
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path 'test_helper', File.dirname(__FILE__)
3
+ require 'tmpdir'
4
+
5
+ class TestTiqavImage < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @img = Tiqav::Image.new '3om'
9
+ end
10
+
11
+ def test_image_class
12
+ assert @img.class == Tiqav::Image
13
+ end
14
+
15
+ def test_image_exists?
16
+ assert @img.exists?
17
+ end
18
+
19
+ def test_image_url
20
+ assert @img.url.kind_of? URI::HTTP
21
+ end
22
+
23
+ def test_image_permalink
24
+ assert @img.permalink.kind_of? URI::HTTP
25
+ end
26
+
27
+ def test_image_thumbnail
28
+ assert @img.thumbnail.kind_of? URI::HTTP
29
+ res = Net::HTTP.start(@img.thumbnail.host, @img.thumbnail.port).
30
+ request(Net::HTTP::Head.new @img.thumbnail.path)
31
+ assert res.code.to_i == 200
32
+ end
33
+
34
+ def test_image_glitch
35
+ assert @img.glitch.kind_of? URI::HTTP
36
+ res = Net::HTTP.start(@img.glitch.host, @img.glitch.port).
37
+ request(Net::HTTP::Head.new @img.glitch.path)
38
+ assert res.code.to_i == 200
39
+ end
40
+
41
+ def test_image_filename
42
+ assert @img.filename =~ /^.+\.#{@img.ext}$/
43
+ end
44
+
45
+ def test_image_save
46
+ Dir.mktmpdir do |dir|
47
+ fpath = File.expand_path @img.filename, dir
48
+ @img.save(fpath)
49
+ assert File.exists?(fpath)
50
+ assert File.stat(fpath).size > 0
51
+ end
52
+ end
53
+
54
+ end
@@ -4,42 +4,18 @@ require 'tmpdir'
4
4
 
5
5
  class TestTiqavSearch < Test::Unit::TestCase
6
6
 
7
- def setup
8
- @imgs = Tiqav.search('ちくわ')
9
- @img = @imgs[0]
10
- end
11
-
12
7
  def test_search
13
- assert @imgs.size > 0
14
- end
15
-
16
- def test_image_class
17
- assert @img.class == Tiqav::Image
18
- end
19
-
20
- def test_image_exists?
21
- assert @img.exists?
22
- end
23
-
24
- def test_image_url
25
- assert @img.url.kind_of? URI::HTTP
26
- end
27
-
28
- def test_image_permalink
29
- assert @img.permalink.kind_of? URI::HTTP
8
+ assert Tiqav.search('ちくわ').size > 0
30
9
  end
31
10
 
32
- def test_image_filename
33
- assert @img.filename =~ /^.+\.#{@img.ext}$/
11
+ def test_random
12
+ r = Tiqav.random
13
+ assert r.class == Tiqav::Image
14
+ assert r.id =~ /^[a-zA-Z0-9]+$/
34
15
  end
35
16
 
36
- def test_image_save
37
- Dir.mktmpdir do |dir|
38
- fpath = File.expand_path @img.filename, dir
39
- @img.save(fpath)
40
- assert File.exists?(fpath)
41
- assert File.stat(fpath).size > 0
42
- end
17
+ def test_feelinkg_lucky
18
+ assert Tiqav.feeling_lucky('ちくわ').kind_of? URI::HTTP
43
19
  end
44
20
 
45
21
  end
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sho Hashimoto
@@ -99,7 +99,7 @@ files:
99
99
  - lib/tiqav/alpha_num.rb
100
100
  - lib/tiqav/image.rb
101
101
  - lib/tiqav/search.rb
102
- - lib/tiqav/tiqav.rb
102
+ - lib/tiqav/error.rb
103
103
  - samples/sample.rb
104
104
  - samples/search.rb
105
105
  - script/console
@@ -107,8 +107,8 @@ files:
107
107
  - script/generate
108
108
  - test/test_alpha_num.rb
109
109
  - test/test_helper.rb
110
+ - test/test_tiqav_image.rb
110
111
  - test/test_tiqav_search.rb
111
- - test/test_tiqav_random.rb
112
112
  - .gemtest
113
113
  homepage: http://github.com/shokai/ruby-tiqav
114
114
  licenses: []
@@ -147,5 +147,5 @@ summary: Search Images on Tiqav.com
147
147
  test_files:
148
148
  - test/test_alpha_num.rb
149
149
  - test/test_helper.rb
150
- - test/test_tiqav_random.rb
150
+ - test/test_tiqav_image.rb
151
151
  - test/test_tiqav_search.rb
@@ -1,15 +0,0 @@
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