redd 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +10 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +10 -0
- data/Rakefile +10 -0
- data/github/redd.png +0 -0
- data/lib/redd.rb +14 -0
- data/lib/redd/RedditKit.LICENSE.md +13 -0
- data/lib/redd/base.rb +35 -0
- data/lib/redd/client/authenticated.rb +88 -0
- data/lib/redd/client/authenticated/account.rb +9 -0
- data/lib/redd/client/authenticated/apps.rb +12 -0
- data/lib/redd/client/authenticated/flair.rb +9 -0
- data/lib/redd/client/authenticated/gold.rb +12 -0
- data/lib/redd/client/authenticated/links_comments.rb +9 -0
- data/lib/redd/client/authenticated/live.rb +12 -0
- data/lib/redd/client/authenticated/moderation.rb +9 -0
- data/lib/redd/client/authenticated/multis.rb +9 -0
- data/lib/redd/client/authenticated/private_messages.rb +40 -0
- data/lib/redd/client/authenticated/subreddits.rb +9 -0
- data/lib/redd/client/authenticated/users.rb +9 -0
- data/lib/redd/client/authenticated/wiki.rb +9 -0
- data/lib/redd/client/oauth2.rb +9 -0
- data/lib/redd/client/unauthenticated.rb +104 -0
- data/lib/redd/client/unauthenticated/account.rb +21 -0
- data/lib/redd/client/unauthenticated/links_comments.rb +15 -0
- data/lib/redd/client/unauthenticated/listing.rb +44 -0
- data/lib/redd/client/unauthenticated/subreddits.rb +13 -0
- data/lib/redd/client/unauthenticated/utilities.rb +61 -0
- data/lib/redd/client/unauthenticated/wiki.rb +9 -0
- data/lib/redd/error.rb +93 -0
- data/lib/redd/object/comment.rb +41 -0
- data/lib/redd/object/listing.rb +24 -0
- data/lib/redd/object/submission.rb +94 -0
- data/lib/redd/object/subreddit.rb +10 -0
- data/lib/redd/rate_limit.rb +48 -0
- data/lib/redd/response/parse_json.rb +31 -0
- data/lib/redd/response/raise_error.rb +20 -0
- data/lib/redd/thing.rb +27 -0
- data/lib/redd/version.rb +5 -0
- data/redd.gemspec +32 -0
- data/spec/redd_spec.rb +7 -0
- data/spec/spec_helper.rb +33 -0
- metadata +234 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eefcb4605d95ff4dd74d15293cfc83ad525d1c6a
|
4
|
+
data.tar.gz: f9f7689a053500c5d0021edf35476cbd019b0ca2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b1ce4746c616835b1115000c04685f8f24b009a79e26857f60d0bce2f50c3a53078d0ec5f46dc28819bc92dd46d4d645899901219a80fdf8556e2d03cc376ca
|
7
|
+
data.tar.gz: 6ab5345939dae63c5cc132a5ca9b91efb331c55c3a7e137659306094ce2ffbe7ceb150df490e688f06484f062e2f614395797384e96cef64473c38099429f700
|
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Working on Codio!
|
13
|
+
# Seriously, it's free and it's awesome.
|
14
|
+
.codio
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
|
21
|
+
## Documentation cache and generated files:
|
22
|
+
/.yardoc/
|
23
|
+
/_yardoc/
|
24
|
+
/doc/
|
25
|
+
/rdoc/
|
26
|
+
|
27
|
+
## Environment normalisation:
|
28
|
+
/.bundle/
|
29
|
+
/lib/bundler/man/
|
30
|
+
|
31
|
+
# for a library or gem, you might want to ignore these files since the code is
|
32
|
+
# intended to run in multiple environments; otherwise, check them in:
|
33
|
+
Gemfile.lock
|
34
|
+
.ruby-version
|
35
|
+
.ruby-gemset
|
36
|
+
|
37
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
38
|
+
.rvmrc
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--private
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Avinash Dwarapu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<img src="github/redd.png?raw=true" alt="redd"><br>
|
3
|
+
</p>
|
4
|
+
|
5
|
+
**redd** is an API wrapper for [reddit](http://reddit.com/dev/api) written in ruby that focuses on being *simple and extensible*.
|
6
|
+
**NOTE: Major features are not implemented yet!**
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
##
|
data/Rakefile
ADDED
data/github/redd.png
ADDED
Binary file
|
data/lib/redd.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "redd/client/unauthenticated"
|
2
|
+
require "redd/client/authenticated"
|
3
|
+
require "redd/client/oauth2"
|
4
|
+
|
5
|
+
module Redd
|
6
|
+
def self.client(username = nil, password = nil)
|
7
|
+
client = Redd::Client::Unauthenticated.new
|
8
|
+
if username.nil? || password.nil?
|
9
|
+
client
|
10
|
+
else
|
11
|
+
client.login(username, password)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
The errors file would have been impossible if it weren't for @samsymons :)
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
Copyright (c) 2013 Sam Symons
|
6
|
+
|
7
|
+
MIT License
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/redd/base.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "memoizable"
|
2
|
+
|
3
|
+
module Redd
|
4
|
+
# A container for various models with attributes and a client.
|
5
|
+
class Base
|
6
|
+
include Memoizable
|
7
|
+
|
8
|
+
# @!attribute [r] attributes
|
9
|
+
# @return [Hash] A list of attributes returned by reddit for this object.
|
10
|
+
attr_reader :attributes
|
11
|
+
alias_method :to_h, :attributes
|
12
|
+
|
13
|
+
# @!attribute [r] client
|
14
|
+
# @return The client instance used to make requests with this object.
|
15
|
+
attr_reader :client
|
16
|
+
|
17
|
+
# Define and memoize the method that returns a key from the
|
18
|
+
# attributes hash.
|
19
|
+
# @param [Symbol, String] key The key to construct a method out of.
|
20
|
+
# @param [Symbol] attribute The attribute in the given hash to return.
|
21
|
+
def self.attr_reader(key, attribute = key)
|
22
|
+
define_method(key) { @attributes[attribute] }
|
23
|
+
memoize(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param client The client to use when making requests with this object.
|
27
|
+
# This is similar to reddit_session in praw.
|
28
|
+
# @param [Hash] attributes
|
29
|
+
def initialize(client, attributes)
|
30
|
+
@client = client
|
31
|
+
@attributes = attributes[:data]
|
32
|
+
@attributes[:kind] = attributes[:kind]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Redd
|
2
|
+
module Client
|
3
|
+
# The class that handles requests when authenticated using a username and
|
4
|
+
# password.
|
5
|
+
class Authenticated < Redd::Client::Unauthenticated
|
6
|
+
require "redd/client/authenticated/account"
|
7
|
+
require "redd/client/authenticated/apps"
|
8
|
+
require "redd/client/authenticated/flair"
|
9
|
+
require "redd/client/authenticated/gold"
|
10
|
+
require "redd/client/authenticated/links_comments"
|
11
|
+
require "redd/client/authenticated/live"
|
12
|
+
require "redd/client/authenticated/moderation"
|
13
|
+
require "redd/client/authenticated/multis"
|
14
|
+
require "redd/client/authenticated/private_messages"
|
15
|
+
require "redd/client/authenticated/subreddits"
|
16
|
+
require "redd/client/authenticated/users"
|
17
|
+
require "redd/client/authenticated/wiki"
|
18
|
+
|
19
|
+
include Redd::Client::Authenticated::Account
|
20
|
+
include Redd::Client::Authenticated::Apps
|
21
|
+
include Redd::Client::Authenticated::Flair
|
22
|
+
include Redd::Client::Authenticated::Gold
|
23
|
+
include Redd::Client::Authenticated::LinksComments
|
24
|
+
include Redd::Client::Authenticated::Live
|
25
|
+
include Redd::Client::Authenticated::Moderation
|
26
|
+
include Redd::Client::Authenticated::Multis
|
27
|
+
include Redd::Client::Authenticated::PrivateMessages
|
28
|
+
include Redd::Client::Authenticated::Subreddits
|
29
|
+
include Redd::Client::Authenticated::Users
|
30
|
+
include Redd::Client::Authenticated::Wiki
|
31
|
+
|
32
|
+
# @!attribute [r] username
|
33
|
+
# @return [String] The username of the logged-in user.
|
34
|
+
attr_reader :username
|
35
|
+
|
36
|
+
# @!attribute [r] cookie
|
37
|
+
# @return [String] The cookie used to store the current session.
|
38
|
+
attr_reader :cookie
|
39
|
+
|
40
|
+
# @!attribute [r] modhash
|
41
|
+
# @return [String] The returned modhash used when making requests.
|
42
|
+
attr_reader :modhash
|
43
|
+
|
44
|
+
# @!attribute [rw] auth_endpoint
|
45
|
+
# @return [String] The site to connect to authenticate with.
|
46
|
+
attr_accessor :auth_endpoint
|
47
|
+
|
48
|
+
# Set up an authenticated connection to reddit.
|
49
|
+
#
|
50
|
+
# @param [String] cookie The cookie to use when sending a request.
|
51
|
+
# @param [String] modhash The modhash to use when sending a request.
|
52
|
+
# @param [Hash] options A hash of options to connect using.
|
53
|
+
# @option options [String] :user_agent The User-Agent string to use in the
|
54
|
+
# header of every request.
|
55
|
+
# @option options [String] :api_endpoint The main domain to connect to, in
|
56
|
+
# this case, the URL for reddit.
|
57
|
+
# @option options [String] :auth_endpoint The domain to login with, in
|
58
|
+
# this case, the ssl subdomain using https.
|
59
|
+
def initialize(cookie, modhash, options = {})
|
60
|
+
@cookie = cookie
|
61
|
+
@modhash = modhash
|
62
|
+
|
63
|
+
@rate_limit = options[:rate_limit] || Redd::RateLimit.new
|
64
|
+
@user_agent = options[:user_agent] || "Redd/Ruby, v#{Redd::VERSION}"
|
65
|
+
@api_endpoint = options[:api_endpoint] || "http://www.reddit.com/"
|
66
|
+
@auth_endpoint = options[:auth_endpoint] || "https://ssl.reddit.com/"
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Gets the Faraday connection or creates one if it doesn't exist yet.
|
72
|
+
#
|
73
|
+
# @return [Faraday] A new Faraday connection.
|
74
|
+
def connection
|
75
|
+
@connection ||= Faraday.new(url: api_endpoint) do |faraday|
|
76
|
+
faraday.use Faraday::Request::UrlEncoded
|
77
|
+
faraday.use Redd::Response::ParseJson
|
78
|
+
faraday.use Redd::Response::RaiseError
|
79
|
+
faraday.adapter Faraday.default_adapter
|
80
|
+
|
81
|
+
faraday.headers["User-Agent"] = user_agent
|
82
|
+
faraday.headers["Cookie"] = "reddit_session=#{cookie}"
|
83
|
+
faraday.headers["X-Modhash"] = modhash
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Redd
|
2
|
+
module Client
|
3
|
+
class Authenticated
|
4
|
+
module PrivateMessages
|
5
|
+
def block_message(message)
|
6
|
+
fullname = extract_fullname(message)
|
7
|
+
send(:post, "/api/block", id: fullname)
|
8
|
+
end
|
9
|
+
|
10
|
+
def compose_message(to, subject, text, captcha = nil, identifier = nil)
|
11
|
+
meth = :post
|
12
|
+
path = "/api/compose"
|
13
|
+
params = {
|
14
|
+
api_type: "json", to: to.to_s, subject: subject, text: text
|
15
|
+
}
|
16
|
+
params << {captcha: captcha, iden: identifier} if captcha
|
17
|
+
|
18
|
+
send(meth, path, params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def mark_as_read(message)
|
22
|
+
fullname = extract_fullname(message)
|
23
|
+
send(:post, "/api/read_message", id: fullname)
|
24
|
+
end
|
25
|
+
|
26
|
+
def mark_as_unread(message)
|
27
|
+
fullname = extract_fullname(message)
|
28
|
+
send(:post, "/api/unread_message", id: fullname)
|
29
|
+
end
|
30
|
+
|
31
|
+
def messages(category = "inbox", params = {})
|
32
|
+
meth = :get
|
33
|
+
path = "/message/#{category}.json"
|
34
|
+
|
35
|
+
object_from_response(meth, path, params)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|