English 中文(简体)
我能用HTT党 归还一份子编辑名单吗?
原标题:Can I return a listing of subreddits using HTTParty?

我的问题是请求信头

这是我编造的小剧本 不起作用:

require  httparty 
require  highline/import 

#Login.new.post lets us log in. Everything works up to the subreddits method.

class Login
  include HTTParty
  base_uri  www.reddit.com 
#So far, so good.

  def post(username, password)
    options = {:body => {:user => username, :passwd => password, :api_type =>  json }}
    self.class.post("/api/login/#{username}", options)
  end

#I think this part is right, in and of itself. The problem is in how the headers
#are composed (which is why I keep bonking my head on the wall.)
  def subreddits(headers)
    self.class.get("/reddits/mine", headers)
  end

  def cli_user_login(user, password)
    a = Login.new.post(user, password);
    puts a;
    #We logged in and got some JSON with an empty errors array and, nestled deep, a cookie.
    reddit_session = a["json"]["data"]["cookie"]
    #Just putting the cookie in a variable. Print it to make sure it s there:
    puts reddit_session
    #reddit_session displays, no problem. We HAVE the cookie.
  b = Login.new.subreddits("headers" => {"reddit_session" => reddit_session})
  puts b
  #Then suddenly it spits out a mountain of html....... but not the subreddits! :(
  end

end


##The following is just for testing, because I m whimsical or stupid or something
class IWouldLikeToPlayAGame
  def initialize
    puts "PLEASE ETNER YOUR REDDIT CRITERIALS"
    a = gets.chomp.strip
    b = ask("PLEASE BE ENTERING YOUR RREDDIT password"){ |q| q.echo = false }

    Login.new.cli_user_login(a, b)
  end
end

IWouldLikeToPlayAGame.new

我想我的错误是在30线周围 我的页眉胡须看起来是这样的:

{"headers" => {"reddit_session" => cookie}}

GET reddit.com/reddits/mine.xml 与该信头和我应该 有子编辑列表,对吗?

最佳回答

首先,您需要为您想要获取的数据指定格式扩展名, xml json :

/reddits/mine.extension

第二,您需要在 cookie hash 中发送 reddit_session , 而不是信头 :

:cookies => { reddit_session  => reddit_session}

红宝石分号是可选的,最好省略。

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签