Class: Capgun::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Request
Defined in:
lib/capgun/client.rb

Overview

Wrapper for the Capgun REST API

Instance Method Summary collapse

Methods included from Request

#get, #post

Constructor Details

#initialize(attrs = {}) ⇒ Capgun::Client

Initializes a new API object. Accessor attributes are set based on Capgun::Config::VALID_OPTIONS_KEYS



28
29
30
31
32
33
# File 'lib/capgun/client.rb', line 28

def initialize(attrs={})
  attrs = Capgun.options.merge(attrs)
  Config::VALID_OPTIONS_KEYS.each do |key|
    instance_variable_set("@#{key}".to_sym, attrs[key])
  end
end

Instance Method Details

#accountCapgun::Account

Fetch account information



78
79
80
81
# File 'lib/capgun/client.rb', line 78

def 
   = get("/v1/account.json")
  Capgun::.new(['account'])
end

#capture(url, options = {}, &block) ⇒ Capgun::Order

Creates a capgun job



51
52
53
54
55
# File 'lib/capgun/client.rb', line 51

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

#estimate(url, options = {}, &block) ⇒ Capgun::Estimate

Estimates a capgun job cost / availability.



40
41
42
43
44
# File 'lib/capgun/client.rb', line 40

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

#order(order_id) ⇒ Capgun::Order

Query the order



61
62
63
64
# File 'lib/capgun/client.rb', line 61

def order(order_id)
  order = get("/v1/orders/#{order_id}.json")
  Capgun::Order.new(order['order'])
end

#status(job_id) ⇒ Capgun::Job

Query the status of a capture job.



70
71
72
73
# File 'lib/capgun/client.rb', line 70

def status(job_id)
  job = get("/v1/jobs/#{job_id}.json")
  Capgun::Job.new(job['job'])
end