Skip to content

Commit

Permalink
Fixed broken core method
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahzs committed Dec 12, 2017
1 parent 690373a commit 27ff9ce
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/se/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ module API
class Client
API_VERSION = 2.2

attr_reader :quota
attr_reader :quota, :quota_used
attr_accessor :params

def initialize(key, **params)
@key = key
@params = params
@quota = nil
@quota_used = 0
end

def posts(ids = "", **params)
Expand All @@ -28,12 +29,14 @@ def posts(ids = "", **params)

private

def json(uri, site: nil, **params)
throw "No site specified" if site.nil?
def json(uri, **params)
throw "No site specified" if params[:site].nil?
params = @params.merge(params).merge({key: @key}).map { |k,v| "#{k}=#{v}" }.join('&')
puts "Posting to https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params}"
resp_raw = Net::HTTP.get_response(URI("https://api.stackexchange.com/#{API_VERSION}/#{uri}?#{params}")).body
resp = JSON.parse(resp_raw)
@quota = resp["quota_remaining"]
@quota_used += 1
resp["items"]
end
end
Expand Down

0 comments on commit 27ff9ce

Please sign in to comment.