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

Parameters:

  • attrs (Hash) (defaults to: {})

    Addition client attributes.



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

Returns:



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

Parameters:

  • url (String)

    A url that will be captured.

  • options (Hash) (defaults to: {})

    Additional options to the capture request.

Returns:



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.

Parameters:

  • url (String)

    A url that will be captured.

  • options (Hash) (defaults to: {})

    Additional options to the capture request.

Returns:



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

Parameters:

  • order_id (String)

    The id of a previously submitted order.

Returns:



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.

Parameters:

  • job_id (String)

    The id of a previously submitted capture job.

Returns:

  • (Capgun::Job)

    The capture request is a job that encapsulates status.



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