lib/capgun/client.rb in capgun-0.0.3 vs lib/capgun/client.rb in capgun-0.1.0
- old
+ new
@@ -1,7 +1,8 @@
require 'json'
require 'json/pure'
+require 'ostruct'
require 'capgun/base'
require 'capgun/account'
require 'capgun/estimate'
require 'capgun/job'
require 'capgun/order'
@@ -34,21 +35,23 @@
# Estimates a capgun job cost / availability.
#
# @param [String] url A url that will be captured.
# @param [Hash] options Additional options to the capture request.
# @return [Capgun::Estimate] The estimate for the capture request.
- def estimate(url, options = {})
+ def estimate(url, options = {}, &block)
+ options = with_options(options, &block)
estimate = post("/v1/orders/estimate.json", options.merge(:url => url))
Capgun::Estimate.new(estimate['order'])
end
# Creates a capgun job
#
# @param [String] url A url that will be captured.
# @param [Hash] options Additional options to the capture request.
# @return [Capgun::Order] The capture request order.
- def capture(url, options = {})
+ def capture(url, options = {}, &block)
+ options = with_options(options, &block)
order = post("/v1/orders.json", options.merge(:url => url))
Capgun::Order.new(order['order'])
end
# Query the order
@@ -73,9 +76,20 @@
#
# @return [Capgun::Account] The account
def account
account = get("/v1/account.json")
Capgun::Account.new(account['account'])
+ end
+
+ private
+
+ def with_options(options, &block)
+ if block_given?
+ options = OpenStruct.new(options)
+ yield(options)
+ options = options.marshal_dump
+ end
+ options
end
end
end