forked from jamescook/RubyRedditAPI
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Place the JSON parsing in own module and include wherever needed.
- Loading branch information
james cook
committed
Oct 6, 2010
1 parent
2de661d
commit a8ff599
Showing
8 changed files
with
52 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.4 | ||
0.1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
$LOAD_PATH.unshift File.dirname(__FILE__) | ||
|
||
module Reddit | ||
VERSION = File.exist?("VERSION") ? File.read("VERSION").chomp : "" | ||
end | ||
|
||
require "httparty" | ||
require "json" | ||
require "reddit/base" | ||
require "reddit/json_listing" | ||
require "reddit/api" | ||
require "reddit/user" | ||
require "reddit/vote" | ||
require "reddit/submission" | ||
require "reddit/comment" | ||
require "reddit/message" | ||
|
||
module Reddit | ||
VERSION = File.exist?("VERSION") ? File.read("VERSION").chomp : "" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Reddit | ||
module JsonListing | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
base.send(:include, InstanceMethods) | ||
end | ||
|
||
module ClassMethods | ||
def parse(json) | ||
results = [] | ||
if json.is_a?(Array) | ||
json.each do |j| | ||
results << parse(j) | ||
end | ||
else | ||
data = json["data"] | ||
Reddit::Base.instance_variable_set("@modhash", data["modhash"]) # Needed for api calls | ||
|
||
children = data["children"] | ||
children.each do |message| | ||
kind = message["kind"] | ||
message["data"]["kind"] = kind | ||
results << self.new(message["data"]) | ||
end | ||
end | ||
|
||
return results.flatten | ||
end | ||
end | ||
module InstanceMethods | ||
def parse(json) | ||
json.keys.each do |key| | ||
instance_variable_set("@#{key}", json[key]) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters