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



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

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



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

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

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

Creates a capgun job



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

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.



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

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



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

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.



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

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