meminator 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -2
- data/demo.rb +9 -0
- data/lib/meminator.rb +22 -27
- data/lib/meminator/auth.rb +34 -0
- data/lib/meminator/list.rb +1 -1
- data/meminator.gemspec +1 -3
- data/spec/meminator/auth_spec.rb +29 -0
- data/spec/meminator_spec.rb +3 -2
- metadata +5 -18
data/README.md
CHANGED
@@ -12,8 +12,13 @@ stupid things that it shouldn't. I intend to fix them at some point.
|
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
require 'meminator'
|
16
|
+
Meminator.username = 'richo' # USERNAME GOES HERE
|
17
|
+
Meminator.password = 'password' # PASSWORD GOES HERE
|
18
|
+
|
19
|
+
memer = Meminator::Meminator.new
|
20
|
+
|
21
|
+
puts memer.get_url("I_WOLF", "Patient stubbed his toe", "Had to put him down")
|
17
22
|
|
18
23
|
```
|
19
24
|
|
data/demo.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
require 'meminator'
|
4
|
+
Meminator.username = 'richo' # USERNAME GOES HERE
|
5
|
+
Meminator.password = 'password' # PASSWORD GOES HERE
|
6
|
+
|
7
|
+
memer = Meminator::Meminator.new
|
8
|
+
|
9
|
+
puts memer.get_url("I_WOLF", "Patient stubbed his toe", "Had to put him down")
|
data/lib/meminator.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'net/http'
|
2
|
-
require 'nokogiri'
|
3
2
|
require 'cgi'
|
3
|
+
require 'json'
|
4
4
|
|
5
5
|
##
|
6
6
|
# Generate memes using http://memegenerator.net
|
7
7
|
|
8
8
|
module Meminator
|
9
|
-
VERSION = '0.0.
|
10
|
-
GENERATOR_URL = 'http://memegenerator.net/
|
9
|
+
VERSION = '0.0.2'
|
10
|
+
GENERATOR_URL = 'http://version1.api.memegenerator.net/Instance_Create'
|
11
|
+
DISPLAY_URL = 'http://cdn.memegenerator.net'
|
11
12
|
class Error < Exception; end
|
12
13
|
class Meminator
|
13
14
|
|
@@ -20,53 +21,47 @@ module Meminator
|
|
20
21
|
|
21
22
|
url = URI.parse(GENERATOR_URL)
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
params = { 'username' => ::Meminator.username,
|
25
|
+
'password' => ::Meminator.password,
|
26
|
+
'templateType' => template_type,
|
27
|
+
'generatorID' => template_id,
|
28
|
+
'imageID' => 20, # TODO infer from generatorID
|
29
|
+
'generatorName' => generator_name }
|
26
30
|
|
27
31
|
[default_line, *text].compact.each_with_index do |item, idx|
|
28
|
-
|
32
|
+
params.merge! "text#{idx}" => item
|
29
33
|
end
|
30
34
|
|
31
35
|
begin
|
32
|
-
return fetch(url,
|
36
|
+
return fetch(url, params)
|
33
37
|
rescue Error => e
|
34
38
|
return e.message
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
def fetch(url,
|
42
|
+
def fetch(url, params)
|
43
|
+
params = params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
|
39
44
|
Net::HTTP.start url.host do |http|
|
40
|
-
|
41
|
-
|
42
|
-
post.set_form_data post_data
|
45
|
+
get = Net::HTTP::Get.new url.path + "?#{params}"
|
46
|
+
get['User-Agent'] = ::Meminator.user_agent
|
43
47
|
|
44
|
-
res = http.request
|
48
|
+
res = http.request get
|
45
49
|
|
46
50
|
unless Net::HTTPSuccess === res
|
47
51
|
raise Error, "memegenerator.net appears to be down, got #{res.code}"
|
48
52
|
end
|
49
53
|
|
50
|
-
|
51
|
-
redirect = url + location
|
52
|
-
|
53
|
-
get = Net::HTTP::Get.new redirect.request_uri
|
54
|
-
get['User-Agent'] = ::Meminator.user_agent
|
55
|
-
|
56
|
-
res = http.request get
|
57
|
-
end
|
54
|
+
ret = JSON.load(res.body)
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
else
|
63
|
-
raise Error, "memegenerator.net appears to be down, got #{res.code}"
|
56
|
+
if ret["success"]
|
57
|
+
return "#{DISPLAY_URL}#{ret["result"]["instanceImageUrl"]}"
|
58
|
+
end
|
64
59
|
end
|
65
60
|
end
|
66
61
|
|
67
62
|
end
|
68
63
|
end
|
69
64
|
|
70
|
-
%w[list user_agent].each do |filename|
|
65
|
+
%w[list user_agent auth].each do |filename|
|
71
66
|
require "meminator/#{filename}"
|
72
67
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Meminator
|
2
|
+
extend self
|
3
|
+
|
4
|
+
@@username = nil
|
5
|
+
@@password = nil
|
6
|
+
|
7
|
+
def username
|
8
|
+
if @@username
|
9
|
+
@@username
|
10
|
+
else
|
11
|
+
raise NotAuthorized
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def password
|
16
|
+
if @@password
|
17
|
+
@@password
|
18
|
+
else
|
19
|
+
raise NotAuthorized
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def username=(uname)
|
24
|
+
@@username = uname
|
25
|
+
end
|
26
|
+
|
27
|
+
def password=(pword)
|
28
|
+
@@password = pword
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Meminator
|
33
|
+
class NotAuthorized < Exception; end
|
34
|
+
end
|
data/lib/meminator/list.rb
CHANGED
@@ -34,7 +34,7 @@ module Meminator
|
|
34
34
|
advice_dog 'G_GRANDPA', 185650, 'Grumpy-Grandpa'
|
35
35
|
advice_dog 'H_MERMAID', 405224, 'Hipster-Mermaid'
|
36
36
|
advice_dog 'I_DONT_ALWAYS', 38926, 'The-Most-Interesting-Man-in-the-World'
|
37
|
-
advice_dog 'I_WOLF',
|
37
|
+
advice_dog 'I_WOLF', 45, 'Insanity-Wolf'
|
38
38
|
advice_dog 'JESUS', 1281, 'jesus-says'
|
39
39
|
advice_dog 'J_DUCREUX', 1356, 'Joseph-Ducreux'
|
40
40
|
advice_dog 'KANYE', 622033, 'kanyee'
|
data/meminator.gemspec
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "meminator"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.2"
|
4
4
|
s.authors = ["Eric Hodel", "Rich Healey"]
|
5
5
|
s.email = ["richo@psych0tik.net"]
|
6
6
|
s.homepage = "http://github.com/richoH/meminator"
|
7
7
|
s.summary = "API to retrieve urls for memes"
|
8
8
|
s.description = s.summary
|
9
9
|
|
10
|
-
s.add_dependency "nokogiri"
|
11
10
|
s.add_development_dependency "mocha"
|
12
11
|
s.add_development_dependency "rspec"
|
13
12
|
|
14
13
|
s.files = `git ls-files`.split("\n")
|
15
|
-
# s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
14
|
s.require_paths = ["lib"]
|
17
15
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Meminator do
|
4
|
+
|
5
|
+
it "Should raise an exception when no username set" do
|
6
|
+
::Meminator.username = nil
|
7
|
+
lambda {
|
8
|
+
::Meminator.username
|
9
|
+
}.should raise_error ::Meminator::NotAuthorized
|
10
|
+
end
|
11
|
+
|
12
|
+
it "Should raise an exception when no password set" do
|
13
|
+
::Meminator.password = nil
|
14
|
+
lambda {
|
15
|
+
::Meminator.password
|
16
|
+
}.should raise_error ::Meminator::NotAuthorized
|
17
|
+
end
|
18
|
+
|
19
|
+
it "Should return the set username" do
|
20
|
+
::Meminator.username = "richo"
|
21
|
+
::Meminator.username.should == "richo"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "Should return the set password" do
|
25
|
+
::Meminator.password = "rawk"
|
26
|
+
::Meminator.password.should == "rawk"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/meminator_spec.rb
CHANGED
@@ -4,10 +4,11 @@ describe Meminator do
|
|
4
4
|
|
5
5
|
it "Should serialize it's arguments" do
|
6
6
|
meminator = Meminator::Meminator.new
|
7
|
-
|
7
|
+
Meminator.username = "richo2"
|
8
|
+
Meminator.password = "richo3"
|
8
9
|
|
9
10
|
meminator.expects(:fetch).with(URI.parse(Meminator::GENERATOR_URL),
|
10
|
-
{'templateType' => 'AdviceDogSpinoff', '
|
11
|
+
{'username' => 'richo2', 'password' => 'richo3', 'templateType' => 'AdviceDogSpinoff', 'generatorID' => 45, 'imageID' => 20, 'generatorName' => 'Insanity-Wolf', 'text0' => 'First line', 'text1' => 'Second line'}
|
11
12
|
)
|
12
13
|
|
13
14
|
meminator.get_url("I_WOLF", "First line", "Second line")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meminator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,24 +10,8 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: nokogiri
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '0'
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - ! '>='
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '0'
|
31
15
|
- !ruby/object:Gem::Dependency
|
32
16
|
name: mocha
|
33
17
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,10 +59,13 @@ files:
|
|
75
59
|
- Manifest.txt
|
76
60
|
- README.md
|
77
61
|
- Rakefile
|
62
|
+
- demo.rb
|
78
63
|
- lib/meminator.rb
|
64
|
+
- lib/meminator/auth.rb
|
79
65
|
- lib/meminator/list.rb
|
80
66
|
- lib/meminator/user_agent.rb
|
81
67
|
- meminator.gemspec
|
68
|
+
- spec/meminator/auth_spec.rb
|
82
69
|
- spec/meminator/list_spec.rb
|
83
70
|
- spec/meminator/user_agent_spec.rb
|
84
71
|
- spec/meminator_spec.rb
|