Giter VIP home page Giter VIP logo

redditkit.rb's Issues

no implicit conversion of Symbol into Integer (TypeError)

Hi!

Following the example in your documentation I got the following error

/Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:71:in '[]': no implicit conversion of Symbol into Integer (TypeError) from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:71:in 'object_kind_from_response' from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:41:in 'object_class_from_response' from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:78:in 'object_from_response' from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/users.rb:17:in 'user' from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/account.rb:22:in 'sign_in' from /Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit.rb:23:in 'method_missing' from scripts/api_calls.rb:109:in '<main>'

My source code is as follows:

require 'redditkit' RedditKit.sign_in 'myusername', 'mypassword' subreddits = RedditKit.subscribed_subreddits

I have verified that my credentials are correct so I am not quite sure why this is happening.

Support for reddit forced SSL accounts

When a reddit user enables forced SSL, it seems to break the API. I've tested it using the save and unsave methods on a post. It returns a 307 redirect, and the method fails. I'm not sure what's involved to get this working. For now the fix is to disable forced SSL for the account.

#<struct Faraday::Env
 method=:post,
 body=
  "<html>\n <head>\n  <title>307 Temporary Redirect</title>\n </head>\n <body>\n  <h1>307 Temporary Redirect</h1>\n  The resource has been moved to <a href=\"https://reddit.com/modify_hsts_grant?dest=https%3A%2F%2Fwww.reddit.com%2Fapi%2Funsave\">https://reddit.com/modify_hsts_grant?dest=https%3A%2F%2Fwww.reddit.com%2Fapi%2Funsave</a>;\nyou should be redirected automatically.\n\n\n </body>\n</html>",
 url=#<URI::HTTP:0x007faa52847bb0 URL:http://www.reddit.com/api/unsave>,
 request=
  #<struct Faraday::RequestOptions
   params_encoder=nil,
   proxy=nil,
   bind=nil,
   timeout=nil,
   open_timeout=nil,
   boundary=nil,
   oauth=nil>,
 request_headers=
  {"User-Agent"=>"Faraday v0.9.0",
   "Cookie"=>
    "reddit_session=XXXXXXXXXXXXX",
   "X-Modhash"=>"XXXXXXXXXXXXX",
   "Content-Type"=>"application/x-www-form-urlencoded"},
 ssl=
  #<struct Faraday::SSLOptions
   verify=nil,
   ca_file=nil,
   ca_path=nil,
   verify_mode=nil,
   cert_store=nil,
   client_cert=nil,
   client_key=nil,
   certificate=nil,
   private_key=nil,
   verify_depth=nil,
   version=nil>,
 parallel_manager=nil,
 params=nil,
 response=nil,
 response_headers=
  {"date"=>"Tue, 28 Oct 2014 00:43:20 GMT",
   "content-type"=>"text/html; charset=UTF-8",
   "transfer-encoding"=>"chunked",
   "connection"=>"close",
   "set-cookie"=>
    "XXXXXXXXXXXXX; path=/; domain=.reddit.com; HttpOnly",
   "pragma"=>"no-cache",
   "cache-control"=>"no-cache, no-cache",
   "location"=>
    "https://reddit.com/modify_hsts_grant?dest=https%3A%2F%2Fwww.reddit.com%2Fapi%2Funsave",
   "x-ua-compatible"=>"IE=edge",
   "x-moose"=>"majestic",
   "server"=>"cloudflare-nginx",
   "cf-ray"=>"XXXXXXXXXXXXX"},
 status=307>

Options hash being modified unexpectedly

I found it unexpected that optional parameter hashes are being modified, and keys are deleted. The specific example that was tripping me up was in Links::links.
I noticed that the first set of results that were returned were from the correct ':category', and the rest were from the default.

p q_opts = {:limit=>100,:category=>:new}
#> {:limit=>100, :category=>:new}
client.links(subreddit,q_opts)
p q_opts
#>{:limit=>100}

I worked around it by cloning the hash each time I use it.

Comment.replies? returns NoMethodError: undefined method `empty?' for nil:NilClass

Hi there,
While trying to iterate through all the comments in a thread, I'm getting the error NoMethodError: undefined methodempty?' for nil:NilClass`.

Example (using rails console):

