Guest User

2ch.net API example client (Ruby)

a guest
Feb 20th, 2015
1,184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.19 KB | None | 0 0
  1. require 'net/https'
  2. require 'kconv'
  3. require 'openssl'
  4.  
  5. APPKEY='xxfvFQcOzpTBvwuwPMwwzLZxiCSaGb'
  6. HMKEY='DgQ3aNpoluV1cl3GFJAqitBg5xKiXZ'
  7.  
  8. def authenticate()
  9.     http = Net::HTTP.new('api.2ch.net', 443)
  10.     http.use_ssl = true
  11.     http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  12.     path = '/v1/auth/'
  13.     data ={:ID=>'', :PW=>'', :KY=>APPKEY, :CT=>'',:HB=>''}
  14.     headers = {
  15.         'User-Agent' => '',
  16.         'X-2ch-UA' => 'JaneStyle/3.80'
  17.     }
  18.     res=http.post(path, URI.encode_www_form(data), headers)
  19.     sid=res.body.split(':')[1]
  20.     return sid
  21. end
  22.  
  23. def getDAT(serverName,boardName,threadId,sid)
  24.     http = Net::HTTP.new('api.2ch.net', 443)
  25.     http.use_ssl = true
  26.     http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  27.     path="/v1/#{serverName}/#{boardName}/#{threadId}"
  28.     message = "#{path}#{sid}#{APPKEY}"
  29.     hobo=OpenSSL::HMAC::hexdigest(OpenSSL::Digest::SHA256.new, HMKEY, message)
  30.     data="sid=#{sid}&hobo=#{hobo}&appkey=#{APPKEY}"
  31.     headers = {
  32.         'User-Agent' =>'Mozilla/3.0 (compatible; JaneStyle/3.80..)'
  33.     }
  34.     res=http.post(path, data, headers)
  35.     return res.body.toutf8
  36. end
  37.  
  38. sid=authenticate()
  39. dat=getDAT('anago','software','1424327586',sid)
  40. p dat
Advertisement
Add Comment
Please, Sign In to add comment