Class: Capture

Inherits:
Object
  • Object
show all
Defined in:
lib/capture.rb

Constant Summary collapse

API_URL =
"https://cdn.capture.page"
EDGE_URL =
"https://edge.capture.page"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, options = {}) ⇒ Capture

Returns a new instance of Capture.

Raises:

  • (TypeError)


25
26
27
28
29
30
31
# File 'lib/capture.rb', line 25

def initialize(key, secret, options = {})
  @key = key
  @secret = secret
  options = options.nil? ? {} : options
  raise TypeError, "options must be a Hash" unless options.is_a?(Hash)
  @options = options
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



23
24
25
# File 'lib/capture.rb', line 23

def key
  @key
end

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/capture.rb', line 23

def options
  @options
end

Instance Method Details

#build_animated_url(url, options = {}) ⇒ Object



49
50
51
# File 'lib/capture.rb', line 49

def build_animated_url(url, options = {})
  build_url(url, "animated", options)
end

#build_content_url(url, options = {}) ⇒ Object



41
42
43
# File 'lib/capture.rb', line 41

def build_content_url(url, options = {})
  build_url(url, "content", options)
end

#build_image_url(url, options = {}) ⇒ Object



33
34
35
# File 'lib/capture.rb', line 33

def build_image_url(url, options = {})
  build_url(url, "image", options)
end

#build_metadata_url(url, options = {}) ⇒ Object



45
46
47
# File 'lib/capture.rb', line 45

def (url, options = {})
  build_url(url, "metadata", options)
end

#build_pdf_url(url, options = {}) ⇒ Object



37
38
39
# File 'lib/capture.rb', line 37

def build_pdf_url(url, options = {})
  build_url(url, "pdf", options)
end

#close_session(session_id) ⇒ Object



84
85
86
# File 'lib/capture.rb', line 84

def close_session(session_id)
  sessions_request("/#{escape_path(session_id)}", :delete)
end

#create_session(options = {}) ⇒ Object

Raises:

  • (TypeError)


73
74
75
76
77
78
# File 'lib/capture.rb', line 73

def create_session(options = {})
  options = options.nil? ? {} : options
  raise TypeError, "options must be a Hash" unless options.is_a?(Hash)

  sessions_request("", :post, options)
end

#execute_action(session_id, action_type, payload = {}) ⇒ Object

Raises:

  • (TypeError)


88
89
90
91
92
93
# File 'lib/capture.rb', line 88

def execute_action(session_id, action_type, payload = {})
  payload = payload.nil? ? {} : payload
  raise TypeError, "payload must be a Hash" unless payload.is_a?(Hash)

  sessions_request("/#{escape_path(session_id)}/actions", :post, "type" => action_type, "payload" => payload)
end

#fetch_animated(url, options = {}) ⇒ Object



69
70
71
# File 'lib/capture.rb', line 69

def fetch_animated(url, options = {})
  fetch_binary(build_animated_url(url, options))
end

#fetch_content(url, options = {}) ⇒ Object



61
62
63
# File 'lib/capture.rb', line 61

def fetch_content(url, options = {})
  fetch_json(build_content_url(url, options))
end

#fetch_image(url, options = {}) ⇒ Object



53
54
55
# File 'lib/capture.rb', line 53

def fetch_image(url, options = {})
  fetch_binary(build_image_url(url, options))
end

#fetch_metadata(url, options = {}) ⇒ Object



65
66
67
# File 'lib/capture.rb', line 65

def (url, options = {})
  fetch_json((url, options))
end

#fetch_pdf(url, options = {}) ⇒ Object



57
58
59
# File 'lib/capture.rb', line 57

def fetch_pdf(url, options = {})
  fetch_binary(build_pdf_url(url, options))
end

#get_session(session_id) ⇒ Object



80
81
82
# File 'lib/capture.rb', line 80

def get_session(session_id)
  sessions_request("/#{escape_path(session_id)}", :get)
end