meme 0.1.2 → 0.2.0
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.
- data/README.rdoc +24 -2
- data/VERSION +1 -1
- data/lib/meme.rb +3 -60
- data/lib/meme/info.rb +111 -0
- data/lib/meme/request.rb +13 -0
- data/lib/meme/search.rb +47 -0
- data/meme.gemspec +16 -3
- data/spec/fixtures/meme_followers.json +112 -0
- data/spec/fixtures/meme_followers_all.json +372 -0
- data/spec/fixtures/meme_followers_count.json +62 -0
- data/spec/fixtures/meme_following.json +112 -0
- data/spec/fixtures/meme_following_all.json +402 -0
- data/spec/fixtures/meme_following_count.json +82 -0
- data/spec/info_spec.rb +87 -0
- data/spec/meme_spec.rb +0 -136
- data/spec/search_spec.rb +75 -0
- data/spec/spec_helper.rb +9 -1
- metadata +15 -2
data/README.rdoc
CHANGED
@@ -24,6 +24,24 @@ Meme uses {YQL}[http://developer.yahoo.com/yql/] to get API of {Yahoo! Meme}[htt
|
|
24
24
|
user.avatar_url
|
25
25
|
=> "http://d.yimg.com/gg/jtadeulopes/avatars/44251e70378d4d225f8cda09a6c3aec87301833a.jpeg"
|
26
26
|
|
27
|
+
=== Followers and Following
|
28
|
+
|
29
|
+
followers = user.followers
|
30
|
+
followers.count
|
31
|
+
=> 10
|
32
|
+
|
33
|
+
follower = followers.first
|
34
|
+
|
35
|
+
follower.name
|
36
|
+
=> "zigotto"
|
37
|
+
|
38
|
+
follower.url
|
39
|
+
=> "http://meme.yahoo.com/zigotto/"
|
40
|
+
|
41
|
+
following = user.following
|
42
|
+
following.count
|
43
|
+
=> 10
|
44
|
+
|
27
45
|
=== Find posts
|
28
46
|
|
29
47
|
posts = Meme::Post.find('brhackday')
|
@@ -31,8 +49,8 @@ Meme uses {YQL}[http://developer.yahoo.com/yql/] to get API of {Yahoo! Meme}[htt
|
|
31
49
|
posts.first.category
|
32
50
|
=> "text"
|
33
51
|
|
34
|
-
|
35
|
-
=> "RT @codepo8: And I am off - plane leaves BR for London. Thanks to everybody I met at #brhackday
|
52
|
+
posts.first.content
|
53
|
+
=> "RT @codepo8: And I am off - plane leaves BR for London. Thanks to everybody I met at #brhackday...
|
36
54
|
|
37
55
|
Find by type:
|
38
56
|
|
@@ -43,6 +61,10 @@ Find by type:
|
|
43
61
|
|
44
62
|
For more information, please refer the {project wiki}[http://wiki.github.com/jtadeulopes/meme/]
|
45
63
|
|
64
|
+
== Installation
|
65
|
+
|
66
|
+
sudo gem install meme
|
67
|
+
|
46
68
|
== TODO
|
47
69
|
|
48
70
|
Much remains to be done! Please refer the {project wiki}[http://wiki.github.com/jtadeulopes/meme/]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/meme.rb
CHANGED
@@ -1,63 +1,6 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
VARS = ["avatar_url", "name", "title", "guid", "followers", "language", "url", "description"]
|
9
|
-
|
10
|
-
attr_accessor *VARS
|
11
|
-
|
12
|
-
def initialize(data)
|
13
|
-
unless data.nil?
|
14
|
-
VARS.each do |var|
|
15
|
-
self.instance_variable_set("@#{var}", data[var])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.find(name)
|
21
|
-
url = URI.escape("https://query.yahooapis.com/v1/public/yql?q=SELECT * FROM meme.info WHERE name='#{name}'&format=json")
|
22
|
-
buffer = open(url).read
|
23
|
-
parse = JSON.parse(buffer)
|
24
|
-
if parse
|
25
|
-
results = parse['query']['results']
|
26
|
-
results.nil? ? nil : Info.new(results['meme'])
|
27
|
-
else
|
28
|
-
parse.error!
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
class Post
|
35
|
-
|
36
|
-
VARS = ["category", "timestamp", "guid", "pubid", "url", "repost_count", "caption", "type", "content"]
|
37
|
-
|
38
|
-
attr_accessor *VARS
|
39
|
-
|
40
|
-
def initialize(data)
|
41
|
-
unless data.nil?
|
42
|
-
VARS.each do |var|
|
43
|
-
self.instance_variable_set("@#{var}", data[var])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.find(query, options = {})
|
49
|
-
type = " and type='#{options.delete(:type).to_s}'" if options.has_key?(:type)
|
50
|
-
url = URI.escape("https://query.yahooapis.com/v1/public/yql?q=SELECT * FROM meme.search WHERE query='#{query}'#{type}&format=json")
|
51
|
-
buffer = open(url).read
|
52
|
-
parse = JSON.parse(buffer)
|
53
|
-
if parse
|
54
|
-
results = parse['query']['results']
|
55
|
-
results.nil? ? nil : results['post'].map {|m| Post.new(m)}
|
56
|
-
else
|
57
|
-
parse.error!
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
4
|
+
require 'meme/info'
|
5
|
+
require 'meme/search'
|
6
|
+
require 'meme/request'
|
data/lib/meme/info.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
module Meme
|
2
|
+
|
3
|
+
class Info
|
4
|
+
|
5
|
+
VARS = ["avatar_url", "name", "title", "guid", "language", "url", "description"] #:nodoc:
|
6
|
+
|
7
|
+
attr_accessor *VARS
|
8
|
+
|
9
|
+
def initialize(data) #:nodoc:
|
10
|
+
unless data.nil?
|
11
|
+
VARS.each do |var|
|
12
|
+
self.instance_variable_set("@#{var}", data[var])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Find user
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
#
|
21
|
+
# # by name
|
22
|
+
# user = Meme::Info.find('jtadeulopes')
|
23
|
+
# user.name
|
24
|
+
# => "jtadeulopes"
|
25
|
+
#
|
26
|
+
def self.find(name)
|
27
|
+
query = "SELECT * FROM meme.info WHERE name='#{name}'"
|
28
|
+
parse = Request.parse(query)
|
29
|
+
if parse
|
30
|
+
results = parse['query']['results']
|
31
|
+
results.nil? ? nil : Info.new(results['meme'])
|
32
|
+
else
|
33
|
+
parse.error!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return user followers
|
38
|
+
#
|
39
|
+
# Example:
|
40
|
+
#
|
41
|
+
# # Search user
|
42
|
+
# user = Meme::Info.find('jtadeulopes')
|
43
|
+
#
|
44
|
+
# # Default
|
45
|
+
# followers = user.followers
|
46
|
+
# followers.count
|
47
|
+
# => 10
|
48
|
+
#
|
49
|
+
# # Specify a count
|
50
|
+
# followers = user.followers(100)
|
51
|
+
# followers.count
|
52
|
+
# => 100
|
53
|
+
#
|
54
|
+
# # All followers
|
55
|
+
# followers = user.followers(:all)
|
56
|
+
# followers.count
|
57
|
+
#
|
58
|
+
# follower = followers.first
|
59
|
+
# follower.name
|
60
|
+
# => "zigotto"
|
61
|
+
# follower.url
|
62
|
+
# => "http://meme.yahoo.com/zigotto/"
|
63
|
+
#
|
64
|
+
def followers(count=10)
|
65
|
+
count = 0 if count.is_a?(Symbol) && count == :all
|
66
|
+
query = "SELECT * FROM meme.followers(#{count}) WHERE owner_guid='#{self.guid}'"
|
67
|
+
parse = Request.parse(query)
|
68
|
+
if parse
|
69
|
+
results = parse['query']['results']
|
70
|
+
results.nil? ? nil : results['meme'].map {|m| Info.new(m)}
|
71
|
+
else
|
72
|
+
parse.error!
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Return user following
|
77
|
+
#
|
78
|
+
# Example:
|
79
|
+
#
|
80
|
+
# # Search user
|
81
|
+
# user = Meme::Info.find('jtadeulopes')
|
82
|
+
#
|
83
|
+
# # Default
|
84
|
+
# following = user.following
|
85
|
+
# following.count
|
86
|
+
# => 10
|
87
|
+
#
|
88
|
+
# # Specify a count
|
89
|
+
# following = user.following(100)
|
90
|
+
# following.count
|
91
|
+
# => 100
|
92
|
+
#
|
93
|
+
# # All following
|
94
|
+
# following = user.following(:all)
|
95
|
+
# following.count
|
96
|
+
#
|
97
|
+
def following(count=10)
|
98
|
+
count = 0 if count.is_a?(Symbol) && count == :all
|
99
|
+
query = "SELECT * FROM meme.following(#{count}) WHERE owner_guid='#{self.guid}'"
|
100
|
+
parse = Request.parse(query)
|
101
|
+
if parse
|
102
|
+
results = parse['query']['results']
|
103
|
+
results.nil? ? nil : results['meme'].map {|m| Info.new(m)}
|
104
|
+
else
|
105
|
+
parse.error!
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
data/lib/meme/request.rb
ADDED
data/lib/meme/search.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Meme
|
2
|
+
|
3
|
+
class Post
|
4
|
+
|
5
|
+
VARS = ["category", "timestamp", "guid", "pubid", "url", "repost_count", "caption", "type", "content"] #:nodoc:
|
6
|
+
|
7
|
+
attr_accessor *VARS
|
8
|
+
|
9
|
+
def initialize(data) #:nodoc:
|
10
|
+
unless data.nil?
|
11
|
+
VARS.each do |var|
|
12
|
+
self.instance_variable_set("@#{var}", data[var])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Find posts
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
#
|
21
|
+
# # type text
|
22
|
+
# posts = Meme::Post.find('brhackday')
|
23
|
+
#
|
24
|
+
# # type photo
|
25
|
+
# posts = Meme::Post.find('brhackday', :type => :photo)
|
26
|
+
#
|
27
|
+
# # type video
|
28
|
+
# posts = Meme::Post.find('brhackday', :type => :video)
|
29
|
+
#
|
30
|
+
# posts.first.content
|
31
|
+
# => "RT @codepo8: And I am off - plane leaves BR for London. Thanks to everybody...
|
32
|
+
#
|
33
|
+
def self.find(query, options = {})
|
34
|
+
type = " and type='#{options.delete(:type).to_s}'" if options.has_key?(:type)
|
35
|
+
query = "SELECT * FROM meme.search WHERE query='#{query}'#{type}"
|
36
|
+
parse = Request.parse(query)
|
37
|
+
if parse
|
38
|
+
results = parse['query']['results']
|
39
|
+
results.nil? ? nil : results['post'].map {|m| Post.new(m)}
|
40
|
+
else
|
41
|
+
parse.error!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/meme.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{meme}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["J\303\251sus Lopes"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-01}
|
13
13
|
s.description = %q{Yahoo! Meme API wrapper library in Ruby}
|
14
14
|
s.email = %q{jlopes@zigotto.com.br}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,14 +24,25 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"lib/meme.rb",
|
27
|
+
"lib/meme/info.rb",
|
28
|
+
"lib/meme/request.rb",
|
29
|
+
"lib/meme/search.rb",
|
27
30
|
"meme.gemspec",
|
31
|
+
"spec/fixtures/meme_followers.json",
|
32
|
+
"spec/fixtures/meme_followers_all.json",
|
33
|
+
"spec/fixtures/meme_followers_count.json",
|
34
|
+
"spec/fixtures/meme_following.json",
|
35
|
+
"spec/fixtures/meme_following_all.json",
|
36
|
+
"spec/fixtures/meme_following_count.json",
|
28
37
|
"spec/fixtures/meme_info.json",
|
29
38
|
"spec/fixtures/meme_info_not_found.json",
|
30
39
|
"spec/fixtures/meme_search.json",
|
31
40
|
"spec/fixtures/meme_search_type_audio.json",
|
32
41
|
"spec/fixtures/meme_search_type_photo.json",
|
33
42
|
"spec/fixtures/meme_search_type_video.json",
|
43
|
+
"spec/info_spec.rb",
|
34
44
|
"spec/meme_spec.rb",
|
45
|
+
"spec/search_spec.rb",
|
35
46
|
"spec/spec.opts",
|
36
47
|
"spec/spec_helper.rb"
|
37
48
|
]
|
@@ -42,7 +53,9 @@ Gem::Specification.new do |s|
|
|
42
53
|
s.summary = %q{Ruby Yahoo! Meme API}
|
43
54
|
s.test_files = [
|
44
55
|
"spec/meme_spec.rb",
|
45
|
-
"spec/
|
56
|
+
"spec/search_spec.rb",
|
57
|
+
"spec/spec_helper.rb",
|
58
|
+
"spec/info_spec.rb"
|
46
59
|
]
|
47
60
|
|
48
61
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,112 @@
|
|
1
|
+
{
|
2
|
+
"query":{
|
3
|
+
"count":"10",
|
4
|
+
"created":"2010-04-01T10:31:02Z",
|
5
|
+
"lang":"en-US",
|
6
|
+
"updated":"2010-04-01T10:31:02Z",
|
7
|
+
"uri":"https://query.yahooapis.com/v1/yql?q=SELECT+*+FROM+meme.followers+WHERE+owner_guid%3D%27EMREXCV4R5OTM3CZW3HBD5QAGY%27",
|
8
|
+
"results":{
|
9
|
+
"meme":[{
|
10
|
+
"guid":"J7B4OWIQWFXHJDYZWAARA2RYZE",
|
11
|
+
"name":"zigotto",
|
12
|
+
"title":"Zigotto",
|
13
|
+
"description":"Criação e Desenvolvimento para todo Vale do Paraíba e Brasil",
|
14
|
+
"url":"http://meme.yahoo.com/zigotto/",
|
15
|
+
"avatar_url":"http://d.yimg.com/gg/zigotto/avatars/c0fbd3fe6c109cebaf0c0c871e45e338b7c04ed8.png",
|
16
|
+
"language":"pt",
|
17
|
+
"followers":"1"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"guid":"2FPYHHRLJK5XMBSSXNL5NQGGB4",
|
21
|
+
"name":"fabilouco8000",
|
22
|
+
"title":"Fabilouco8000",
|
23
|
+
"description":"Diversão é comigo mesmo!",
|
24
|
+
"url":"http://meme.yahoo.com/fabilouco8000/",
|
25
|
+
"avatar_url":"http://d.yimg.com/gg/fabilouco8000/avatars/73d91d124dbf68ad706798de4ed0a3f4661446f3.jpeg",
|
26
|
+
"language":"pt",
|
27
|
+
"followers":"510"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"guid":"6M46NNM2LO5YQ7XNYCU5MVITKE",
|
31
|
+
"name":"acsouza09",
|
32
|
+
"title":"acsouza09",
|
33
|
+
"description":"Sou uma pessoa feliz, extremamente vaidoosa!",
|
34
|
+
"url":"http://meme.yahoo.com/acsouza09/",
|
35
|
+
"avatar_url":"http://d.yimg.com/gg/acsouza09/avatars/013fb916b1362f68acbbea5ec643012380d942e6.jpeg",
|
36
|
+
"language":"pt",
|
37
|
+
"followers":"3"
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"guid":"CETYPLO3WBYWGEBEUXMC2FO4EU",
|
41
|
+
"name":"marcetolosa",
|
42
|
+
"title":"Marcetolosa",
|
43
|
+
"description":"BA - Yahoo!",
|
44
|
+
"url":"http://meme.yahoo.com/marcetolosa/",
|
45
|
+
"avatar_url":"http://d.yimg.com/gg/marcetolosa/avatars/59a1e60f21b9c5d478ec1816dd827bdde64b8f52.jpeg",
|
46
|
+
"language":"es",
|
47
|
+
"followers":"1183"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"guid":"NEUNUDTFXKL4Q3IQK2JEH4NMDI",
|
51
|
+
"name":"edercosta",
|
52
|
+
"title":"edercosta",
|
53
|
+
"description":"desenvolvedor web, só!",
|
54
|
+
"url":"http://meme.yahoo.com/edercosta/",
|
55
|
+
"avatar_url":"http://d.yimg.com/gg/edercosta/avatars/7e7b464e2af1e413ca421101d57b3c5684325076.jpeg",
|
56
|
+
"language":"pt",
|
57
|
+
"followers":"6"
|
58
|
+
},
|
59
|
+
{
|
60
|
+
"guid":"GNQZXVPVCUUVFODPRUGPYSK5LA",
|
61
|
+
"name":"marcelofraga",
|
62
|
+
"title":"Marcelo Fraga",
|
63
|
+
"description":"Web Developer",
|
64
|
+
"url":"http://meme.yahoo.com/marcelofraga/",
|
65
|
+
"avatar_url":"http://d.yimg.com/gg/marcelofraga/avatars/8dc4fde72c2f718386a44f52c5384ed83f7eea67.jpeg",
|
66
|
+
"language":"pt",
|
67
|
+
"followers":"5"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"guid":"SNTS64IYOYICF2TMB2QN2EGG2Y",
|
71
|
+
"name":"berg_te_amo",
|
72
|
+
"title":"°•๋ °Loறa°•๋ °",
|
73
|
+
"description":"°•๋ °navegando no றar dos றeus sonhos°•๋ °",
|
74
|
+
"url":"http://meme.yahoo.com/berg_te_amo/",
|
75
|
+
"avatar_url":"http://d.yimg.com/gg/berg_te_amo/avatars/24872b74162ea7ca3a0db798e25dccd7250aac33.jpeg",
|
76
|
+
"language":"pt",
|
77
|
+
"followers":"403"
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"guid":"M7OYDALP7ODIEAH6W2ZUQTVIB4",
|
81
|
+
"name":"matiaz",
|
82
|
+
"title":"Matiaz",
|
83
|
+
"description":"Yahoo! Argentina",
|
84
|
+
"url":"http://meme.yahoo.com/matiaz/",
|
85
|
+
"avatar_url":"http://d.yimg.com/gg/matiaz/avatars/711923e770e1c66f86e8ceb2743dd09e0d6a35cf.jpeg",
|
86
|
+
"language":"en",
|
87
|
+
"followers":"1492"
|
88
|
+
},
|
89
|
+
{
|
90
|
+
"guid":"QLET3EJ5XXYIVAHBOQVSPZB6BM",
|
91
|
+
"name":"mariano",
|
92
|
+
"title":"mariano",
|
93
|
+
"description":"Coisas engraçadas e informática!! O.o",
|
94
|
+
"url":"http://meme.yahoo.com/mariano/",
|
95
|
+
"avatar_url":"http://d.yimg.com/gg/mariano/avatars/13311faeddf76382df7806b8ad188e8b455cd2ca.jpeg",
|
96
|
+
"language":"pt",
|
97
|
+
"followers":"287"
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"guid":"LKMTQUYO4NA3HWE2MHPCC2UVOU",
|
101
|
+
"name":"willweb",
|
102
|
+
"title":"willweb",
|
103
|
+
"description":"Imerso no mundo digital, para descobrir intenções e realidades físicas!",
|
104
|
+
"url":"http://meme.yahoo.com/willweb/",
|
105
|
+
"avatar_url":"http://d.yimg.com/gg/willweb/avatars/480c433a64d2b433e618cd6acb7436dafffe5299.jpeg",
|
106
|
+
"language":"pt",
|
107
|
+
"followers":"12283"
|
108
|
+
}
|
109
|
+
]
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|