Class: SpadeIO::Client
- Inherits:
-
Object
- Object
- SpadeIO::Client
- Defined in:
- lib/spadeio/client.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Client
constructor
A new instance of Client.
- #scrape(uri, bucket = nil) ⇒ Object
- #scrape_all(uri, bucket) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
6 7 8 |
# File 'lib/spadeio/client.rb', line 6 def conn @conn end |
Instance Method Details
#scrape(uri, bucket = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# 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 |