lib/hackpad/client.rb in hackpad-cli-0.0.2 vs lib/hackpad/client.rb in hackpad-cli-0.0.3

- old
+ new

@@ -6,29 +6,28 @@ require_relative 'config' module Hackpad class Client - def initialize(configdir) - @configdir = configdir - @config = Config.load configdir + def initialize(options) + @config = Config.load options site = URI.parse @config['site'] consumer = OAuth::Consumer.new( @config['client_id'], @config['secret'], site: @config['site'] ) @token = OAuth::AccessToken.new consumer end # GET /api/1.0/pads/all - def list + def listall res = @token.get "/api/1.0/pads/all" if res.is_a? Net::HTTPSuccess all = JSON.parse res.body all.each do |a| - puts getinfo(a) + getinfo(a) end else puts "#{res.inspect}".colorize :red puts "#{res.body}".colorize :red return back @@ -36,10 +35,10 @@ end def getinfo(pad) res = @token.get "/api/1.0/pad/#{pad}/content.txt" if res.is_a? Net::HTTPSuccess - puts "#{@config['site']}/#{pad} - #{res.body.lines.first.chomp}" + puts "#{@config['site']}/#{pad} - #{pad} - #{res.body.lines.first.chomp}" else puts "#{pad} failed".colorize :red end end