irb(main):024:0> c = RedditKit.comments "2g240u"   
# the whole json...
irb(main):025:0> c.replies?  
=> true                                          
irb(main):026:0> c.replies[0].replies?
=> true 
irb(main):027:0> c.replies[0].replies[0].replies? 
=> true
# keep going until you reach the last comment that doesn't have child comments
irb(main):028:0>  c.replies[0].replies[0].replies[0].replies[0].replies[0].replies[0].replies?
NoMethodError: undefined method `empty?' for nil:NilClass                                        

I would expect the last command to return false instead of an exception. The line that throws the error is this one btw redditkit (1.0.1) lib/redditkit/comment.rb:40:inreplies'`.

client login yields error

I tried:

@client = RedditKit::Client.new 'MyAccount', 'xyz'

and I get this. Using ruby 2.3.0. Ideas?

/Users/cpg/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:71:in `[]': no implicit conversion of Symbol into Integer (TypeError)
    from /Users/cpg/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:71:in `object_kind_from_response'
    from /Users/cpg/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:41:in `object_class_from_response'
    from /Users/cpg/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:78:in `object_from_response'
    from /Users/cpg/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/users.rb:17:in `user'
    from /Users/cpg/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/account.rb:22:in `sign_in'
    from /Users/cpg/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client.rb:61:in `initialize'
 ....

Permalink contains extra /

It looks like an extra forward slash has found it's way back into the permalink method. I had a look in the code, but it isn't obvious where it's happening. I don't believe that it was caused by either of the newest commits for permalink.

require 'redditkit'
reddit = RedditKit::Client.new "username", "password"
post = reddit.my_content(category: :saved).first
post.permalink
=> "http://reddit.com//r/technology/comments/2k8dqo/new_evidence_of_the_nsa_deliberately_weakening/"

Note: Using version 1.0.1

no implicit conversion of Symbol into Integer (TypeError)

Seems to be different from the other similar bug

/Users/petermckinney/.rvm/gems/ruby-2.2.2/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:71:in []': no implicit conversion of Symbol into Integer (TypeError)
from /Users/petermckinney/.rvm/gems/ruby-2.2.2/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:71:in object_kind_from_response' from /Users/petermckinney/.rvm/gems/ruby-2.2.2/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:41:in object_class_from_response'
from /Users/petermckinney/.rvm/gems/ruby-2.2.2/gems/redditkit-1.0.2/lib/redditkit/client/utilities.rb:78:in object_from_response' from /Users/petermckinney/.rvm/gems/ruby-2.2.2/gems/redditkit-1.0.2/lib/redditkit/client/users.rb:17:in user'
from /Users/petermckinney/.rvm/gems/ruby-2.2.2/gems/redditkit-1.0.2/lib/redditkit/client/account.rb:22:in sign_in' from /Users/petermckinney/.rvm/gems/ruby-2.2.2/gems/redditkit-1.0.2/lib/redditkit/client.rb:61:in initialize'
from /Users/petermckinney/workspace/sawit/reddit_helper.rb:11:in new' from /Users/petermckinney/workspace/sawit/reddit_helper.rb:11:in initialize'
from sawit.rb:3:in new' from sawit.rb:3:in

'
`

ruby 2.2.2

new lines when submitting text

I have a string that I am trying to post to reddit.
I can't figure out how to get it to create new lines in the post.
I tried adding '/n', tried adding 2 spaces, also tried 2 spaces followed by a '/n'.

RedditKit::RequestError

Generated a brand new app (fresh install) and Im trying to use this gem.

Ive tried both ways of authenticating (modules and instances) and Im getting this error with both:

RedditKit::RequestError

Is there any known fix for this or am I missing something?

upvote_ratio

Am I missing something from the doc or is there no way to see the upvote_ratio currently?

Client.comments() returns array with nil objects?

When iterating through comments to get all the replies in a tree, I often run into a problem where a nil object is returned as part of the initial comments array, and I'm fairly certain the top level list of comments isn't complete. It happens more frequently on links with > 200 comments.

Example code, in case I'm just missing something basic:

def iterate_through_replies( comment )
  replies = comment.replies
  if !replies.empty?
    replies.each do |r|
      iterate_through_replies( r )
    end
  end
end

link = RedditKit.link( some_full_name )
comments = RedditKit.comments( link.id )
comments.each do |c|
  iterate_through_replies( c ) 
end

At some point this error gets returned:
in 'iterate_through_replies': undefined method 'replies' for nil:NilClass (NoMethodError)

