giffer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/giffer.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'giffer/version'
2
+ require 'giffer/http_client'
3
+ require 'giffer/gif_bin'
4
+
5
+ module Giffer
6
+
7
+ end
@@ -0,0 +1,13 @@
1
+ module Giffer
2
+ class GifBin < HttpClient
3
+
4
+ def uri
5
+ 'http://www.gifbin.com/f/random'
6
+ end
7
+
8
+ def xpath
9
+ "//img"
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
3
+
4
+ module Giffer
5
+ class HttpClient
6
+
7
+ def gif_href
8
+ doc = Nokogiri::HTML(retrieve_page)
9
+ doc.xpath(xpath).attribute('src').to_s
10
+ end
11
+
12
+ def retrieve_page
13
+ parsed_uri = URI(uri)
14
+ Net::HTTP.get(parsed_uri)
15
+ end
16
+
17
+ def xpath
18
+ raise 'Abstract, please do the OOP thang.'
19
+ end
20
+
21
+ def uri
22
+ raise 'Abstract, please do the OOP thang.'
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Giffer
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+ require 'giffer'
3
+
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Giffer::GifBin do
4
+ let(:client){ Giffer::GifBin.new }
5
+
6
+ context 'when randomly pulling gifs' do
7
+ it 'knows the source uri' do
8
+ client.uri.should match(/www.gifbin.com/)
9
+ end
10
+
11
+ it 'knows the xpath to use to find the image' do
12
+ client.xpath.should_not be_nil
13
+ end
14
+
15
+ it 'returns the URL of a random gif' do
16
+ client.gif_href.should match(/gifs.gifbin.com.*gif/)
17
+ end
18
+
19
+ it 'retrieves source HTML page' do
20
+ page = client.retrieve_page
21
+ page.should match(/Gifs Updated Daily - Gif Bin/)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Giffer::HttpClient do
4
+ let(:client){ Giffer::HttpClient.new }
5
+
6
+ context 'on abstract methods' do
7
+ it 'raises an error' do
8
+ lambda { client.uri }.should raise_error
9
+ lambda { client.xpath }.should raise_error
10
+ end
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: giffer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Denis Ivanov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-05-11 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "1.5"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: "2.10"
35
+ type: :development
36
+ version_requirements: *id002
37
+ description: Sends a request to www.gifbin.com and parses out the GIF url
38
+ email:
39
+ - visible@jumph4x.net
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - lib/giffer/version.rb
48
+ - lib/giffer/http_client.rb
49
+ - lib/giffer/gif_bin.rb
50
+ - lib/giffer.rb
51
+ - spec/unit/giffer/gif_bin_spec.rb
52
+ - spec/unit/giffer/http_client_spec.rb
53
+ - spec/spec_helper.rb
54
+ homepage: https://github.com/jumph4x/giffer
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.16
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Giffer gives .GIFs
81
+ test_files:
82
+ - spec/unit/giffer/gif_bin_spec.rb
83
+ - spec/unit/giffer/http_client_spec.rb
84
+ - spec/spec_helper.rb