quijotipsum_api 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README.markdown +25 -0
  3. data/bin/quijotipsum +26 -0
  4. data/lib/quijotipsum.rb +29 -0
  5. metadata +96 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Vicente Reig Rincón de Arellano
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ An Interface to Quijotipsum.com written in Ruby
2
+ ===============================================
3
+
4
+ (IT'S NOT WORKING YET... it's lunch time by the time I'm committing this thingy!)
5
+
6
+ It provides an API and a terminal command.
7
+
8
+
9
+ Installation
10
+ ------------
11
+ ``gem install quijotipsum_api``
12
+
13
+
14
+ Usage
15
+ -----
16
+ Requiring quijotipsum_api will add the next methods to any Fixnum:
17
+
18
+ * QuijotipsumAPI#lipsum_words -> "En un lugar de la Mancha, de cuyo nombre no quiero acordarme"
19
+ * QuijotipsumAPI#lipsum_paragraphs -> ["En un lugar de la Mancha, de cuyo nombre no quiero acordarme...", ...]
20
+
21
+ require 'rubygems'
22
+ require 'quijotipsum'
23
+
24
+ puts 6.quijotipsum_words
25
+ puts 2.quijotipsum_paragraphs
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'quijotipsum'
5
+
6
+ def print_usage
7
+ STDERR.puts "Usage: "
8
+ STDERR.puts "quijotipsum what amount"
9
+ STDERR.puts " Where 'what' can be 'words' or 'paragraphs'"
10
+ STDOUT.puts " 'amount' is the number of words, paragraphs to be retrieved"
11
+ puts ARGV.inspect
12
+ exit(1)
13
+ end
14
+
15
+
16
+ print_usage if ARGV.size < 2
17
+
18
+
19
+ command = ARGV[0]
20
+ amount = ARGV[1].to_i
21
+
22
+ if !['words', 'paragraphs'].include?(command)
23
+ print_usage
24
+ end
25
+
26
+ STDOUT.puts amount.send("quijotipsum_#{command}")
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ module QuijotipsumAPI
5
+
6
+ QuijotipsumURL = "http://quijotipsum.com/utils/lescript.php?%s=%s"
7
+
8
+ def method_missing(method, *args)
9
+ results = []
10
+ if method.to_s =~ /^quijotipsum_(.*)/ && ["paragraphs", "words"].include?($1)
11
+ opts = { :what => ($1 =~ /^par/? "par" : "pal") }
12
+ opts [:amount] = self if self.is_a? Fixnum
13
+ plain_doc = HTTParty.get(QuijotipsumURL % [opts[:what], opts[:amount]])
14
+
15
+ paragraphs = plain_doc.split("\n\n").collect { |t|
16
+ t.gsub(/<br \/>/, " ")
17
+ }.map(&:rstrip).reject(&:empty?)
18
+
19
+ return paragraphs.first if opts[:what] == 'words'
20
+ paragraphs
21
+ else
22
+ raise NoMethodError
23
+ end
24
+ end
25
+ end
26
+
27
+ class Fixnum
28
+ include QuijotipsumAPI
29
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quijotipsum_api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - "Vicente Reig Rinc\xC3\xB3n de Arellano"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-06-07 00:00:00 +02:00
18
+ default_executable: quijotipsum
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thor
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: httparty
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description:
49
+ email: vicente.reig@gmail.com
50
+ executables:
51
+ - quijotipsum
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - bin/quijotipsum
58
+ - lib/quijotipsum.rb
59
+ - LICENSE
60
+ - README.markdown
61
+ has_rdoc: true
62
+ homepage: http://github.com/vicentereig/quijotipsum-api
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.5.2
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: An Interface to Quijotipsum.com written in Ruby. It provides an API and a command line command.
95
+ test_files: []
96
+