forked from jamescook/RubyRedditAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove cruft. Fix friending/unfriending.
- Loading branch information
james cook
committed
Oct 6, 2010
1 parent
07adf11
commit 1ab822d
Showing
11 changed files
with
121 additions
and
51 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
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 @@ | ||
0.1.4 |
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,25 @@ | ||
Before do | ||
load_server_config | ||
Reddit::Api.base_uri @address | ||
Reddit::Submission.base_uri @address | ||
Reddit::Comment.base_uri @address | ||
Reddit::User.base_uri @address | ||
@api = Reddit::Api.new @user, @pass | ||
@api.login | ||
end | ||
|
||
Given /^I select a redditor$/ do | ||
@submission = @api.browse("reddit_test1")[0] | ||
@user = @submission.author | ||
end | ||
|
||
Then /^I should be able to friend them$/ do | ||
@user.friend.should be true | ||
end | ||
|
||
Then /^I should be able to unfriend them$/ do | ||
@user.unfriend.should be true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@user | ||
Feature: User | ||
In order have friends | ||
As a Redditor | ||
I want to be able to add and remove them | ||
|
||
Scenario: Valid user and password | ||
Given I select a redditor | ||
Then I should be able to friend them | ||
And I should be able to unfriend them | ||
|
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
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,47 @@ | ||
|
||
module Reddit | ||
class User < Api | ||
attr_reader :name, :debug, :created, :created_utc, :link_karma, :comment_karma, :is_mod, :has_mod_mail, :kind | ||
def initialize(json) | ||
@debug = StringIO.new | ||
parse(json) | ||
end | ||
|
||
def inspect | ||
"<Reddit::User name='#{name}'>" | ||
end | ||
|
||
def id | ||
"#{kind}_#{@id}" | ||
end | ||
|
||
def to_s | ||
name | ||
end | ||
|
||
def friend | ||
capture_user_id | ||
resp=self.class.post("/api/friend", {:body => {:name => name, :container => user_id, :type => "friend", :uh => modhash}, :headers => base_headers, :debug_output => @debug }) | ||
resp.code == 200 | ||
end | ||
|
||
def unfriend | ||
capture_user_id | ||
resp=self.class.post("/api/unfriend", {:body => {:name => name, :container => user_id, :type => "friend", :uh => modhash}, :headers => base_headers, :debug_output => @debug }) | ||
resp.code == 200 | ||
end | ||
|
||
protected | ||
def parse(json) | ||
json.keys.each do |key| | ||
instance_variable_set("@#{key}", json[key]) | ||
end | ||
end | ||
|
||
def self.parse(json) | ||
kind, data = json["kind"], json["data"] | ||
data["kind"] = kind | ||
return Reddit::User.new(data) | ||
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