class SpadeIO::Client
Attributes
conn[RW]
Public Class Methods
new(opts)
click to toggle source
# File lib/spadeio/client.rb, line 8 def initialize(opts) if !opts[:key] raise build_helpful_error(:key) end @opts = opts @conn = Faraday.new(:url => SpadeIO::API::STABLE) do |faraday| faraday.response :json faraday.adapter Faraday.default_adapter faraday.basic_auth(opts[:key],'') end end
Public Instance Methods
scrape(uri, bucket=nil)
click to toggle source
# File lib/spadeio/client.rb, line 21 def scrape(uri, bucket=nil) res = scrape_all(uri, bucket) body = res ? res.body : nil unless bucket if body && body.count > 0 && body.first['objects'] body = body.first['objects'] else body = nil end end body end
scrape_all(uri, bucket)
click to toggle source
# File lib/spadeio/client.rb, line 36 def scrape_all(uri, bucket) res = @conn.get("scrape", { :url => uri }) if res.status != 200 code_class = res.status - (res.status % 100) raise build_helpful_error(code_class, (res.body || "").to_s[0..50]) end res end
Private Instance Methods
build_helpful_error(key, snipt="")
click to toggle source
# File lib/spadeio/client.rb, line 50 def build_helpful_error(key, snipt="") res = <<EOF Error: #{ SpadeIO::API::WHAT_HAPPENED[key]} ------ #{ if snipt != "" "\n<<------ response ------>>\n" + snipt + \ "\n<<----------------------->>\n" end } Try one of these fix it: ------------------------ #{ bullets( SpadeIO::API::FIX_WITH[key]) } Find out more here: ------------------- #{ bullets( SpadeIO::API::FIND_OUT_MORE[key]) } EOF end
bullets(arr)
click to toggle source
# File lib/spadeio/client.rb, line 74 def bullets(arr) arr.map{|s| "* #{s}"}.join("\n") end