Is a comment getting parsed weirdly? Maybe this is related to this PRAW issue?

rate limiting?

I was looking into pythons praw client and rubys snoo client. Both take some stance on rate limiting. I think the docs for this gem could be improved if it was clearer.

Know if it rate limits automatically gives me a better idea of where this gem is on the features vs lightweight spectrum.

Can I use this gem to fetch a users latest comment?

My use case is quite simple, I just need to fetch the latest comments given a user.

For example:

user = RedditKit.user 'foobar'
user.comments.each do |comment|
  puts #{comment.body} - #{comment.post_date}
end

Is this possible at the moment, I couldn't seem to find anything related to Comments in the source code.

comment on a post

I am trying to figure out how to post a comment to a reddit post I just made.
So far I have tried saving the object that is returned when I do a submit and doing:
RedditKit.submit_comment(submit_object, "test") -- which errors with permission denied
I have tried making a link that I could put in the submit_comment but that just keeps returning nil even though within the same session I was able to make the post originally.
test_link = RedditKit.link("http://www.reddit.com/r/redditbotplaygroundsw/comments/2poh23/test_title/")
Not sure what else to try. The ruby doc says that it will return nil if I am not currently signed in but I am:

2.1.2 :021 > RedditKit.sign_in 'OMIT', "OMIT"
=> "OMIT"
2.1.2 :022 > test_link = RedditKit.link("http://www.reddit.com/r/redditbotplaygroundsw/comments/2poh23/test_title/")
=> nil

This is a private reddit I have for getting my bot working. I am the moderator and I can without issue make posts. I just can't comment.

Lots of undefined errors when trying to access attributes.

I'm fetching the comments for a user:

  comments.each do |comment|
    if comment.subreddit == 'Foobar'
      post = Post.new(
          author: comment.author,
          body: comment.body_html,
          permalink: comment.name,
          post_date: comment.created
      )
      post.save!
    end
  end

And I'm getting undefined method for 'name' errors. And not only for name, also for ups and downs.

Using the RubyMine debugger I can see these properties values, yet I can't access them in code or in the Watches window. Is this a known bug?

Error (RedditKit::RequestError)

Trying to make a redditbot. Didn't even get to do anything fun.

Here's my code:


require "redditkit"

RedditKit.sign_in "FluffyRibbot", "#{redacted}"

Here are some things you might want to know.

PS C:\Users\TOSHIBA\Desktop\Challenges\daily_programmer\hard> ruby challenge7.rb
C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client.rb:115:in `rescue in request': RedditKit::Request
Error (RedditKit::RequestError)
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client.rb:108:in `request'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client.rb:96:in `https_post'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit/client/account.rb:13:in `sign_in'
        from C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/redditkit-1.0.2/lib/redditkit.rb:23:in `method_missing'
        from challenge7.rb:3:in `<main>'
PS C:\Users\TOSHIBA\Desktop\Challenges\daily_programmer\hard> ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]

Can't request the "SEEN IT" section with #search + link.

So, if you put a link into the reddit's search box, then it will show you where has that link already been submitted. It will redirect to /submit?url=your_url. Now, RedditKit doesn't do redirects.

With this code, it does:

module RedditKit
  class Client
    def middleware
      @middleware ||= Faraday::Builder.new do |builder|
        builder.use Faraday::Request::UrlEncoded
        builder.use RedditKit::Response::RaiseError
        builder.use RedditKit::Response::ParseJSON
        # *These two lines below allow the redirects to happen.*
        builder.use FaradayMiddleware::FollowRedirects
        builder.adapter :net_http
      end
    end
  end
end

And without the redirects, client.search('http://www.youtube.com/watch?v=XAAgXaMCdfI') just returned nil. Now, it returns nil only when it hasn't been submitted, a listing otherwise.

Using with Rails, tried to store RedditKit::Client in a session. "no _dump_data is defined for class Proc"

I am using RedditKit to make a Reddit app with limited capabilities, with rails. I am trying to figure out how to properly persist users session after logging in. My first idea was session[:client] = RedditKit::Client.new params[:username], params[:password], and I get no _dump_data is defined for class Proc error when I try to sign in.

I take it that RedditKit::Client cannot be marshalled? I have further suspicion that I shouldn't be storing the client in a session in the first place. Is there a recommended way?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.